Skip to content

Commit f5c3935

Browse files
committed
check node sync status before sign self snapshot
1 parent 43a0e74 commit f5c3935

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

kernel/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (node *Node) handleSnapshotInput(s *common.Snapshot) error {
2121
return node.handleSyncFinalSnapshot(s)
2222
}
2323

24-
if !node.CheckSync() {
24+
if !node.CheckCatchUp() {
2525
return node.queueSnapshotOrPanic(s, false)
2626
}
2727

kernel/node.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (node *Node) QueueAppendSnapshot(peerId crypto.Hash, s *common.Snapshot) er
267267
if !signersMap[peerId] {
268268
return nil
269269
}
270-
if !node.CheckSync() {
270+
if !node.CheckCatchUp() {
271271
return nil
272272
}
273273
return node.store.QueueAppendSnapshot(peerId, s, false)
@@ -311,6 +311,21 @@ func (node *Node) UpdateSyncPoint(peerId crypto.Hash, points []*network.SyncPoin
311311
}
312312

313313
func (node *Node) CheckSync() bool {
314+
count := 1
315+
final := node.Graph.MyFinalNumber
316+
for id, _ := range node.ConsensusNodes {
317+
remote := node.SyncPoints.Get(id)
318+
if remote == nil {
319+
continue
320+
}
321+
if remote.Number+1 >= final {
322+
count += 1
323+
}
324+
}
325+
return count >= len(node.ConsensusNodes)*2/3+1
326+
}
327+
328+
func (node *Node) CheckCatchUp() bool {
314329
if node.SyncPoints.Len() != len(node.ConsensusNodes)-1 {
315330
return false
316331
}

kernel/self.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@ func (node *Node) signSelfSnapshot(s *common.Snapshot, tx *common.SignedTransact
138138
if s.NodeId != node.IdForNetwork || len(s.Signatures) != 0 || s.Timestamp != 0 {
139139
panic("should never be here")
140140
}
141+
142+
cache := node.Graph.CacheRound[s.NodeId].Copy()
143+
final := node.Graph.FinalRound[s.NodeId].Copy()
144+
141145
if !node.checkCacheCapability() {
142146
time.Sleep(10 * time.Millisecond)
143147
return node.queueSnapshotOrPanic(s, false)
144148
}
145-
146-
cache := node.Graph.CacheRound[s.NodeId].Copy()
147-
final := node.Graph.FinalRound[s.NodeId].Copy()
149+
if !node.CheckSync() && len(cache.Snapshots) == 0 {
150+
time.Sleep(time.Duration(config.SnapshotRoundGap / 2))
151+
return node.queueSnapshotOrPanic(s, false)
152+
}
148153

149154
for {
150155
s.Timestamp = uint64(time.Now().UnixNano())

0 commit comments

Comments
 (0)