more capella (#4350)
This commit is contained in:
parent
8fa6064b9a
commit
1fceb33b2e
|
@ -917,13 +917,13 @@ func getSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
|
|||
|
||||
subnets + node.getNextSyncCommitteeSubnets(epoch)
|
||||
|
||||
proc addAltairMessageHandlers(node: BeaconNode, forkDigest: ForkDigest, slot: Slot) =
|
||||
proc addAltairMessageHandlers(
|
||||
node: BeaconNode, forkDigest: ForkDigest, slot: Slot) =
|
||||
node.addPhase0MessageHandlers(forkDigest, slot)
|
||||
|
||||
# If this comes online near sync committee period, it'll immediately get
|
||||
# replaced as usual by trackSyncCommitteeTopics, which runs at slot end.
|
||||
let
|
||||
syncnets = node.getSyncCommitteeSubnets(slot.epoch)
|
||||
let syncnets = node.getSyncCommitteeSubnets(slot.epoch)
|
||||
|
||||
for subcommitteeIdx in SyncSubcommitteeIndex:
|
||||
if syncnets[subcommitteeIdx]:
|
||||
|
@ -935,6 +935,11 @@ proc addAltairMessageHandlers(node: BeaconNode, forkDigest: ForkDigest, slot: Sl
|
|||
|
||||
node.network.updateSyncnetsMetadata(syncnets)
|
||||
|
||||
proc addCapellaMessageHandlers(
|
||||
node: BeaconNode, forkDigest: ForkDigest, slot: Slot) =
|
||||
node.addAltairMessageHandlers(forkDigest, slot)
|
||||
node.network.subscribe(getBlsToExecutionChangeTopic(forkDigest), basicParams)
|
||||
|
||||
proc removeAltairMessageHandlers(node: BeaconNode, forkDigest: ForkDigest) =
|
||||
node.removePhase0MessageHandlers(forkDigest)
|
||||
|
||||
|
@ -946,6 +951,10 @@ proc removeAltairMessageHandlers(node: BeaconNode, forkDigest: ForkDigest) =
|
|||
node.network.unsubscribe(
|
||||
getSyncCommitteeContributionAndProofTopic(forkDigest))
|
||||
|
||||
proc removeCapellaMessageHandlers(node: BeaconNode, forkDigest: ForkDigest) =
|
||||
node.removeAltairMessageHandlers(forkDigest)
|
||||
node.network.unsubscribe(getBlsToExecutionChangeTopic(forkDigest))
|
||||
|
||||
proc updateSyncCommitteeTopics(node: BeaconNode, slot: Slot) =
|
||||
template lastSyncUpdate: untyped =
|
||||
node.consensusManager[].actionTracker.lastSyncUpdate
|
||||
|
@ -1082,7 +1091,7 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
|
|||
removePhase0MessageHandlers,
|
||||
removeAltairMessageHandlers,
|
||||
removeAltairMessageHandlers, # with different forkDigest
|
||||
if capellaImplementationMissing: removeAltairMessageHandlers else: removeAltairMessageHandlers
|
||||
removeCapellaMessageHandlers
|
||||
]
|
||||
|
||||
for gossipFork in oldGossipForks:
|
||||
|
@ -1092,7 +1101,7 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
|
|||
addPhase0MessageHandlers,
|
||||
addAltairMessageHandlers,
|
||||
addAltairMessageHandlers, # with different forkDigest
|
||||
if capellaImplementationMissing: addAltairMessageHandlers else: addAltairMessageHandlers
|
||||
addCapellaMessageHandlers
|
||||
]
|
||||
|
||||
for gossipFork in newGossipForks:
|
||||
|
|
|
@ -296,11 +296,8 @@ proc getBlockRefOptimistic*(node: BeaconNode, blck: BlockRef): bool =
|
|||
case blck.kind
|
||||
of BeaconBlockFork.Phase0, BeaconBlockFork.Altair:
|
||||
false
|
||||
of BeaconBlockFork.Bellatrix:
|
||||
of BeaconBlockFork.Bellatrix, BeaconBlockFork.Capella:
|
||||
node.dag.is_optimistic(blck.root)
|
||||
of BeaconBlockFork.Capella:
|
||||
if true: raiseAssert $capellaImplementationMissing
|
||||
true
|
||||
|
||||
const
|
||||
jsonMediaType* = MediaType.init("application/json")
|
||||
|
|
|
@ -1075,7 +1075,19 @@ proc readValue*[BlockType: Web3SignerForkedBeaconBlock](
|
|||
kind: BeaconBlockFork.Bellatrix,
|
||||
bellatrixData: res.get())
|
||||
of BeaconBlockFork.Capella:
|
||||
reader.raiseUnexpectedValue($capellaImplementationMissing)
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
BeaconBlockHeader,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[BeaconBlockHeader]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect capella block format")
|
||||
value = Web3SignerForkedBeaconBlock(
|
||||
kind: BeaconBlockFork.Capella,
|
||||
capellaData: res.get())
|
||||
|
||||
proc writeValue*[
|
||||
BlockType: Web3SignerForkedBeaconBlock|ForkedBeaconBlock|ForkedBlindedBeaconBlock](
|
||||
|
@ -1201,6 +1213,7 @@ proc readValue*(reader: var JsonReader[RestJson],
|
|||
if voluntary_exits.isNone():
|
||||
reader.raiseUnexpectedValue("Field `voluntary_exits` is missing")
|
||||
|
||||
discard $capellaImplementationMissing & ": autodetect via added field"
|
||||
let bodyKind =
|
||||
if execution_payload.isSome() and sync_aggregate.isSome():
|
||||
BeaconBlockFork.Bellatrix
|
||||
|
@ -1344,7 +1357,15 @@ proc readValue*(reader: var JsonReader[RestJson],
|
|||
)
|
||||
)
|
||||
of BeaconBlockFork.Capella:
|
||||
reader.raiseUnexpectedValue($capellaImplementationMissing)
|
||||
ForkedBeaconBlock.init(
|
||||
capella.BeaconBlock(
|
||||
slot: slot.get(),
|
||||
proposer_index: proposer_index.get(),
|
||||
parent_root: parent_root.get(),
|
||||
state_root: state_root.get(),
|
||||
body: body.capellaBody
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
## RestPublishedSignedBeaconBlock
|
||||
|
@ -1483,7 +1504,17 @@ proc readValue*(reader: var JsonReader[RestJson],
|
|||
reader.raiseUnexpectedValue("Incorrect bellatrix block format")
|
||||
value = ForkedSignedBeaconBlock.init(res.get())
|
||||
of BeaconBlockFork.Capella:
|
||||
reader.raiseUnexpectedValue($capellaImplementationMissing)
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
capella.SignedBeaconBlock,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[capella.SignedBeaconBlock]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect capella block format")
|
||||
value = ForkedSignedBeaconBlock.init(res.get())
|
||||
withBlck(value):
|
||||
blck.root = hash_tree_root(blck.message)
|
||||
|
||||
|
@ -1584,10 +1615,18 @@ proc readValue*(reader: var JsonReader[RestJson],
|
|||
requireAllFields = true,
|
||||
allowUnknownFields = true)
|
||||
except SerializationError:
|
||||
reader.raiseUnexpectedValue("Incorrect altair beacon state format")
|
||||
reader.raiseUnexpectedValue("Incorrect bellatrix beacon state format")
|
||||
toValue(bellatrixData)
|
||||
of BeaconStateFork.Capella:
|
||||
reader.raiseUnexpectedValue($capellaImplementationMissing)
|
||||
try:
|
||||
tmp[].capellaData.data = RestJson.decode(
|
||||
string(data.get()),
|
||||
capella.BeaconState,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true)
|
||||
except SerializationError:
|
||||
reader.raiseUnexpectedValue("Incorrect capella beacon state format")
|
||||
toValue(capellaData)
|
||||
|
||||
proc writeValue*(writer: var JsonWriter[RestJson], value: ForkedHashedBeaconState)
|
||||
{.raises: [IOError, Defect].} =
|
||||
|
@ -2495,7 +2534,14 @@ proc decodeBody*(
|
|||
return err("Unexpected deserialization error")
|
||||
ok(RestPublishedSignedBeaconBlock(ForkedSignedBeaconBlock.init(blck)))
|
||||
of BeaconBlockFork.Capella:
|
||||
return err($capellaImplementationMissing)
|
||||
let blck =
|
||||
try:
|
||||
SSZ.decode(body.data, capella.SignedBeaconBlock)
|
||||
except SerializationError:
|
||||
return err("Unable to deserialize data")
|
||||
except CatchableError:
|
||||
return err("Unexpected deserialization error")
|
||||
ok(RestPublishedSignedBeaconBlock(ForkedSignedBeaconBlock.init(blck)))
|
||||
else:
|
||||
return err("Unsupported or invalid content media type")
|
||||
|
||||
|
|
|
@ -262,10 +262,10 @@ type
|
|||
|
||||
RestPublishedBeaconBlockBody* = object
|
||||
case kind*: BeaconBlockFork
|
||||
of BeaconBlockFork.Phase0: phase0Body*: phase0.BeaconBlockBody
|
||||
of BeaconBlockFork.Altair: altairBody*: altair.BeaconBlockBody
|
||||
of BeaconBlockFork.Phase0: phase0Body*: phase0.BeaconBlockBody
|
||||
of BeaconBlockFork.Altair: altairBody*: altair.BeaconBlockBody
|
||||
of BeaconBlockFork.Bellatrix: bellatrixBody*: bellatrix.BeaconBlockBody
|
||||
of BeaconBlockFork.Capella: cappellaBody*: capella.BeaconBlockBody
|
||||
of BeaconBlockFork.Capella: capellaBody*: capella.BeaconBlockBody
|
||||
|
||||
RestSpec* = object
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/phase0.yaml
|
||||
|
|
|
@ -384,9 +384,8 @@ proc emptyPayloadToBlockHeader*(
|
|||
fee : some payload.base_fee_per_gas
|
||||
)
|
||||
|
||||
func build_empty_execution_payload*(
|
||||
state: bellatrix.BeaconState,
|
||||
feeRecipient: Eth1Address): bellatrix.ExecutionPayload =
|
||||
func build_empty_execution_payload*[BS, EP](
|
||||
state: BS, feeRecipient: Eth1Address): EP =
|
||||
## Assuming a pre-state of the same slot, build a valid ExecutionPayload
|
||||
## without any transactions.
|
||||
let
|
||||
|
@ -397,7 +396,7 @@ func build_empty_execution_payload*(
|
|||
GasInt.saturate latest.gas_used,
|
||||
latest.base_fee_per_gas)
|
||||
|
||||
var payload = bellatrix.ExecutionPayload(
|
||||
var payload = EP(
|
||||
parent_hash: latest.block_hash,
|
||||
fee_recipient: bellatrix.ExecutionAddress(data: distinctBase(feeRecipient)),
|
||||
state_root: latest.state_root, # no changes to the state
|
||||
|
|
|
@ -18,11 +18,13 @@ export base
|
|||
|
||||
const
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#topics-and-messages
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/p2p-interface.md#topics-and-messages
|
||||
topicBeaconBlocksSuffix* = "beacon_block/ssz_snappy"
|
||||
topicVoluntaryExitsSuffix* = "voluntary_exit/ssz_snappy"
|
||||
topicProposerSlashingsSuffix* = "proposer_slashing/ssz_snappy"
|
||||
topicAttesterSlashingsSuffix* = "attester_slashing/ssz_snappy"
|
||||
topicAggregateAndProofsSuffix* = "beacon_aggregate_and_proof/ssz_snappy"
|
||||
topicBlsToExecutionChangeSuffix* = "bls_to_execution_change/ssz_snappy"
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#configuration
|
||||
MAX_CHUNK_SIZE* = 1 * 1024 * 1024 # bytes
|
||||
|
@ -63,6 +65,10 @@ func getAttesterSlashingsTopic*(forkDigest: ForkDigest): string =
|
|||
func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string =
|
||||
eth2Prefix(forkDigest) & topicAggregateAndProofsSuffix
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/p2p-interface.md#topics-and-messages
|
||||
func getBlsToExecutionChangeTopic*(forkDigest: ForkDigest): string =
|
||||
eth2Prefix(forkDigest) & topicBlsToExecutionChangeSuffix
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#broadcast-attestation
|
||||
func compute_subnet_for_attestation*(
|
||||
committees_per_slot: uint64, slot: Slot, committee_index: CommitteeIndex):
|
||||
|
|
|
@ -1735,7 +1735,7 @@ proc publishBlock*(
|
|||
of BeaconBlockFork.Bellatrix:
|
||||
publishBlock(it, data.bellatrixData)
|
||||
of BeaconBlockFork.Capella:
|
||||
raiseAssert $capellaImplementationMissing
|
||||
publishBlock(it, data.capellaData)
|
||||
do:
|
||||
if apiResponse.isErr():
|
||||
debug ErrorMessage, endpoint = node, error = apiResponse.error()
|
||||
|
@ -1880,7 +1880,7 @@ proc publishBlindedBlock*(
|
|||
of BeaconBlockFork.Bellatrix:
|
||||
publishBlindedBlock(it, data.bellatrixData)
|
||||
of BeaconBlockFork.Capella:
|
||||
raiseAssert $capellaImplementationMissing
|
||||
publishBlindedBlock(it, data.capellaData)
|
||||
do:
|
||||
if apiResponse.isErr():
|
||||
debug ErrorMessage, endpoint = node, error = apiResponse.error()
|
||||
|
@ -1929,7 +1929,7 @@ proc publishBlindedBlock*(
|
|||
of BeaconBlockFork.Bellatrix:
|
||||
publishBlindedBlock(it, data.bellatrixData)
|
||||
of BeaconBlockFork.Capella:
|
||||
raiseAssert $capellaImplementationMissing
|
||||
publishBlindedBlock(it, data.capellaData)
|
||||
do:
|
||||
if apiResponse.isErr():
|
||||
debug ErrorMessage, endpoint = node, error = apiResponse.error()
|
||||
|
|
|
@ -19,7 +19,7 @@ import
|
|||
std/[os, tables],
|
||||
|
||||
# Nimble packages
|
||||
stew/[byteutils, objects],
|
||||
stew/byteutils,
|
||||
chronos, metrics,
|
||||
chronicles, chronicles/timings,
|
||||
json_serialization/std/[options, sets, net],
|
||||
|
@ -388,10 +388,9 @@ proc getExecutionPayload[T](
|
|||
|
||||
template empty_execution_payload(): auto =
|
||||
withState(proposalState[]):
|
||||
when stateFork >= BeaconStateFork.Capella:
|
||||
raiseAssert $capellaImplementationMissing & ": beacon_chain/validators/validator_duties.nim: getExecutionPayload"
|
||||
elif stateFork >= BeaconStateFork.Bellatrix:
|
||||
build_empty_execution_payload(forkyState.data, feeRecipient)
|
||||
when stateFork >= BeaconStateFork.Bellatrix:
|
||||
build_empty_execution_payload[typeof forkyState.data, T](
|
||||
forkyState.data, feeRecipient)
|
||||
else:
|
||||
default(T)
|
||||
|
||||
|
|
|
@ -354,7 +354,9 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
|
|||
kind: BeaconBlockFork.Bellatrix,
|
||||
bellatrixData: blck.bellatrixData.toBeaconBlockHeader)
|
||||
of BeaconBlockFork.Capella:
|
||||
raiseAssert $capellaImplementationMissing
|
||||
Web3SignerForkedBeaconBlock(
|
||||
kind: BeaconBlockFork.Capella,
|
||||
capellaData: blck.capellaData.toBeaconBlockHeader)
|
||||
|
||||
request = Web3SignerRequest.init(
|
||||
fork, genesis_validators_root, web3SignerBlock)
|
||||
|
@ -383,7 +385,9 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
|
|||
kind: BeaconBlockFork.Bellatrix,
|
||||
bellatrixData: blck.bellatrixData.toBeaconBlockHeader)
|
||||
of BeaconBlockFork.Capella:
|
||||
raiseAssert $capellaImplementationMissing & "beacon_chain/validators/validator_pool.nim: getBlockSignature"
|
||||
Web3SignerForkedBeaconBlock(
|
||||
kind: BeaconBlockFork.Capella,
|
||||
capellaData: blck.capellaData.toBeaconBlockHeader)
|
||||
|
||||
request = Web3SignerRequest.init(
|
||||
fork, genesis_validators_root, web3SignerBlock)
|
||||
|
|
|
@ -70,7 +70,9 @@ suite "Spec helpers":
|
|||
|
||||
template testCase(recipient: Eth1Address): untyped =
|
||||
block:
|
||||
let payload = build_empty_execution_payload(state[].data, recipient)
|
||||
let payload = build_empty_execution_payload[
|
||||
typeof state[].data, bellatrix.ExecutionPayload](
|
||||
state[].data, recipient)
|
||||
check payload.fee_recipient ==
|
||||
bellatrix.ExecutionAddress(data: distinctBase(recipient))
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ suite "Honest validator":
|
|||
getProposerSlashingsTopic(forkDigest) == "/eth2/00000000/proposer_slashing/ssz_snappy"
|
||||
getAttesterSlashingsTopic(forkDigest) == "/eth2/00000000/attester_slashing/ssz_snappy"
|
||||
getAggregateAndProofsTopic(forkDigest) == "/eth2/00000000/beacon_aggregate_and_proof/ssz_snappy"
|
||||
getBlsToExecutionChangeTopic(forkDigest) == "/eth2/00000000/bls_to_execution_change/ssz_snappy"
|
||||
getSyncCommitteeContributionAndProofTopic(forkDigest) == "/eth2/00000000/sync_committee_contribution_and_proof/ssz_snappy"
|
||||
getLightClientFinalityUpdateTopic(forkDigest) == "/eth2/00000000/light_client_finality_update/ssz_snappy"
|
||||
getLightClientOptimisticUpdateTopic(forkDigest) == "/eth2/00000000/light_client_optimistic_update/ssz_snappy"
|
||||
|
|
|
@ -146,7 +146,9 @@ proc addTestBlock*(
|
|||
cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH + 10:
|
||||
if is_merge_transition_complete(forkyState.data):
|
||||
const feeRecipient = default(Eth1Address)
|
||||
build_empty_execution_payload(forkyState.data, feeRecipient)
|
||||
build_empty_execution_payload[
|
||||
bellatrix.BeaconState, bellatrix.ExecutionPayload](
|
||||
forkyState.data, feeRecipient)
|
||||
else:
|
||||
build_empty_merge_execution_payload(forkyState.data)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue