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

feat: add support for justified block id in Beacon Node API #5459

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 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: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can compute the correct executionOptimistic boolean value with the forkChoice returned data structure. Check other API endpoints can't recall the exact helper fn name

};
}

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(() => {});
Copy link
Contributor

@dapplion dapplion May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the silent catch all errors here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why, all other tests for resolveBlockId have the same structure, so I didn't want to make it different in case I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing this with @nazarhussain, we found that without the catch all these tests fail here

throw new ApiError(404, `No block found for id '${blockId}'`);

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