rm unused code/type conversoins; re-enable Electra block gossip verification (#6545)

This commit is contained in:
tersec 2024-09-12 09:11:08 +00:00 committed by GitHub
parent da48c6f3f4
commit 16c21e1c1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 91 additions and 109 deletions

View File

@ -559,9 +559,7 @@ proc new*(T: type BeaconChainDB,
sealedPeriods: "lc_sealed_periods")).expectDb() sealedPeriods: "lc_sealed_periods")).expectDb()
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
var blobs : KvStoreRef var blobs = kvStore db.openKvStore("deneb_blobs").expectDb()
if cfg.DENEB_FORK_EPOCH != FAR_FUTURE_EPOCH:
blobs = kvStore db.openKvStore("deneb_blobs").expectDb()
# Versions prior to 1.4.0 (altair) stored validators in `immutable_validators` # Versions prior to 1.4.0 (altair) stored validators in `immutable_validators`
# which stores validator keys in compressed format - this is # which stores validator keys in compressed format - this is

View File

@ -276,10 +276,6 @@ template checkedReject(
pool: ValidatorChangePool, error: ValidationError): untyped = pool: ValidatorChangePool, error: ValidationError): untyped =
pool.dag.checkedReject(error) pool.dag.checkedReject(error)
template checkedResult(
pool: ValidatorChangePool, error: ValidationError): untyped =
pool.dag.checkedResult(error)
template validateBeaconBlockBellatrix( template validateBeaconBlockBellatrix(
signed_beacon_block: phase0.SignedBeaconBlock | altair.SignedBeaconBlock, signed_beacon_block: phase0.SignedBeaconBlock | altair.SignedBeaconBlock,
parent: BlockRef): untyped = parent: BlockRef): untyped =
@ -483,7 +479,7 @@ proc validateBlobSidecar*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/p2p-interface.md#beacon_block # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/p2p-interface.md#beacon_block
proc validateBeaconBlock*( proc validateBeaconBlock*(
dag: ChainDAGRef, quarantine: ref Quarantine, dag: ChainDAGRef, quarantine: ref Quarantine,
signed_beacon_block: phase0.SignedBeaconBlock | altair.SignedBeaconBlock | bellatrix.SignedBeaconBlock | capella.SignedBeaconBlock | deneb.SignedBeaconBlock, signed_beacon_block: ForkySignedBeaconBlock,
wallTime: BeaconTime, flags: UpdateFlags): Result[void, ValidationError] = wallTime: BeaconTime, flags: UpdateFlags): Result[void, ValidationError] =
# In general, checks are ordered from cheap to expensive. Especially, crypto # In general, checks are ordered from cheap to expensive. Especially, crypto
# verification could be quite a bit more expensive than the rest. This is an # verification could be quite a bit more expensive than the rest. This is an
@ -673,13 +669,6 @@ proc validateBeaconBlock*(
ok() ok()
proc validateBeaconBlock*(
dag: ChainDAGRef, quarantine: ref Quarantine,
signed_beacon_block: electra.SignedBeaconBlock,
wallTime: BeaconTime, flags: UpdateFlags): Result[void, ValidationError] =
debugComment "it's sometimes not"
ok()
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/deneb/p2p-interface.md#beacon_aggregate_and_proof # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/deneb/p2p-interface.md#beacon_aggregate_and_proof
proc validateAttestation*( proc validateAttestation*(
@ -897,11 +886,9 @@ proc validateAttestation*(
attestation = shortLog(attestation), target = shortLog(target) attestation = shortLog(attestation), target = shortLog(target)
return errIgnore("Attestation: no shuffling") return errIgnore("Attestation: no shuffling")
let let attesting_index = get_attesting_indices_one(
fork = pool.dag.forkAtEpoch(attestation.data.slot.epoch) shufflingRef, slot, attestation.committee_bits,
attesting_index = get_attesting_indices_one( attestation.aggregation_bits, false)
shufflingRef, slot, attestation.committee_bits,
attestation.aggregation_bits, false)
# The number of aggregation bits matches the committee size, which ensures # The number of aggregation bits matches the committee size, which ensures
# this condition holds. # this condition holds.
@ -1177,11 +1164,8 @@ proc validateAggregate*(
"Attestation: committee index not within expected range") "Attestation: committee index not within expected range")
idx.get() idx.get()
let let
fork = pool.dag.forkAtEpoch(aggregate.data.slot.epoch)
attesting_indices = get_attesting_indices( attesting_indices = get_attesting_indices(
shufflingRef, slot, committee_index, aggregate.aggregation_bits, false) shufflingRef, slot, committee_index, aggregate.aggregation_bits, false)
let
sig = sig =
aggregate.signature.load().valueOr: aggregate.signature.load().valueOr:
return pool.checkedReject("Aggregate: unable to load signature") return pool.checkedReject("Aggregate: unable to load signature")

View File

@ -269,7 +269,7 @@ when const_preset == "gnosis":
for network in [gnosisMetadata, chiadoMetadata]: for network in [gnosisMetadata, chiadoMetadata]:
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
static: doAssert ConsensusFork.high == ConsensusFork.Electra doAssert ConsensusFork.high == ConsensusFork.Electra
elif const_preset == "mainnet": elif const_preset == "mainnet":
when incbinEnabled: when incbinEnabled:
@ -321,7 +321,7 @@ elif const_preset == "mainnet":
for network in [mainnetMetadata, sepoliaMetadata, holeskyMetadata]: for network in [mainnetMetadata, sepoliaMetadata, holeskyMetadata]:
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
static: doAssert ConsensusFork.high == ConsensusFork.Electra doAssert ConsensusFork.high == ConsensusFork.Electra
proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata = proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata =
template loadRuntimeMetadata(): auto = template loadRuntimeMetadata(): auto =

View File

@ -2271,7 +2271,7 @@ proc doRunBeaconNode(config: var BeaconNodeConf, rng: ref HmacDrbgContext) {.rai
bnStatus = BeaconNodeStatus.Stopping bnStatus = BeaconNodeStatus.Stopping
c_signal(ansi_c.SIGTERM, SIGTERMHandler) c_signal(ansi_c.SIGTERM, SIGTERMHandler)
if metadata.cfg.DENEB_FORK_EPOCH != FAR_FUTURE_EPOCH: block:
let res = let res =
if config.trustedSetupFile.isNone: if config.trustedSetupFile.isNone:
conf.loadKzgTrustedSetup() conf.loadKzgTrustedSetup()

View File

@ -122,7 +122,7 @@ proc publishBlockV3(vc: ValidatorClientRef, currentSlot, slot: Slot,
let let
maybeBlock = maybeBlock =
try: try:
await vc.produceBlockV3(slot, randao_reveal, graffiti, await vc.produceBlockV3(slot, randaoReveal, graffiti,
vc.config.builderBoostFactor, vc.config.builderBoostFactor,
ApiStrategyKind.Best) ApiStrategyKind.Best)
except ValidatorApiError as exc: except ValidatorApiError as exc:

View File

@ -150,7 +150,6 @@ proc serveContributionAndProof*(service: SyncCommitteeServiceRef,
vc = service.client vc = service.client
startTime = Moment.now() startTime = Moment.now()
slot = proof.contribution.slot slot = proof.contribution.slot
validatorIdx = validator.index.get()
genesisRoot = vc.beaconGenesis.genesis_validators_root genesisRoot = vc.beaconGenesis.genesis_validators_root
fork = vc.forkAtEpoch(slot.epoch) fork = vc.forkAtEpoch(slot.epoch)

View File

@ -22,17 +22,11 @@ import
./logtrace ./logtrace
from std/os import changeFileExt, fileExists from std/os import changeFileExt, fileExists
from std/sequtils import mapIt, toSeq
from std/times import toUnix from std/times import toUnix
from ../beacon_chain/el/engine_api_conversions import asEth2Digest from ../beacon_chain/el/engine_api_conversions import asEth2Digest
from ../beacon_chain/spec/beaconstate import initialize_beacon_state_from_eth1 from ../beacon_chain/spec/beaconstate import initialize_beacon_state_from_eth1
from ../tests/mocking/mock_genesis import mockEth1BlockHash from ../tests/mocking/mock_genesis import mockEth1BlockHash
# Compiled version of /scripts/depositContract.v.py in this repo
# The contract was compiled in Remix (https://remix.ethereum.org/) with vyper (remote) compiler.
const depositContractCode =
hexToSeqByte staticRead "../beacon_chain/el/deposit_contract_code.txt"
# For nim-confutils, which uses this kind of init(Type, value) pattern # For nim-confutils, which uses this kind of init(Type, value) pattern
func init(T: type IpAddress, ip: IpAddress): T = ip func init(T: type IpAddress, ip: IpAddress): T = ip
@ -389,19 +383,6 @@ proc createEnr(rng: var HmacDrbgContext,
]) ])
bootstrapEnr.tryGet() bootstrapEnr.tryGet()
proc doCreateTestnetEnr(config: CliConfig,
rng: var HmacDrbgContext)
{.raises: [CatchableError].} =
let
cfg = getRuntimeConfig(config.eth2Network)
bootstrapEnr = parseBootstrapAddress(toSeq(lines(string config.inputBootstrapEnr))[0]).get()
forkIdField = bootstrapEnr.tryGet(enrForkIdField, seq[byte]).get()
enr =
createEnr(rng, string config.enrDataDir, string config.enrNetKeyFile,
config.enrNetKeyInsecurePassword, cfg, forkIdField,
config.enrAddress, config.enrPort)
stderr.writeLine(enr.toURI)
proc doCreateTestnet*(config: CliConfig, proc doCreateTestnet*(config: CliConfig,
rng: var HmacDrbgContext) rng: var HmacDrbgContext)
{.raises: [CatchableError].} = {.raises: [CatchableError].} =
@ -504,29 +485,6 @@ proc doCreateTestnet*(config: CliConfig,
writeFile(bootstrapFile, enr.toURI) writeFile(bootstrapFile, enr.toURI)
echo "Wrote ", bootstrapFile echo "Wrote ", bootstrapFile
proc deployContract(web3: Web3, code: seq[byte]): Future[ReceiptObject] {.async.} =
let tr = TransactionArgs(
`from`: Opt.some web3.defaultAccount,
data: Opt.some code,
gas: Opt.some Quantity(3000000),
gasPrice: Opt.some Quantity(1))
let r = await web3.send(tr)
result = await web3.getMinedTransactionReceipt(r)
proc sendEth(web3: Web3, to: Eth1Address, valueEth: int): Future[TxHash] =
let tr = TransactionArgs(
`from`: Opt.some web3.defaultAccount,
# TODO: Force json-rpc to generate 'data' field
# should not be needed anymore, new execution-api schema
# is using `input` field
data: Opt.some(newSeq[byte]()),
gas: Opt.some Quantity(3000000),
gasPrice: Opt.some Quantity(1),
value: Opt.some(valueEth.u256 * 1000000000000000000.u256),
to: Opt.some(to))
web3.send(tr)
type type
DelayGenerator = proc(): chronos.Duration {.gcsafe, raises: [].} DelayGenerator = proc(): chronos.Duration {.gcsafe, raises: [].}
@ -542,43 +500,6 @@ proc initWeb3(web3Url, privateKey: string): Future[Web3] {.async.} =
doAssert(accounts.len > 0) doAssert(accounts.len > 0)
result.defaultAccount = accounts[0] result.defaultAccount = accounts[0]
# TODO: async functions should note take `seq` inputs because
# this leads to full copies.
proc sendDeposits(deposits: seq[LaunchPadDeposit],
web3Url, privateKey: string,
depositContractAddress: Eth1Address,
delayGenerator: DelayGenerator = nil) {.async.} =
notice "Sending deposits",
web3 = web3Url,
depositContract = depositContractAddress
var web3 = await initWeb3(web3Url, privateKey)
let gasPrice = int(await web3.provider.eth_gasPrice()) * 2
let depositContract = web3.contractSender(
DepositContract, depositContractAddress)
for i in 4200 ..< deposits.len:
let dp = deposits[i] as DepositData
while true:
try:
let tx = depositContract.deposit(
PubKeyBytes(@(dp.pubkey.toRaw())),
WithdrawalCredentialsBytes(@(dp.withdrawal_credentials.data)),
SignatureBytes(@(dp.signature.toRaw())),
FixedBytes[32](hash_tree_root(dp).data))
let status = await tx.send(value = 32.u256.ethToWei, gasPrice = gasPrice)
info "Deposit sent", tx = $status
if delayGenerator != nil:
await sleepAsync(delayGenerator())
break
except CatchableError:
await sleepAsync(chronos.seconds 60)
web3 = await initWeb3(web3Url, privateKey)
{.pop.} # TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError {.pop.} # TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
when isMainModule: when isMainModule:
@ -586,8 +507,88 @@ when isMainModule:
web3/confutils_defs, web3/confutils_defs,
../beacon_chain/filepath ../beacon_chain/filepath
from std/sequtils import mapIt, toSeq
from std/terminal import readPasswordFromStdin from std/terminal import readPasswordFromStdin
# Compiled version of /scripts/depositContract.v.py in this repo
# The contract was compiled in Remix (https://remix.ethereum.org/) with vyper (remote) compiler.
const depositContractCode =
hexToSeqByte staticRead "../beacon_chain/el/deposit_contract_code.txt"
proc doCreateTestnetEnr(config: CliConfig,
rng: var HmacDrbgContext)
{.raises: [CatchableError].} =
let
cfg = getRuntimeConfig(config.eth2Network)
bootstrapEnr = parseBootstrapAddress(toSeq(lines(string config.inputBootstrapEnr))[0]).get()
forkIdField = bootstrapEnr.tryGet(enrForkIdField, seq[byte]).get()
enr =
createEnr(rng, string config.enrDataDir, string config.enrNetKeyFile,
config.enrNetKeyInsecurePassword, cfg, forkIdField,
config.enrAddress, config.enrPort)
stderr.writeLine(enr.toURI)
proc deployContract(web3: Web3, code: seq[byte]): Future[ReceiptObject] {.async.} =
let tr = TransactionArgs(
`from`: Opt.some web3.defaultAccount,
data: Opt.some code,
gas: Opt.some Quantity(3000000),
gasPrice: Opt.some Quantity(1))
let r = await web3.send(tr)
result = await web3.getMinedTransactionReceipt(r)
proc sendEth(web3: Web3, to: Eth1Address, valueEth: int): Future[TxHash] =
let tr = TransactionArgs(
`from`: Opt.some web3.defaultAccount,
# TODO: Force json-rpc to generate 'data' field
# should not be needed anymore, new execution-api schema
# is using `input` field
data: Opt.some(newSeq[byte]()),
gas: Opt.some Quantity(3000000),
gasPrice: Opt.some Quantity(1),
value: Opt.some(valueEth.u256 * 1000000000000000000.u256),
to: Opt.some(to))
web3.send(tr)
# TODO: async functions should note take `seq` inputs because
# this leads to full copies.
proc sendDeposits(deposits: seq[LaunchPadDeposit],
web3Url, privateKey: string,
depositContractAddress: Eth1Address,
delayGenerator: DelayGenerator = nil) {.async.} =
notice "Sending deposits",
web3 = web3Url,
depositContract = depositContractAddress
var web3 = await initWeb3(web3Url, privateKey)
let gasPrice = int(await web3.provider.eth_gasPrice()) * 2
let depositContract = web3.contractSender(
DepositContract, depositContractAddress)
for i in 4200 ..< deposits.len:
let dp = deposits[i] as DepositData
while true:
try:
let tx = depositContract.deposit(
PubKeyBytes(@(dp.pubkey.toRaw())),
WithdrawalCredentialsBytes(@(dp.withdrawal_credentials.data)),
SignatureBytes(@(dp.signature.toRaw())),
FixedBytes[32](hash_tree_root(dp).data))
let status = await tx.send(
value = 32.u256.ethToWei, gasPrice = gasPrice)
info "Deposit sent", tx = $status
if delayGenerator != nil:
await sleepAsync(delayGenerator())
break
except CatchableError:
await sleepAsync(chronos.seconds 60)
web3 = await initWeb3(web3Url, privateKey)
proc main() {.async.} = proc main() {.async.} =
var conf = try: CliConfig.load() var conf = try: CliConfig.load()
except CatchableError as exc: except CatchableError as exc:

View File

@ -67,7 +67,7 @@ suite "Sync committee pool":
nextPeriod = cfg.BELLATRIX_FORK_EPOCH.sync_committee_period + 1 nextPeriod = cfg.BELLATRIX_FORK_EPOCH.sync_committee_period + 1
bid1 = BlockId( bid1 = BlockId(
slot: Slot(nextPeriod.start_slot - 2), # Committee based on `slot + 1` slot: nextPeriod.start_slot - 2, # Committee based on `slot + 1`
root: eth2digest(@[1.byte])) root: eth2digest(@[1.byte]))
sig1 = get_sync_committee_message_signature( sig1 = get_sync_committee_message_signature(

View File

@ -226,7 +226,7 @@ func findValidatorIndexBruteforce(
h2: ValidatorPubKey): Opt[ValidatorIndex] = h2: ValidatorPubKey): Opt[ValidatorIndex] =
for validatorIndex in bsv.extraItems: for validatorIndex in bsv.extraItems:
if validators[validatorIndex.distinctBase].pubkey == h2: if validators[validatorIndex.distinctBase].pubkey == h2:
return Opt.some validatorIndex.ValidatorIndex return Opt.some validatorIndex
for validatorIndex in bsv.bucketSorted: for validatorIndex in bsv.bucketSorted:
if validators[validatorIndex].pubkey == h2: if validators[validatorIndex].pubkey == h2:
return Opt.some validatorIndex.ValidatorIndex return Opt.some validatorIndex.ValidatorIndex