Skip to content

Commit

Permalink
feat: add support for justified block id in Beacon Node API (#5459)
Browse files Browse the repository at this point in the history
* feat: add support for `justified` block id

* fix: use hot db instead of archive db

* fix: apply correct execution optimistic flag
  • Loading branch information
acuarica authored May 8, 2023
1 parent 28efaea commit c4a7fde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/beacon-node/src/api/impl/beacon/blocks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ async function resolveBlockIdOrNull(
};
}

if (blockId === "justified") {
const justified = forkChoice.getJustifiedBlock();
return {
block: await db.block.get(fromHexString(justified.blockRoot)),
executionOptimistic: isOptimisticBlock(justified),
};
}

let blockSummary;
let getBlockByBlockArchive;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ describe("block api utils", function () {
expect(dbStub.blockArchive.get).to.be.calledOnceWithExactly(expected);
});

it("should resolve justified", async function () {
forkChoiceStub.getJustifiedBlock.returns(expectedSummary);
await resolveBlockId(forkChoiceStub, dbStub, "justified").catch(() => {});
expect(dbStub.block.get).to.be.calledOnceWithExactly(bufferEqualsMatcher(expectedBuffer));
});

it("should resolve finalized block root", async function () {
forkChoiceStub.getBlock.returns(expectedSummary);
forkChoiceStub.getFinalizedBlock.returns(expectedSummary);
Expand Down

0 comments on commit c4a7fde

Please sign in to comment.