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 1 commit
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
7 changes: 7 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,13 @@ async function resolveBlockIdOrNull(
};
}

if (blockId === "justified") {
return {
block: await db.blockArchive.get(forkChoice.getJustifiedBlock().slot),
Copy link
Contributor

Choose a reason for hiding this comment

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

Non finalized blocks are not in the archive, but in the block hot db. blockArchive will most likely return null for this query. Instead grab by root from the hot db.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed a fix for this, thanks @nazarhussain for helping me to validate the solution.

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,13 @@ describe("block api utils", function () {
expect(dbStub.blockArchive.get).to.be.calledOnceWithExactly(expected);
});

it("should resolve justified", async function () {
const expected = 0;
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.blockArchive.get).to.be.calledOnceWithExactly(expected);
});

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