1
1
# beacon_chain
2
- # Copyright (c) 2021-2024 Status Research & Development GmbH
2
+ # Copyright (c) 2021-2025 Status Research & Development GmbH
3
3
# Licensed and distributed under either of
4
4
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
5
5
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
236
236
beaconGenesis* : RestGenesis
237
237
proposerTasks* : Table[Slot, seq [ProposerTask]]
238
238
dynamicFeeRecipientsStore* : ref DynamicFeeRecipientsStore
239
- validatorsRegCache* : Table[ValidatorPubKey, SignedValidatorRegistrationV1]
240
239
blocksSeen* : Table[Slot, BlockDataItem]
241
240
rootsSeen* : Table[Eth2Digest, Slot]
242
241
processingDelay* : Opt[Duration]
@@ -1059,68 +1058,64 @@ proc isExpired(vc: ValidatorClientRef,
1059
1058
EPOCHS_BETWEEN_VALIDATOR_REGISTRATION
1060
1059
1061
1060
proc getValidatorRegistration(
1062
- vc: ValidatorClientRef,
1063
- validator: AttachedValidator,
1064
- timestamp: Time,
1065
- fork: Fork
1066
- ): Result[PendingValidatorRegistration, RegistrationKind] =
1061
+ vc: ValidatorClientRef,
1062
+ validator: AttachedValidator,
1063
+ timestamp: Time,
1064
+ fork: Fork
1065
+ ): Result[PendingValidatorRegistration, RegistrationKind] =
1067
1066
if validator.index.isNone():
1068
1067
debug " Validator registration missing validator index" ,
1069
1068
validator = validatorLog(validator)
1070
1069
return err(RegistrationKind.MissingIndex)
1071
1070
1072
1071
let
1073
- cached = vc.validatorsRegCache.getOrDefault(validator.pubkey)
1074
1072
currentSlot =
1075
1073
block :
1076
1074
let res = vc.beaconClock.toSlot(timestamp)
1077
1075
if not (res.afterGenesis):
1078
1076
return err(RegistrationKind.IncorrectTime)
1079
1077
res.slot
1080
1078
1081
- if cached.isDefault() or vc.isExpired(cached, currentSlot):
1082
- if not cached.isDefault():
1083
- # Want to send it to relay, but not recompute perfectly fine cache
1084
- return ok(PendingValidatorRegistration(registration: cached, future: nil ))
1079
+ if validator.externalBuilderRegistration.isSome():
1080
+ let cached = validator.externalBuilderRegistration.get()
1081
+ return
1082
+ if not (vc.isExpired(cached, currentSlot)):
1083
+ err(RegistrationKind.Cached)
1084
+ else :
1085
+ ok(PendingValidatorRegistration(registration: cached, future: nil ))
1085
1086
1086
- let
1087
- feeRecipient = vc.getFeeRecipient(validator, currentSlot.epoch())
1088
- gasLimit = vc.getGasLimit(validator)
1089
- var registration =
1090
- SignedValidatorRegistrationV1(
1091
- message: ValidatorRegistrationV1 (
1092
- fee_recipient: ExecutionAddress(data: distinctBase(feeRecipient)),
1093
- gas_limit: gasLimit ,
1094
- timestamp: uint64 (timestamp.toUnix()) ,
1095
- pubkey: validator.pubkey
1096
- )
1087
+ let
1088
+ feeRecipient = vc.getFeeRecipient(validator, currentSlot.epoch())
1089
+ gasLimit = vc.getGasLimit(validator)
1090
+
1091
+ var registration =
1092
+ SignedValidatorRegistrationV1 (
1093
+ message: ValidatorRegistrationV1(
1094
+ fee_recipient: ExecutionAddress(data: distinctBase(feeRecipient)) ,
1095
+ gas_limit: gasLimit ,
1096
+ timestamp: uint64 (timestamp.toUnix()),
1097
+ pubkey: validator.pubkey
1097
1098
)
1098
-
1099
- let sigfut = validator.getBuilderSignature(fork, registration.message)
1100
- if sigfut.finished():
1101
- # This is short-path if we able to create signature locally.
1102
- if not (sigfut.completed()):
1103
- let exc = sigfut.error()
1104
- debug " Got unexpected exception while signing validator registration" ,
1105
- validator = validatorLog(validator), error = exc.name,
1106
- reason = exc.msg
1107
- return err(RegistrationKind.ErrorSignature)
1108
- let sigres = sigfut.value()
1109
- if sigres.isErr():
1110
- debug " Failed to get signature for validator registration" ,
1111
- validator = validatorLog(validator), reason = sigres.error()
1112
- return err(RegistrationKind.NoSignature)
1113
- registration.signature = sigres.get()
1114
- # Updating cache table with new signed registration data
1115
- vc.validatorsRegCache[registration.message.pubkey] = registration
1116
- ok(PendingValidatorRegistration(registration: registration, future: nil ))
1117
- else :
1118
- # Remote signature service involved, cache will be updated later.
1119
- ok(PendingValidatorRegistration(registration: registration,
1120
- future: sigfut))
1099
+ )
1100
+
1101
+ let sigfut = validator.getBuilderSignature(fork, registration.message)
1102
+ if sigfut.finished():
1103
+ # This is short-path if we able to create signature locally.
1104
+ if not (sigfut.completed()):
1105
+ let exc = sigfut.error()
1106
+ debug " Got unexpected exception while signing validator registration" ,
1107
+ validator = validatorLog(validator), error = exc.name,
1108
+ reason = exc.msg
1109
+ return err(RegistrationKind.ErrorSignature)
1110
+
1111
+ registration.signature = sigfut.value().valueOr:
1112
+ debug " Failed to get signature for validator registration" ,
1113
+ validator = validatorLog(validator), reason = error
1114
+ return err(RegistrationKind.NoSignature)
1115
+
1116
+ ok(PendingValidatorRegistration(registration: registration, future: nil ))
1121
1117
else :
1122
- # Returning cached result.
1123
- err(RegistrationKind.Cached)
1118
+ ok(PendingValidatorRegistration(registration: registration, future: sigfut))
1124
1119
1125
1120
proc prepareRegistrationList* (
1126
1121
vc: ValidatorClientRef,
@@ -1131,6 +1126,7 @@ proc prepareRegistrationList*(
1131
1126
1132
1127
var
1133
1128
messages: seq [SignedValidatorRegistrationV1]
1129
+ validators: seq [AttachedValidator]
1134
1130
futures: seq [Future[SignatureResult]]
1135
1131
registrations: seq [SignedValidatorRegistrationV1]
1136
1132
total = vc.attachedValidators[].count()
@@ -1151,6 +1147,7 @@ proc prepareRegistrationList*(
1151
1147
registrations.add(preg.registration)
1152
1148
else :
1153
1149
messages.add(preg.registration)
1150
+ validators.add(validator)
1154
1151
futures.add(preg.future)
1155
1152
else :
1156
1153
case res.error()
@@ -1174,8 +1171,7 @@ proc prepareRegistrationList*(
1174
1171
var reg = messages[index]
1175
1172
reg.signature = sres.get()
1176
1173
registrations.add(reg)
1177
- # Updating cache table
1178
- vc.validatorsRegCache[reg.message.pubkey] = reg
1174
+ validators[index].externalBuilderRegistration = Opt.some(reg)
1179
1175
inc(succeed)
1180
1176
else :
1181
1177
inc(bad)
0 commit comments