aboutsummaryrefslogtreecommitdiffstats
path: root/consensus
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-04-01 22:03:46 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:55 +0800
commit8012e32fb72dc05cfa995d2934569b9411871395 (patch)
treee68c957e804f6375154be619bf9a6bd855736350 /consensus
parent982a812904ae3b1ccd99bc82efbd08ac70ec490b (diff)
downloadgo-tangerine-8012e32fb72dc05cfa995d2934569b9411871395.tar
go-tangerine-8012e32fb72dc05cfa995d2934569b9411871395.tar.gz
go-tangerine-8012e32fb72dc05cfa995d2934569b9411871395.tar.bz2
go-tangerine-8012e32fb72dc05cfa995d2934569b9411871395.tar.lz
go-tangerine-8012e32fb72dc05cfa995d2934569b9411871395.tar.xz
go-tangerine-8012e32fb72dc05cfa995d2934569b9411871395.tar.zst
go-tangerine-8012e32fb72dc05cfa995d2934569b9411871395.zip
dexcon: correctly fine DKGSet for not producing blocks (#325)
Diffstat (limited to 'consensus')
-rw-r--r--consensus/dexcon/dexcon.go47
-rw-r--r--consensus/dexcon/dexcon_test.go2
2 files changed, 26 insertions, 23 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go
index 4e474bfa3..c4f399c43 100644
--- a/consensus/dexcon/dexcon.go
+++ b/consensus/dexcon/dexcon.go
@@ -21,6 +21,7 @@ import (
"fmt"
"math/big"
+ dexCore "github.com/dexon-foundation/dexon-consensus/core"
"github.com/dexon-foundation/dexon/common"
"github.com/dexon-foundation/dexon/consensus"
"github.com/dexon-foundation/dexon/core/state"
@@ -32,7 +33,7 @@ import (
type GovernanceStateFetcher interface {
GetStateForConfigAtRound(round uint64) *vm.GovernanceState
- NotarySetNodeKeyAddresses(round uint64) (map[common.Address]struct{}, error)
+ DKGSetNodeKeyAddresses(round uint64) (map[common.Address]struct{}, error)
}
// Dexcon is a delegated proof-of-stake consensus engine.
@@ -159,31 +160,33 @@ func (d *Dexcon) Finalize(chain consensus.ChainReader, header *types.Header, sta
if header.Round > 0 && height.Uint64() == 0 {
gs.PushRoundHeight(header.Number)
- // Check for dead node and disqualify them.
- // A dead node node is defined as: a notary set node that did not propose
- // any block in the past round.
- addrs, err := d.govStateFetcer.NotarySetNodeKeyAddresses(header.Round - 1)
- if err != nil {
- panic(err)
- }
+ if header.Round > dexCore.DKGDelayRound {
+ // Check for dead node and disqualify them.
+ // A dead node node is defined as: a notary set node that did not propose
+ // any block in the past round.
+ addrs, err := d.govStateFetcer.DKGSetNodeKeyAddresses(header.Round - 1)
+ if err != nil {
+ panic(err)
+ }
- gcs := d.govStateFetcer.GetStateForConfigAtRound(header.Round - 1)
+ gcs := d.govStateFetcer.GetStateForConfigAtRound(header.Round - 1)
- for addr := range addrs {
- offset := gcs.NodesOffsetByNodeKeyAddress(addr)
- if offset.Cmp(big.NewInt(0)) < 0 {
- panic(fmt.Errorf("invalid notary set found, addr = %s", addr.String()))
- }
+ for addr := range addrs {
+ offset := gcs.NodesOffsetByNodeKeyAddress(addr)
+ if offset.Cmp(big.NewInt(0)) < 0 {
+ panic(fmt.Errorf("invalid notary set found, addr = %s", addr.String()))
+ }
- node := gcs.Node(offset)
- lastHeight := gs.LastProposedHeight(node.Owner)
- prevRoundHeight := gs.RoundHeight(big.NewInt(int64(header.Round - 1)))
+ node := gcs.Node(offset)
+ lastHeight := gs.LastProposedHeight(node.Owner)
+ 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))
- err = gs.Disqualify(node)
- if err != nil {
- log.Error("Failed to disqualify node", "err", err)
+ if lastHeight.Uint64() < prevRoundHeight.Uint64() {
+ log.Info("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 bfded8db8..af20fbb1e 100644
--- a/consensus/dexcon/dexcon_test.go
+++ b/consensus/dexcon/dexcon_test.go
@@ -39,7 +39,7 @@ func (g *govStateFetcher) GetStateForConfigAtRound(_ uint64) *vm.GovernanceState
return &vm.GovernanceState{g.statedb}
}
-func (g *govStateFetcher) NotarySetNodeKeyAddresses(round uint64) (map[common.Address]struct{}, error) {
+func (g *govStateFetcher) DKGSetNodeKeyAddresses(round uint64) (map[common.Address]struct{}, error) {
return make(map[common.Address]struct{}), nil
}