Skip to content

Commit

Permalink
Fix isGenesis implementation and add REST test rules for both calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatfate committed Sep 18, 2024
1 parent b216cba commit 23e6d3b
Show file tree
Hide file tree
Showing 2 changed files with 383 additions and 4 deletions.
16 changes: 12 additions & 4 deletions beacon_chain/rpc/rest_rewards_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ export rest_utils

logScope: topics = "rest_rewardsapi"

func isGenesis(blockId: BlockIdent, genesisBsid: BlockSlotId): bool =
func isGenesis(node: BeaconNode,
blockId: BlockIdent,
genesisBsid: BlockSlotId): bool =
case blockId.kind
of BlockQueryKind.Named:
blockId.value == BlockIdentType.Genesis
case blockId.value
of BlockIdentType.Genesis:
true
of BlockIdentType.Head:
node.dag.head.bid.slot == GENESIS_SLOT
of BlockIdentType.Finalized:
node.dag.finalizedHead.slot == GENESIS_SLOT
of BlockQueryKind.Slot:
blockId.slot == GENESIS_SLOT
of BlockQueryKind.Root:
Expand All @@ -51,7 +59,7 @@ proc installRewardsApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, InvalidBlockIdValueError,
$error)

if bident.isGenesis(genesisBsid):
if node.isGenesis(bident, genesisBsid):
return RestApiResponse.response(
genesisBlockRewardsResponse, Http200, "application/json")

Expand Down Expand Up @@ -140,7 +148,7 @@ proc installRewardsApiHandlers*(router: var RestRouter, node: BeaconNode) =

targetBlock =
withBlck(bdata):
if bident.isGenesis(genesisBsid):
if node.isGenesis(bident, genesisBsid):
genesisBsid
else:
let parentBid =
Expand Down
Loading

0 comments on commit 23e6d3b

Please sign in to comment.