Increase time buffer; add db cache; change log level

pull/3275/head v2.3.2
Rongjian Lan 4 years ago committed by Leo Chen
parent 9013f160cc
commit 19db99d3f7
  1. 2
      consensus/leader.go
  2. 5
      consensus/quorum/one-node-staked-vote.go
  3. 40
      consensus/view_change.go
  4. 2
      internal/shardchain/dbfactory.go
  5. 2
      node/node_newblock.go

@ -289,7 +289,7 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) {
consensus.getLogger().Info().Msg("[OnCommit] Starting Grace Period")
go func(viewID uint64) {
time.Sleep(2 * time.Second)
time.Sleep(2500 * time.Millisecond)
logger.Info().Msg("[OnCommit] Commit Grace Period Ended")
consensus.commitFinishChan <- viewID
}(viewID)

@ -88,18 +88,19 @@ func (v *stakedVoteWeight) AddNewVote(
t := v.QuorumThreshold()
msg := "Attempt to reach quorum"
if !tallyQuorum.quorumAchieved {
tallyQuorum.quorumAchieved = tallyQuorum.tally.GT(t)
msg := "Attempt to reach quorum"
if tallyQuorum.quorumAchieved {
msg = "Quorum Achieved!"
}
}
utils.Logger().Info().
Str("phase", p.String()).
Int64("signer-count", v.SignersCount(p)).
Str("total-power-of-signers", tallyQuorum.tally.String()).
Msg(msg)
}
return ballet, nil
}

