prune conf.nim

This commit is contained in:
Jenkins 2024-03-19 05:23:32 +02:00
parent 6b9b22ce7d
commit b6bec0ed6e
5 changed files with 4 additions and 386 deletions

View File

@ -7,8 +7,7 @@ import
json_serialization, web3/[primitives, confutils_defs],
./spec/[keystore, crypto],
./spec/datatypes/base,
./networking/network_metadata,
./filepath
./networking/network_metadata
from std/os import getHomeDir, parentDir, `/`
from std/strutils import parseBiggestUInt, replace
@ -22,10 +21,6 @@ export
type
BNStartUpCmd* {.pure.} = enum
noCommand
deposits
wallets
web3
trustedNodeSync
WalletsCmd* {.pure.} = enum
create = "Creates a new EIP-2386 wallet"
@ -431,20 +426,6 @@ type
defaultValue: true # the use of the nimbus_signing_process binary by default will be delayed until async I/O over stdin/stdout is developed for the child process.
name: "in-process-validators" .}: bool
discv5Enabled* {.
desc: "Enable Discovery v5"
defaultValue: true
name: "discv5" .}: bool
dumpEnabled* {.
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
defaultValue: false
name: "dump" .}: bool
directPeers* {.
desc: "The list of privileged, secure and known peers to connect and maintain the connection to. This requires a not random netkey-file. In the multiaddress format like: /ip4/<address>/tcp/<port>/p2p/<peerId-public-key>, or enr format (enr:-xx). Peering agreements are established out of band and must be reciprocal"
name: "direct-peer" .}: seq[string]
doppelgangerDetection* {.
desc: "If enabled, the beacon node prudently listens for 2 epochs for attestations from a validator with the same index (a doppelganger), before sending an attestation itself. This protects against slashing (due to double-voting) but means you will miss two attestations when restarting."
defaultValue: true
@ -457,171 +438,6 @@ type
desc: "Suggested fee recipient"
name: "suggested-fee-recipient" .}: Option[Address]
suggestedGasLimit* {.
desc: "Suggested gas limit"
defaultValue: defaultGasLimit
name: "suggested-gas-limit" .}: uint64
payloadBuilderEnable* {.
desc: "Enable external payload builder"
defaultValue: false
name: "payload-builder" .}: bool
payloadBuilderUrl* {.
desc: "Payload builder URL"
defaultValue: ""
name: "payload-builder-url" .}: string
# Flag name and semantics borrowed from Prysm
# https://github.com/prysmaticlabs/prysm/pull/12227/files
localBlockValueBoost* {.
desc: "Increase execution layer block values for builder bid comparison by a percentage"
defaultValue: 0
name: "local-block-value-boost" .}: uint8
historyMode* {.
desc: "Retention strategy for historical data (archive/prune)"
defaultValue: HistoryMode.Prune
name: "history".}: HistoryMode
# https://notes.ethereum.org/@bbusa/dencun-devnet-6
# "Please ensure that there is a way for us to specify the file through a
# runtime flag such as --trusted-setup-file (or similar)."
trustedSetupFile* {.
hidden
desc: "Experimental, debug option; could disappear at any time without warning"
name: "temporary-debug-trusted-setup-file" .}: Option[string]
bandwidthEstimate* {.
hidden
desc: "Bandwidth estimate for the node (bits per second)"
name: "debug-bandwidth-estimate" .}: Option[Natural]
of BNStartUpCmd.wallets:
case walletsCmd* {.command.}: WalletsCmd
of WalletsCmd.create:
nextAccount* {.
desc: "Initial value for the 'nextaccount' property of the wallet"
name: "next-account" .}: Option[Natural]
createdWalletFileFlag* {.
desc: "Output wallet file"
name: "out" .}: Option[OutFile]
of WalletsCmd.restore:
restoredWalletFileFlag* {.
desc: "Output wallet file"
name: "out" .}: Option[OutFile]
restoredDepositsCount* {.
desc: "Expected number of deposits to recover. If not specified, " &
"Nimbus will try to guess the number by inspecting the latest " &
"beacon state"
name: "deposits".}: Option[Natural]
of WalletsCmd.list:
discard
of BNStartUpCmd.deposits:
case depositsCmd* {.command.}: DepositsCmd
of DepositsCmd.createTestnetDeposits:
totalDeposits* {.
desc: "Number of deposits to generate"
defaultValue: 1
name: "count" .}: int
outValidatorsDir* {.
desc: "Output folder for validator keystores"
defaultValue: "validators"
name: "out-validators-dir" .}: string
outSecretsDir* {.
desc: "Output folder for randomly generated keystore passphrases"
defaultValue: "secrets"
name: "out-secrets-dir" .}: string
outDepositsFile* {.
desc: "The name of generated deposits file"
name: "out-deposits-file" .}: Option[OutFile]
newWalletFileFlag* {.
desc: "Output wallet file"
name: "new-wallet-file" .}: Option[OutFile]
#[
of DepositsCmd.status:
discard
]#
of DepositsCmd.`import`:
importedDepositsDir* {.
argument
desc: "A directory with keystores to import" .}: Option[InputDir]
importMethod* {.
desc: "Specifies which import method will be used (" &
"normal, single-salt)"
defaultValue: ImportMethod.Normal
name: "method" .}: ImportMethod
of DepositsCmd.exit:
exitedValidators* {.
desc: "One or more validator index, public key or a keystore path of " &
"the exited validator(s)"
name: "validator" .}: seq[string]
exitAllValidatorsFlag* {.
desc: "Exit all validators in the specified data directory or validators directory"
defaultValue: false
name: "all" .}: bool
exitAtEpoch* {.
name: "epoch"
defaultValueDesc: "immediately"
desc: "The desired exit epoch" .}: Option[uint64]
printData* {.
desc: "Print signed exit message instead of publishing it"
defaultValue: false
name: "print" .}: bool
of BNStartUpCmd.web3:
case web3Cmd* {.command.}: Web3Cmd
of Web3Cmd.test:
web3TestUrl* {.
argument
desc: "The web3 provider URL to test"
name: "url" .}: Uri
of BNStartUpCmd.trustedNodeSync:
stateId* {.
desc: "State id to sync to - this can be \"finalized\", a slot number or state hash or \"head\""
name: "state-id"
.}: Option[string]
blockId* {.
hidden
desc: "Block id to sync to - this can be a block root, slot number, \"finalized\" or \"head\" (deprecated)"
.}: Option[string]
lcTrustedBlockRoot* {.
desc: "Recent trusted finalized block root to initialize light client from"
name: "trusted-block-root" .}: Option[Eth2Digest]
backfillBlocks* {.
desc: "Backfill blocks directly from REST server instead of fetching via API"
defaultValue: true
name: "backfill" .}: bool
reindex* {.
desc: "Recreate historical state index at end of backfill, allowing full history access (requires full backfill)"
defaultValue: false .}: bool
downloadDepositSnapshot* {.
desc: "Also try to download a snapshot of the deposit contract state"
defaultValue: false
name: "with-deposit-snapshot" .}: bool
AnyConf* = BeaconNodeConf
proc defaultDataDir*[Conf](config: Conf): string =
@ -646,21 +462,6 @@ func dumpDirIncoming*(config: AnyConf): string =
func dumpDirOutgoing*(config: AnyConf): string =
config.dumpDir / "outgoing" # things we produced
proc createDumpDirs*(config: BeaconNodeConf) =
proc fail {.noreturn.} =
raiseAssert "createDumpDirs should be used only in the right context"
case config.cmd
of BNStartUpCmd.noCommand:
if config.dumpEnabled:
if (let res = secureCreatePath(config.dumpDirInvalid); res.isErr):
discard
if (let res = secureCreatePath(config.dumpDirIncoming); res.isErr):
discard
if (let res = secureCreatePath(config.dumpDirOutgoing); res.isErr):
discard
else: fail()
func parseCmdArg*(T: type Eth2Digest, input: string): T
{.raises: [ValueError].} =
Eth2Digest.fromHex(input)
@ -723,46 +524,12 @@ func eraDir*(config: BeaconNodeConf): string =
# The era directory should be shared between networks of the same type..
string config.eraDirFlag.get(InputDir(config.dataDir / "era"))
{.push warning[ProveField]:off.} # https://github.com/nim-lang/Nim/issues/22791
func outWalletFile*(config: BeaconNodeConf): Option[OutFile] =
proc fail {.noreturn.} =
raiseAssert "outWalletFile should be used only in the right context"
case config.cmd
of wallets:
case config.walletsCmd
of WalletsCmd.create: config.createdWalletFileFlag
of WalletsCmd.restore: config.restoredWalletFileFlag
of WalletsCmd.list: fail()
of deposits:
case config.depositsCmd
of DepositsCmd.createTestnetDeposits: config.newWalletFileFlag
else: fail()
else:
fail()
{.pop.}
func databaseDir*(dataDir: OutDir): string =
dataDir / "db"
template databaseDir*(config: AnyConf): string =
config.dataDir.databaseDir
func runAsService*(config: BeaconNodeConf): bool =
case config.cmd
of noCommand:
config.runAsServiceFlag
else:
false
func web3SignerUrls*(conf: AnyConf): seq[Web3SignerUrl] =
for url in conf.web3Signers:
result.add Web3SignerUrl(url: url)
for url in conf.verifyingWeb3Signers:
result.add Web3SignerUrl(url: url,
provenBlockProperties: conf.provenBlockProperties)
template writeValue*(writer: var JsonWriter,
value: TypedInputFile|InputFile|InputDir|OutPath|OutDir|OutFile) =
writer.writeValue(string value)

