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,
wallSlot = node.currentSlot
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:
template payload(): auto = blck.message.body.execution_payload

View File

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

View File

@ -290,6 +290,17 @@ proc newExecutionPayload*(
error "newPayload failed", msg = err.msg
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(
eth1Monitor: Eth1Monitor,
blck: phase0.SignedBeaconBlock | altair.SignedBeaconBlock):
@ -332,6 +343,12 @@ proc getExecutionValidity(
error "getExecutionValidity: newPayload failed", err = err.msg
return NewPayloadStatus.noResponse
proc getExecutionValidity(
eth1Monitor: Eth1Monitor,
blck: eip4844.SignedBeaconBlock):
Future[NewPayloadStatus] {.async.} =
debugRaiseAssert $eip4844ImplementationMissing & ": block_processor.nim:getExecutionValidity"
proc storeBlock*(
self: ref BlockProcessor, src: MsgSource, wallTime: BeaconTime,
signedBlock: ForkySignedBeaconBlock, queueTick: Moment = Moment.now(),

View File

@ -387,6 +387,15 @@ proc validateBeaconBlock*(
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
proc validateAttestation*(
pool: ref AttestationPool,

View File

@ -2632,9 +2632,22 @@ proc broadcastBeaconBlock*(
let topic = getBeaconBlocksTopic(node.forkDigests.capella)
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*(
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*(
node: Eth2Node, msg: SyncCommitteeMessage,

View File

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

View File

@ -984,3 +984,6 @@ func checkForkConsistency*(cfg: RuntimeConfig) =
const capellaImplementationMissing* = 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("data", value.capellaData)
of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing
writer.writeField("version", forkIdentifier "eip4844")
writer.writeField("data", value.eip4844Data)
writer.endRecord()
## RestPublishedBeaconBlockBody
@ -1591,7 +1592,8 @@ proc writeValue*(writer: var JsonWriter[RestJson],
writer.writeField("version", "capella")
writer.writeField("data", value.capellaData)
of BeaconBlockFork.EIP4844:
raiseAssert $eip4844ImplementationMissing
writer.writeField("version", "eip4844")
writer.writeField("data", value.eip4844Data)
writer.endRecord()
# ForkedHashedBeaconState is used where a `ForkedBeaconState` normally would

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,9 +8,6 @@
{.used.}
import
# Standard library
os, strutils, streams, strformat,
macros, sets,
# Third-party
yaml,
# Beacon chain internals
@ -20,6 +17,11 @@ import
# Test utilities
../../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)
# Parsing definitions

View File

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