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 getLastVerifiedBlock and getLastSyncedBlock #17566

Merged
merged 5 commits into from
Jun 12, 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
28 changes: 27 additions & 1 deletion packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,37 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
{
return LibUtils.getTransition(state, getConfig(), _blockId, _tid);
}

/// @notice Returns information about the last verified block.
/// @return blockId_ The last verified block's ID.
/// @return blockHash_ The last verified block's blockHash.
/// @return stateRoot_ The last verified block's stateRoot.
function getLastVerifiedBlock()
public
view
returns (uint64 blockId_, bytes32 blockHash_, bytes32 stateRoot_)
{
blockId_ = state.slotB.lastVerifiedBlockId;
(blockHash_, stateRoot_) = LibUtils.getBlockInfo(state, getConfig(), blockId_);
}

/// @notice Returns information about the last synchronized block.
/// @return blockId_ The last verified block's ID.
/// @return blockHash_ The last verified block's blockHash.
/// @return stateRoot_ The last verified block's stateRoot.
function getLastSyncedBlock()
public
view
returns (uint64 blockId_, bytes32 blockHash_, bytes32 stateRoot_)
{
blockId_ = state.slotA.lastSyncedBlockId;
(blockHash_, stateRoot_) = LibUtils.getBlockInfo(state, getConfig(), blockId_);
}

/// @notice Gets the state variables of the TaikoL1 contract.
/// @dev This method can be deleted once node/client stops using it.
/// @return State variables stored at SlotA.
/// @return State variables stored at SlotB.

function getStateVariables()
public
view
Expand Down
20 changes: 20 additions & 0 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ library LibUtils {
}
}

function getBlockInfo(
TaikoData.State storage _state,
TaikoData.Config memory _config,
uint64 _blockId
)
internal
view
returns (bytes32 blockHash_, bytes32 stateRoot_)
{
(TaikoData.Block storage blk, uint64 slot) = getBlock(_state, _config, _blockId);

if (blk.verifiedTransitionId != 0) {
TaikoData.TransitionState storage transition =
_state.transitions[slot][blk.verifiedTransitionId];

blockHash_ = transition.blockHash;
stateRoot_ = transition.stateRoot;
}
}

function isPostDeadline(
uint256 _tsTimestamp,
uint256 _lastUnpausedAt,
Expand Down