Skip to content

Commit

Permalink
dependent slot helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed May 16, 2023
1 parent 3acbb3e commit 83393ce
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
5 changes: 3 additions & 2 deletions AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 5 additions & 2 deletions beacon_chain/consensus_object_pools/block_pools_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/rpc/rest_validator_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions beacon_chain/spec/beacon_time.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_beacon_time.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 83393ce

Please sign in to comment.