Skip to content

Commit

Permalink
fix(protocol): Fix bug in getProposedBlock (#11679)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Jan 10, 2023
1 parent a164ac9 commit a6a596c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
function getProposedBlock(
uint256 id
) public view returns (TaikoData.ProposedBlock memory) {
return state.getProposedBlock(getConfig().maxNumBlocks, id);
return
LibProposing.getProposedBlock(state, getConfig().maxNumBlocks, id);
}

function getSyncedHeader(
Expand Down
9 changes: 9 additions & 0 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ library LibProposing {
emit BlockProposed(state.nextBlockId++, meta);
}

function getProposedBlock(
TaikoData.State storage state,
uint256 maxNumBlocks,
uint256 id
) internal view returns (TaikoData.ProposedBlock storage) {
require(id > state.latestVerifiedId && id < state.nextBlockId, "L1:id");
return state.getProposedBlock(maxNumBlocks, id);
}

function getBlockFee(
TaikoData.State storage state,
TaikoData.Config memory config
Expand Down
13 changes: 7 additions & 6 deletions packages/protocol/test/L1/TaikoL1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ describe("integration:TaikoL1", function () {
);

l2Signer = await l2Provider.getSigner(
(await l2Provider.listAccounts())[0]
(
await l2Provider.listAccounts()
)[0]
);

const addressManager = await (
Expand Down Expand Up @@ -267,11 +269,10 @@ describe("integration:TaikoL1", function () {
});

describe("getProposedBlock()", function () {
it("proposed block does not exist", async function () {
const block = await taikoL1.getProposedBlock(123);
expect(block[0]).to.be.eq(ethers.constants.HashZero);
expect(block[1]).to.be.eq(ethers.constants.AddressZero);
expect(block[2]).to.be.eq(BigNumber.from(0));
it("reverts when id is not a valid proposed block in range", async function () {
await expect(taikoL1.getProposedBlock(123)).to.be.revertedWith(
"L1:id"
);
});
});
describe("commitBlock() -> proposeBlock() integration", async function () {
Expand Down

0 comments on commit a6a596c

Please sign in to comment.