Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[R4R] add timeout for catch up condition check with no peers #174

Merged
merged 3 commits into from
Jan 7, 2023
Merged
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
11 changes: 9 additions & 2 deletions blockchain/v0/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,15 @@ func (pool *BlockPool) IsCaughtUp() bool {
pool.mtx.Lock()
defer pool.mtx.Unlock()

// Need at least 1 peer to be considered caught up.
// Normally it needs at least 1 peer to be considered caught up.
// There is a change that a node with the majority of voting power has no peers, it will never have changes
// to catch up and switch to consensus reactor, resulting in stopping the chain.
// So we add a 10 minutes timeout to prevent this case.
if len(pool.peers) == 0 {
pool.Logger.Debug("Blockpool has no peers")
pool.Logger.Debug("Blockpool has no peers", "duration", time.Since(pool.startTime), "height", pool.height, "initHeight", pool.initHeight)
if time.Since(pool.startTime) > 10*time.Minute && pool.height == pool.initHeight {
return true
}
return false
}

Expand All @@ -187,6 +193,7 @@ func (pool *BlockPool) IsCaughtUp() bool {
receivedBlockOrTimedOut := pool.height > 0 || time.Since(pool.startTime) > 5*time.Second
ourChainIsLongestAmongPeers := pool.maxPeerHeight == 0 || pool.height >= (pool.maxPeerHeight-1)
isCaughtUp := receivedBlockOrTimedOut && ourChainIsLongestAmongPeers
pool.Logger.Debug("IsCaughtUp", "isCaughtUp", isCaughtUp, "receivedBlockOrTimedOut", receivedBlockOrTimedOut, "ourChainIsLongestAmongPeers", ourChainIsLongestAmongPeers, "pool.maxPeerHeight", pool.maxPeerHeight, "pool.height", pool.height, "pool.startTime", pool.startTime)
return isCaughtUp
}

Expand Down