Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/nknd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
27 changes: 18 additions & 9 deletions consensus/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion consensus/proposing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down