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): add lastProposedIn to slotB #18379

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/protocol/contracts/layer1/based/ITaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ interface ITaikoL1 {
view
returns (TaikoData.TransitionState memory);

/// @notice Retrieves the ID of the L1 block where the most recent L2 block was proposed.
/// @return The ID of the Li block where the most recent block was proposed.
function lastProposedIn() external view returns (uint56);

/// @notice Gets the configuration of the TaikoL1 contract.
/// @return Config struct containing configuration parameters.
function getConfig() external pure returns (TaikoData.Config memory);
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/layer1/based/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ library LibProposing {
unchecked {
++_state.slotB.numBlocks;
}
_state.slotB.lastProposedIn = uint56(block.number);

LibBonds.debitBond(_state, _resolver, local.params.proposer, meta_.id, _config.livenessBond);

Expand Down
4 changes: 1 addition & 3 deletions packages/protocol/contracts/layer1/based/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ library TaikoData {
uint64 numBlocks;
uint64 lastVerifiedBlockId;
bool provingPaused;
uint8 __reservedB1;
uint16 __reservedB2;
uint32 __reservedB3;
uint56 lastProposedIn;
uint64 lastUnpausedAt;
}

Expand Down
10 changes: 6 additions & 4 deletions packages/protocol/contracts/layer1/based/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {

/// @notice This function shall be called by previously deployed contracts.
function init2() external onlyOwner reinitializer(2) {
// reset some previously used slots for future reuse
state.slotB.__reservedB1 = 0;
state.slotB.__reservedB2 = 0;
state.slotB.__reservedB3 = 0;
state.__reserve1 = 0;
}

Expand Down Expand Up @@ -287,6 +283,12 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
return state.slotB.lastUnpausedAt;
}

/// @notice Retrieves the ID of the L1 block where the most recent L2 block was proposed.
/// @return The ID of the Li block where the most recent block was proposed.
function lastProposedIn() external view returns (uint56) {
return state.slotB.lastProposedIn;
}

/// @inheritdoc ITaikoL1
function getConfig() public pure virtual returns (TaikoData.Config memory) {
return TaikoData.Config({
Expand Down
15 changes: 15 additions & 0 deletions packages/protocol/contracts/layer1/provers/ProverSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ contract ProverSet is EssentialContract, IERC1271 {

error INVALID_STATUS();
error PERMISSION_DENIED();
error NOT_FIRST_PROPOSAL();

modifier onlyAuthorized() {
require(
Expand Down Expand Up @@ -81,6 +82,20 @@ contract ProverSet is EssentialContract, IERC1271 {
LibAddress.sendEtherAndVerify(admin, _amount);
}

/// @notice Proposes a block only when it is the first block proposal in the current L1 block.
function proposeBlockV2Conditionally(
bytes calldata _params,
bytes calldata _txList
)
external
onlyProver
{
ITaikoL1 taiko = ITaikoL1(taikoL1());
// Ensure this block is the first block proposed in the current L1 block.
require(taiko.lastProposedIn() != block.number, NOT_FIRST_PROPOSAL());
taiko.proposeBlockV2(_params, _txList);
}

/// @notice Propose a Taiko block.
function proposeBlockV2(bytes calldata _params, bytes calldata _txList) external onlyProver {
ITaikoL1(taikoL1()).proposeBlockV2(_params, _txList);
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/test/layer1/based/MockTaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ contract MockTaikoL1 is ITaikoL1 {
returns (TaikoData.TransitionState memory)
{ }

function lastProposedIn() external view returns (uint56) { }

function getConfig() external pure virtual returns (TaikoData.Config memory) { }
}
Loading