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(bridge): add getMessageStatusSlot function #12940

Merged
merged 3 commits into from
Jan 13, 2023
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
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));
}
}