Skip to content

Commit 9dfc876

Browse files
Merge pull request #169 from canopy-network/sync-timestamp-fix
Node Sync Fixes
2 parents 472fc35 + 5aed17b commit 9dfc876

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

controller/consensus.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ func (c *Controller) Sync() {
112112
for _, peer := range peers {
113113
syncingPeers = append(syncingPeers, lib.BytesToString(peer.Address.PublicKey))
114114
}
115-
// Remove requests that have timed out
116-
c.applyTimeouts(queue)
117115
// Calculate the height to stop at when updating queue
118116
stopHeight := min(fsmHeight+blockSyncQueueSize, maxHeight)
119117
// Send block requests for any missing heights in the queue
@@ -141,6 +139,8 @@ func (c *Controller) Sync() {
141139
maxHeight, minVDFIterations = m, v
142140
c.log.Debugf("Updated chain %d with max height: %d and iterations %d", c.Config.ChainId, maxHeight, minVDFIterations)
143141
}
142+
// Remove any block requests that have timed out
143+
c.applyTimeouts(queue)
144144
}
145145
}
146146
// Syncing complete
@@ -168,8 +168,14 @@ func (c *Controller) processQueue(startHeight, stopHeight uint64, queue map[uint
168168
blockMsg := req.blockMessage
169169
// start timing the HandlePeerBlock call
170170
start := time.Now()
171+
// lock the controller
172+
c.Lock()
171173
// process the block message received from the peer
172-
if _, err := c.HandlePeerBlock(blockMsg, true); err != nil {
174+
_, err := c.HandlePeerBlock(blockMsg, true)
175+
// unlock controller
176+
c.Unlock()
177+
// check error from HandlePeerBlock
178+
if err != nil {
173179
h := blockMsg.BlockAndCertificate.Header.Height
174180
// log this unexpected behavior
175181
c.log.Warnf("Syncing peer block height %d invalid:\n%s", h, err.Error())
@@ -229,6 +235,7 @@ func (c *Controller) sendBlockRequests(start, stop uint64, queue map[uint64]bloc
229235

230236
// Add new request to queue
231237
queue[height] = blockSyncRequest{
238+
timestamp: time.Now(),
232239
height: height,
233240
peerPublicKey: peerPublicKey,
234241
}

0 commit comments

Comments
 (0)