diff --git a/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim b/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim index 579c37e46a..26d4787652 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim @@ -428,10 +428,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 @@ -598,7 +602,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 @@ -703,7 +707,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 @@ -722,7 +726,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 @@ -757,7 +761,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: diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index 99f02faf7a..e26a182da6 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -261,9 +261,27 @@ proc getMetadataForNetwork*( proc getRuntimeConfig*( eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} = + ## Returns the run-time config for a network specified on the command line + ## If the network is not explicitly specified, the function will act as the + ## regular Nimbus binary, returning the mainnet config. + ## + ## TODO the assumption that the input variable is a CLI config option is not + ## quite appropriate in such as low-level function. The "assume mainnet by + ## default" behavior is something that should be handled closer to the `conf` + ## layer. if eth2Network.isSome: return getMetadataForNetwork(eth2Network.get).cfg - defaultRuntimeConfig + + when const_preset == "mainnet": + when defined(gnosisChainBinary): + gnosisMetadata.cfg + else: + mainnetMetadata.cfg + else: + # This is a non-standard build (i.e. minimal), and the function was most + # likely executed in a test. The best we can do is return a fully default + # config: + defaultRuntimeConfig proc extractGenesisValidatorRootFromSnapshot*( snapshot: string): Eth2Digest {.raises: [Defect, IOError, SszError].} = diff --git a/beacon_chain/spec/presets.nim b/beacon_chain/spec/presets.nim index 91de88002c..d47e1f1954 100644 --- a/beacon_chain/spec/presets.nim +++ b/beacon_chain/spec/presets.nim @@ -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 # --------------------------------------------------------------- diff --git a/research/block_sim.nim b/research/block_sim.nim index a9a9930501..ccf116285a 100644 --- a/research/block_sim.nim +++ b/research/block_sim.nim @@ -376,7 +376,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 diff --git a/research/simutils.nim b/research/simutils.nim index 310ea626d4..c475f358f5 100644 --- a/research/simutils.nim +++ b/research/simutils.nim @@ -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()))