From 4c3850f7dfada0f798385567cb9caad078f58e38 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Fri, 19 May 2023 04:08:02 +0300 Subject: [PATCH] Disable the use of incbin as it breaks the retail build on Linux/ARM --- beacon_chain/networking/network_metadata.nim | 84 ++++++++++++-------- beacon_chain/nimbus_beacon_node.nim | 4 +- beacon_chain/nimbus_light_client.nim | 4 +- tests/test_network_metadata.nim | 2 +- 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index b477cb86ec..88b3f48dec 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -31,6 +31,13 @@ import export ethtypes, conversions, RuntimeConfig +const + vendorDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor" + + # TODO: Currently, this breaks the Linux/ARM packaging due + # to a toolchain incompatibility problem + incbinEnabled* = false + type Eth1BlockHash* = ethtypes.BlockHash @@ -64,11 +71,21 @@ type # `genesisData` will have `len == 0` for networks with a still # unknown genesis state. - genesisData*: seq[byte] - genesisDepositsSnapshot*: seq[byte] + when incbinEnabled: + genesisData*: seq[byte] + else: + genesisData*: string + + genesisDepositsSnapshot*: string else: incompatibilityDesc*: string +template genesisBytes*(metadata: Eth2NetworkMetadata): auto = + when incbinEnabled: + metadata.genesisData + else: + metadata.genesisData.toOpenArrayByte(0, metadata.genesisData.high) + proc readBootstrapNodes*(path: string): seq[string] {.raises: [IOError].} = # Read a list of ENR values from a YAML file containing a flat list of entries if fileExists(path): @@ -157,14 +174,17 @@ proc loadEth2NetworkMetadata*( readBootEnr(bootEnrPath)) genesisData = if loadGenesis and fileExists(genesisPath): - toBytes(readFile(genesisPath)) + when incbinEnabled: + toBytes readFile(genesisPath) + else: + readFile(genesisPath) else: - @[] + "" genesisDepositsSnapshot = if fileExists(genesisDepositsSnapshotPath): - toBytes(readFile(genesisDepositsSnapshotPath)) + readFile(genesisDepositsSnapshotPath) else: - @[] + "" Eth2NetworkMetadata( incompatible: false, @@ -196,21 +216,19 @@ proc loadCompileTimeNetworkMetadata( else: macros.error "config.yaml not found for network '" & path -const vendorDir = - currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor" - when const_preset == "gnosis": import stew/assign2 - let - gnosisGenesis {.importc: "gnosis_mainnet_genesis".}: ptr UncheckedArray[byte] - gnosisGenesisSize {.importc: "gnosis_mainnet_genesis_size".}: int - - {.compile: "network_metadata_gnosis.S".} + when incbinEnabled: + let + gnosisGenesis {.importc: "gnosis_mainnet_genesis".}: ptr UncheckedArray[byte] + gnosisGenesisSize {.importc: "gnosis_mainnet_genesis_size".}: int + {.compile: "network_metadata_gnosis.S".} const gnosisMetadata = loadCompileTimeNetworkMetadata( - vendorDir & "/gnosis-chain-configs/mainnet") + vendorDir & "/gnosis-chain-configs/mainnet", + none(Eth1Network), not incbinEnabled) static: checkForkConsistency(gnosisMetadata.cfg) @@ -220,30 +238,31 @@ when const_preset == "gnosis": elif const_preset == "mainnet": import stew/assign2 - # Nim is very inefficent at loading large constants from binary files so we - # use this trick instead which saves significant amounts of compile time - let - mainnetGenesis {.importc: "eth2_mainnet_genesis".}: ptr UncheckedArray[byte] - mainnetGenesisSize {.importc: "eth2_mainnet_genesis_size".}: int + when incbinEnabled: + # Nim is very inefficent at loading large constants from binary files so we + # use this trick instead which saves significant amounts of compile time + let + mainnetGenesis {.importc: "eth2_mainnet_genesis".}: ptr UncheckedArray[byte] + mainnetGenesisSize {.importc: "eth2_mainnet_genesis_size".}: int - praterGenesis {.importc: "eth2_goerli_genesis".}: ptr UncheckedArray[byte] - praterGenesisSize {.importc: "eth2_goerli_genesis_size".}: int + praterGenesis {.importc: "eth2_goerli_genesis".}: ptr UncheckedArray[byte] + praterGenesisSize {.importc: "eth2_goerli_genesis_size".}: int - sepoliaGenesis {.importc: "eth2_sepolia_genesis".}: ptr UncheckedArray[byte] - sepoliaGenesisSize {.importc: "eth2_sepolia_genesis_size".}: int + sepoliaGenesis {.importc: "eth2_sepolia_genesis".}: ptr UncheckedArray[byte] + sepoliaGenesisSize {.importc: "eth2_sepolia_genesis_size".}: int - {.compile: "network_metadata_mainnet.S".} + {.compile: "network_metadata_mainnet.S".} const eth2NetworksDir = vendorDir & "/eth2-networks" sepoliaDir = vendorDir & "/sepolia" mainnetMetadata = loadCompileTimeNetworkMetadata( - vendorDir & "/eth2-networks/shared/mainnet", some mainnet, false) + vendorDir & "/eth2-networks/shared/mainnet", some mainnet, not incbinEnabled) praterMetadata = loadCompileTimeNetworkMetadata( - vendorDir & "/eth2-networks/shared/prater", some goerli, false) + vendorDir & "/eth2-networks/shared/prater", some goerli, not incbinEnabled) sepoliaMetadata = loadCompileTimeNetworkMetadata( - vendorDir & "/sepolia/bepolia", some sepolia, false) + vendorDir & "/sepolia/bepolia", some sepolia, not incbinEnabled) static: for network in [mainnetMetadata, praterMetadata, sepoliaMetadata]: @@ -272,9 +291,12 @@ proc getMetadataForNetwork*( warn "Ropsten is unsupported; https://blog.ethereum.org/2022/11/30/ropsten-shutdown-announcement suggests migrating to Goerli or Sepolia" template withGenesis(metadata, genesis: untyped): untyped = - var tmp = metadata - assign(tmp.genesisData, genesis.toOpenArray(0, `genesis Size` - 1)) - tmp + when incbinEnabled: + var tmp = metadata + assign(tmp.genesisData, genesis.toOpenArray(0, `genesis Size` - 1)) + tmp + else: + metadata let metadata = when const_preset == "gnosis": diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 4e70680d75..3d3c01d9fa 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -542,7 +542,7 @@ proc init*(T: type BeaconNode, var genesisState = if metadata.genesisData.len > 0: try: - newClone readSszForkedHashedBeaconState(cfg, metadata.genesisData) + newClone readSszForkedHashedBeaconState(cfg, metadata.genesisBytes) except CatchableError as err: raiseAssert "Invalid baked-in state: " & err.msg else: @@ -2028,7 +2028,7 @@ proc handleStartUpCmd(config: var BeaconNodeConf) {.raises: [Defect, CatchableEr stateId: "finalized") genesis = if network.genesisData.len > 0: - newClone(readSszForkedHashedBeaconState(cfg, network.genesisData)) + newClone(readSszForkedHashedBeaconState(cfg, network.genesisBytes)) else: nil if config.blockId.isSome(): diff --git a/beacon_chain/nimbus_light_client.nim b/beacon_chain/nimbus_light_client.nim index a7f8301c4a..c8d1f12f82 100644 --- a/beacon_chain/nimbus_light_client.nim +++ b/beacon_chain/nimbus_light_client.nim @@ -11,7 +11,7 @@ import eth/db/kvstore_sqlite3, eth/keys, ./el/el_manager, ./gossip_processing/optimistic_processor, - ./networking/topic_params, + ./networking/[topic_params, network_metadata], ./spec/beaconstate, ./spec/datatypes/[phase0, altair, bellatrix, capella, deneb], "."/[filepath, light_client, light_client_db, nimbus_binary_common, version] @@ -65,7 +65,7 @@ programMain: let genesisState = try: - newClone(readSszForkedHashedBeaconState(cfg, metadata.genesisData)) + newClone(readSszForkedHashedBeaconState(cfg, metadata.genesisBytes)) except CatchableError as err: raiseAssert "Invalid baked-in state: " & err.msg diff --git a/tests/test_network_metadata.nim b/tests/test_network_metadata.nim index 3e59d4bdc3..ad4e4f6602 100644 --- a/tests/test_network_metadata.nim +++ b/tests/test_network_metadata.nim @@ -17,7 +17,7 @@ template checkRoot(name, root) = metadata = getMetadataForNetwork(name) cfg = metadata.cfg state = newClone(readSszForkedHashedBeaconState( - metadata.cfg, metadata.genesisData)) + metadata.cfg, metadata.genesisBytes)) check: $getStateRoot(state[]) == root