Skip to content

Commit

Permalink
feat(protocol): add getLastVerifiedBlock and getLastSyncedBlock (#17566)
Browse files Browse the repository at this point in the history
Co-authored-by: D <[email protected]>
  • Loading branch information
dantaik and adaki2004 authored Jun 12, 2024
1 parent e66a0c8 commit cf0743f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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

0 comments on commit cf0743f

Please sign in to comment.