Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Deneb RestPublishedSignedBlockContents REST JSON decoding #5520

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ OK: 12/12 Fail: 0/12 Skip: 0/12
+ prune states OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## REST JSON decoding
```diff
+ DenebSignedBlockContents OK
+ RestPublishedSignedBlockContents OK
```
OK: 2/2 Fail: 0/2 Skip: 0/2
## Remove keystore testing suite
```diff
+ Many remotes OK
Expand Down Expand Up @@ -705,4 +711,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 9/9 Fail: 0/9 Skip: 0/9

---TOTAL---
OK: 398/403 Fail: 0/403 Skip: 5/403
OK: 400/405 Fail: 0/405 Skip: 5/405
25 changes: 12 additions & 13 deletions beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ proc readValue*(reader: var JsonReader[RestJson],
"RestPublishedBeaconBlockBody")
bls_to_execution_changes = Opt.some(
reader.readValue(SignedBLSToExecutionChangeList))
of "blob_kzg_commitments_changes":
of "blob_kzg_commitments":
if blob_kzg_commitments.isSome():
reader.raiseUnexpectedField("Multiple `blob_kzg_commitments` fields found",
"RestPublishedBeaconBlockBody")
Expand Down Expand Up @@ -1750,6 +1750,8 @@ proc readValue*(reader: var JsonReader[RestJson],
Opt.none(RestPublishedSignedBeaconBlock)
if signed_message.isNone():
reader.raiseUnexpectedValue("Incorrect signed_block format")

# Only needed to signal fork to the blck.kind case selection
let blck = ForkedSignedBeaconBlock(signed_message.get())
message = Opt.some(RestPublishedBeaconBlock(
case blck.kind
Expand All @@ -1759,28 +1761,27 @@ proc readValue*(reader: var JsonReader[RestJson],
of ConsensusFork.Deneb:
ForkedBeaconBlock.init(blck.denebData.message)
))

signature = Opt.some(forks.signature(
ForkedSignedBeaconBlock(signed_message.get())))
of "signed_blob_sidecars":
if signed_blob_sidecars.isSome():
reader.raiseUnexpectedField(
"Multiple `signed_blob_sidecars` fields found",
"RestPublishedSignedBlockContents")
if signature.isSome():
reader.raiseUnexpectedField(
"Found `signed_block` field alongside message or signature fields",
"Found `signed_blob_sidecars` field alongside signature field",
"RestPublishedSignedBlockContents")
signed_blob_sidecars = Opt.some(reader.readValue(
List[SignedBlobSidecar, Limit MAX_BLOBS_PER_BLOCK]))

else:
unrecognizedFieldWarning()

if signature.isNone():
reader.raiseUnexpectedValue("Field `signature` is missing")
if message.isNone():
reader.raiseUnexpectedValue("Field `message` is missing")
if signed_message.isNone():
# Pre-Deneb; conditions for when signed_message.isSome checked in case body
if signature.isNone():
reader.raiseUnexpectedValue("Field `signature` is missing")
if message.isNone():
reader.raiseUnexpectedValue("Field `message` is missing")

let blck = ForkedBeaconBlock(message.get())
case blck.kind
Expand Down Expand Up @@ -1820,10 +1821,8 @@ proc readValue*(reader: var JsonReader[RestJson],
value = RestPublishedSignedBlockContents(
kind: ConsensusFork.Deneb,
denebData: DenebSignedBlockContents(
signed_block: deneb.SignedBeaconBlock(
message: blck.denebData,
signature: signature.get()
),
# Constructed to be interally consistent
signed_block: signed_message.get().distinctBase.denebData,
signed_blob_sidecars: signed_blob_sidecars.get()
)
)
Expand Down
1 change: 0 additions & 1 deletion beacon_chain/spec/eth2_apis/rest_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import
".."/mev/[capella_mev, deneb_mev]

from ".."/datatypes/capella import BeaconBlockBody
from ".."/mev/deneb_mev import ExecutionPayloadAndBlobsBundle

export forks, phase0, altair, bellatrix, capella, capella_mev, deneb_mev,
tables, httputils
Expand Down
1 change: 1 addition & 0 deletions tests/all_tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import # Unit test
./test_network_metadata,
./test_peer_pool,
./test_remote_keystore,
./test_rest_json_serialization,
./test_serialization,
./test_spec,
./test_statediff,
Expand Down
Loading
Loading