aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-03-08 15:54:15 +0800
committerGitHub <noreply@github.com>2019-03-08 15:54:15 +0800
commitc4e3025d230dbbab64a2f286835a65d797260ec9 (patch)
tree99f4c0c207f95c9decf7b6626d9e41743719c5d7 /core
parentcb2dc00068227b9544031c085b8f17124773256c (diff)
downloaddexon-consensus-c4e3025d230dbbab64a2f286835a65d797260ec9.tar
dexon-consensus-c4e3025d230dbbab64a2f286835a65d797260ec9.tar.gz
dexon-consensus-c4e3025d230dbbab64a2f286835a65d797260ec9.tar.bz2
dexon-consensus-c4e3025d230dbbab64a2f286835a65d797260ec9.tar.lz
dexon-consensus-c4e3025d230dbbab64a2f286835a65d797260ec9.tar.xz
dexon-consensus-c4e3025d230dbbab64a2f286835a65d797260ec9.tar.zst
dexon-consensus-c4e3025d230dbbab64a2f286835a65d797260ec9.zip
syncer: avoid attacked by older AgreementResult when syncing (#471)
One possible attack for syncer is: - byzantine nodes periodically broadcast some very old types.AgreementResults. - If some syncer receive those types.AgreementResult, they might synced directly while still fall behind other nodes. A quick workaround is ignore types.AgreementResults older than the chain tip when creating the syncer.Consensus instance.
Diffstat (limited to 'core')
-rw-r--r--core/syncer/consensus.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/core/syncer/consensus.go b/core/syncer/consensus.go
index 7ba659f..3053396 100644
--- a/core/syncer/consensus.go
+++ b/core/syncer/consensus.go
@@ -85,6 +85,7 @@ type Consensus struct {
dummyCancel context.CancelFunc
dummyFinished <-chan struct{}
dummyMsgBuffer []interface{}
+ initChainTipHeight uint64
}
// NewConsensus creates an instance for Consensus (syncer consensus).
@@ -116,6 +117,7 @@ func NewConsensus(
randomnessResults: make(map[common.Hash]*types.BlockRandomnessResult),
}
con.ctx, con.ctxCancel = context.WithCancel(context.Background())
+ _, con.initChainTipHeight = db.GetCompactionChainTipInfo()
con.agreementModule = newAgreement(
con.receiveChan, con.pullChan, con.nodeSetCache, con.logger)
con.agreementWaitGroup.Add(1)
@@ -466,6 +468,12 @@ func (con *Consensus) startNetwork() {
switch v := val.(type) {
case *types.Block:
case *types.AgreementResult:
+ // Avoid byzantine nodes attack by broadcasting older
+ // agreement results. Normal nodes might report 'synced'
+ // while still fall behind other nodes.
+ if v.Position.Height <= con.initChainTipHeight {
+ continue loop
+ }
case *types.BlockRandomnessResult:
con.cacheRandomnessResult(v)
continue loop