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:
parent
846e7c585b
commit
f8ba2e3882
|
@ -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(
|
||||||
|
|
|
@ -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] =
|
||||||
|
|
Loading…
Reference in New Issue