@@ -31,6 +31,13 @@ import
3131export
3232 ethtypes, conversions, RuntimeConfig
3333
34+ const
35+ vendorDir = currentSourcePath.parentDir.replace ('\\ ' , '/' ) & " /../../vendor"
36+
37+ # TODO : Currently, this breaks the Linux/ARM packaging due
38+ # to a toolchain incompatibility problem
39+ incbinEnabled* = false
40+
3441type
3542 Eth1BlockHash * = ethtypes.BlockHash
3643
6471
6572 # `genesisData` will have `len == 0` for networks with a still
6673 # unknown genesis state.
67- genesisData* : seq [byte ]
68- genesisDepositsSnapshot* : seq [byte ]
74+ when incbinEnabled:
75+ genesisData* : seq [byte ]
76+ else :
77+ genesisData* : string
78+
79+ genesisDepositsSnapshot* : string
6980 else :
7081 incompatibilityDesc* : string
7182
83+ template genesisBytes * (metadata: Eth2NetworkMetadata ): auto =
84+ when incbinEnabled:
85+ metadata.genesisData
86+ else :
87+ metadata.genesisData.toOpenArrayByte (0 , metadata.genesisData.high)
88+
7289proc readBootstrapNodes * (path: string ): seq [string ] {.raises : [IOError ].} =
7390 # Read a list of ENR values from a YAML file containing a flat list of entries
7491 if fileExists (path):
@@ -157,14 +174,17 @@ proc loadEth2NetworkMetadata*(
157174 readBootEnr (bootEnrPath))
158175
159176 genesisData = if loadGenesis and fileExists (genesisPath):
160- toBytes (readFile (genesisPath))
177+ when incbinEnabled:
178+ toBytes readFile (genesisPath)
179+ else :
180+ readFile (genesisPath)
161181 else :
162- @ []
182+ " "
163183
164184 genesisDepositsSnapshot = if fileExists (genesisDepositsSnapshotPath):
165- toBytes ( readFile (genesisDepositsSnapshotPath) )
185+ readFile (genesisDepositsSnapshotPath)
166186 else :
167- @ []
187+ " "
168188
169189 Eth2NetworkMetadata (
170190 incompatible: false ,
@@ -196,21 +216,19 @@ proc loadCompileTimeNetworkMetadata(
196216 else :
197217 macros.error " config.yaml not found for network '" & path
198218
199- const vendorDir =
200- currentSourcePath.parentDir.replace ('\\ ' , '/' ) & " /../../vendor"
201-
202219when const_preset == " gnosis" :
203220 import stew/ assign2
204221
205- let
206- gnosisGenesis {. importc : " gnosis_mainnet_genesis " .}: ptr UncheckedArray [ byte ]
207- gnosisGenesisSize {.importc : " gnosis_mainnet_genesis_size " .}: int
208-
209- {.compile : " network_metadata_gnosis.S" .}
222+ when incbinEnabled:
223+ let
224+ gnosisGenesis {.importc : " gnosis_mainnet_genesis " .}: ptr UncheckedArray [ byte ]
225+ gnosisGenesisSize {. importc : " gnosis_mainnet_genesis_size " .}: int
226+ {.compile : " network_metadata_gnosis.S" .}
210227
211228 const
212229 gnosisMetadata = loadCompileTimeNetworkMetadata (
213- vendorDir & " /gnosis-chain-configs/mainnet" )
230+ vendorDir & " /gnosis-chain-configs/mainnet" ,
231+ none (Eth1Network ), not incbinEnabled)
214232
215233 static :
216234 checkForkConsistency (gnosisMetadata.cfg)
@@ -220,30 +238,31 @@ when const_preset == "gnosis":
220238elif const_preset == " mainnet" :
221239 import stew/ assign2
222240
223- # Nim is very inefficent at loading large constants from binary files so we
224- # use this trick instead which saves significant amounts of compile time
225- let
226- mainnetGenesis {.importc : " eth2_mainnet_genesis" .}: ptr UncheckedArray [byte ]
227- mainnetGenesisSize {.importc : " eth2_mainnet_genesis_size" .}: int
241+ when incbinEnabled:
242+ # Nim is very inefficent at loading large constants from binary files so we
243+ # use this trick instead which saves significant amounts of compile time
244+ let
245+ mainnetGenesis {.importc : " eth2_mainnet_genesis" .}: ptr UncheckedArray [byte ]
246+ mainnetGenesisSize {.importc : " eth2_mainnet_genesis_size" .}: int
228247
229- praterGenesis {.importc : " eth2_goerli_genesis" .}: ptr UncheckedArray [byte ]
230- praterGenesisSize {.importc : " eth2_goerli_genesis_size" .}: int
248+ praterGenesis {.importc : " eth2_goerli_genesis" .}: ptr UncheckedArray [byte ]
249+ praterGenesisSize {.importc : " eth2_goerli_genesis_size" .}: int
231250
232- sepoliaGenesis {.importc : " eth2_sepolia_genesis" .}: ptr UncheckedArray [byte ]
233- sepoliaGenesisSize {.importc : " eth2_sepolia_genesis_size" .}: int
251+ sepoliaGenesis {.importc : " eth2_sepolia_genesis" .}: ptr UncheckedArray [byte ]
252+ sepoliaGenesisSize {.importc : " eth2_sepolia_genesis_size" .}: int
234253
235- {.compile : " network_metadata_mainnet.S" .}
254+ {.compile : " network_metadata_mainnet.S" .}
236255
237256 const
238257 eth2NetworksDir = vendorDir & " /eth2-networks"
239258 sepoliaDir = vendorDir & " /sepolia"
240259
241260 mainnetMetadata = loadCompileTimeNetworkMetadata (
242- vendorDir & " /eth2-networks/shared/mainnet" , some mainnet, false )
261+ vendorDir & " /eth2-networks/shared/mainnet" , some mainnet, not incbinEnabled )
243262 praterMetadata = loadCompileTimeNetworkMetadata (
244- vendorDir & " /eth2-networks/shared/prater" , some goerli, false )
263+ vendorDir & " /eth2-networks/shared/prater" , some goerli, not incbinEnabled )
245264 sepoliaMetadata = loadCompileTimeNetworkMetadata (
246- vendorDir & " /sepolia/bepolia" , some sepolia, false )
265+ vendorDir & " /sepolia/bepolia" , some sepolia, not incbinEnabled )
247266
248267 static :
249268 for network in [mainnetMetadata, praterMetadata, sepoliaMetadata]:
@@ -272,9 +291,12 @@ proc getMetadataForNetwork*(
272291 warn " Ropsten is unsupported; https://blog.ethereum.org/2022/11/30/ropsten-shutdown-announcement suggests migrating to Goerli or Sepolia"
273292
274293 template withGenesis (metadata, genesis: untyped ): untyped =
275- var tmp = metadata
276- assign (tmp.genesisData, genesis.toOpenArray (0 , `genesis Size` - 1 ))
277- tmp
294+ when incbinEnabled:
295+ var tmp = metadata
296+ assign (tmp.genesisData, genesis.toOpenArray (0 , `genesis Size` - 1 ))
297+ tmp
298+ else :
299+ metadata
278300
279301 let metadata =
280302 when const_preset == " gnosis" :
0 commit comments