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(protocol): expose getUncleProofDelay function #7058

Merged
merged 6 commits into from
Jan 4, 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
4 changes: 4 additions & 0 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events {
return state.forkChoices[id][parentHash].provers;
}

function getDelayForBlockId(uint256 blockId) public view returns (uint64) {
return V1Utils.getDelay(state, blockId);
}

function getConstants()
public
pure
Expand Down
11 changes: 9 additions & 2 deletions packages/protocol/contracts/L1/v1/V1Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ library V1Utils {
LibData.State storage state,
LibData.ForkChoice storage fc,
uint256 blockId
) internal view returns (uint64) {
return fc.provenAt + getDelay(state, blockId);
}

function getDelay(
dantaik marked this conversation as resolved.
Show resolved Hide resolved
LibData.State storage state,
uint256 blockId
) internal view returns (uint64) {
if (blockId <= 2 * LibConstants.K_MAX_NUM_BLOCKS) {
return fc.provenAt + LibConstants.K_INITIAL_UNCLE_DELAY;
return LibConstants.K_INITIAL_UNCLE_DELAY;
} else {
return fc.provenAt + state.avgProofTime;
return state.avgProofTime;
}
}

Expand Down
20 changes: 20 additions & 0 deletions packages/protocol/test/L1/TaikoL1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ describe("TaikoL1", function () {
expect(provers).to.be.empty;
});
});

describe("getDelayForBlockId()", async function () {
it("should return initial uncle delay for block id <= 2 * K_MAX_NUM_BLOCKS", async function () {
const constants = await taikoL1.getConstants();
const maxNumBlocks = constants[2];
const delay = await taikoL1.getDelayForBlockId(maxNumBlocks.mul(2));
const initialUncleDelay = 3600;
expect(delay).to.be.eq(initialUncleDelay);
});

it("should return avg proof time for block id > 2 * K_MAX_NUM_BLOCKS", async function () {
const constants = await taikoL1.getConstants();
const maxNumBlocks = constants[2];
const delay = await taikoL1.getDelayForBlockId(
maxNumBlocks.mul(2).add(1)
);
const avgProofTime = 0; // no proofs have been generated
expect(delay).to.be.eq(avgProofTime);
});
});
});

function randomBytes32() {
Expand Down