Skip to content

Commit

Permalink
remove block fork guessing/inference from REST JSON decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Sep 18, 2024
1 parent 6ab3568 commit 496f290
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 642 deletions.
5 changes: 2 additions & 3 deletions AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ DenebSignedBlockContents decoding OK
+ KzgCommitment OK
+ KzgProof OK
+ RestPublishedSignedBlockContents decoding OK
+ Validator pubkey hack OK
```
OK: 6/6 Fail: 0/6 Skip: 0/6
OK: 5/5 Fail: 0/5 Skip: 0/5
## Remove keystore testing suite
```diff
+ Many remotes OK
Expand Down Expand Up @@ -1125,4 +1124,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 9/9 Fail: 0/9 Skip: 0/9

---TOTAL---
OK: 762/767 Fail: 0/767 Skip: 5/767
OK: 761/766 Fail: 0/766 Skip: 5/766
33 changes: 28 additions & 5 deletions beacon_chain/rpc/rest_beacon_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,23 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
let
body = contentBody.get()
version = request.headers.getString("eth-consensus-version")
restBlock = decodeBody(
RestPublishedSignedBlockContents, body, version).valueOr:
return RestApiResponse.jsonError(error)
currentEpochFork =
node.dag.cfg.consensusForkAtEpoch(node.currentSlot().epoch())
rawVersion = request.headers.getString("eth-consensus-version")

# The V1 endpoint doesn't require the version to be specified but the
# only fork which works is the current gossip fork. Either it can use
# and broadcast a block in that fork or that broadcast will not prove
# useful anyway, so allow it to fail at the decoding stage.
version =
if rawVersion == "":
currentEpochFork.toString
else:
rawVersion

let restBlock = decodeBody(
RestPublishedSignedBlockContents, body, version).valueOr:
return RestApiResponse.jsonError(error)

withForkyBlck(restBlock):
if restBlock.kind != node.dag.cfg.consensusForkAtEpoch(
Expand Down Expand Up @@ -1047,9 +1060,19 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
let
currentEpochFork =
node.dag.cfg.consensusForkAtEpoch(node.currentSlot().epoch())
version = request.headers.getString("eth-consensus-version")
rawVersion = request.headers.getString("eth-consensus-version")
body = contentBody.get()

# The V1 endpoint doesn't require the version to be specified but the
# only fork which works is the current gossip fork. Either it can use
# and broadcast a block in that fork or that broadcast will not prove
# useful anyway, so allow it to fail at the decoding stage.
version =
if rawVersion == "":
currentEpochFork.toString
else:
rawVersion

if (body.contentType == OctetStreamMediaType) and
(currentEpochFork.toString != version):
return RestApiResponse.jsonError(Http400, BlockIncorrectFork)
Expand Down
Loading

0 comments on commit 496f290

Please sign in to comment.