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 #3267 #3367

Merged
merged 8 commits into from
Feb 13, 2022
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
48 changes: 14 additions & 34 deletions beacon_chain/rpc/rest_beacon_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -747,45 +747,25 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
# https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlock
router.api(MethodPost, "/eth/v1/beacon/blocks") do (
contentBody: Option[ContentBody]) -> RestApiResponse:
let forked =
let forkedBlock =
block:
if contentBody.isNone():
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
let body = contentBody.get()
let altairRes = decodeBody(altair.SignedBeaconBlock, body)
if altairRes.isOk():
var res = altairRes.get()
if res.message.slot.epoch < node.dag.cfg.ALTAIR_FORK_EPOCH:
# This message deserialized successfully as altair but should
# actually be a phase0 block - try again with phase0
let phase0res = decodeBody(phase0.SignedBeaconBlock, body)
if phase0res.isOk():
var res = phase0res.get()
# `SignedBeaconBlock` deserialization do not update `root` field,
# so we need to calculate it.
res.root = hash_tree_root(res.message)
ForkedSignedBeaconBlock.init(res)
else:
return RestApiResponse.jsonError(Http400, InvalidBlockObjectError,
$phase0res.error())
else:
# `SignedBeaconBlock` deserialization do not update `root` field,
# so we need to calculate it.
res.root = hash_tree_root(res.message)
ForkedSignedBeaconBlock.init(res)
else:
let phase0res = decodeBody(phase0.SignedBeaconBlock, body)
if phase0res.isOk():
var res = phase0res.get()
# `SignedBeaconBlock` deserialization do not update `root` field,
# so we need to calculate it.
res.root = hash_tree_root(res.message)
ForkedSignedBeaconBlock.init(res)
else:
return RestApiResponse.jsonError(Http400, InvalidBlockObjectError,
$phase0res.error())
let res = decodeBody(RestPublishedSignedBeaconBlock, body)
if res.isErr():
return RestApiResponse.jsonError(Http400, InvalidBlockObjectError,
$res.error())
var forked = ForkedSignedBeaconBlock(res.get())
if forked.kind != node.dag.cfg.blockForkAtEpoch(
getForkedBlockField(forked, slot).epoch):
return RestApiResponse.jsonError(Http400, InvalidBlockObjectError)

withBlck(forked):
blck.root = hash_tree_root(blck.message)
forked

let res = await node.sendBeaconBlock(forked)
let res = await node.sendBeaconBlock(forkedBlock)
if res.isErr():
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
if not(res.get()):
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/datatypes/bellatrix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ proc fromHex*(T: typedesc[BloomLogs], s: string): T {.raises: [Defect, ValueErro
proc fromHex*(T: typedesc[ExecutionAddress], s: string): T {.raises: [Defect, ValueError].} =
hexToByteArray(s, result.data)

proc writeValue*(w: var JsonWriter, a: ExecutionAddress) {.raises: [Defect, IOError, SerializationError].} =
proc writeValue*(w: var JsonWriter, a: ExecutionAddress) {.raises: [Defect, IOError].} =
w.writeValue $a

proc readValue*(r: var JsonReader, a: var ExecutionAddress) {.raises: [Defect, IOError, SerializationError].} =
Expand Down
Loading