Skip to content

Commit c10e227

Browse files
committed
Fix bug that parses non existent turn length in blocks before bohr
1 parent c2a43ea commit c10e227

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

chain/bsc2/snapshot.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ func loadSnapshot(database db.Database, hash common.Hash, log log.Logger) (*Snap
127127
return nil, err
128128
}
129129
snap := new(Snapshot)
130+
snap.CurrTurnLength = 1
131+
snap.NextTurnLength = 1
130132
if err := json.Unmarshal(blob, snap); err != nil {
131133
return nil, err
132134
}
@@ -234,7 +236,7 @@ func (s *Snapshot) apply(config *params.ChainConfig, head *types.Header, cid *bi
234236

235237
snap := s.copy()
236238
number := head.Number.Uint64()
237-
if limit := snap.minerHistoryCheckLen() + 1; number >= limit {
239+
if limit := s.minerHistoryCheckLen() + 1; number >= limit {
238240
delete(snap.Recents, number-limit)
239241
}
240242
validator, err := ecrecover(head, cid)
@@ -246,12 +248,12 @@ func (s *Snapshot) apply(config *params.ChainConfig, head *types.Header, cid *bi
246248
}
247249
if config.IsBohr(head.Number, head.Time) {
248250
if snap.SignRecently(validator) {
249-
return nil, errors.New("RecentlySigned")
251+
return nil, errors.New("RecentlySigned(>=Bohr)")
250252
}
251253
} else {
252254
for _, recent := range snap.Recents {
253255
if recent == validator {
254-
return nil, errors.New("RecentlySigned")
256+
return nil, errors.New("RecentlySigned(<Bohr)")
255257
}
256258
}
257259
}
@@ -299,6 +301,9 @@ func (s *Snapshot) apply(config *params.ChainConfig, head *types.Header, cid *bi
299301
}
300302

301303
func parseTurnLength(config *params.ChainConfig, head *types.Header) (uint8, error) {
304+
if !config.IsBohr(head.Number, head.Time) {
305+
return 1, nil
306+
}
302307
if len(head.Extra) <= extraVanity+extraSeal {
303308
return 0, errors.New("invalid span validators")
304309
}

0 commit comments

Comments
 (0)