diff options
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/syncer')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/agreement.go | 34 | ||||
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go | 30 |
2 files changed, 29 insertions, 35 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/agreement.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/agreement.go index 13da027bd..d39c24627 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/agreement.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/agreement.go @@ -18,6 +18,7 @@ package syncer import ( + "bytes" "context" "fmt" "time" @@ -87,7 +88,7 @@ func (a *agreement) run() { } switch v := val.(type) { case *types.Block: - if v.IsFinalized() { + if v.Position.Round >= core.DKGDelayRound && v.IsFinalized() { a.processFinalizedBlock(v) } else { a.processBlock(v) @@ -106,9 +107,8 @@ func (a *agreement) processBlock(b *types.Block) { return } if rand, exist := a.agreementResults[b.Hash]; exist { - if b.Position.Round >= core.DKGDelayRound && - len(b.Finalization.Randomness) == 0 { - b.Finalization.Randomness = rand + if len(b.Randomness) == 0 { + b.Randomness = rand } a.confirm(b) } else { @@ -120,9 +120,6 @@ func (a *agreement) processBlock(b *types.Block) { } func (a *agreement) processFinalizedBlock(block *types.Block) { - if block.Position.Round < core.DKGDelayRound { - return - } // Cache those results that CRS is not ready yet. if _, exists := a.confirmedBlocks[block.Hash]; exists { a.logger.Trace("finalized block already confirmed", "block", block) @@ -141,7 +138,8 @@ func (a *agreement) processFinalizedBlock(block *types.Block) { if err := utils.VerifyBlockSignature(block); err != nil { return } - verifier, ok, err := a.tsigVerifierCache.UpdateAndGet(block.Position.Round) + verifier, ok, err := a.tsigVerifierCache.UpdateAndGet( + block.Position.Round) if err != nil { a.logger.Error("error verifying block randomness", "block", block, @@ -154,7 +152,7 @@ func (a *agreement) processFinalizedBlock(block *types.Block) { } if !verifier.VerifySignature(block.Hash, crypto.Signature{ Type: "bls", - Signature: block.Finalization.Randomness, + Signature: block.Randomness, }) { a.logger.Error("incorrect block randomness", "block", block) return @@ -203,13 +201,17 @@ func (a *agreement) processAgreementResult(r *types.AgreementResult) { a.logger.Error("incorrect agreement result randomness", "result", r) return } + } else { + // Special case for rounds before DKGDelayRound. + if bytes.Compare(r.Randomness, core.NoRand) != 0 { + a.logger.Error("incorrect agreement result randomness", "result", r) + return + } } if r.IsEmptyBlock { b := &types.Block{ - Position: r.Position, - Finalization: types.FinalizationResult{ - Randomness: r.Randomness, - }, + Position: r.Position, + Randomness: r.Randomness, } // Empty blocks should be confirmed directly, they won't be sent over // the wire. @@ -218,7 +220,7 @@ func (a *agreement) processAgreementResult(r *types.AgreementResult) { } if bs, exist := a.blocks[r.Position]; exist { if b, exist := bs[r.BlockHash]; exist { - b.Finalization.Randomness = r.Randomness + b.Randomness = r.Randomness a.confirm(b) return } @@ -271,11 +273,9 @@ func (a *agreement) processNewCRS(round uint64) { // confirm notifies consensus the confirmation of a block in BA. func (a *agreement) confirm(b *types.Block) { - if b.Position.Round >= core.DKGDelayRound && - len(b.Finalization.Randomness) == 0 { + if !b.IsFinalized() { panic(fmt.Errorf("confirm a block %s without randomness", b)) } - b.Finalization.Height = b.Position.Height + 1 if _, exist := a.confirmedBlocks[b.Hash]; !exist { delete(a.blocks, b.Position) delete(a.agreementResults, b.Hash) diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go index b692b56ef..f777e35bb 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go @@ -42,13 +42,9 @@ var ( // ErrInvalidBlockOrder is reported when SyncBlocks receives unordered // blocks. ErrInvalidBlockOrder = fmt.Errorf("invalid block order") - // ErrMismatchBlockHashSequence means the delivering sequence is not - // correct, compared to finalized blocks. - ErrMismatchBlockHashSequence = fmt.Errorf("mismatch block hash sequence") - // ErrInvalidSyncingFinalizationHeight raised when the blocks to sync is - // not following the compaction chain tip in database. - ErrInvalidSyncingFinalizationHeight = fmt.Errorf( - "invalid syncing finalization height") + // ErrInvalidSyncingHeight raised when the blocks to sync is not following + // the compaction chain tip in database. + ErrInvalidSyncingHeight = fmt.Errorf("invalid syncing height") ) // Consensus is for syncing consensus module. @@ -150,13 +146,12 @@ func (con *Consensus) assureBuffering() { ) if height == 0 { con.roundEvt, err = utils.NewRoundEvent(con.ctx, con.gov, con.logger, - 0, 0, core.ConfigRoundShift) + types.Position{}, core.ConfigRoundShift) } else { var b types.Block if b, err = con.db.GetBlock(blockHash); err == nil { con.roundEvt, err = utils.NewRoundEvent(con.ctx, con.gov, - con.logger, b.Position.Round, b.Finalization.Height, - core.ConfigRoundShift) + con.logger, b.Position, core.ConfigRoundShift) } } if err != nil { @@ -297,7 +292,7 @@ func (con *Consensus) SyncBlocks( } // Check if blocks are consecutive. for i := 1; i < len(blocks); i++ { - if blocks[i].Finalization.Height != blocks[i-1].Finalization.Height+1 { + if blocks[i].Position.Height != blocks[i-1].Position.Height+1 { err = ErrInvalidBlockOrder return } @@ -305,17 +300,16 @@ func (con *Consensus) SyncBlocks( // Make sure the first block is the next block of current compaction chain // tip in DB. _, tipHeight := con.db.GetCompactionChainTipInfo() - if blocks[0].Finalization.Height != tipHeight+1 { - con.logger.Error("Mismatched finalization height", - "now", blocks[0].Finalization.Height, + if blocks[0].Position.Height != tipHeight+1 { + con.logger.Error("Mismatched block height", + "now", blocks[0].Position.Height, "expected", tipHeight+1, ) - err = ErrInvalidSyncingFinalizationHeight + err = ErrInvalidSyncingHeight return } con.logger.Trace("SyncBlocks", "position", &blocks[0].Position, - "final height", blocks[0].Finalization.Height, "len", len(blocks), "latest", latest, ) @@ -331,10 +325,10 @@ func (con *Consensus) SyncBlocks( } } if err = con.db.PutCompactionChainTipInfo( - b.Hash, b.Finalization.Height); err != nil { + b.Hash, b.Position.Height); err != nil { return } - con.heightEvt.NotifyHeight(b.Finalization.Height) + con.heightEvt.NotifyHeight(b.Position.Height) } if latest { con.assureBuffering() |