Skip to content

Commit

Permalink
feat(bridge): add getMessageStatusSlot function (#12940)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jan 13, 2023
1 parent 0e596cb commit 9837fa3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
18 changes: 9 additions & 9 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,6 @@ library LibProposing {
emit BlockProposed(state.nextBlockId++, meta);
}

function getProposedBlock(
TaikoData.State storage state,
uint256 maxNumBlocks,
uint256 id
) internal view returns (TaikoData.ProposedBlock storage) {
require(id > state.latestVerifiedId && id < state.nextBlockId, "L1:id");
return state.getProposedBlock(maxNumBlocks, id);
}

function getBlockFee(
TaikoData.State storage state,
TaikoData.Config memory config
Expand Down Expand Up @@ -185,6 +176,15 @@ library LibProposing {
block.number >= commitHeight + commitConfirmations;
}

function getProposedBlock(
TaikoData.State storage state,
uint256 maxNumBlocks,
uint256 id
) internal view returns (TaikoData.ProposedBlock storage) {
require(id > state.latestVerifiedId && id < state.nextBlockId, "L1:id");
return state.getProposedBlock(maxNumBlocks, id);
}

function _saveProposedBlock(
TaikoData.State storage state,
uint256 maxNumBlocks,
Expand Down
6 changes: 6 additions & 0 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,10 @@ contract Bridge is EssentialContract, IBridge {
return
LibBridgeSend.isDestChainEnabled(AddressResolver(this), _chainId);
}

function getMessageStatusSlot(
bytes32 signal
) public pure returns (bytes32) {
return LibBridgeStatus.getMessageStatusSlot(signal);
}
}
4 changes: 2 additions & 2 deletions packages/protocol/contracts/bridge/libs/LibBridgeSend.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ library LibBridgeSend {
*
* @param message Specifies the `depositValue`, `callValue`,
* and `processingFee`. These must sum to `msg.value`. It also specifies the
* `destChainId` which must have a `bridge` address set on the AddressResolver
* and differ from the current chain ID.
* `destChainId` which must have a `bridge` address set on the
* AddressResolver and differ from the current chain ID.
*
* @return signal The message is hashed, stored, and emitted as a signal.
* This is picked up by an off-chain relayer which indicates a
Expand Down
24 changes: 13 additions & 11 deletions packages/protocol/contracts/bridge/libs/LibBridgeStatus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,25 @@ library LibBridgeStatus {
function getMessageStatus(
bytes32 signal
) internal view returns (MessageStatus) {
bytes32 k = _statusSlot(signal);
uint256 v;
bytes32 slot = getMessageStatusSlot(signal);
uint256 value;
assembly {
v := sload(k)
value := sload(slot)
}
return MessageStatus(v);
return MessageStatus(value);
}

function getMessageStatusSlot(
bytes32 signal
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("MESSAGE_STATUS", signal));
}

function _setMessageStatus(bytes32 signal, MessageStatus status) private {
bytes32 k = _statusSlot(signal);
uint256 v = uint256(status);
bytes32 slot = getMessageStatusSlot(signal);
uint256 value = uint256(status);
assembly {
sstore(k, v)
sstore(slot, value)
}
}

function _statusSlot(bytes32 signal) private pure returns (bytes32) {
return keccak256(abi.encodePacked("MESSAGE_STATUS", signal));
}
}

0 comments on commit 9837fa3

Please sign in to comment.