diff options
author | Mission Liao <mission.liao@dexon.org> | 2019-04-01 12:25:09 +0800 |
---|---|---|
committer | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-01 12:25:09 +0800 |
commit | ecc5e12b1ac4826e302607769f5b831ab4c27046 (patch) | |
tree | e01fbf5d796c555f1d343e14023c282ad83bcba8 /core/syncer/agreement.go | |
parent | 46f00c345dc0993cf888523e482ae0ff385c4391 (diff) | |
download | dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.gz dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.zst dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.zip |
core: clean TODOs (#539)
* core: fix block timestamp (#529)
* Remove TODO
dMoment is still required when the block timestamp of
the genesis block is still need to be verified.
* Refine timestamp when preparing blocks
* Add timestamp checking in sanity check
* Revert code to patch position when preparing
* Remove TODOs that seems meaningless now
* Remove TODOs related to refactoring
* core: remove finalization (#531)
- Remove types.FinalizationResult, randomness
field would be moved to `types.Block` directly.
- Add a placeholder for types.Block.Randomness
field for blocks proposed from
round < DKGDelayRound. (refer to core.NoRand)
- Make the height of the genesis block starts
from 1. (refer to types.GenesisHeight)
- The fullnode's behavior of
core.Governance.GetRoundHeight is (assume
round-length is 100):
- round: 0 -> 0 (we need to workaround this)
- round: 1 -> 101
- round: 2 -> 201
- test.Governance already simulate this
behavior, and the workaround is wrapped at
utils.GetRoundHeight.
* core: fix issues (#536)
fixing code in these condition:
- assigning position without initializing them
and expected it's for genesis
- compare height with 0
Diffstat (limited to 'core/syncer/agreement.go')
-rw-r--r-- | core/syncer/agreement.go | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/core/syncer/agreement.go b/core/syncer/agreement.go index 13da027..d39c246 100644 --- a/core/syncer/agreement.go +++ b/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) |