aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/logger.go15
-rw-r--r--core/blockpool.go4
-rw-r--r--core/configuration-chain.go2
-rw-r--r--core/consensus.go7
-rw-r--r--core/syncer/agreement.go4
-rw-r--r--core/syncer/consensus.go10
-rw-r--r--core/types/block.go25
7 files changed, 32 insertions, 35 deletions
diff --git a/common/logger.go b/common/logger.go
index 29eac35..3328e93 100644
--- a/common/logger.go
+++ b/common/logger.go
@@ -29,6 +29,7 @@ import "log"
// })
type Logger interface {
// Info logs info level logs.
+ Trace(msg string, ctx ...interface{})
Debug(msg string, ctx ...interface{})
Info(msg string, ctx ...interface{})
Warn(msg string, ctx ...interface{})
@@ -38,6 +39,10 @@ type Logger interface {
// NullLogger logs nothing.
type NullLogger struct{}
+// Trace implements Logger interface.
+func (logger *NullLogger) Trace(msg string, ctx ...interface{}) {
+}
+
// Debug implements Logger interface.
func (logger *NullLogger) Debug(msg string, ctx ...interface{}) {
}
@@ -66,6 +71,11 @@ func composeVargs(msg string, ctxs []interface{}) []interface{} {
return args
}
+// Trace implements Logger interface.
+func (logger *SimpleLogger) Trace(msg string, ctx ...interface{}) {
+ log.Println(composeVargs(msg, ctx)...)
+}
+
// Debug implements Logger interface.
func (logger *SimpleLogger) Debug(msg string, ctx ...interface{}) {
log.Println(composeVargs(msg, ctx)...)
@@ -98,6 +108,11 @@ func NewCustomLogger(logger *log.Logger) *CustomLogger {
}
}
+// Trace implements Logger interface.
+func (logger *CustomLogger) Trace(msg string, ctx ...interface{}) {
+ logger.logger.Println(composeVargs(msg, ctx)...)
+}
+
// Debug implements Logger interface.
func (logger *CustomLogger) Debug(msg string, ctx ...interface{}) {
logger.logger.Println(composeVargs(msg, ctx)...)
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