Fix and document some usages of defaultRuntimeConfig (#4147)
Other changes: * Make the light client store compatible with phase0-only networks and simulations
This commit is contained in:
parent
32039e95f0
commit
7c783644a2
|
@ -434,10 +434,14 @@ proc cacheLightClientData(
|
|||
if dag.lcDataStore.cache.data.hasKeyOrPut(bid, cachedData):
|
||||
doAssert false, "Redundant `cacheLightClientData` call"
|
||||
|
||||
func shouldImportLcData(dag: ChainDAGref): bool =
|
||||
dag.lcDataStore.importMode != LightClientDataImportMode.None and
|
||||
dag.cfg.ALTAIR_FORK_EPOCH != FAR_FUTURE_EPOCH
|
||||
|
||||
proc deleteLightClientData*(dag: ChainDAGRef, bid: BlockId) =
|
||||
## Delete cached light client data for a given block. This needs to be called
|
||||
## when a block becomes unreachable due to finalization of a different fork.
|
||||
if dag.lcDataStore.importMode == LightClientDataImportMode.None:
|
||||
if not dag.shouldImportLcData:
|
||||
return
|
||||
|
||||
dag.lcDataStore.cache.data.del bid
|
||||
|
@ -604,7 +608,7 @@ proc createLightClientUpdates(
|
|||
|
||||
proc initLightClientDataCache*(dag: ChainDAGRef) =
|
||||
## Initialize cached light client data
|
||||
if dag.lcDataStore.importMode == LightClientDataImportMode.None:
|
||||
if not dag.shouldImportLcData:
|
||||
return
|
||||
|
||||
# Prune non-finalized data
|
||||
|
@ -709,7 +713,7 @@ proc processNewBlockForLightClient*(
|
|||
signedBlock: ForkyTrustedSignedBeaconBlock,
|
||||
parentBid: BlockId) =
|
||||
## Update light client data with information from a new block.
|
||||
if dag.lcDataStore.importMode == LightClientDataImportMode.None:
|
||||
if not dag.shouldImportLcData:
|
||||
return
|
||||
if signedBlock.message.slot < dag.lcDataStore.cache.tailSlot:
|
||||
return
|
||||
|
@ -731,7 +735,7 @@ proc processNewBlockForLightClient*(
|
|||
proc processHeadChangeForLightClient*(dag: ChainDAGRef) =
|
||||
## Update light client data to account for a new head block.
|
||||
## Note that `dag.finalizedHead` is not yet updated when this is called.
|
||||
if dag.lcDataStore.importMode == LightClientDataImportMode.None:
|
||||
if not dag.shouldImportLcData:
|
||||
return
|
||||
if dag.head.slot < dag.lcDataStore.cache.tailSlot:
|
||||
return
|
||||
|
@ -766,7 +770,7 @@ proc processFinalizationForLightClient*(
|
|||
## Prune cached data that is no longer useful for creating future
|
||||
## `LightClientUpdate` and `LightClientBootstrap` instances.
|
||||
## This needs to be called whenever `finalized_checkpoint` changes.
|
||||
if dag.lcDataStore.importMode == LightClientDataImportMode.None:
|
||||
if not dag.shouldImportLcData:
|
||||
return
|
||||
let finalizedSlot = dag.finalizedHead.slot
|
||||
if finalizedSlot < dag.lcDataStore.cache.tailSlot:
|
||||
|
|
|
@ -103,8 +103,12 @@ when const_preset == "mainnet":
|
|||
# TODO Move this to RuntimeConfig
|
||||
const SECONDS_PER_SLOT* {.intdefine.}: uint64 = 12
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/configs/mainnet.yaml
|
||||
# TODO Read these from yaml file
|
||||
# The default run-time config specifies the default configuration values
|
||||
# that will be used if a particular run-time config is missing specific
|
||||
# confugration values (which will be then taken from this config object).
|
||||
# It mostly matches the mainnet config with the exception of few properties
|
||||
# such as `CONFIG_NAME`, `TERMINAL_TOTAL_DIFFICULTY`, `*_FORK_EPOCH`, etc
|
||||
# which must be effectively overriden in all network (including mainnet).
|
||||
const defaultRuntimeConfig* = RuntimeConfig(
|
||||
# Mainnet config
|
||||
|
||||
|
@ -118,7 +122,7 @@ when const_preset == "mainnet":
|
|||
# * 'ropsten' - testnet
|
||||
# * 'sepolia' - testnet
|
||||
# Must match the regex: [a-z0-9\-]
|
||||
CONFIG_NAME: "mainnet",
|
||||
CONFIG_NAME: "",
|
||||
|
||||
# Transition
|
||||
# ---------------------------------------------------------------
|
||||
|
@ -130,8 +134,6 @@ when const_preset == "mainnet":
|
|||
"0x0000000000000000000000000000000000000000000000000000000000000000"),
|
||||
# TODO TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: Epoch(uint64.high),
|
||||
|
||||
|
||||
|
||||
# Genesis
|
||||
# ---------------------------------------------------------------
|
||||
# `2**14` (= 16,384)
|
||||
|
@ -143,7 +145,6 @@ when const_preset == "mainnet":
|
|||
# 604800 seconds (7 days)
|
||||
GENESIS_DELAY: 604800,
|
||||
|
||||
|
||||
# Forking
|
||||
# ---------------------------------------------------------------
|
||||
# Some forks are disabled for now:
|
||||
|
@ -152,17 +153,16 @@ when const_preset == "mainnet":
|
|||
|
||||
# Altair
|
||||
ALTAIR_FORK_VERSION: Version [byte 0x01, 0x00, 0x00, 0x00],
|
||||
ALTAIR_FORK_EPOCH: Epoch(74240), # Oct 27, 2021, 10:56:23am UTC
|
||||
ALTAIR_FORK_EPOCH: FAR_FUTURE_EPOCH,
|
||||
# Bellatrix
|
||||
BELLATRIX_FORK_VERSION: Version [byte 0x02, 0x00, 0x00, 0x00],
|
||||
BELLATRIX_FORK_EPOCH: Epoch(uint64.high),
|
||||
BELLATRIX_FORK_EPOCH: FAR_FUTURE_EPOCH,
|
||||
# Capella
|
||||
CAPELLA_FORK_VERSION: Version [byte 0x03, 0x00, 0x00, 0x00],
|
||||
CAPELLA_FORK_EPOCH: Epoch(uint64.high),
|
||||
CAPELLA_FORK_EPOCH: FAR_FUTURE_EPOCH,
|
||||
# Sharding
|
||||
SHARDING_FORK_VERSION: Version [byte 0x04, 0x00, 0x00, 0x00],
|
||||
SHARDING_FORK_EPOCH: Epoch(uint64.high),
|
||||
|
||||
SHARDING_FORK_EPOCH: FAR_FUTURE_EPOCH,
|
||||
|
||||
# Time parameters
|
||||
# ---------------------------------------------------------------
|
||||
|
|
|
@ -590,7 +590,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
|||
|
||||
while true:
|
||||
let nextBlockTime = lastEth1BlockAt +
|
||||
max(1.0, gauss(r, float defaultRuntimeConfig.SECONDS_PER_ETH1_BLOCK, 3.0))
|
||||
max(1.0, gauss(r, float cfg.SECONDS_PER_ETH1_BLOCK, 3.0))
|
||||
if nextBlockTime > now:
|
||||
break
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ proc loadGenesis*(validators: Natural, validate: bool):
|
|||
&"deposit_contract_snapshot_{const_preset}_{validators}_{SPEC_VERSION}.ssz"
|
||||
cfg = defaultRuntimeConfig
|
||||
|
||||
|
||||
if fileExists(genesisFn) and fileExists(contractSnapshotFn):
|
||||
let res = newClone(readSszForkedHashedBeaconState(
|
||||
cfg, readAllBytes(genesisFn).tryGet()))
|
||||
|
|
Loading…
Reference in New Issue