Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and document some usages of defaultRuntimeConfig #4147

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions beacon_chain/spec/presets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
# ---------------------------------------------------------------
Expand All @@ -130,8 +134,6 @@ when const_preset == "mainnet":
"0x0000000000000000000000000000000000000000000000000000000000000000"),
# TODO TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: Epoch(uint64.high),



# Genesis
# ---------------------------------------------------------------
# `2**14` (= 16,384)
Expand All @@ -143,7 +145,6 @@ when const_preset == "mainnet":
# 604800 seconds (7 days)
GENESIS_DELAY: 604800,


# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
Expand All @@ -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
# ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion research/block_sim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion research/simutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down