View File

@ -495,7 +495,7 @@ proc proposeBlock(node: BeaconNode,
template proposeBlockContinuation(type1, type2: untyped): auto =
await proposeBlockAux(
type1, type2, node, validator, validator_pubkey, validator_index, head, slot, randao, fork,
genesis_validators_root, node.config.localBlockValueBoost)
genesis_validators_root, 0)
discard withConsensusFork(node.cfg.consensusForkAtEpoch(slot.epoch)):
when consensusFork >= ConsensusFork.Electra:

View File

@ -2,9 +2,9 @@
import
std/[json, options],
chronos, bearssl/rand, confutils, stint, json_serialization,
chronos, bearssl/rand, confutils, json_serialization,
web3, eth/keys, eth/p2p/discoveryv5/random2,
stew/[io2, byteutils], json_rpc/jsonmarshal,
stew/[io2, byteutils],
../beacon_chain/conf,
../beacon_chain/spec/eth2_merkleization,
../beacon_chain/spec/datatypes/base,

View File

@ -1,116 +0,0 @@
# Vyper target 0.1.0b12
MIN_DEPOSIT_AMOUNT: constant(uint256) = 1000000000 # Gwei
DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32
MAX_DEPOSIT_COUNT: constant(uint256) = 4294967295 # 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1
PUBKEY_LENGTH: constant(uint256) = 48 # bytes
WITHDRAWAL_CREDENTIALS_LENGTH: constant(uint256) = 32 # bytes
SIGNATURE_LENGTH: constant(uint256) = 96 # bytes
AMOUNT_LENGTH: constant(uint256) = 8 # bytes
DepositEvent: event({
pubkey: bytes[48],
withdrawal_credentials: bytes[32],
amount: bytes[8],
signature: bytes[96],
index: bytes[8],
})
branch: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH]
deposit_count: uint256
# Compute hashes in empty sparse Merkle tree
zero_hashes: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH]
drain_address: address
@public
def __init__():
self.drain_address = msg.sender
for i in range(DEPOSIT_CONTRACT_TREE_DEPTH - 1):
self.zero_hashes[i + 1] = sha256(concat(self.zero_hashes[i], self.zero_hashes[i]))
@private
@constant
def to_little_endian_64(value: uint256) -> bytes[8]:
# Reversing bytes using bitwise uint256 manipulations
# Note: array accesses of bytes[] are not currently supported in Vyper
# Note: this function is only called when `value < 2**64`
y: uint256 = 0
x: uint256 = value
for _ in range(8):
y = shift(y, 8)
y = y + bitwise_and(x, 255)
x = shift(x, -8)
return slice(convert(y, bytes32), start=24, len=8)
@public
@constant
def get_deposit_root() -> bytes32:
zero_bytes32: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000
node: bytes32 = zero_bytes32
size: uint256 = self.deposit_count
for height in range(DEPOSIT_CONTRACT_TREE_DEPTH):
if bitwise_and(size, 1) == 1: # More gas efficient than `size % 2 == 1`
node = sha256(concat(self.branch[height], node))
else:
node = sha256(concat(node, self.zero_hashes[height]))
size /= 2
return sha256(concat(node, self.to_little_endian_64(self.deposit_count), slice(zero_bytes32, start=0, len=24)))
@public
@constant
def get_deposit_count() -> bytes[8]:
return self.to_little_endian_64(self.deposit_count)
@payable
@public
def deposit(pubkey: bytes[PUBKEY_LENGTH],
withdrawal_credentials: bytes[WITHDRAWAL_CREDENTIALS_LENGTH],
signature: bytes[SIGNATURE_LENGTH],
deposit_data_root: bytes32):
# Avoid overflowing the Merkle tree (and prevent edge case in computing `self.branch`)
assert self.deposit_count < MAX_DEPOSIT_COUNT
# Check deposit amount
deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei")
assert deposit_amount >= MIN_DEPOSIT_AMOUNT
# Length checks to facilitate formal verification (see https://github.com/ethereum/eth2.0-specs/pull/1362/files#r320361859)
assert len(pubkey) == PUBKEY_LENGTH
assert len(withdrawal_credentials) == WITHDRAWAL_CREDENTIALS_LENGTH
assert len(signature) == SIGNATURE_LENGTH
# Emit `DepositEvent` log
amount: bytes[8] = self.to_little_endian_64(deposit_amount)
log.DepositEvent(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count))
# Compute deposit data root (`DepositData` hash tree root)
zero_bytes32: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000
pubkey_root: bytes32 = sha256(concat(pubkey, slice(zero_bytes32, start=0, len=64 - PUBKEY_LENGTH)))
signature_root: bytes32 = sha256(concat(
sha256(slice(signature, start=0, len=64)),
sha256(concat(slice(signature, start=64, len=SIGNATURE_LENGTH - 64), zero_bytes32)),
))
node: bytes32 = sha256(concat(
sha256(concat(pubkey_root, withdrawal_credentials)),
sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)),
))
# Verify computed and expected deposit data roots match
assert node == deposit_data_root
# Add deposit data root to Merkle tree (update a single `branch` node)
self.deposit_count += 1
size: uint256 = self.deposit_count
for height in range(DEPOSIT_CONTRACT_TREE_DEPTH):
if bitwise_and(size, 1) == 1: # More gas efficient than `size % 2 == 1`
self.branch[height] = node
break
node = sha256(concat(self.branch[height], node))
size /= 2
@public
def drain():
send(self.drain_address, self.balance)

