From f9c0c405152380136ef3f342a89156183468fcd8 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 12 Nov 2022 12:19:28 +0800 Subject: [PATCH] change devnet switch block for large scale test (#205) * change switch block * use mainnet masternode * update mining and timeout time * add timer on round number * remove bug code --- consensus/XDPoS/engines/engine_v2/engine.go | 5 +++++ consensus/XDPoS/engines/engine_v2/vote.go | 14 ++++++++++++-- params/config.go | 10 +++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/consensus/XDPoS/engines/engine_v2/engine.go b/consensus/XDPoS/engines/engine_v2/engine.go index da52ae2604..4b0c0b3c6b 100644 --- a/consensus/XDPoS/engines/engine_v2/engine.go +++ b/consensus/XDPoS/engines/engine_v2/engine.go @@ -60,6 +60,8 @@ type XDPoS_v2 struct { HookPenalty func(chain consensus.ChainReader, number *big.Int, parentHash common.Hash, candidates []common.Address) ([]common.Address, error) ForensicsProcessor *Forensics + + votePoolCollectionTime time.Time } func New(config *params.XDPoSConfig, db ethdb.Database, waitPeriodCh chan int) *XDPoS_v2 { @@ -756,6 +758,7 @@ func (x *XDPoS_v2) verifyQC(blockChainReader consensus.ChainReader, quorumCert * log.Warn("[verifyHeader] Invalid QC Signature is nil or empty", "QC", quorumCert, "QCNumber", quorumCert.ProposedBlockInfo.Number, "Signatures len", len(signatures)) return utils.ErrInvalidQC } + start := time.Now() var wg sync.WaitGroup wg.Add(len(signatures)) @@ -781,6 +784,8 @@ func (x *XDPoS_v2) verifyQC(blockChainReader consensus.ChainReader, quorumCert * }(signature) } wg.Wait() + elapsed := time.Since(start) + log.Info("[verifyQC] time verify message signatures of qc", "elapsed", elapsed) if haveError != nil { return haveError } diff --git a/consensus/XDPoS/engines/engine_v2/vote.go b/consensus/XDPoS/engines/engine_v2/vote.go index 60963ded22..ad90a22ac6 100644 --- a/consensus/XDPoS/engines/engine_v2/vote.go +++ b/consensus/XDPoS/engines/engine_v2/vote.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/consensus" @@ -54,7 +55,6 @@ func (x *XDPoS_v2) sendVote(chainReader consensus.ChainReader, blockInfo *types. } func (x *XDPoS_v2) voteHandler(chain consensus.ChainReader, voteMsg *types.Vote) error { - // checkRoundNumber if (voteMsg.ProposedBlockInfo.Round != x.currentRound) && (voteMsg.ProposedBlockInfo.Round != x.currentRound+1) { return &utils.ErrIncomingMessageRoundTooFarFromCurrentRound{ @@ -64,6 +64,11 @@ func (x *XDPoS_v2) voteHandler(chain consensus.ChainReader, voteMsg *types.Vote) } } + if x.votePoolCollectionTime.IsZero() { + log.Info("[voteHandler] set vote pool time", "round", x.currentRound) + x.votePoolCollectionTime = time.Now() + } + // Collect vote thresholdReached, numberOfVotesInPool, pooledVotes := x.votePool.Add(voteMsg) log.Debug("[voteHandler] collect votes", "number", numberOfVotesInPool) @@ -87,6 +92,9 @@ func (x *XDPoS_v2) voteHandler(chain consensus.ChainReader, voteMsg *types.Vote) if err != nil { return err } + elapsed := time.Since(x.votePoolCollectionTime) + log.Info("[voteHandler] time cost from receive first vote under QC create", "elapsed", elapsed) + x.votePoolCollectionTime = time.Time{} } return nil @@ -99,7 +107,7 @@ func (x *XDPoS_v2) voteHandler(chain consensus.ChainReader, voteMsg *types.Vote) func (x *XDPoS_v2) onVotePoolThresholdReached(chain consensus.ChainReader, pooledVotes map[common.Hash]utils.PoolObj, currentVoteMsg utils.PoolObj, proposedBlockHeader *types.Header) error { masternodes := x.GetMasternodes(chain, proposedBlockHeader) - + start := time.Now() // Filter out non-Master nodes signatures var wg sync.WaitGroup wg.Add(len(pooledVotes)) @@ -121,6 +129,8 @@ func (x *XDPoS_v2) onVotePoolThresholdReached(chain consensus.ChainReader, poole counter++ } wg.Wait() + elapsed := time.Since(start) + log.Info("[onVotePoolThresholdReached] verify message signatures of vote pool took", "elapsed", elapsed) // The signature list may contain empty entey. we only care the ones with values var validSignatureSlice []types.Signature diff --git a/params/config.go b/params/config.go index 3fd99ae176..75454b14b9 100644 --- a/params/config.go +++ b/params/config.go @@ -54,12 +54,12 @@ var ( SkipV2Validation: true, } DevnetXDPoSV2Config = &V2{ - SwitchBlock: big.NewInt(7060500), - CertThreshold: 4, + SwitchBlock: big.NewInt(7074000), + CertThreshold: common.MaxMasternodesV2*2/3 + 1, TimeoutSyncThreshold: 5, - TimeoutPeriod: 10, - WaitPeriod: 5, - MinePeriod: 5, + TimeoutPeriod: 25, + WaitPeriod: 10, + MinePeriod: 10, } // XDPoSChain mainnet config