remove some debugRaiseAsserts and fill in actual Electra functionality (#6172)

This commit is contained in:
tersec 2024-04-04 03:17:31 +00:00 committed by GitHub
parent 13a70e9d69
commit 0b6f75b88b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 76 additions and 36 deletions

View File

@ -57,13 +57,9 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
elif contentType == sszMediaType:
let headers = [("eth-consensus-version", state.kind.toString())]
withState(state):
debugRaiseAssert "debug beacon API"
when consensusFork != ConsensusFork.Electra:
RestApiResponse.sszResponse(forkyState.data, headers)
else:
RestApiResponse.jsonError(Http500, InvalidAcceptError)
else:
RestApiResponse.jsonError(Http500, InvalidAcceptError)
RestApiResponse.jsonError(Http404, StateNotFoundError)

View File

@ -67,11 +67,13 @@ RestJson.useDefaultSerializationFor(
DenebSignedBlockContents,
Deposit,
DepositData,
DepositReceipt,
DepositTreeSnapshot,
DistributedKeystoreInfo,
EmptyBody,
Eth1Data,
EventBeaconBlockObject,
ExecutionLayerExit,
ExecutionPayloadAndBlobsBundle,
Fork,
GetBlockAttestationsResponse,
@ -240,6 +242,12 @@ RestJson.useDefaultSerializationFor(
deneb_mev.BuilderBid,
deneb_mev.SignedBlindedBeaconBlock,
deneb_mev.SignedBuilderBid,
electra.BeaconBlock,
electra.BeaconState,
electra.BeaconBlockBody,
electra.ExecutionPayload,
electra.ExecutionPayloadHeader,
electra.SignedBeaconBlock,
phase0.BeaconBlock,
phase0.BeaconBlockBody,
phase0.BeaconState,
@ -597,8 +605,6 @@ proc jsonResponseBlock*(t: typedesc[RestApiResponse],
writer.writeField("execution_optimistic", execOpt.get())
writer.writeField("finalized", finalized)
withBlck(data):
debugRaiseAssert "foo"
when consensusFork != ConsensusFork.Electra:
writer.writeField("data", forkyBlck)
writer.endRecord()
stream.getOutput(seq[byte])
@ -622,8 +628,6 @@ proc jsonResponseState*(t: typedesc[RestApiResponse],
if execOpt.isSome():
writer.writeField("execution_optimistic", execOpt.get())
withState(data):
debugRaiseAssert "foo"
when consensusFork != ConsensusFork.Electra:
writer.writeField("data", forkyState.data)
writer.endRecord()
stream.getOutput(seq[byte])
@ -2007,8 +2011,15 @@ proc readValue*(reader: var JsonReader[RestJson],
)
)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
default(ForkedBeaconBlock)
ForkedBeaconBlock.init(
electra.BeaconBlock(
slot: slot.get(),
proposer_index: proposer_index.get(),
parent_root: parent_root.get(),
state_root: state_root.get(),
body: body.electraBody
)
)
)
## RestPublishedSignedBeaconBlock
@ -2253,7 +2264,16 @@ proc readValue*(reader: var JsonReader[RestJson],
value = ForkedSignedBeaconBlock.init(res)
of ConsensusFork.Electra:
debugRaiseAssert "electra support missing"
let res =
try:
RestJson.decode(string(data.get()),
electra.SignedBeaconBlock,
requireAllFields = true,
allowUnknownFields = true)
except SerializationError:
reader.raiseUnexpectedValue("Incorrect electra block format")
value = ForkedSignedBeaconBlock.init(res)
withBlck(value):
forkyBlck.root = hash_tree_root(forkyBlck.message)
@ -2278,6 +2298,7 @@ proc writeValue*(
writer.writeField("version", "deneb")
writer.writeField("data", value.denebData)
of ConsensusFork.Electra:
writer.writeField("version", "electra")
debugRaiseAssert "writeValue RestJson Electra ForkedSignedBaconBlock"
writer.endRecord()
@ -2303,6 +2324,7 @@ proc readValue*(reader: var JsonReader[RestJson],
of "bellatrix": Opt.some(ConsensusFork.Bellatrix)
of "capella": Opt.some(ConsensusFork.Capella)
of "deneb": Opt.some(ConsensusFork.Deneb)
of "electra": Opt.some(ConsensusFork.Electra)
else: reader.raiseUnexpectedValue("Incorrect version field value")
of "data":
if data.isSome():
@ -2383,8 +2405,15 @@ proc readValue*(reader: var JsonReader[RestJson],
reader.raiseUnexpectedValue("Incorrect deneb beacon state format")
toValue(denebData)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
reader.raiseUnexpectedValue("electra missing")
try:
tmp[].electraData.data = RestJson.decode(
string(data.get()),
electra.BeaconState,
requireAllFields = true,
allowUnknownFields = true)
except SerializationError:
reader.raiseUnexpectedValue("Incorrect electra beacon state format")
toValue(electraData)
proc writeValue*(
writer: var JsonWriter[RestJson], value: ForkedHashedBeaconState
@ -2407,7 +2436,8 @@ proc writeValue*(
writer.writeField("version", "deneb")
writer.writeField("data", value.denebData.data)
of ConsensusFork.Electra:
debugRaiseAssert "writeValue RestJson ForkedHashedBeaconState Electra missing"
writer.writeField("version", "electra")
writer.writeField("data", value.electraData.data)
writer.endRecord()
## SomeForkedLightClientObject

View File

@ -662,8 +662,7 @@ func init*(T: type ForkedSignedBeaconBlock,
of ConsensusFork.Deneb:
ForkedSignedBeaconBlock.init(contents.denebData.signed_block)
of ConsensusFork.Electra:
debugRaiseAssert "electra init ForkedSignedBeaconBlock from RestPublished*"
default(ForkedSignedBeaconBlock)
ForkedSignedBeaconBlock.init(contents.electraData.signed_block)
func init*(t: typedesc[RestPublishedSignedBlockContents],
blck: phase0.BeaconBlock, root: Eth2Digest,

View File

@ -517,10 +517,9 @@ template Forky*(
template withAll*(
x: typedesc[ConsensusFork], body: untyped): untyped =
static: doAssert ConsensusFork.high == ConsensusFork.Electra
debugRaiseAssert "don't turn on electra here yet"
#block:
# const consensusFork {.inject, used.} = ConsensusFork.Electra
# body
block:
const consensusFork {.inject, used.} = ConsensusFork.Electra
body
block:
const consensusFork {.inject, used.} = ConsensusFork.Deneb
body
@ -638,6 +637,8 @@ template init*(T: type ForkedBeaconBlock, blck: capella.BeaconBlock): T =
T(kind: ConsensusFork.Capella, capellaData: blck)
template init*(T: type ForkedBeaconBlock, blck: deneb.BeaconBlock): T =
T(kind: ConsensusFork.Deneb, denebData: blck)
template init*(T: type ForkedBeaconBlock, blck: electra.BeaconBlock): T =
T(kind: ConsensusFork.Electra, electraData: blck)
template init*(T: type ForkedSignedBeaconBlock, blck: phase0.SignedBeaconBlock): T =
T(kind: ConsensusFork.Phase0, phase0Data: blck)

View File

@ -113,8 +113,14 @@ proc produceBlock(
kzgProofsOpt: Opt.some(kzgProofs),
blobsOpt: Opt.some(blobs)))
of ConsensusFork.Electra:
debugRaiseAssert ""
return Opt.none(PreparedBeaconBlock)
let
blck = produceBlockResponse.electraData.`block`
kzgProofs = produceBlockResponse.electraData.kzg_proofs
blobs = produceBlockResponse.electraData.blobs
return Opt.some(PreparedBeaconBlock(blockRoot: hash_tree_root(blck),
data: ForkedBeaconBlock.init(blck),
kzgProofsOpt: Opt.some(kzgProofs),
blobsOpt: Opt.some(blobs)))
proc produceBlindedBlock(
vc: ValidatorClientRef,

View File

@ -247,7 +247,8 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
seq[altair.TrustedSignedBeaconBlock],
seq[bellatrix.TrustedSignedBeaconBlock],
seq[capella.TrustedSignedBeaconBlock],
seq[deneb.TrustedSignedBeaconBlock])
seq[deneb.TrustedSignedBeaconBlock],
seq[electra.TrustedSignedBeaconBlock])
echo "Loaded head slot ", dag.head.slot,
" selected ", blockRefs.len, " blocks"
@ -287,7 +288,8 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
(ref altair.HashedBeaconState)(),
(ref bellatrix.HashedBeaconState)(),
(ref capella.HashedBeaconState)(),
(ref deneb.HashedBeaconState)())
(ref deneb.HashedBeaconState)(),
(ref electra.HashedBeaconState)())
withTimer(timers[tLoadState]):
doAssert dag.updateState(
@ -349,8 +351,8 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
doAssert dbBenchmark.getState(
forkyState.root, loadedState[4][].data, noRollback)
of ConsensusFork.Electra:
debugRaiseAssert ""
let x = 5
doAssert dbBenchmark.getState(
forkyState.root, loadedState[5][].data, noRollback)
if forkyState.data.slot.epoch mod 16 == 0:
let loadedRoot = case consensusFork
@ -359,9 +361,7 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
of ConsensusFork.Bellatrix: hash_tree_root(loadedState[2][].data)
of ConsensusFork.Capella: hash_tree_root(loadedState[3][].data)
of ConsensusFork.Deneb: hash_tree_root(loadedState[4][].data)
of ConsensusFork.Electra:
debugRaiseAssert ""
ZERO_HASH
of ConsensusFork.Electra: hash_tree_root(loadedState[5][].data)
doAssert hash_tree_root(forkyState.data) == loadedRoot
processBlocks(blocks[0])
@ -369,6 +369,7 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
processBlocks(blocks[2])
processBlocks(blocks[3])
processBlocks(blocks[4])
processBlocks(blocks[5])
printTimers(false, timers)

View File

@ -222,8 +222,14 @@ cli do(validatorsDir: string, secretsDir: string,
validators[proposer]).toValidatorSig())
dump(".", signedBlock)
of ConsensusFork.Electra:
debugRaiseAssert ""
let x =5
blockRoot = hash_tree_root(message.electraData)
let signedBlock = electra.SignedBeaconBlock(
message: message.electraData,
root: blockRoot,
signature: get_block_signature(
fork, genesis_validators_root, slot, blockRoot,
validators[proposer]).toValidatorSig())
dump(".", signedBlock)
except CatchableError:
raiseAssert "unreachable"
notice "Block proposed", message, blockRoot

View File

@ -136,8 +136,9 @@ func init(t: typedesc[Web3SignerForkedBeaconBlock],
kind: ConsensusFork.Deneb,
data: forked.denebData.toBeaconBlockHeader)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
raiseAssert "electra missing"
Web3SignerForkedBeaconBlock(
kind: ConsensusFork.Electra,
data: forked.electraData.toBeaconBlockHeader)
proc createKeystore(dataDir, pubkey,
store, password: string): Result[void, string] =