diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index c1b3805a2..8d809e074 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -22,6 +22,7 @@ import eth/common/eth_types as commonEthTypes, eth/net/nat, eth/p2p/discoveryv5/enr, json_serialization, web3/[ethtypes, confutils_defs], + kzg4844/kzg_ex, ./spec/[engine_authentication, keystore, network, crypto], ./spec/datatypes/base, ./networking/network_metadata, @@ -1347,3 +1348,16 @@ proc engineApiUrls*(config: BeaconNodeConf): seq[EngineApiUrl] = config.elUrls (elUrls & config.web3Urls).toFinalEngineApiUrls(config.jwtSecret) + +proc loadKzgTrustedSetup*(): Result[void, string] = + const trustedSetup = + when const_preset == "mainnet": + staticRead"../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt" + elif const_preset == "minimal": + staticRead"../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup_4.txt" + else: + "" + if const_preset == "mainnet" or const_preset == "minimal": + Kzg.loadTrustedSetupFromString(trustedSetup) + else: + ok() diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 16e7306c0..276d7f88f 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -453,7 +453,8 @@ proc initFullNode( node.updateValidatorMetrics() -const SlashingDbName = "slashing_protection" +const + SlashingDbName = "slashing_protection" # changing this requires physical file rename as well or history is lost. proc init*(T: type BeaconNode, @@ -1912,6 +1913,11 @@ proc doRunBeaconNode(config: var BeaconNodeConf, rng: ref HmacDrbgContext) {.rai let node = BeaconNode.init(rng, config, metadata) + if node.dag.cfg.DENEB_FORK_EPOCH != FAR_FUTURE_EPOCH: + let res = conf.loadKzgTrustedSetup() + if res.isErr(): + raiseAssert res.error() + if bnStatus == BeaconNodeStatus.Stopping: return diff --git a/scripts/compile_nim_program.sh b/scripts/compile_nim_program.sh index 03de46002..f37d3f155 100755 --- a/scripts/compile_nim_program.sh +++ b/scripts/compile_nim_program.sh @@ -1,5 +1,13 @@ #!/usr/bin/env bash +# Copyright (c) 2020-2023 Status Research & Development GmbH. Licensed under +# either of: +# - Apache License, version 2.0 +# - MIT license +# at your option. This file may not be copied, modified, or distributed except +# according to those terms. + + set -e cd "$(dirname "${BASH_SOURCE[0]}")"/.. @@ -31,7 +39,13 @@ fi # parallel. # We can't use '--nimcache:...' here, because the same path is being used by # LTO on macOS, in "config.nims" -"$NIMC" c --compileOnly -o:build/${BINARY} "$@" -d:nimCachePathOverride=nimcache/release/${BINARY} "${SOURCE}" +# We have to use the `-f` flag here because running nim compile with +# different -d defines (as we do when for mainnet/minimal in CI) does +# not lead to a rebuild of changed deps - nim uses the cached +# version. The specific instance here is `-d:FIELD_ELEMENTS_PER_BLOB` +# that is used in the nim-kzg library and its dependency. +# TODO find a way not to have to -f here. +"$NIMC" c -f --compileOnly -o:build/${BINARY} "$@" -d:nimCachePathOverride=nimcache/release/${BINARY} "${SOURCE}" build/generate_makefile "nimcache/release/${BINARY}/${PROJECT_NAME}.json" "nimcache/release/${BINARY}/${BINARY}.makefile" # Don't swallow stderr, in case it's important. [[ "$V" == "0" ]] && exec >/dev/null diff --git a/scripts/launch_local_testnet.sh b/scripts/launch_local_testnet.sh index b1716e362..6fef08aed 100755 --- a/scripts/launch_local_testnet.sh +++ b/scripts/launch_local_testnet.sh @@ -396,9 +396,11 @@ openssl rand -hex 32 | tr -d "\n" > "${JWT_FILE}" if [[ "$CONST_PRESET" == "minimal" ]]; then SECONDS_PER_SLOT=6 SLOTS_PER_EPOCH=8 + FIELD_ELEMENTS_PER_BLOB=4 else SECONDS_PER_SLOT=12 SLOTS_PER_EPOCH=32 + FIELD_ELEMENTS_PER_BLOB=4096 fi VALIDATORS_DIR="${DATA_DIR}/validators" @@ -714,7 +716,7 @@ done if [[ "${REUSE_BINARIES}" == "0" || "${BINARIES_MISSING}" == "1" ]]; then log "Rebuilding binaries ${BINARIES}" - ${MAKE} -j ${NPROC} LOG_LEVEL=TRACE NIMFLAGS="${NIMFLAGS} -d:local_testnet -d:const_preset=${CONST_PRESET} -d:web3_consensus_const_preset=${CONST_PRESET}" ${BINARIES} + ${MAKE} -j ${NPROC} LOG_LEVEL=TRACE NIMFLAGS="${NIMFLAGS} -d:local_testnet -d:const_preset=${CONST_PRESET} -d:web3_consensus_const_preset=${CONST_PRESET} -d:FIELD_ELEMENTS_PER_BLOB=${FIELD_ELEMENTS_PER_BLOB}" ${BINARIES} fi if [[ "${RUN_NIMBUS_ETH1}" == "1" ]]; then