Skip to content

Commit

Permalink
Merge pull request #54 from calmbeing/fix
Browse files Browse the repository at this point in the history
Fix getCurrentValidators issue
  • Loading branch information
calmbeing authored May 5, 2023
2 parents d6e114d + f0a0444 commit 7bfcc2b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ type Parlia struct {
fakeDiff bool // Skip difficulty verifications
heightForks, timeForks []uint64 // Forks extracted from the chainConfig
snapshots *snapshotsync.RoSnapshots
newValidators []libcommon.Address
voteAddressMapmap map[libcommon.Address]*types.BLSPublicKey
}

// New creates a Parlia consensus engine.
Expand Down Expand Up @@ -872,18 +874,26 @@ func (p *Parlia) Prepare(chain consensus.ChainHeaderReader, header *types.Header
}

func (p *Parlia) verifyValidators(header, parentHeader *types.Header, state *state.IntraBlockState) error {
if header.Number.Uint64()%p.config.Epoch != 0 {
if (header.Number.Uint64()+1)%p.config.Epoch == 0 {
newValidators, voteAddressMap, err := p.getCurrentValidators(header, state)
if err != nil {
return err
}
p.newValidators = newValidators
p.voteAddressMapmap = voteAddressMap
return nil
}

newValidators, voteAddressMap, err := p.getCurrentValidators(parentHeader, state)
if err != nil {
return err
if header.Number.Uint64()%p.config.Epoch != 0 {
return nil
}

newValidators, voteAddressMap := p.newValidators, p.voteAddressMapmap
// sort validator by address
sort.Sort(validatorsAscending(newValidators))
var validatorsBytes []byte
validatorsNumber := len(newValidators)

if !p.chainConfig.IsLuban(header.Number.Uint64()) {
validatorsBytes = make([]byte, validatorsNumber*validatorBytesLengthBeforeLuban)
for i, validator := range newValidators {
Expand Down

0 comments on commit 7bfcc2b

Please sign in to comment.