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@dexon.org>2019-04-09 21:32:59 +0800
commit37257d9e7981661d3f19eae5ea5d49bcedea3698 (patch)
tree3e9f22d1fb295dc4b9dd2f48b290abdc07b2b22a /consensus
parent1b8bb239546f1703a6a0ada2211cc607b4c55b81 (diff)
downloaddexon-37257d9e7981661d3f19eae5ea5d49bcedea3698.tar
dexon-37257d9e7981661d3f19eae5ea5d49bcedea3698.tar.gz
dexon-37257d9e7981661d3f19eae5ea5d49bcedea3698.tar.bz2
dexon-37257d9e7981661d3f19eae5ea5d49bcedea3698.tar.lz
dexon-37257d9e7981661d3f19eae5ea5d49bcedea3698.tar.xz
dexon-37257d9e7981661d3f19eae5ea5d49bcedea3698.tar.zst
dexon-37257d9e7981661d3f19eae5ea5d49bcedea3698.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
}