dependent slot helpers

This commit is contained in:
Jacek Sieka 2023-05-16 10:21:52 +02:00
parent 3acbb3ea6c
commit 83393cea8d
No known key found for this signature in database
GPG Key ID: A1B09461ABB656B8
6 changed files with 25 additions and 9 deletions

View File

@ -64,9 +64,10 @@ OK: 24/24 Fail: 0/24 Skip: 0/24
OK: 7/7 Fail: 0/7 Skip: 0/7
## Beacon time
```diff
+ Dependent slots OK
+ basics OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
OK: 2/2 Fail: 0/2 Skip: 0/2
## Block pool altair processing [Preset: mainnet]
```diff
+ Invalid signatures [Preset: mainnet] OK
@ -676,4 +677,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 9/9 Fail: 0/9 Skip: 0/9
---TOTAL---
OK: 385/390 Fail: 0/390 Skip: 5/390
OK: 386/391 Fail: 0/391 Skip: 5/391

View File

@ -353,8 +353,11 @@ type
block_root* {.serializedFieldName: "block".}: Eth2Digest
optimistic* {.serializedFieldName: "execution_optimistic".}: Option[bool]
func attester_dependent_slot*(shuffling: ShufflingRef): Slot =
dependent_slot((if shuffling.epoch == 0: Epoch(0) else: shuffling.epoch - 1))
func proposer_dependent_slot*(epochRef: EpochRef): Slot =
epochRef.key.epoch.proposer_dependent_slot()
func attester_dependent_slot*(shufflingRef: ShufflingRef): Slot =
shufflingRef.epoch.attester_dependent_slot()
template head*(dag: ChainDAGRef): BlockRef = dag.headState.blck

View File

@ -480,7 +480,7 @@ func findShufflingRef*(
## Lookup a shuffling in the cache, returning `none` if it's not present - see
## `getShufflingRef` for a version that creates a new instance if it's missing
let
dependent_slot = if epoch >= 2: (epoch - 1).start_slot() - 1 else: Slot(0)
dependent_slot = epoch.attester_dependent_slot()
dependent_bsi = dag.atSlot(bid, dependent_slot).valueOr:
return Opt.none(ShufflingRef)

View File

@ -156,7 +156,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
res
let optimistic = node.getShufflingOptimistic(
(qepoch + 1).shufflingDependentSlot,
epochRef.proposer_dependent_slot,
epochRef.proposer_dependent_root)
return RestApiResponse.jsonResponseWRoot(

View File

@ -254,9 +254,11 @@ template start_slot*(period: SyncCommitteePeriod): Slot =
if period >= maxPeriod: FAR_FUTURE_SLOT
else: Slot(period * SLOTS_PER_SYNC_COMMITTEE_PERIOD)
func dependent_slot*(epoch: Epoch): Slot =
if epoch == 0: Slot(0)
else: epoch.start_slot() - 1
func proposer_dependent_slot*(epoch: Epoch): Slot =
if epoch >= 1: epoch.start_slot() - 1 else: Slot(0)
func attester_dependent_slot*(epoch: Epoch): Slot =
if epoch >= 2: (epoch - 1).start_slot() - 1 else: Slot(0)
func `$`*(t: BeaconTime): string =
if t.ns_since_genesis >= 0:

View File

@ -54,3 +54,13 @@ suite "Beacon time":
counts += 1
check:
counts == 2
test "Dependent slots":
check:
Epoch(0).proposer_dependent_slot() == Slot(0)
Epoch(1).proposer_dependent_slot() == Epoch(1).start_slot() - 1
Epoch(2).proposer_dependent_slot() == Epoch(2).start_slot() - 1
Epoch(0).attester_dependent_slot() == Slot(0)
Epoch(1).attester_dependent_slot() == Slot(0)
Epoch(2).attester_dependent_slot() == Epoch(1).start_slot() - 1