From 0fc69ecb7a8e01cad1be63679e6b790839a10651 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Thu, 7 Mar 2019 12:58:48 +0800 Subject: vendor: sync to latest core (#231) --- .../dexon-foundation/dexon-consensus/core/blockchain.go | 14 ++++++++++++++ .../dexon-foundation/dexon-consensus/core/consensus.go | 15 ++++++++++----- .../dexon-consensus/core/utils/nodeset-cache.go | 6 ++++++ 3 files changed, 30 insertions(+), 5 deletions(-) (limited to 'vendor/github.com') diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go index 03c8561c5..30895f8ec 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go @@ -530,6 +530,17 @@ func (bc *blockChain) prepareBlock(position types.Position, return } else if empty { b.Timestamp = bc.dMoment + } else { + bc.logger.Debug("Calling genesis Application.PreparePayload") + if b.Payload, err = bc.app.PreparePayload(b.Position); err != nil { + b = nil + return + } + bc.logger.Debug("Calling genesis Application.PrepareWitness") + if b.Witness, err = bc.app.PrepareWitness(0); err != nil { + b = nil + return + } } } else { tipConfig := bc.tipConfig() @@ -553,12 +564,14 @@ func (bc *blockChain) prepareBlock(position types.Position, bc.logger.Debug("Calling Application.PreparePayload", "position", b.Position) if b.Payload, err = bc.app.PreparePayload(b.Position); err != nil { + b = nil return } bc.logger.Debug("Calling Application.PrepareWitness", "height", tip.Witness.Height) if b.Witness, err = bc.app.PrepareWitness( tip.Witness.Height); err != nil { + b = nil return } if !b.Timestamp.After(tip.Timestamp) { @@ -578,6 +591,7 @@ func (bc *blockChain) prepareBlock(position types.Position, } } else { if err = bc.signer.SignBlock(b); err != nil { + b = nil return } } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go index 0f665f29a..0f4daa766 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go @@ -41,8 +41,6 @@ var ( "hash of block is incorrect") ErrIncorrectSignature = fmt.Errorf( "signature of block is incorrect") - ErrGenesisBlockNotEmpty = fmt.Errorf( - "genesis block should be empty") ErrUnknownBlockProposed = fmt.Errorf( "unknown block is proposed") ErrIncorrectAgreementResultPosition = fmt.Errorf( @@ -831,6 +829,16 @@ func (con *Consensus) initialRound( con.initialRound( startHeight+config.RoundLength, nextRound, nextConfig) }) + // Touch nodeSetCache for next round. + con.event.RegisterHeight(startHeight+config.RoundLength*9/10, func(uint64) { + go func() { + // TODO(jimmy): check DKGResetCount and do not touch if nextRound is reset. + if err := con.nodeSetCache.Touch(round + 1); err != nil { + con.logger.Warn("Failed to update nodeSetCache", + "round", round+1, "error", err) + } + }() + }) } // Stop the Consensus core. @@ -1242,8 +1250,5 @@ func (con *Consensus) proposeBlock(position types.Position) ( if err = con.signer.SignCRS(b, crs); err != nil { return nil, err } - if b.IsGenesis() && len(b.Payload) != 0 { - return nil, ErrGenesisBlockNotEmpty - } return b, nil } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/nodeset-cache.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/nodeset-cache.go index 6249665ac..e09120d9a 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/nodeset-cache.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/nodeset-cache.go @@ -165,6 +165,12 @@ func (cache *NodeSetCache) GetLeaderNode(pos types.Position) ( return IDs.leaderNode[pos.Height], nil } +// Touch updates the internal cache of round. +func (cache *NodeSetCache) Touch(round uint64) (err error) { + _, err = cache.update(round) + return +} + func (cache *NodeSetCache) cloneMap( nIDs map[types.NodeID]struct{}) map[types.NodeID]struct{} { nIDsCopy := make(map[types.NodeID]struct{}, len(nIDs)) -- cgit v1.2.3