Load trusted setup (#4870)

* Kzg: Load trusted setup

* scripts/launch_local_testnet.sh: set FIELD_ELEMENTS_PER_BLOB

* Use right setup file for mainnet/minimal

* Force rebuild

* Add comment explaining why build with -f
This commit is contained in:
henridf 2023-05-11 10:52:44 +02:00 committed by GitHub
parent e44b51e955
commit 5dfd814588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 3 deletions

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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