View File

@ -1,33 +0,0 @@
# beacon_chain
# Copyright (c) 2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
if [ -z "${NIMBUS_ETH1_VARS_SOURCED:-}" ]; then
NIMBUS_ETH1_VARS_SOURCED=1
NIMBUS_ETH1_NUM_NODES="${NIMBUS_ETH1_NUM_NODES:-4}"
NIMBUS_ETH1_BASE_NET_PORT="${BASE_EL_NET_PORT:-40404}"
NIMBUS_ETH1_BASE_RPC_PORT="${BASE_EL_RPC_PORT:-9545}"
NIMBUS_ETH1_BASE_WS_PORT="${BASE_EL_WS_PORT:-9546}"
NIMBUS_ETH1_BASE_AUTH_RPC_PORT="${BASE_EL_AUTH_RPC_PORT:-9551}"
NIMBUS_ETH1_PORT_OFFSET="${EL_PORT_OFFSET:-10}"
CURL_BINARY=${CURL_BINARY:-curl}
JQ_BINARY=${JQ_BINARY:-jq}
NIMBUS_ETH1_NET_PORTS=()
NIMBUS_ETH1_RPC_PORTS=()
NIMBUS_ETH1_AUTH_RPC_PORTS=()
NIMBUS_ETH1_LAST_NODE_IDX=$((NIMBUS_ETH1_NUM_NODES - 1))
for NIMBUS_ETH1_NODE_IDX in $(seq 0 $NIMBUS_ETH1_LAST_NODE_IDX); do
NIMBUS_ETH1_NET_PORTS+=($(( NIMBUS_ETH1_NODE_IDX * NIMBUS_ETH1_PORT_OFFSET + 1 + NIMBUS_ETH1_BASE_NET_PORT )))
NIMBUS_ETH1_RPC_PORTS+=($(( NIMBUS_ETH1_NODE_IDX * NIMBUS_ETH1_PORT_OFFSET + 1 + NIMBUS_ETH1_BASE_RPC_PORT )))
NIMBUS_ETH1_AUTH_RPC_PORTS+=($(( NIMBUS_ETH1_NODE_IDX * NIMBUS_ETH1_PORT_OFFSET + 1 + NIMBUS_ETH1_BASE_AUTH_RPC_PORT )))
done
fi