Skip to content

Commit

Permalink
Use existing validator set when static call to get new one fails (eth…
Browse files Browse the repository at this point in the history
  • Loading branch information
asaj authored Jun 9, 2019
1 parent 8837030 commit a5ab9f2
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,6 @@ func (sb *Backend) UpdateValSetDiff(chain consensus.ChainReader, header *types.H
validatorAddress := sb.regAdd.GetRegisteredAddress(params.ValidatorsRegistryId)
if validatorAddress == nil {
log.Warn("Finalizing last block of an epoch, and the validator smart contract is not deployed. Using the previous epoch's validator set")

extra, err := assembleExtra(header, []common.Address{}, []common.Address{})
if err != nil {
return err
}
header.Extra = extra

} else {
// Get the last epoch's validator set
snap, err := sb.snapshot(chain, header.Number.Uint64()-1, header.ParentHash, nil)
Expand All @@ -389,29 +382,28 @@ func (sb *Backend) UpdateValSetDiff(chain consensus.ChainReader, header *types.H
// Get the new epoch's validator set
var newValSet []common.Address

maxGasForGetValidators := uint64(1000000)
// TODO(kevjue) - Once the validator election smart contract is completed, then a more accurate gas value should be used.
leftoverGas, err := sb.iEvmH.MakeStaticCall(*validatorAddress, getValidatorsFuncABI, "getValidators", []interface{}{}, &newValSet, 20000, header, state)
leftoverGas, err := sb.iEvmH.MakeStaticCall(*validatorAddress, getValidatorsFuncABI, "getValidators", []interface{}{}, &newValSet, maxGasForGetValidators, header, state)
if err != nil {
log.Error("Istanbul.Finalize - Error in retrieving the validator set", "leftoverGas", leftoverGas, "err", err)
return err
}

// add validators in snapshot to extraData's validators section
extra, err := assembleExtra(header, snap.validators(), newValSet)
if err != nil {
return err
log.Error("Istanbul.Finalize - Error in retrieving the validator set. Using the previous epoch's validator set", "leftoverGas", leftoverGas, "err", err)
} else {
// add validators in snapshot to extraData's validators section
extra, err := assembleExtra(header, snap.validators(), newValSet)
if err != nil {
return err
}
header.Extra = extra
return nil
}
header.Extra = extra
}
} else {
// If it's not the last block, then the validator set diff should be empty
extra, err := assembleExtra(header, []common.Address{}, []common.Address{})
if err != nil {
return err
}
header.Extra = extra
}

// If it's not the last block or we were unable to pull the new validator set, then the validator set diff should be empty
extra, err := assembleExtra(header, []common.Address{}, []common.Address{})
if err != nil {
return err
}
header.Extra = extra
return nil
}

Expand Down Expand Up @@ -790,7 +782,7 @@ func assembleExtra(header *types.Header, oldValSet []common.Address, newValSet [

addedValidators, removedValidators := istanbul.ValidatorSetDiff(oldValSet, newValSet)

log.Trace("Setting istanbul header validator fields", "oldValSet", common.ConvertToStringSlice(oldValSet), "newValSet", common.ConvertToStringSlice(newValSet),
log.Info("Setting istanbul header validator fields", "oldValSet", common.ConvertToStringSlice(oldValSet), "newValSet", common.ConvertToStringSlice(newValSet),
"addedValidators", common.ConvertToStringSlice(addedValidators), "removedValidators", common.ConvertToStringSlice(removedValidators))

ist := &types.IstanbulExtra{
Expand Down

0 comments on commit a5ab9f2

Please sign in to comment.