generalize `ShufflingRef` acceleration logic (#5197) (#5204)

Split up the `ShufflingRef` acceleration logic into generically usable
parts and attester shuffling specific parts. The generic parts could be
used to accelerate other purposes, e.g., REST `/states/xxx/randao` API.
This commit is contained in:
Etan Kissling 2023-07-31 20:12:15 +02:00 committed by GitHub
parent 846e7c585b
commit f8ba2e3882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -749,6 +749,17 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
# the state will be obtained. # the state will be obtained.
bslot.slot.epoch() bslot.slot.epoch()
# Try to obtain RANDAO in an accelerated way
let bsi = node.dag.atSlot(bslot.bid, (qepoch + 1).start_slot - 1)
if bsi.isSome:
let mix = node.dag.computeRandaoMix(bsi.get.bid)
if mix.isSome:
return RestApiResponse.jsonResponseWOpt(
RestEpochRandao(randao: mix.get),
node.getBidOptimistic(bsi.get.bid)
)
# Fall back to full state computation
node.withStateForBlockSlotId(bslot): node.withStateForBlockSlotId(bslot):
withState(state): withState(state):
return RestApiResponse.jsonResponseWOpt( return RestApiResponse.jsonResponseWOpt(

View File

@ -279,6 +279,12 @@ func keysToIndices*(cacheTable: var Table[ValidatorPubKey, ValidatorIndex],
indices[listIndex[]] = some(ValidatorIndex(validatorIndex)) indices[listIndex[]] = some(ValidatorIndex(validatorIndex))
indices indices
proc getBidOptimistic*(node: BeaconNode, bid: BlockId): Option[bool] =
if node.currentSlot().epoch() >= node.dag.cfg.BELLATRIX_FORK_EPOCH:
some[bool](node.dag.is_optimistic(bid))
else:
none[bool]()
proc getShufflingOptimistic*(node: BeaconNode, proc getShufflingOptimistic*(node: BeaconNode,
dependentSlot: Slot, dependentSlot: Slot,
dependentRoot: Eth2Digest): Option[bool] = dependentRoot: Eth2Digest): Option[bool] =