From 23ed73f5a32580b710ecf6904a13540033874c81 Mon Sep 17 00:00:00 2001 From: tak Date: Tue, 24 Sep 2024 22:28:54 +0530 Subject: [PATCH] fix null pointer error after taking #69 --- consensus/oasys/snapshot.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/consensus/oasys/snapshot.go b/consensus/oasys/snapshot.go index 9fdf5ecf5..920a6f862 100644 --- a/consensus/oasys/snapshot.go +++ b/consensus/oasys/snapshot.go @@ -281,9 +281,16 @@ func (s *Snapshot) ToNextValidators() *nextValidators { operators := make([]common.Address, len(s.Validators)) stakes := make([]*big.Int, len(s.Validators)) voteAddresses := make([]types.BLSPublicKey, len(s.Validators)) + var counter int for address, info := range s.Validators { - // No worry, voterIndex is assured when creating snapshot + // Basically, voterIndex is assured when creating snapshot i := info.Index - 1 + if info.Index == 0 { + // The is one scenario that the index is 0, which is the first run after the upgrade(v1.6.0). + // In this case, As the snapshot is loaded from disk, the format is old one. + i = counter + counter++ + } operators[i] = address stakes[i] = new(big.Int).Set(info.Stake) copy(voteAddresses[i][:], info.VoteAddress[:])