diff --git a/cmd/nknd/commands/root.go b/cmd/nknd/commands/root.go index d1fdbc6ec..912b41d22 100644 --- a/cmd/nknd/commands/root.go +++ b/cmd/nknd/commands/root.go @@ -47,7 +47,7 @@ import ( ) const ( - NetVersionNum = 32 // This will be removed later + NetVersionNum = 33 // This will be removed later ) // rootCmd represents the base command when called without any subcommands diff --git a/config/config.go b/config/config.go index 7f5df8bb7..27bc637c5 100644 --- a/config/config.go +++ b/config/config.go @@ -31,12 +31,12 @@ const ( SigChainBlockDelay = 1 SigChainPropogationTime = 2 MinNumSuccessors = 8 - NumRandomGossipNeighborsFactor = 1 - NumRandomVotingNeighborsFactor = 3 + NumRandomGossipNeighborsFactor = 2 + NumRandomVotingNeighborsFactor = 4 MinNumRandomGossipNeighbors = 8 MinNumRandomVotingNeighbors = 24 MaxNumInboundRandomNeighbors = 256 - GossipSampleChordNeighbor = 0.15 + GossipSampleChordNeighbor = 0.25 GossipMinChordNeighbor = 8 VotingSampleChordNeighbor = 0.0 VotingMinChordNeighbor = 0 @@ -238,6 +238,11 @@ var ( Heights: []uint32{3030000, 0}, Values: []bool{true, false}, } + + // use these config for network restart + MinVerifiableHeightResetHeight = 8843191 + MinVerifiableHeightResetTime = time.Unix(1767441600, 0) + ProposingStartTime = time.Unix(1767441600, 0) ) var ( diff --git a/consensus/proposal.go b/consensus/proposal.go index 83528c327..bd5115351 100644 --- a/consensus/proposal.go +++ b/consensus/proposal.go @@ -77,10 +77,12 @@ func (consensus *Consensus) waitAndHandleProposal() (*election.Election, error) } for { - if consensus.canVerifyHeight(consensusHeight) { + if consensus.canVerifyHeight(consensusHeight) || time.Now().Before(config.ProposingStartTime) { break } + log.Debugf("Cannot verify height %d, neighbor vote count %d", consensusHeight, elc.NeighborVoteCount()) + if elc.NeighborVoteCount() > 0 { timerStartOnce.Do(func() { timer.StopTimer(timeoutTimer) @@ -109,12 +111,21 @@ func (consensus *Consensus) waitAndHandleProposal() (*election.Election, error) receivedTime := proposalInfo.receivedTime blockHash := proposal.Hash() - if !consensus.canVerifyHeight(consensusHeight) { - err = consensus.iHaveBlockProposal(consensusHeight, blockHash) - if err != nil { - log.Errorf("Send I have block message error: %v", err) + log.Debugf("Process block proposal %s, proposal count %d", blockHash.ToHexString(), proposalCount) + + acceptProposal := true + + if time.Now().Before(config.ProposingStartTime) { + acceptProposal = false + } else { + if !consensus.canVerifyHeight(consensusHeight) { + log.Debugf("Cannot verify height %d, send I have block message", consensusHeight) + err = consensus.iHaveBlockProposal(consensusHeight, blockHash) + if err != nil { + log.Errorf("Send I have block message error: %v", err) + } + continue } - continue } timerStartOnce.Do(func() { @@ -124,8 +135,6 @@ func (consensus *Consensus) waitAndHandleProposal() (*election.Election, error) initialVoteDeadline = receivedTime.Add(initialVoteDelay) }) - acceptProposal := true - proposals[blockHash] = proposal if len(proposals) > 2 { log.Warningf("Received more than 2 different proposals, ignoring the rest") @@ -248,7 +257,7 @@ func (consensus *Consensus) startRequestingProposal() { func (consensus *Consensus) receiveProposal(block *block.Block) error { blockHash := block.Hash() - log.Infof("Receive block proposal %s (%d txn, %d bytes) by %x", blockHash.ToHexString(), len(block.Transactions), block.GetTxsSize(), block.Header.UnsignedHeader.SignerPk) + log.Infof("Receive block proposal %s (%d txn, %d bytes) by %x (height %d, timestamp %d)", blockHash.ToHexString(), len(block.Transactions), block.GetTxsSize(), block.Header.UnsignedHeader.SignerPk, block.Header.UnsignedHeader.Height, block.Header.UnsignedHeader.Timestamp) consensus.proposalLock.RLock() defer consensus.proposalLock.RUnlock() diff --git a/consensus/proposing.go b/consensus/proposing.go index d8a6396ac..1b96003dd 100644 --- a/consensus/proposing.go +++ b/consensus/proposing.go @@ -18,7 +18,14 @@ func (consensus *Consensus) startProposing() { var timestamp int64 var ctx context.Context var cancel context.CancelFunc - proposingTimer := time.NewTimer(proposingStartDelay) + + var proposingTimer *time.Timer + if time.Now().Before(config.ProposingStartTime) { + proposingTimer = time.NewTimer(config.ProposingStartTime.Sub(time.Now())) + } else { + proposingTimer = time.NewTimer(proposingStartDelay) + } + for { select { case <-proposingTimer.C: diff --git a/consensus/state.go b/consensus/state.go index 0b563e7f8..f484503bd 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -6,6 +6,7 @@ import ( "github.com/nknorg/nkn/v2/chain" "github.com/nknorg/nkn/v2/common" + "github.com/nknorg/nkn/v2/config" "github.com/nknorg/nkn/v2/node" "github.com/nknorg/nkn/v2/pb" "github.com/nknorg/nkn/v2/por" @@ -20,6 +21,15 @@ import ( func (consensus *Consensus) startGettingNeighborConsensusState() { consensus.localNode.SetMinVerifiableHeight(chain.DefaultLedger.Store.GetHeight() + por.SigChainMiningHeightOffset) + if config.MinVerifiableHeightResetHeight > 0 && chain.DefaultLedger.Store.GetHeight() == uint32(config.MinVerifiableHeightResetHeight) && time.Now().Before(config.MinVerifiableHeightResetTime) { + go func() { + time.Sleep(time.Until(config.MinVerifiableHeightResetTime)) + if chain.DefaultLedger.Store.GetHeight() == uint32(config.MinVerifiableHeightResetHeight) { + consensus.localNode.SetMinVerifiableHeight(uint32(config.MinVerifiableHeightResetHeight + 1)) + } + }() + } + initialized := false getNeighborConsensusStateTimer := time.NewTimer(proposingStartDelay / 2) for {