fix EIP4844 withBlck (#4411)

* fix EIP4844 withBlck

* don't raiseAssert by default
This commit is contained in:
tersec 2022-12-14 17:30:56 +00:00 committed by GitHub
parent ebca6879c6
commit 7faef7827e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 106 additions and 32 deletions

View File

@ -48,7 +48,9 @@ proc initLightClient*(
dag = node.dag.head.bid, dag = node.dag.head.bid,
wallSlot = node.currentSlot wallSlot = node.currentSlot
withBlck(signedBlock): withBlck(signedBlock):
when stateFork >= BeaconStateFork.Bellatrix: when stateFork == BeaconStateFork.EIP4844:
debugRaiseAssert $eip4844ImplementationMissing & ": beacon_node_light_client.nim:initLightClient"
elif stateFork >= BeaconStateFork.Bellatrix:
if blck.message.is_execution_block: if blck.message.is_execution_block:
template payload(): auto = blck.message.body.execution_payload template payload(): auto = blck.message.body.execution_payload

View File

@ -385,9 +385,9 @@ iterator getBlockIds*(
if not getPartialState(db, historical_roots, stateSlot, state[]): if not getPartialState(db, historical_roots, stateSlot, state[]):
state = nil # No `return` in iterators state = nil # No `return` in iterators
of BeaconStateFork.Capella: of BeaconStateFork.Capella:
raiseAssert $capellaImplementationMissing debugRaiseAssert $capellaImplementationMissing & ": era_db.nim: getBlockIds"
of BeaconStateFork.EIP4844: of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing debugRaiseAssert $eip4844ImplementationMissing & ": era_db.nim: getBlockIds"
if state == nil: if state == nil:
break break

View File

@ -290,6 +290,17 @@ proc newExecutionPayload*(
error "newPayload failed", msg = err.msg error "newPayload failed", msg = err.msg
return Opt.none PayloadExecutionStatus return Opt.none PayloadExecutionStatus
# TODO investigate why this seems to allow compilation even though it doesn't
# directly address eip4844.ExecutionPayload when complaint was that it didn't
# know about "eip4844"
from ../spec/datatypes/eip4844 import SignedBeaconBlock, asTrusted, shortLog
proc newExecutionPayload*(
eth1Monitor: Eth1Monitor,
executionPayload: eip4844.ExecutionPayload):
Future[Opt[PayloadExecutionStatus]] {.async.} =
debugRaiseAssert $eip4844ImplementationMissing & ": block_processor.nim:newExecutionPayload"
proc getExecutionValidity( proc getExecutionValidity(
eth1Monitor: Eth1Monitor, eth1Monitor: Eth1Monitor,
blck: phase0.SignedBeaconBlock | altair.SignedBeaconBlock): blck: phase0.SignedBeaconBlock | altair.SignedBeaconBlock):
@ -332,6 +343,12 @@ proc getExecutionValidity(
error "getExecutionValidity: newPayload failed", err = err.msg error "getExecutionValidity: newPayload failed", err = err.msg
return NewPayloadStatus.noResponse return NewPayloadStatus.noResponse
proc getExecutionValidity(
eth1Monitor: Eth1Monitor,
blck: eip4844.SignedBeaconBlock):
Future[NewPayloadStatus] {.async.} =
debugRaiseAssert $eip4844ImplementationMissing & ": block_processor.nim:getExecutionValidity"
proc storeBlock*( proc storeBlock*(
self: ref BlockProcessor, src: MsgSource, wallTime: BeaconTime, self: ref BlockProcessor, src: MsgSource, wallTime: BeaconTime,
signedBlock: ForkySignedBeaconBlock, queueTick: Moment = Moment.now(), signedBlock: ForkySignedBeaconBlock, queueTick: Moment = Moment.now(),

View File

@ -387,6 +387,15 @@ proc validateBeaconBlock*(
ok() ok()
from ../spec/datatypes/eip4844 import SignedBeaconBlock
proc validateBeaconBlock*(
dag: ChainDAGRef, quarantine: ref Quarantine,
signed_beacon_block: eip4844.SignedBeaconBlock,
wallTime: BeaconTime, flags: UpdateFlags): Result[void, ValidationError] =
debugRaiseAssert $eip4844ImplementationMissing & ": gossip_validation.nim: validateBeaconBlock not how EIP4844 works anymore"
err(default(ValidationError))
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id # https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
proc validateAttestation*( proc validateAttestation*(
pool: ref AttestationPool, pool: ref AttestationPool,

View File

@ -2632,9 +2632,22 @@ proc broadcastBeaconBlock*(
let topic = getBeaconBlocksTopic(node.forkDigests.capella) let topic = getBeaconBlocksTopic(node.forkDigests.capella)
node.broadcast(topic, blck) node.broadcast(topic, blck)
from ../spec/datatypes/eip4844 import SignedBeaconBlock
proc broadcastBeaconBlock*(
node: Eth2Node, blck: eip4844.SignedBeaconBlock): Future[SendResult] =
debugRaiseAssert $eip4844ImplementationMissing & ": eth2_network.nim:broadcastBeaconBlock EIP4844 uses different approach (1)"
proc broadcastBeaconBlock*( proc broadcastBeaconBlock*(
node: Eth2Node, forked: ForkedSignedBeaconBlock): Future[SendResult] = node: Eth2Node, forked: ForkedSignedBeaconBlock): Future[SendResult] =
withBlck(forked): node.broadcastBeaconBlock(blck) withBlck(forked):
when stateFork == BeaconStateFork.EIP4844:
debugRaiseAssert $eip4844ImplementationMissing & ": eth2_network.nim:broadcastBeaconBlock EIP4844 uses different approach (2)"
let f = newFuture[SendResult]()
f.fail(new CatchableError)
f
else:
node.broadcastBeaconBlock(blck)
proc broadcastSyncCommitteeMessage*( proc broadcastSyncCommitteeMessage*(
node: Eth2Node, msg: SyncCommitteeMessage, node: Eth2Node, msg: SyncCommitteeMessage,

View File

@ -301,11 +301,8 @@ proc getBlockRefOptimistic*(node: BeaconNode, blck: BlockRef): bool =
case blck.kind case blck.kind
of BeaconBlockFork.Phase0, BeaconBlockFork.Altair: of BeaconBlockFork.Phase0, BeaconBlockFork.Altair:
false false
of BeaconBlockFork.Bellatrix, BeaconBlockFork.Capella: of BeaconBlockFork.Bellatrix, BeaconBlockFork.Capella, BeaconBlockFork.EIP4844:
node.dag.is_optimistic(blck.root) node.dag.is_optimistic(blck.root)
of BeaconBlockFork.EIP4844:
if true: raiseAssert $eip4844ImplementationMissing
true
const const
jsonMediaType* = MediaType.init("application/json") jsonMediaType* = MediaType.init("application/json")

View File

@ -984,3 +984,6 @@ func checkForkConsistency*(cfg: RuntimeConfig) =
const capellaImplementationMissing* = false const capellaImplementationMissing* = false
const eip4844ImplementationMissing* = false const eip4844ImplementationMissing* = false
#template debugRaiseAssert*(x: string) = raiseAssert x
template debugRaiseAssert*(x: string) = discard

View File

@ -1160,7 +1160,8 @@ proc writeValue*[
writer.writeField("version", forkIdentifier "capella") writer.writeField("version", forkIdentifier "capella")
writer.writeField("data", value.capellaData) writer.writeField("data", value.capellaData)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing writer.writeField("version", forkIdentifier "eip4844")
writer.writeField("data", value.eip4844Data)
writer.endRecord() writer.endRecord()
## RestPublishedBeaconBlockBody ## RestPublishedBeaconBlockBody
@ -1591,7 +1592,8 @@ proc writeValue*(writer: var JsonWriter[RestJson],
writer.writeField("version", "capella") writer.writeField("version", "capella")
writer.writeField("data", value.capellaData) writer.writeField("data", value.capellaData)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing writer.writeField("version", "eip4844")
writer.writeField("data", value.eip4844Data)
writer.endRecord() writer.endRecord()
# ForkedHashedBeaconState is used where a `ForkedBeaconState` normally would # ForkedHashedBeaconState is used where a `ForkedBeaconState` normally would

View File

@ -686,8 +686,8 @@ template withBlck*(
template blck: untyped {.inject.} = x.capellaData template blck: untyped {.inject.} = x.capellaData
body body
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
const stateFork {.inject, used.} = BeaconStateFork.Capella const stateFork {.inject, used.} = BeaconStateFork.EIP4844
template blck: untyped {.inject.} = x.capellaData template blck: untyped {.inject.} = x.eip4844Data
body body
func proposer_index*(x: ForkedBeaconBlock): uint64 = func proposer_index*(x: ForkedBeaconBlock): uint64 =

View File

@ -584,7 +584,7 @@ proc makeBeaconBlock*[T: bellatrix.ExecutionPayload | capella.ExecutionPayload](
BeaconStateFork.Bellatrix, BeaconStateFork.Capella: BeaconStateFork.Bellatrix, BeaconStateFork.Capella:
raiseAssert "Attempt to use EIP4844 payload with non-EIP4844 state" raiseAssert "Attempt to use EIP4844 payload with non-EIP4844 state"
of BeaconStateFork.EIP4844: of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": state_transition" debugRaiseAssert $eip4844ImplementationMissing & ": state_transition"
# workaround for https://github.com/nim-lang/Nim/issues/20900 rather than have # workaround for https://github.com/nim-lang/Nim/issues/20900 rather than have
# these be default arguments # these be default arguments

View File

@ -46,6 +46,8 @@ proc fetchDepositSnapshot(client: RestClientRef):
return ok snapshot return ok snapshot
from ./spec/datatypes/eip4844 import asSigVerified, shortLog
proc doTrustedNodeSync*( proc doTrustedNodeSync*(
cfg: RuntimeConfig, cfg: RuntimeConfig,
databaseDir: string, databaseDir: string,

View File

@ -1688,7 +1688,10 @@ proc publishBlock*(
of BeaconBlockFork.Capella: of BeaconBlockFork.Capella:
publishBlock(it, data.capellaData) publishBlock(it, data.capellaData)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing debugRaiseAssert $eip4844ImplementationMissing & ": validator_client/api.nim:publishBlock (1)"
let f = newFuture[RestPlainResponse]("")
f.fail(new RestError)
f
do: do:
if apiResponse.isErr(): if apiResponse.isErr():
@ -1740,7 +1743,10 @@ proc publishBlock*(
of BeaconBlockFork.Capella: of BeaconBlockFork.Capella:
publishBlock(it, data.capellaData) publishBlock(it, data.capellaData)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing debugRaiseAssert $eip4844ImplementationMissing & ": validator_client/api.nim:publishBlock (2)"
let f = newFuture[RestPlainResponse]("")
f.fail(new RestError)
f
do: do:
if apiResponse.isErr(): if apiResponse.isErr():
debug ErrorMessage, endpoint = node, error = apiResponse.error() debug ErrorMessage, endpoint = node, error = apiResponse.error()
@ -1887,7 +1893,10 @@ proc publishBlindedBlock*(
of BeaconBlockFork.Capella: of BeaconBlockFork.Capella:
publishBlindedBlock(it, data.capellaData) publishBlindedBlock(it, data.capellaData)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing debugRaiseAssert $eip4844ImplementationMissing & ": validator_client/api.nim:publishBlindedBlock (1)"
let f = newFuture[RestPlainResponse]("")
f.fail(new RestError)
f
do: do:
if apiResponse.isErr(): if apiResponse.isErr():
debug ErrorMessage, endpoint = node, error = apiResponse.error() debug ErrorMessage, endpoint = node, error = apiResponse.error()
@ -1938,7 +1947,10 @@ proc publishBlindedBlock*(
of BeaconBlockFork.Capella: of BeaconBlockFork.Capella:
publishBlindedBlock(it, data.capellaData) publishBlindedBlock(it, data.capellaData)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing debugRaiseAssert $eip4844ImplementationMissing & ": validator_client/api.nim:publishBlindedBlock (2)"
let f = newFuture[RestPlainResponse]("")
f.fail(new RestError)
f
do: do:
if apiResponse.isErr(): if apiResponse.isErr():
debug ErrorMessage, endpoint = node, error = apiResponse.error() debug ErrorMessage, endpoint = node, error = apiResponse.error()

View File

@ -321,7 +321,8 @@ proc get_execution_payload[EP](
asConsensusExecutionPayload( asConsensusExecutionPayload(
await execution_engine.getPayload(payload_id.get)) await execution_engine.getPayload(payload_id.get))
else: else:
raiseAssert $capellaImplementationMissing & ": implement getPayload V2" debugRaiseAssert $capellaImplementationMissing & ": implement getPayload V2"
default(EP)
proc getFeeRecipient(node: BeaconNode, proc getFeeRecipient(node: BeaconNode,
pubkey: ValidatorPubKey, pubkey: ValidatorPubKey,
@ -795,6 +796,8 @@ proc makeBlindedBeaconBlockForHeadAndSlot*(
return ok constructPlainBlindedBlock[BlindedBeaconBlock]( return ok constructPlainBlindedBlock[BlindedBeaconBlock](
forkedBlck, executionPayloadHeader) forkedBlck, executionPayloadHeader)
from ../spec/datatypes/eip4844 import shortLog
proc proposeBlock(node: BeaconNode, proc proposeBlock(node: BeaconNode,
validator: AttachedValidator, validator: AttachedValidator,
validator_index: ValidatorIndex, validator_index: ValidatorIndex,
@ -895,6 +898,9 @@ proc proposeBlock(node: BeaconNode,
elif blck is capella.BeaconBlock: elif blck is capella.BeaconBlock:
capella.SignedBeaconBlock( capella.SignedBeaconBlock(
message: blck, signature: signature, root: blockRoot) message: blck, signature: signature, root: blockRoot)
elif blck is eip4844.BeaconBlock:
eip4844.SignedBeaconBlock(
message: blck, signature: signature, root: blockRoot)
else: else:
static: doAssert "Unknown SignedBeaconBlock type" static: doAssert "Unknown SignedBeaconBlock type"
newBlockRef = newBlockRef =

View File

@ -725,6 +725,8 @@ proc registerAttestationInBlock*(
update_if_lt( update_if_lt(
epochSummary.attestation_min_block_inclusion_distance, inclusion_lag) epochSummary.attestation_min_block_inclusion_distance, inclusion_lag)
from ../spec/datatypes/eip4844 import shortLog
proc registerBeaconBlock*( proc registerBeaconBlock*(
self: var ValidatorMonitor, self: var ValidatorMonitor,
src: MsgSource, src: MsgSource,

View File

@ -389,7 +389,9 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
kind: BeaconBlockFork.Capella, kind: BeaconBlockFork.Capella,
capellaData: blck.capellaData.toBeaconBlockHeader) capellaData: blck.capellaData.toBeaconBlockHeader)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing Web3SignerForkedBeaconBlock(
kind: BeaconBlockFork.EIP4844,
eip4844Data: blck.eip4844Data.toBeaconBlockHeader)
request = Web3SignerRequest.init( request = Web3SignerRequest.init(
fork, genesis_validators_root, web3SignerBlock) fork, genesis_validators_root, web3SignerBlock)
@ -422,7 +424,9 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
kind: BeaconBlockFork.Capella, kind: BeaconBlockFork.Capella,
capellaData: blck.capellaData.toBeaconBlockHeader) capellaData: blck.capellaData.toBeaconBlockHeader)
of BeaconBlockFork.EIP4844: of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing Web3SignerForkedBeaconBlock(
kind: BeaconBlockFork.EIP4844,
eip4844Data: blck.eip4844Data.toBeaconBlockHeader)
request = Web3SignerRequest.init( request = Web3SignerRequest.init(
fork, genesis_validators_root, web3SignerBlock) fork, genesis_validators_root, web3SignerBlock)

View File

@ -1000,7 +1000,7 @@ proc cmdValidatorDb(conf: DbConf, cfg: RuntimeConfig) =
withState(tmpState[]): withState(tmpState[]):
var stateData = newClone(forkyState.data) var stateData = newClone(forkyState.data)
when stateFork == BeaconStateFork.EIP4844: when stateFork == BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": ncli_db.nim:cmdValidatorDb" debugRaiseAssert $eip4844ImplementationMissing & ": ncli_db.nim:cmdValidatorDb"
else: else:
rewardsAndPenalties.collectEpochRewardsAndPenalties( rewardsAndPenalties.collectEpochRewardsAndPenalties(
stateData[], cache, cfg, flags) stateData[], cache, cfg, flags)

View File

@ -8,8 +8,6 @@
{.used.} {.used.}
import import
# Standard library
os,
# Beacon chain internals # Beacon chain internals
../../../beacon_chain/spec/[beaconstate, helpers], ../../../beacon_chain/spec/[beaconstate, helpers],
../../../beacon_chain/spec/datatypes/[phase0, altair], ../../../beacon_chain/spec/datatypes/[phase0, altair],
@ -18,6 +16,8 @@ import
../fixtures_utils, ../fixtures_utils,
../../helpers/debug_state ../../helpers/debug_state
from std/os import walkDir, `/`
const OpForkDir = SszTestsDir/const_preset/"altair"/"fork"/"fork"/"pyspec_tests" const OpForkDir = SszTestsDir/const_preset/"altair"/"fork"/"fork"/"pyspec_tests"
proc runTest(identifier: string) = proc runTest(identifier: string) =

View File

@ -8,8 +8,6 @@
{.used.} {.used.}
import import
# Standard library
os,
# Beacon chain internals # Beacon chain internals
../../../beacon_chain/spec/[beaconstate, helpers], ../../../beacon_chain/spec/[beaconstate, helpers],
../../../beacon_chain/spec/datatypes/[altair, bellatrix], ../../../beacon_chain/spec/datatypes/[altair, bellatrix],
@ -18,6 +16,8 @@ import
../fixtures_utils, ../fixtures_utils,
../../helpers/debug_state ../../helpers/debug_state
from std/os import walkDir, `/`
const OpForkDir = SszTestsDir/const_preset/"bellatrix"/"fork"/"fork"/"pyspec_tests" const OpForkDir = SszTestsDir/const_preset/"bellatrix"/"fork"/"fork"/"pyspec_tests"
proc runTest(identifier: string) = proc runTest(identifier: string) =

View File

@ -8,8 +8,6 @@
{.used.} {.used.}
import import
# Standard library
std/[os, sequtils, sets, strutils],
# Utilities # Utilities
chronicles, chronicles,
unittest2, unittest2,
@ -22,6 +20,10 @@ import
../fixtures_utils, ../fixtures_utils,
../../helpers/debug_state ../../helpers/debug_state
from std/os import fileExists, walkDir, `/`
from std/sequtils import mapIt, toSeq
from std/strutils import contains
const const
OpDir = SszTestsDir/const_preset/"bellatrix"/"operations" OpDir = SszTestsDir/const_preset/"bellatrix"/"operations"
OpAttestationsDir = OpDir/"attestation" OpAttestationsDir = OpDir/"attestation"

View File

@ -8,9 +8,6 @@
{.used.} {.used.}
import import
# Standard library
os, strutils, streams, strformat,
macros, sets,
# Third-party # Third-party
yaml, yaml,
# Beacon chain internals # Beacon chain internals
@ -20,6 +17,11 @@ import
# Test utilities # Test utilities
../../testutil, ../fixtures_utils ../../testutil, ../fixtures_utils
from std/os import dirExists, pcDir, walkDir, `/`
from std/streams import close, openFileStream
from std/strformat import `&`
from std/strutils import toLowerAscii
# SSZ tests of consensus objects (minimal/mainnet preset specific) # SSZ tests of consensus objects (minimal/mainnet preset specific)
# Parsing definitions # Parsing definitions

View File

@ -10,8 +10,6 @@
import import
chronicles, chronicles,
yaml, yaml,
# Standard library
std/[os, sequtils, strutils],
# Status internal # Status internal
faststreams, streams, faststreams, streams,
# Beacon chain internals # Beacon chain internals
@ -21,6 +19,9 @@ import
../../testutil, ../../testutil,
../fixtures_utils ../fixtures_utils
from std/os import walkDir, walkPattern, `/`
from std/sequtils import toSeq
const const
TransitionDir = SszTestsDir/const_preset/"capella"/"transition"/"core"/"pyspec_tests" TransitionDir = SszTestsDir/const_preset/"capella"/"transition"/"core"/"pyspec_tests"