Skip to content

Commit

Permalink
Merge pull request #126 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.5.1
  • Loading branch information
danil-lashin authored Oct 22, 2018
2 parents 6314589 + 2c53de1 commit c88e704
Show file tree
Hide file tree
Showing 124 changed files with 180 additions and 22,218 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.5.1
*Oct 22th, 2018*

BUG FIXES

- [core] Fixed bug with unexpected node backoff

## 0.5.0
*Oct 15th, 2018*

Expand Down
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ check: check_tools ensure_deps
### Build

build:
CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/minter ./cmd/minter/
CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/minter ./cmd/minter/

install:
CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' ./cmd/minter
CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' ./cmd/minter


########################################
Expand Down Expand Up @@ -106,4 +106,4 @@ build-linux:
GOOS=linux GOARCH=amd64 $(MAKE) build

build-compress:
upx --brute -9 build/minter
upx build/minter
9 changes: 4 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package api
import (
"github.com/MinterTeam/minter-go-node/config"
"github.com/MinterTeam/minter-go-node/eventsdb"
"github.com/MinterTeam/minter-go-node/log"
"github.com/gorilla/mux"
"github.com/rs/cors"
"io"
"io/ioutil"
"log"
"net/http"

"github.com/gorilla/mux"
"github.com/rs/cors"

"github.com/MinterTeam/minter-go-node/core/minter"
"github.com/MinterTeam/minter-go-node/core/state"
"github.com/tendermint/go-amino"
Expand Down Expand Up @@ -70,7 +69,7 @@ func RunApi(b *minter.Blockchain, node *node.Node) {
// wait for tendermint to start
waitForTendermint()

log.Fatal(http.ListenAndServe(config.GetConfig().APIListenAddress, handler))
log.Error("Failed to start API", "err", http.ListenAndServe(config.GetConfig().APIListenAddress, handler))
}

func wrapper(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
Expand Down
8 changes: 7 additions & 1 deletion api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import (
"time"
)

var edb *eventsdb.EventsDB

func init() {
edb = eventsdb.NewEventsDB(eventsdb.GetCurrentDB())
}

type BlockResponse struct {
Hash common.HexBytes `json:"hash"`
Height int64 `json:"height"`
Expand Down Expand Up @@ -113,7 +119,7 @@ func Block(w http.ResponseWriter, r *http.Request) {

var eventsRaw []byte

events := eventsdb.GetCurrent().LoadEvents(height)
events := edb.LoadEvents(height)

if len(events) > 0 {
eventsRaw, err = cdc.MarshalJSON(events)
Expand Down
1 change: 0 additions & 1 deletion api/net_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
)

func NetInfo(w http.ResponseWriter, r *http.Request) {

result, err := client.NetInfo()

w.Header().Set("Content-Type", "application/json; charset=UTF-8")
Expand Down
12 changes: 9 additions & 3 deletions api/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ func SendTransaction(w http.ResponseWriter, r *http.Request) {

result, err := client.BroadcastTxCommit(types.Hex2Bytes(req.Transaction))

w.Header().Set("Content-Type", "application/json; charset=UTF-8")

if err != nil {
panic(err)
}
w.WriteHeader(http.StatusInternalServerError)

w.Header().Set("Content-Type", "application/json; charset=UTF-8")
_ = json.NewEncoder(w).Encode(Response{
Code: 500,
Log: err.Error(),
})
return
}

if result.CheckTx.Code != code.OK {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
14 changes: 12 additions & 2 deletions api/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,24 @@ func GetValidators(w http.ResponseWriter, r *http.Request) {
}

rState := GetStateForRequest(r)
vals := rState.GetStateValidators().Data()
vals := rState.GetStateValidators()

w.Header().Set("Content-Type", "application/json; charset=UTF-8")

if vals == nil {
w.WriteHeader(http.StatusNotFound)
_ = json.NewEncoder(w).Encode(Response{
Code: 404,
Log: "Validators not found",
})
return
}

w.WriteHeader(http.StatusOK)

var responseValidators []Validator

for _, val := range vals {
for _, val := range vals.Data() {
responseValidators = append(responseValidators, makeResponseValidator(val, rState))
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ import (
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy"
"os"
"runtime"
)

var cfg = config.GetConfig()

func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

err := common.EnsureDir(utils.GetMinterHome()+"/config", 0777)

if err != nil {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func DefaultConfig() *Config {
cfg.Mempool.WalPath = "tmdata/mempool.wal"
cfg.Mempool.Recheck = true
cfg.Mempool.RecheckEmpty = true
cfg.Mempool.Size = 10000

cfg.Consensus.WalPath = "tmdata/cs.wal/wal"
cfg.Consensus.TimeoutPropose = 2000
Expand Down
23 changes: 11 additions & 12 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
rpc "github.com/tendermint/tendermint/rpc/client"
"math/big"
"os"
"sync/atomic"
)

type Blockchain struct {
Expand All @@ -31,7 +32,7 @@ type Blockchain struct {
stateDeliver *state.StateDB
stateCheck *state.StateDB
rootHash [20]byte
height uint64
height int64
rewards *big.Int
validatorsStatuses map[[20]byte]int8
tendermintRPC *rpc.Local
Expand Down Expand Up @@ -113,7 +114,7 @@ func (app *Blockchain) InitChain(req abciTypes.RequestInitChain) abciTypes.Respo
}

func (app *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock {
app.height = uint64(req.Header.Height)
atomic.StoreInt64(&app.height, req.Header.Height)
app.rewards = big.NewInt(0)

// clear absent candidates
Expand All @@ -139,12 +140,12 @@ func (app *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.Res
var address [20]byte
copy(address[:], v.Validator.Address)

app.stateDeliver.PunishByzantineValidator(uint64(req.Header.Height), address)
app.stateDeliver.PunishFrozenFundsWithAddress(app.height, app.height+518400, address)
app.stateDeliver.PunishByzantineValidator(req.Header.Height, address)
app.stateDeliver.PunishFrozenFundsWithAddress(uint64(req.Header.Height), uint64(req.Header.Height+518400), address)
}

// apply frozen funds
frozenFunds := app.stateDeliver.GetStateFrozenFunds(app.height)
frozenFunds := app.stateDeliver.GetStateFrozenFunds(uint64(req.Header.Height))
if frozenFunds != nil {
for _, item := range frozenFunds.List() {
app.stateDeliver.AddBalance(item.Address, item.Coin, item.Value)
Expand Down Expand Up @@ -268,7 +269,7 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons
}
}

eventsdb.GetCurrent().FlushEvents(req.Height)
_ = eventsdb.GetCurrent().FlushEvents(req.Height)

return abciTypes.ResponseEndBlock{
ValidatorUpdates: updates,
Expand Down Expand Up @@ -322,11 +323,9 @@ func (app *Blockchain) Commit() abciTypes.ResponseCommit {

// todo: make provider
height := make([]byte, 8)
binary.BigEndian.PutUint64(height, app.height)
binary.BigEndian.PutUint64(height, uint64(app.height))
app.appDB.Set([]byte("height"), height)

// TODO: clear candidates list

app.updateCurrentRootHash()
app.updateCurrentState()

Expand All @@ -353,7 +352,7 @@ func (app *Blockchain) updateCurrentRootHash() {
// todo: make provider
result = app.appDB.Get([]byte("height"))
if result != nil {
app.height = binary.BigEndian.Uint64(result)
app.height = int64(binary.BigEndian.Uint64(result))
} else {
app.height = 0
}
Expand All @@ -371,8 +370,8 @@ func (app *Blockchain) GetStateForHeight(height int) (*state.StateDB, error) {
return state.New(int64(height), app.stateDB)
}

func (app *Blockchain) Height() uint64 {
return app.height
func (app *Blockchain) Height() int64 {
return atomic.LoadInt64(&app.height)
}

func (app *Blockchain) getCurrentValidators() abciTypes.ValidatorUpdates {
Expand Down
16 changes: 8 additions & 8 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (s *StateDB) updateStateFrozenFund(stateFrozenFund *stateFrozenFund) {
panic(fmt.Errorf("can't encode frozen fund at %d: %v", blockHeight, err))
}
height := make([]byte, 8)
binary.BigEndian.PutUint64(height, stateFrozenFund.blockHeight)
binary.BigEndian.PutUint64(height, uint64(stateFrozenFund.blockHeight))

s.iavl.Set(append(frozenFundsPrefix, height...), data)
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func (s *StateDB) deleteStateCoin(stateCoin *stateCoin) {
func (s *StateDB) deleteFrozenFunds(stateFrozenFund *stateFrozenFund) {
stateFrozenFund.deleted = true
height := make([]byte, 8)
binary.BigEndian.PutUint64(height, stateFrozenFund.blockHeight)
binary.BigEndian.PutUint64(height, uint64(stateFrozenFund.blockHeight))
key := append(frozenFundsPrefix, height...)
s.iavl.Remove(key)
}
Expand All @@ -287,7 +287,7 @@ func (s *StateDB) getStateFrozenFunds(blockHeight uint64) (stateFrozenFund *stat
}

height := make([]byte, 8)
binary.BigEndian.PutUint64(height, blockHeight)
binary.BigEndian.PutUint64(height, uint64(blockHeight))
key := append(frozenFundsPrefix, height...)

// Load the object from the database.
Expand All @@ -300,7 +300,7 @@ func (s *StateDB) getStateFrozenFunds(blockHeight uint64) (stateFrozenFund *stat
return nil
}
// Insert into the live set.
obj := newFrozenFund(s, blockHeight, data, s.MarkStateFrozenFundsDirty)
obj := newFrozenFund(s, uint64(blockHeight), data, s.MarkStateFrozenFundsDirty)
s.setStateFrozenFunds(obj)
return obj
}
Expand Down Expand Up @@ -1134,7 +1134,7 @@ func (s *StateDB) SetValidatorAbsent(height int64, address [20]byte) {
s.MarkStateValidatorsDirty()
}

func (s *StateDB) PunishByzantineValidator(currentBlock uint64, address [20]byte) {
func (s *StateDB) PunishByzantineValidator(currentBlock int64, address [20]byte) {

edb := eventsdb.GetCurrent()

Expand Down Expand Up @@ -1176,7 +1176,7 @@ func (s *StateDB) PunishByzantineValidator(currentBlock uint64, address [20]byte
ValidatorPubKey: candidate.PubKey,
})

s.GetOrNewStateFrozenFunds(currentBlock+UnbondPeriod).AddFund(stake.Owner, candidate.PubKey, stake.Coin, newValue)
s.GetOrNewStateFrozenFunds(uint64(currentBlock+UnbondPeriod)).AddFund(stake.Owner, candidate.PubKey, stake.Coin, newValue)
}

candidate.Stakes = []Stake{}
Expand Down Expand Up @@ -1322,7 +1322,7 @@ func (s *StateDB) CandidatesCount() int {
return len(candidates.data)
}

func (s *StateDB) ClearCandidates(height uint64) {
func (s *StateDB) ClearCandidates(height int64) {
maxCandidates := validators.GetCandidatesCountForBlock(height)

candidates := s.getStateCandidates()
Expand All @@ -1348,7 +1348,7 @@ func (s *StateDB) ClearCandidates(height uint64) {
s.MarkStateCandidateDirty()
}

func (s *StateDB) ClearStakes(height uint64) {
func (s *StateDB) ClearStakes(height int64) {
candidates := s.getStateCandidates()

for i := range candidates.data {
Expand Down
Loading

0 comments on commit c88e704

Please sign in to comment.