Skip to content

Commit

Permalink
Merge pull request #95 from MinterTeam/dev
Browse files Browse the repository at this point in the history
fix shutdown issue
  • Loading branch information
danil-lashin authored Sep 8, 2018
2 parents bd08145 + f2da6d3 commit 832549f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

- [api] Add validators rewards to block api

## 0.3.1
*Sept 8th, 2018*

BUG FIXES

- [core] Fix shutdown issue

## 0.3.0
*Sept 8th, 2018*

Expand Down
2 changes: 1 addition & 1 deletion api/get_bip_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ func GetBipVolume(w http.ResponseWriter, r *http.Request) {
Log: "Not implemented",
})
return
}
}
48 changes: 41 additions & 7 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/MinterTeam/minter-go-node/helpers"
"github.com/MinterTeam/minter-go-node/log"
"github.com/MinterTeam/minter-go-node/mintdb"
"github.com/tendermint/go-amino"
abciTypes "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/node"
rpc "github.com/tendermint/tendermint/rpc/client"
Expand All @@ -30,7 +31,6 @@ type Blockchain struct {
rootHash types.Hash
height uint64
rewards *big.Int
activeValidators abciTypes.ValidatorUpdates
validatorsStatuses map[[20]byte]int8
tendermintRPC *rpc.Local

Expand All @@ -47,6 +47,7 @@ const (

var (
blockchain *Blockchain
cdc = amino.NewCodec()
)

func NewMinterBlockchain() *Blockchain {
Expand Down Expand Up @@ -104,7 +105,6 @@ func (app *Blockchain) InitChain(req abciTypes.RequestInitChain) abciTypes.Respo
app.stateDeliver.CreateCandidate(genesisState.FirstValidatorAddress, validator.PubKey.Data, 100, 1, types.GetBaseCoin(), helpers.BipToPip(big.NewInt(1000000)))
app.stateDeliver.CreateValidator(genesisState.FirstValidatorAddress, validator.PubKey.Data, 100, 1, types.GetBaseCoin(), helpers.BipToPip(big.NewInt(1000000)))
app.stateDeliver.SetCandidateOnline(validator.PubKey.Data)
app.activeValidators = append(app.activeValidators, validator)
}

return abciTypes.ResponseInitChain{}
Expand Down Expand Up @@ -237,14 +237,13 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons
// update validators in state
app.stateDeliver.SetNewValidators(newCandidates)

// update validators in app cache
defer func() {
app.activeValidators = newValidators
}()
activeValidators := app.getCurrentValidators()

app.saveCurrentValidators(newValidators)

updates = newValidators

for _, validator := range app.activeValidators {
for _, validator := range activeValidators {
persisted := false
for _, newValidator := range newValidators {
if bytes.Equal(validator.PubKey.Data, newValidator.PubKey.Data) {
Expand Down Expand Up @@ -388,6 +387,41 @@ func (app *Blockchain) Height() uint64 {
return app.height
}

func (app *Blockchain) getCurrentValidators() abciTypes.ValidatorUpdates {
appTable := mintdb.NewTable(app.db, appTableId)

result, _ := appTable.Get([]byte("validators"))

if len(result) == 0 {
return abciTypes.ValidatorUpdates{}
}

var vals abciTypes.ValidatorUpdates

err := cdc.UnmarshalBinary(result, &vals)

if err != nil {
panic(err)
}

return vals
}

func (app *Blockchain) saveCurrentValidators(vals abciTypes.ValidatorUpdates) {
data, err := cdc.MarshalBinary(vals)

if err != nil {
panic(err)
}

appTable := mintdb.NewTable(app.db, appTableId)
err = appTable.Put([]byte("validators"), data)

if err != nil {
panic(err)
}
}

func GetBlockchain() *Blockchain {
return blockchain
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.4"
services:
minter:
image: minterteam/minter:0.3.0
image: minterteam/minter:0.3.1
volumes:
- ~/.minter:/minter
ports:
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package version
const (
Maj = "0"
Min = "3"
Fix = "0"
Fix = "1"
)

var (
// Must be a string because scripts like dist.sh read this file.
Version = "0.3.0"
Version = "0.3.1"

// GitCommit is the current HEAD set using ldflags.
GitCommit string
Expand Down

0 comments on commit 832549f

Please sign in to comment.