diff options
author | Wei-Ning Huang <w@byzantine-lab.io> | 2019-07-25 20:41:46 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-09-17 16:57:31 +0800 |
commit | 174f6bfcdf4e2c7fea3a071653908b477ad9a3b3 (patch) | |
tree | 7990bd656bd9cc7ef3014534ad2fee5163da3790 /consensus | |
parent | a9a85fa746c727063015d6e70881426ce8b3a3fb (diff) | |
download | go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.gz go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.bz2 go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.lz go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.xz go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.zst go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.zip |
core: add GovUtil to unify governance state related access
Add GovUtil so we could use the same logic in everywhere that requires
access to governance state, such as configuration and CRS.
Diffstat (limited to 'consensus')
-rw-r--r-- | consensus/dexcon/dexcon.go | 19 | ||||
-rw-r--r-- | consensus/dexcon/dexcon_test.go | 4 |
2 files changed, 16 insertions, 7 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go index e47a8a8e2..8ececb469 100644 --- a/consensus/dexcon/dexcon.go +++ b/consensus/dexcon/dexcon.go @@ -32,7 +32,7 @@ import ( ) type GovernanceStateFetcher interface { - GetStateForConfigAtRound(round uint64) *vm.GovernanceState + GetConfigState(round uint64) (*vm.GovernanceState, error) DKGSetNodeKeyAddresses(round uint64) (map[common.Address]struct{}, error) } @@ -114,7 +114,10 @@ func (d *Dexcon) Prepare(chain consensus.ChainReader, header *types.Header) erro func (d *Dexcon) inExtendedRound(header *types.Header, state *state.StateDB) bool { gs := vm.GovernanceState{state} - rgs := d.govStateFetcer.GetStateForConfigAtRound(header.Round) + rgs, err := d.govStateFetcer.GetConfigState(header.Round) + if err != nil { + panic(err) + } roundEnd := gs.RoundHeight(new(big.Int).SetUint64(header.Round)).Uint64() + rgs.RoundLength().Uint64() @@ -126,7 +129,10 @@ func (d *Dexcon) inExtendedRound(header *types.Header, state *state.StateDB) boo } func (d *Dexcon) calculateBlockReward(round uint64) *big.Int { - gs := d.govStateFetcer.GetStateForConfigAtRound(round) + gs, err := d.govStateFetcer.GetConfigState(round) + if err != nil { + panic(err) + } config := gs.Configuration() blocksPerRound := config.RoundLength @@ -169,7 +175,10 @@ func (d *Dexcon) Finalize(chain consensus.ChainReader, header *types.Header, sta panic(err) } - gcs := d.govStateFetcer.GetStateForConfigAtRound(header.Round - 1) + gcs, err := d.govStateFetcer.GetConfigState(header.Round - 1) + if err != nil { + panic(err) + } for addr := range addrs { offset := gcs.NodesOffsetByNodeKeyAddress(addr) @@ -182,7 +191,7 @@ func (d *Dexcon) Finalize(chain consensus.ChainReader, header *types.Header, sta prevRoundHeight := gs.RoundHeight(big.NewInt(int64(header.Round - 1))) if lastHeight.Uint64() < prevRoundHeight.Uint64() { - log.Info("Disqualify node", "round", header.Round, "nodePubKey", hex.EncodeToString(node.PublicKey)) + log.Debug("Disqualify node", "round", header.Round, "nodePubKey", hex.EncodeToString(node.PublicKey)) err = gs.Disqualify(node) if err != nil { log.Error("Failed to disqualify node", "err", err) diff --git a/consensus/dexcon/dexcon_test.go b/consensus/dexcon/dexcon_test.go index 09b7281ef..3478b911b 100644 --- a/consensus/dexcon/dexcon_test.go +++ b/consensus/dexcon/dexcon_test.go @@ -35,8 +35,8 @@ type govStateFetcher struct { statedb *state.StateDB } -func (g *govStateFetcher) GetStateForConfigAtRound(_ uint64) *vm.GovernanceState { - return &vm.GovernanceState{g.statedb} +func (g *govStateFetcher) GetConfigState(_ uint64) (*vm.GovernanceState, error) { + return &vm.GovernanceState{g.statedb}, nil } func (g *govStateFetcher) DKGSetNodeKeyAddresses(round uint64) (map[common.Address]struct{}, error) { |