Skip to content

Commit

Permalink
Excluding outdated neighbors when prefilling votes
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <zyl.skysniper@gmail.com>
  • Loading branch information
yilunzhang committed Jul 13, 2019
1 parent 5e0d3e1 commit 693c13a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func (consensus *Consensus) prefillNeighborVotes(elc *election.Election, height
if rn.GetHeight() < height && height < rn.GetMinVerifiableHeight() {
continue
}
// Neighbor's consensus state is not up to date
if time.Since(rn.GetLastUpdateTime()) > getConsensusStateInterval*2 {
continue
}
neighborIDs = append(neighborIDs, rn.GetID())
}

Expand Down
1 change: 1 addition & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (consensus *Consensus) getNeighborConsensusState(neighbor *node.RemoteNode)
neighbor.SetHeight(replyMsg.LedgerHeight)
neighbor.SetMinVerifiableHeight(replyMsg.MinVerifiableHeight)
neighbor.SetSyncState(replyMsg.SyncState)
neighbor.SetLastUpdateTime(time.Now())

return replyMsg, nil
}
Expand Down
2 changes: 1 addition & 1 deletion node/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (localNode *LocalNode) startConnectingToRandomNeighbors() {
}

for {
time.Sleep(util.RandDuration(randomNeighborConnectInterval, 1.0/6.0))
time.Sleep(util.RandDuration(randomNeighborConnectInterval, 1.0/3.0))

if len(localNode.randomNeighbors) >= maxNumRandomNeighbors {
nbr := localNode.GetNbrNode(localNode.randomNeighbors[0])
Expand Down
15 changes: 14 additions & 1 deletion node/remotenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type RemoteNode struct {
sharedKey *[sharedKeySize]byte

sync.RWMutex
height uint32
height uint32
lastUpdateTime time.Time
}

func (remoteNode *RemoteNode) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -83,6 +84,18 @@ func (remoteNode *RemoteNode) SetHeight(height uint32) {
remoteNode.height = height
}

func (remoteNode *RemoteNode) GetLastUpdateTime() time.Time {
remoteNode.RLock()
defer remoteNode.RUnlock()
return remoteNode.lastUpdateTime
}

func (remoteNode *RemoteNode) SetLastUpdateTime(lastUpdateTime time.Time) {
remoteNode.Lock()
defer remoteNode.Unlock()
remoteNode.lastUpdateTime = lastUpdateTime
}

func (remoteNode *RemoteNode) CloseConn() {
remoteNode.nnetNode.Stop(nil)
}
Expand Down

0 comments on commit 693c13a

Please sign in to comment.