@ -151,7 +151,7 @@ func (consensus *Consensus) startViewChange(viewID uint64) {
consensus.consensusTimeout[timeoutViewChange].SetDuration(duration)
consensus.consensusTimeout[timeoutViewChange].Start()
consensus.getLogger().Debug().
consensus.getLogger().Info().
Uint64("ViewChangingID", consensus.current.ViewID()).
Msg("[startViewChange] start view change timer")
}
@ -170,7 +170,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
}
if consensus.Decider.IsQuorumAchieved(quorum.ViewChange) {
consensus.getLogger().Debug().
consensus.getLogger().Info().
Int64("have", consensus.Decider.SignersCount(quorum.ViewChange)).
Int64("need", consensus.Decider.TwoThirdsSignersCount()).
Str("validatorPubKey", recvMsg.SenderPubkey.Bytes.Hex()).
@ -213,7 +213,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
}
}
if hasBlock {
consensus.getLogger().Debug().Msg("[onViewChange] add my M1 type messaage")
consensus.getLogger().Info().Msg("[onViewChange] add my M1 type messaage")
msgToSign := append(preparedMsg.BlockHash[:], preparedMsg.Payload...)
for i, key := range consensus.priKey {
if err := consensus.bhpBitmap[recvMsg.ViewID].SetKey(key.Pub.Bytes, true); err != nil {
@ -227,7 +227,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus.m1Payload = append(preparedMsg.BlockHash[:], preparedMsg.Payload...)
}
} else {
consensus.getLogger().Debug().Msg("[onViewChange] add my M2(NIL) type messaage")
consensus.getLogger().Info().Msg("[onViewChange] add my M2(NIL) type messaage")
for i, key := range consensus.priKey {
if err := consensus.nilBitmap[recvMsg.ViewID].SetKey(key.Pub.Bytes, true); err != nil {
consensus.getLogger().Warn().Msgf("[onViewChange] nilBitmap setkey failed for key at index %d", i)
@ -279,7 +279,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
return
}
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("validatorPubKey", senderKey.Bytes.Hex()).
Msg("[onViewChange] Add M2 (NIL) type message")
consensus.nilSigs[recvMsg.ViewID][senderKey.Bytes.Hex()] = recvMsg.ViewchangeSig
@ -304,7 +304,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
// first time receive m1 type message, need verify validity of prepared message
if len(consensus.m1Payload) == 0 || !bytes.Equal(consensus.m1Payload, recvMsg.Payload) {
if len(recvMsg.Payload) <= 32 {
consensus.getLogger().Debug().
consensus.getLogger().Warn().
Int("len", len(recvMsg.Payload)).
Msg("[onViewChange] M1 RecvMsg Payload Not Enough Length")
return
@ -350,7 +350,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus.FBFTLog.AddBlock(preparedBlock)
}
}
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("validatorPubKey", senderKey.Bytes.Hex()).
Msg("[onViewChange] Add M1 (prepared) type message")
consensus.bhpSigs[recvMsg.ViewID][senderKey.Bytes.Hex()] = recvMsg.ViewchangeSig
@ -372,14 +372,14 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
Msg("[onViewChange] Failed to Verify M3 Message Signature")
return
}
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("validatorPubKey", senderKey.Bytes.Hex()).
Msg("[onViewChange] Add M3 (ViewID) type message")
consensus.viewIDSigs[recvMsg.ViewID][senderKey.Bytes.Hex()] = recvMsg.ViewidSig
// Set the bitmap indicating that this validator signed.
consensus.viewIDBitmap[recvMsg.ViewID].SetKey(recvMsg.SenderPubkey.Bytes, true)
consensus.getLogger().Debug().
consensus.getLogger().Info().
Int("have", len(consensus.viewIDSigs[recvMsg.ViewID])).
Int64("total", consensus.Decider.ParticipantsCount()).
Msg("[onViewChange]")
@ -397,7 +397,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus.ReadySignal <- struct{}{}
}()
} else {
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("From", consensus.phase.String()).
Str("To", FBFTCommit.String()).
Msg("[OnViewChange] Switching phase")
@ -416,7 +416,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
// Leader sign and add commit message
block := consensus.FBFTLog.GetBlockByHash(consensus.blockHash)
if block == nil {
consensus.getLogger().Debug().Msg("[onViewChange] failed to get prepared block for self commit")
consensus.getLogger().Warn().Msg("[onViewChange] failed to get prepared block for self commit")
return
}
commitPayload := signature.ConstructCommitPayload(consensus.ChainReader,
@ -436,7 +436,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
block.NumberU64(),
block.Header().ViewID().Uint64(),
); err != nil {
consensus.getLogger().Debug().Msg("submit vote on viewchange commit failed")
consensus.getLogger().Warn().Msg("submit vote on viewchange commit failed")
return
}
@ -470,7 +470,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus.getLogger().Debug().
Uint64("viewChangingID", consensus.current.ViewID()).
Msg("[onViewChange] New Leader Start Consensus Timer and Stop View Change Timer")
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("myKey", newLeaderKey.Bytes.Hex()).
Uint64("viewID", consensus.viewID).
Uint64("block", consensus.blockNum).
@ -480,7 +480,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
// TODO: move to consensus_leader.go later
func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
consensus.getLogger().Debug().Msg("[onNewView] Received NewView Message")
consensus.getLogger().Info().Msg("[onNewView] Received NewView Message")
recvMsg, err := consensus.ParseNewViewMessage(msg)
if err != nil {
consensus.getLogger().Warn().Err(err).Msg("[onNewView] Unable to Parse NewView Message")
@ -522,7 +522,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
m2Mask := recvMsg.M2Bitmap
if recvMsg.M2AggSig != nil {
consensus.getLogger().Debug().Msg("[onNewView] M2AggSig (NIL) is Not Empty")
consensus.getLogger().Info().Msg("[onNewView] M2AggSig (NIL) is Not Empty")
m2Sig := recvMsg.M2AggSig
if !m2Sig.VerifyHash(m2Mask.AggregatePublic, NIL) {
consensus.getLogger().Warn().
@ -564,7 +564,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
(m2Mask != nil && m2Mask.Bitmap != nil &&
utils.CountOneBits(m3Mask.Bitmap) > utils.CountOneBits(m2Mask.Bitmap)) {
if len(recvMsg.Payload) <= 32 {
consensus.getLogger().Debug().
consensus.getLogger().Info().
Msg("[onNewView] M1 (prepared) Type Payload Not Have Enough Length")
return
}
@ -610,7 +610,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
// change view and leaderKey to keep in sync with network
if consensus.blockNum != recvMsg.BlockNum {
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("newLeaderKey", consensus.LeaderPubKey.Bytes.Hex()).
Uint64("MsgBlockNum", recvMsg.BlockNum).
Msg("[onNewView] New Leader Changed")
@ -644,7 +644,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
p2p.ConstructMessage(msgToSend),
)
}
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("From", consensus.phase.String()).
Str("To", FBFTCommit.String()).
Msg("[OnViewChange] Switching phase")
@ -653,10 +653,10 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
consensus.ResetState()
consensus.getLogger().Info().Msg("onNewView === announce")
}
consensus.getLogger().Debug().
consensus.getLogger().Info().
Str("newLeaderKey", consensus.LeaderPubKey.Bytes.Hex()).
Msg("new leader changed")
consensus.getLogger().Debug().
consensus.getLogger().Info().
Msg("validator start consensus timer and stop view change timer")
consensus.consensusTimeout[timeoutConsensus].Start()
consensus.consensusTimeout[timeoutViewChange].Stop()

@ -22,7 +22,7 @@ type LDBFactory struct {
// NewChainDB returns a new LDB for the blockchain for given shard.
func (f *LDBFactory) NewChainDB(shardID uint32) (ethdb.Database, error) {
dir := path.Join(f.RootDir, fmt.Sprintf("harmony_db_%d", shardID))
return ethdb.NewLDBDatabase(dir, 0, 0)
return ethdb.NewLDBDatabase(dir, 128, 1024)
}
// MemDBFactory is a memory-backed blockchain database factory.

@ -17,6 +17,7 @@ import (
// Constants of proposing a new block
const (
SleepPeriod = 20 * time.Millisecond
IncomingReceiptsLimit = 6000 // 2000 * (numShards - 1)
)
@ -41,6 +42,7 @@ func (node *Node) WaitForConsensusReadyV2(readySignal chan struct{}, stopChan ch
return
case <-readySignal:
for node.Consensus != nil && node.Consensus.IsLeader() {
time.Sleep(SleepPeriod)
utils.Logger().Info().
Uint64("blockNum", node.Blockchain().CurrentBlock().NumberU64()+1).
Msg("PROPOSING NEW BLOCK ------------------------------------------------")

Loading…
Cancel
Save