per payload-builder payload builder validator registration (#5431)

This commit is contained in:
tersec 2023-09-20 19:00:37 +02:00 committed by GitHub
parent ee57a07411
commit 351472a2d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 18 deletions

View File

@ -122,23 +122,26 @@ func getPayloadBuilderAddress*(config: BeaconNodeConf): Opt[string] =
else: else:
Opt.none(string) Opt.none(string)
proc getPayloadBuilderAddress*(
node: BeaconNode, pubkey: ValidatorPubKey): Opt[string] =
let defaultPayloadBuilderAddress = node.config.getPayloadBuilderAddress
if node.keymanagerHost.isNil:
defaultPayloadBuilderAddress
else:
node.keymanagerHost[].getBuilderConfig(pubkey).valueOr:
defaultPayloadBuilderAddress
proc getPayloadBuilderClient*( proc getPayloadBuilderClient*(
node: BeaconNode, validator_index: uint64): RestResult[RestClientRef] = node: BeaconNode, validator_index: uint64): RestResult[RestClientRef] =
if not node.config.payloadBuilderEnable: if not node.config.payloadBuilderEnable:
return err "Payload builder globally disabled" return err "Payload builder globally disabled"
let let
defaultPayloadBuilderAddress = node.config.getPayloadBuilderAddress
pubkey = withState(node.dag.headState): pubkey = withState(node.dag.headState):
if validator_index >= forkyState.data.validators.lenu64: if validator_index >= forkyState.data.validators.lenu64:
return err "Validator index too high" return err "Validator index too high"
forkyState.data.validators.item(validator_index).pubkey forkyState.data.validators.item(validator_index).pubkey
payloadBuilderAddress = payloadBuilderAddress = node.getPayloadBuilderAddress(pubkey)
if node.keymanagerHost.isNil:
defaultPayloadBuilderAddress
else:
node.keymanagerHost[].getBuilderConfig(pubkey).valueOr:
defaultPayloadBuilderAddress
if payloadBuilderAddress.isNone: if payloadBuilderAddress.isNone:
return err "Payload builder disabled" return err "Payload builder disabled"

View File

@ -1556,17 +1556,24 @@ proc getValidatorRegistration(
return ok validatorRegistration return ok validatorRegistration
proc registerValidators*(node: BeaconNode, epoch: Epoch) {.async.} = proc registerValidatorsPerBuilder(
node: BeaconNode, payloadBuilderAddress: string, epoch: Epoch,
attachedValidatorPubkeys: seq[ValidatorPubKey]) {.async.} =
const HttpOk = 200
try: try:
if not node.config.payloadBuilderEnable: return let payloadBuilderClient =
RestClientRef.new(payloadBuilderAddress).valueOr:
const HttpOk = 200
let payloadBuilderClient = node.getPayloadBuilderClient(0).valueOr:
debug "Unable to initialize payload builder client while registering validators", debug "Unable to initialize payload builder client while registering validators",
payloadBuilderAddress, epoch,
err = error err = error
return return
if payloadBuilderClient.isNil:
debug "registerValidatorsPerBuilder: got nil payload builder REST client reference",
payloadBuilderAddress, epoch
return
let restBuilderStatus = awaitWithTimeout(payloadBuilderClient.checkBuilderStatus(), let restBuilderStatus = awaitWithTimeout(payloadBuilderClient.checkBuilderStatus(),
BUILDER_STATUS_DELAY_TOLERANCE): BUILDER_STATUS_DELAY_TOLERANCE):
debug "Timeout when obtaining builder status" debug "Timeout when obtaining builder status"
@ -1578,11 +1585,6 @@ proc registerValidators*(node: BeaconNode, epoch: Epoch) {.async.} =
builderStatus = restBuilderStatus builderStatus = restBuilderStatus
return return
# The async aspect of signing the registrations can cause the attached
# validators to change during the loop.
let attachedValidatorPubkeys =
toSeq(node.attachedValidators[].validators.keys)
const emptyNestedSeq = @[newSeq[SignedValidatorRegistrationV1](0)] const emptyNestedSeq = @[newSeq[SignedValidatorRegistrationV1](0)]
# https://github.com/ethereum/builder-specs/blob/v0.3.0/specs/bellatrix/validator.md#validator-registration # https://github.com/ethereum/builder-specs/blob/v0.3.0/specs/bellatrix/validator.md#validator-registration
# Seed with single empty inner list to avoid special cases # Seed with single empty inner list to avoid special cases
@ -1683,6 +1685,23 @@ proc registerValidators*(node: BeaconNode, epoch: Epoch) {.async.} =
warn "registerValidators: exception", warn "registerValidators: exception",
error = exc.msg error = exc.msg
proc registerValidators*(node: BeaconNode, epoch: Epoch) {.async.} =
if not node.config.payloadBuilderEnable: return
var builderKeys: Table[string, seq[ValidatorPubKey]]
for pubkey in node.attachedValidators[].validators.keys:
let payloadBuilderAddress = node.getPayloadBuilderAddress(pubkey).valueOr:
continue
if payloadBuilderAddress in builderKeys:
builderKeys[payloadBuilderAddress].add pubkey
else:
builderKeys[payloadBuilderAddress] = @[pubkey]
for payloadBuilderAddress in builderKeys.keys:
await node.registerValidatorsPerBuilder(
payloadBuilderAddress, epoch, builderKeys[payloadBuilderAddress])
proc updateValidators( proc updateValidators(
node: BeaconNode, validators: openArray[Validator]) = node: BeaconNode, validators: openArray[Validator]) =
# Since validator indicies are stable, we only check the "updated" range - # Since validator indicies are stable, we only check the "updated" range -