pass `cfg` to `ETHBeaconClockCreateFromState` LC API (#6071)

We don't need the `cfg` right now, but it makes sense to have the object
passed to the clock so that the API doesn't break if we want to support
configurable `SECONDS_PER_SLOT`. As the `libnimbus_lc` library is not
yet widely used, better to add the argument now than later.
This commit is contained in:
Etan Kissling 2024-03-13 13:01:39 +01:00 committed by GitHub
parent 8bd8ffe2bb
commit efb1971d7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View File

@ -211,7 +211,7 @@ typedef struct ETHForkDigests ETHForkDigests;
* Creates a fork digests cache for a given beacon state. * Creates a fork digests cache for a given beacon state.
* *
* - The fork digests cache must be destroyed with `ETHForkDigestsDestroy` * - The fork digests cache must be destroyed with `ETHForkDigestsDestroy`
* once no longer needed, to release memory. * once no longer needed, to release memory.
* *
* @param cfg Ethereum Consensus Layer network configuration. * @param cfg Ethereum Consensus Layer network configuration.
* @param state Beacon state. * @param state Beacon state.
@ -244,13 +244,15 @@ typedef struct ETHBeaconClock ETHBeaconClock;
* - The beacon clock must be destroyed with `ETHBeaconClockDestroy` * - The beacon clock must be destroyed with `ETHBeaconClockDestroy`
* once no longer needed, to release memory. * once no longer needed, to release memory.
* *
* @param cfg Ethereum Consensus Layer network configuration.
* @param state Beacon state. * @param state Beacon state.
* *
* @return Pointer to an initialized beacon clock based on the beacon state or * @return Pointer to an initialized beacon clock based on the beacon state or
* NULL if the state contained an invalid time. * NULL if the state contained an invalid time.
*/ */
ETH_RESULT_USE_CHECK ETH_RESULT_USE_CHECK
ETHBeaconClock *ETHBeaconClockCreateFromState(const ETHBeaconState *state); ETHBeaconClock *ETHBeaconClockCreateFromState(
const ETHConsensusConfig *cfg, const ETHBeaconState *state);
/** /**
* Destroys a beacon clock. * Destroys a beacon clock.

View File

@ -230,6 +230,7 @@ proc ETHForkDigestsDestroy(forkDigests: ptr ForkDigests) {.exported.} =
forkDigests.destroy() forkDigests.destroy()
proc ETHBeaconClockCreateFromState( proc ETHBeaconClockCreateFromState(
cfg: ptr RuntimeConfig,
state: ptr ForkedHashedBeaconState): ptr BeaconClock {.exported.} = state: ptr ForkedHashedBeaconState): ptr BeaconClock {.exported.} =
## Creates a beacon clock for a given beacon state's `genesis_time` field. ## Creates a beacon clock for a given beacon state's `genesis_time` field.
## ##
@ -237,11 +238,12 @@ proc ETHBeaconClockCreateFromState(
## once no longer needed, to release memory. ## once no longer needed, to release memory.
## ##
## Parameters: ## Parameters:
## * `cfg` - Ethereum Consensus Layer network configuration.
## * `state` - Beacon state. ## * `state` - Beacon state.
## ##
## Returns: ## Returns:
## * Pointer to an initialized beacon clock based on the beacon state or NULL ## * Pointer to an initialized beacon clock based on the beacon state or
## if the state contained an invalid time. ## NULL if the state contained an invalid time.
let beaconClock = BeaconClock.new() let beaconClock = BeaconClock.new()
beaconClock[] = beaconClock[] =
BeaconClock.init(getStateField(state[], genesis_time)).valueOr: BeaconClock.init(getStateField(state[], genesis_time)).valueOr:

View File

@ -1,6 +1,6 @@
/** /**
* beacon_chain * beacon_chain
* Copyright (c) 2023 Status Research & Development GmbH * Copyright (c) 2023-2024 Status Research & Development GmbH
* Licensed and distributed under either of * Licensed and distributed under either of
* * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). * * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
* * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). * * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -268,7 +268,7 @@ int main(void)
ETHBeaconState *genesisState = loadGenesis(cfg, __DIR__ "/test_files/genesis.ssz"); ETHBeaconState *genesisState = loadGenesis(cfg, __DIR__ "/test_files/genesis.ssz");
ETHRoot *genesisValRoot = ETHBeaconStateCopyGenesisValidatorsRoot(genesisState); ETHRoot *genesisValRoot = ETHBeaconStateCopyGenesisValidatorsRoot(genesisState);
ETHForkDigests *forkDigests = ETHForkDigestsCreateFromState(cfg, genesisState); ETHForkDigests *forkDigests = ETHForkDigestsCreateFromState(cfg, genesisState);
ETHBeaconClock *beaconClock = ETHBeaconClockCreateFromState(genesisState); ETHBeaconClock *beaconClock = ETHBeaconClockCreateFromState(cfg, genesisState);
ETHBeaconStateDestroy(genesisState); ETHBeaconStateDestroy(genesisState);
printf("Current slot: %d\n", ETHBeaconClockGetSlot(beaconClock)); printf("Current slot: %d\n", ETHBeaconClockGetSlot(beaconClock));
printf("\n"); printf("\n");