Skip to content

Commit 98c5bb1

Browse files
authored
Merge pull request #76 from getamis/feature/crash-when-access-snapshot-too-early
consensus/istanbul: fix crash in snapshot searching
2 parents 8e45c10 + 3da97f1 commit 98c5bb1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

consensus/istanbul/core/checkpoint.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ func (c *core) handleCheckpoint(msg *message, src istanbul.Validator) error {
7878
if snapshotIndex < len(c.snapshots) && c.snapshots[snapshotIndex].Sequence().Cmp(cp.View.Sequence) == 0 {
7979
snapshot = c.snapshots[snapshotIndex]
8080
} else {
81-
min := c.snapshots[0].Sequence()
82-
logger.Warn("Failed to find snapshot entry", "target", cp.View.Sequence, "current", c.current.Sequence(), "min", min)
81+
if len(c.snapshots) > 0 {
82+
min := c.snapshots[0].Sequence()
83+
logger.Warn("Failed to find snapshot entry", "target", cp.View.Sequence, "current", c.current.Sequence(), "min", min)
84+
} else {
85+
logger.Warn("Failed to find snapshot entry", "target", cp.View.Sequence, "current", c.current.Sequence())
86+
}
8387
return errInvalidMessage
8488
}
8589
} else { // future checkpoint

0 commit comments

Comments
 (0)