Skip to content

Commit 2a23b2a

Browse files
authored
Merge pull request #9 from chainstack/bug/fix-sync-isses-chapel
Fix chapel sync issues
2 parents 8fa0a08 + 5fefe60 commit 2a23b2a

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

consensus/parlia/parlia.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ type Parlia struct {
256256
fakeDiff bool // Skip difficulty verifications
257257
heightForks, timeForks []uint64 // Forks extracted from the chainConfig
258258
snapshots *snapshotsync.RoSnapshots
259+
newValidators []libcommon.Address
260+
voteAddressMapmap map[libcommon.Address]*types.BLSPublicKey
259261
}
260262

261263
// New creates a Parlia consensus engine.
@@ -872,18 +874,27 @@ func (p *Parlia) Prepare(chain consensus.ChainHeaderReader, header *types.Header
872874
}
873875

874876
func (p *Parlia) verifyValidators(header, parentHeader *types.Header, state *state.IntraBlockState) error {
875-
if header.Number.Uint64()%p.config.Epoch != 0 {
876-
return nil
877-
}
877+
if (header.Number.Uint64()+1)%p.config.Epoch == 0 {
878+
newValidators, voteAddressMap, err := p.getCurrentValidators(header, state)
879+
if err != nil {
880+
return err
881+
}
882+
p.newValidators = newValidators
883+
p.voteAddressMapmap = voteAddressMap
884+
return nil
885+
}
878886

879-
newValidators, voteAddressMap, err := p.getCurrentValidators(parentHeader, state)
880-
if err != nil {
881-
return err
882-
}
887+
if header.Number.Uint64()%p.config.Epoch != 0 {
888+
return nil
889+
}
890+
891+
892+
newValidators, voteAddressMap := p.newValidators, p.voteAddressMapmap
883893
// sort validator by address
884894
sort.Sort(validatorsAscending(newValidators))
885895
var validatorsBytes []byte
886896
validatorsNumber := len(newValidators)
897+
887898
if !p.chainConfig.IsLuban(header.Number.Uint64()) {
888899
validatorsBytes = make([]byte, validatorsNumber*validatorBytesLengthBeforeLuban)
889900
for i, validator := range newValidators {

0 commit comments

Comments
 (0)