Skip to content

Commit 7706dc3

Browse files
alanchchenMiya Chen
authored andcommitted
consensus/istanbul: fix crash in snapshot searching
1 parent 63daa3c commit 7706dc3

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)