diff options
author | Mission Liao <mission.liao@dexon.org> | 2019-01-05 00:16:15 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-01-05 00:16:15 +0800 |
commit | 65f14ef166d7fd3ea30f50366d55777b54fe305f (patch) | |
tree | 6de40faba33caecc38171377a9ca8d4834562f5b /core | |
parent | c7fdbd64be6228aa87b14f8953311c88cc14b4ff (diff) | |
download | dexon-consensus-65f14ef166d7fd3ea30f50366d55777b54fe305f.tar dexon-consensus-65f14ef166d7fd3ea30f50366d55777b54fe305f.tar.gz dexon-consensus-65f14ef166d7fd3ea30f50366d55777b54fe305f.tar.bz2 dexon-consensus-65f14ef166d7fd3ea30f50366d55777b54fe305f.tar.lz dexon-consensus-65f14ef166d7fd3ea30f50366d55777b54fe305f.tar.xz dexon-consensus-65f14ef166d7fd3ea30f50366d55777b54fe305f.tar.zst dexon-consensus-65f14ef166d7fd3ea30f50366d55777b54fe305f.zip |
core: fix stuffs (#401)
* Remove block recycling mechanism
* Return directly when previous DKG is not finished.
* Adjust some logging level
* Skip pulling when hashes to pull is empty
Diffstat (limited to 'core')
-rw-r--r-- | core/blockpool.go | 4 | ||||
-rw-r--r-- | core/configuration-chain.go | 2 | ||||
-rw-r--r-- | core/consensus.go | 7 | ||||
-rw-r--r-- | core/syncer/agreement.go | 4 | ||||
-rw-r--r-- | core/syncer/consensus.go | 10 | ||||
-rw-r--r-- | core/types/block.go | 25 |
6 files changed, 17 insertions, 35 deletions
diff --git a/core/blockpool.go b/core/blockpool.go index fbd84f2..4e41aa7 100644 --- a/core/blockpool.go +++ b/core/blockpool.go @@ -29,8 +29,8 @@ type blockPool []types.ByPosition func newBlockPool(chainNum uint32) (pool blockPool) { pool = make(blockPool, chainNum) - for _, p := range pool { - heap.Init(&p) + for i := range pool { + heap.Init(&pool[i]) } return } diff --git a/core/configuration-chain.go b/core/configuration-chain.go index a4636cb..4938ba0 100644 --- a/core/configuration-chain.go +++ b/core/configuration-chain.go @@ -91,6 +91,8 @@ func (cc *configurationChain) registerDKG(round uint64, threshold int) { defer cc.dkgLock.Unlock() if cc.dkg != nil { cc.logger.Error("Previous DKG is not finished") + // TODO(mission): do we have to retry DKG initiation here? + return } dkgSet, err := cc.cache.GetDKGSet(round) if err != nil { diff --git a/core/consensus.go b/core/consensus.go index faadbe9..0e5a1fb 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -1015,8 +1015,11 @@ func (con *Consensus) pullRandomness() { case <-time.After(1500 * time.Millisecond): // TODO(jimmy): pulling period should be related to lambdaBA. hashes := con.ccModule.pendingBlocksWithoutRandomness() - con.logger.Debug("Calling Network.PullRandomness", "blocks", hashes) - con.network.PullRandomness(hashes) + if len(hashes) > 0 { + con.logger.Debug( + "Calling Network.PullRandomness", "blocks", hashes) + con.network.PullRandomness(hashes) + } } } } diff --git a/core/syncer/agreement.go b/core/syncer/agreement.go index 08be77a..9b351ea 100644 --- a/core/syncer/agreement.go +++ b/core/syncer/agreement.go @@ -99,7 +99,7 @@ func (a *agreement) processBlock(b *types.Block) { func (a *agreement) processAgreementResult(r *types.AgreementResult) { // Cache those results that CRS is not ready yet. if _, exists := a.confirmedBlocks[r.BlockHash]; exists { - a.logger.Debug("agreement result already confirmed", "result", r) + a.logger.Trace("agreement result already confirmed", "result", r) return } if r.Position.Round > a.latestCRSRound { @@ -109,7 +109,7 @@ func (a *agreement) processAgreementResult(r *types.AgreementResult) { a.pendings[r.Position.Round] = pendingsForRound } pendingsForRound[r.BlockHash] = r - a.logger.Debug("agreement result cached", "result", r) + a.logger.Trace("agreement result cached", "result", r) return } if err := core.VerifyAgreementResult(r, a.cache); err != nil { diff --git a/core/syncer/consensus.go b/core/syncer/consensus.go index 8852a47..92f8fd8 100644 --- a/core/syncer/consensus.go +++ b/core/syncer/consensus.go @@ -262,12 +262,12 @@ func (con *Consensus) ensureAgreementOverlapRound() bool { for r = range tipRoundMap { break } - con.logger.Info("check agreement round cut", + con.logger.Debug("check agreement round cut", "tip-round", r, "configs", len(con.configs)) if tipRoundMap[r] == con.configs[r].NumChains { con.agreementRoundCut = r - con.logger.Debug("agreement round cut found, round", r) + con.logger.Info("agreement round cut found, round", r) return true } } @@ -416,7 +416,7 @@ func (con *Consensus) SyncBlocks( "expected", tipHeight+1) return false, ErrInvalidSyncingFinalizationHeight } - con.logger.Debug("syncBlocks", + con.logger.Trace("syncBlocks", "position", &blocks[0].Position, "final height", blocks[0].Finalization.Height, "len", len(blocks), @@ -601,7 +601,7 @@ func (con *Consensus) setupConfigs(blocks []*types.Block) { maxRound = b.Position.Round } } - con.logger.Info("syncer setupConfigs", + con.logger.Debug("syncer setupConfigs", "max", maxRound, "lattice", con.latticeLastRound) // Get configs from governance. @@ -737,7 +737,7 @@ func (con *Consensus) startCRSMonitor() { if round == lastNotifiedRound { return } - con.logger.Info("CRS is ready", "round", round) + con.logger.Debug("CRS is ready", "round", round) lastNotifiedRound = round for _, a := range con.agreements { a.inputChan <- round diff --git a/core/types/block.go b/core/types/block.go index f42b702..b2a8f57 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -24,7 +24,6 @@ import ( "fmt" "io" "sort" - "sync" "time" "github.com/dexon-foundation/dexon/rlp" @@ -47,15 +46,6 @@ const ( VerifyInvalidBlock ) -var ( - // blockPool is the blocks cache to reuse allocated blocks. - blockPool = sync.Pool{ - New: func() interface{} { - return &Block{} - }, - } -) - type rlpTimestamp struct { time.Time } @@ -133,19 +123,6 @@ type Witness struct { Data []byte `json:"data"` } -// RecycleBlock put unused block into cache, which might be reused if -// not garbage collected. -func RecycleBlock(b *Block) { - blockPool.Put(b) -} - -// NewBlock initiate a block. -func NewBlock() (b *Block) { - b = blockPool.Get().(*Block) - b.Acks = b.Acks[:0] - return -} - // Block represents a single event broadcasted on the network. type Block struct { ProposerID NodeID `json:"proposer_id"` @@ -226,7 +203,7 @@ func (b *Block) String() string { // Clone returns a deep copy of a block. func (b *Block) Clone() (bcopy *Block) { - bcopy = NewBlock() + bcopy = &Block{} bcopy.ProposerID = b.ProposerID bcopy.ParentHash = b.ParentHash bcopy.Hash = b.Hash |