Skip to content

Commit

Permalink
feat(protocol): getBlock also returns the transition used to verify t…
Browse files Browse the repository at this point in the history
…he block (#15917)
  • Loading branch information
dantaik authored Feb 19, 2024
1 parent 0f314c5 commit e583d99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 12 additions & 2 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,18 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
/// @notice Gets the details of a block.
/// @param blockId Index of the block.
/// @return blk The block.
function getBlock(uint64 blockId) public view returns (TaikoData.Block memory blk) {
return LibUtils.getBlock(state, getConfig(), blockId);
/// @return ts The transition used to verify this block.
function getBlock(uint64 blockId)
public
view
returns (TaikoData.Block memory blk, TaikoData.TransitionState memory ts)
{
uint64 slot;
(blk, slot) = LibUtils.getBlock(state, getConfig(), blockId);

if (blk.verifiedTransitionId != 0) {
ts = state.transitions[slot][blk.verifiedTransitionId];
}
}

/// @notice Gets the state transition for a specific block.
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ library LibUtils {
)
external
view
returns (TaikoData.Block storage blk)
returns (TaikoData.Block storage blk, uint64 slot)
{
blk = state.blocks[blockId % config.blockRingBufferSize];
slot = blockId % config.blockRingBufferSize;
blk = state.blocks[slot];
if (blk.blockId != blockId) {
revert L1_INVALID_BLOCK_ID();
}
Expand Down

0 comments on commit e583d99

Please sign in to comment.