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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 @@ -287,4 +287,8 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
function getConfig() public pure virtual returns (TaikoData.Config memory) {
return LibSharedConfig.getConfig();
}

function getUncleProofDelay(uint256 blockId) public view returns (uint64) {
dantaik marked this conversation as resolved.
Show resolved Hide resolved
return LibUtils.getUncleProofDelay(state, getConfig(), blockId);
}
}
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ library LibProving {

require(
block.timestamp <
LibUtils.uncleProofDeadline({
LibUtils.getUncleProofDeadline({
state: state,
config: config,
fc: fc,
Expand Down
18 changes: 13 additions & 5 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,28 @@ library LibUtils {
return (feeBase * gamma) / 1024;
}

// Returns a deterministic deadline for uncle proof submission.
function uncleProofDeadline(
function getUncleProofDelay(
TaikoData.State storage state,
TaikoData.Config memory config,
TaikoData.ForkChoice storage fc,
uint256 blockId
) internal view returns (uint64) {
if (blockId <= 2 * config.maxNumBlocks) {
return fc.provenAt + config.initialUncleDelay;
return config.initialUncleDelay;
} else {
return fc.provenAt + state.avgProofTime;
return state.avgProofTime;
}
}

// Returns a deterministic deadline for uncle proof submission.
function getUncleProofDeadline(
TaikoData.State storage state,
TaikoData.Config memory config,
TaikoData.ForkChoice storage fc,
uint256 blockId
) internal view returns (uint64) {
return fc.provenAt + getUncleProofDelay(state, config, blockId);
}

function hashMetadata(
TaikoData.BlockMetadata memory meta
) internal pure returns (bytes32) {
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ library LibVerifying {
return
fc.blockHash != 0 &&
block.timestamp >
LibUtils.uncleProofDeadline({
LibUtils.getUncleProofDeadline({
state: state,
config: config,
fc: fc,
Expand Down
39 changes: 28 additions & 11 deletions packages/protocol/test/L1/TaikoL1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("TaikoL1", function () {
await ethers.getContractFactory("LibProving", {
libraries: {
LibReceiptDecoder: libReceiptDecoder.address,
LibTxDecoder: libTxDecoder.address
LibTxDecoder: libTxDecoder.address,
},
})
).deploy();
Expand All @@ -41,16 +41,13 @@ describe("TaikoL1", function () {
genesisHash = randomBytes32();
const feeBase = BigNumber.from(10).pow(18);
taikoL1 = await (
await ethers.getContractFactory(
"TestTaikoL1",
{
libraries: {
LibVerifying: libVerifying.address,
LibProposing: libProposing.address,
LibProving: libProving.address,
},
}
)
await ethers.getContractFactory("TestTaikoL1", {
libraries: {
LibVerifying: libVerifying.address,
LibProposing: libProposing.address,
LibProving: libProving.address,
},
})
).deploy();
await taikoL1.init(addressManager.address, genesisHash, feeBase);
});
Expand Down Expand Up @@ -85,6 +82,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.getConfig();
const maxNumBlocks = constants[1];
const delay = await taikoL1.getUncleProofDelay(maxNumBlocks.mul(2));
const initialUncleDelay = 60;
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.getConfig();
const maxNumBlocks = constants[1];
const delay = await taikoL1.getUncleProofDelay(
maxNumBlocks.mul(2).add(1)
);
const avgProofTime = 0; // no proofs have been generated
expect(delay).to.be.eq(avgProofTime);
});
});
});

function randomBytes32() {
Expand Down