Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
fix: workflow file and refactor require in a separate modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
mikirov committed Apr 3, 2023
1 parent 04ee542 commit 5e12e69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Spawn anvil instances
run: |
anvil &
anvil -p 8546 &
sleep 2
- name: Run tests
run: forge test -vvv --via-ir

Expand Down
44 changes: 22 additions & 22 deletions src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,16 @@ contract Gateway is IGateway, ReentrancyGuard {
}

modifier isRegistered() {
(bool registered, ) = getSubnet(msg.sender);
(bool registered, ) = _getSubnet(msg.sender);
require(registered, "subnet is not registered");
_;
}

modifier hasFee() {
require(msg.value > crossMsgFee, "not enough gas to pay cross-message");
_;
}

constructor(address[] memory path, int64 checkpointPeriod, uint256 msgFee) {
networkName = SubnetID(path);
minStake = MIN_COLLATERAL_AMOUNT;
Expand Down Expand Up @@ -138,17 +143,17 @@ contract Gateway is IGateway, ReentrancyGuard {

function getSubnetTopDownMsgsLength(
SubnetID memory subnetId
) public view returns (uint) {
(, Subnet storage subnet) = getSubnet(subnetId);
) external view returns (uint) {
(, Subnet storage subnet) = _getSubnet(subnetId);

return subnet.topDownMsgs.length;
}

function getSubnetTopDownMsg(
SubnetID memory subnetId,
uint index
) public view returns (CrossMsg memory) {
(, Subnet storage subnet) = getSubnet(subnetId);
) external view returns (CrossMsg memory) {
(, Subnet storage subnet) = _getSubnet(subnetId);
return subnet.topDownMsgs[index];
}

Expand All @@ -162,7 +167,7 @@ contract Gateway is IGateway, ReentrancyGuard {
"call to register doesn't include enough funds"
);

(bool registered, Subnet storage subnet) = getSubnet(msg.sender);
(bool registered, Subnet storage subnet) = _getSubnet(msg.sender);

require(registered == false, "subnet is already registered");

Expand All @@ -178,14 +183,14 @@ contract Gateway is IGateway, ReentrancyGuard {
function addStake() external payable isRegistered {
require(msg.value > 0, "no stake to add");

(, Subnet storage subnet) = getSubnet(msg.sender);
(, Subnet storage subnet) = _getSubnet(msg.sender);
subnet.stake += msg.value;
}

function releaseStake(uint amount) external nonReentrant isRegistered {
require(amount > 0, "no funds to release in params");

(, Subnet storage subnet) = getSubnet(msg.sender);
(, Subnet storage subnet) = _getSubnet(msg.sender);
require(
subnet.stake >= amount,
"subnet actor not allowed to release so many funds"
Expand All @@ -205,7 +210,7 @@ contract Gateway is IGateway, ReentrancyGuard {
}

function kill() external isRegistered {
(, Subnet storage subnet) = getSubnet(msg.sender);
(, Subnet storage subnet) = _getSubnet(msg.sender);
require(
address(this).balance >= subnet.stake,
"something went really wrong! the actor doesn't have enough balance to release"
Expand All @@ -227,7 +232,7 @@ contract Gateway is IGateway, ReentrancyGuard {
function commitChildCheck(
Checkpoint calldata commit
) external isRegistered returns (uint fee) {
(, Subnet storage subnet) = getSubnet(msg.sender);
(, Subnet storage subnet) = _getSubnet(msg.sender);
require(
commit.data.source.getActor().normalize() == msg.sender,
"source in checkpoint doesn't belong to subnet"
Expand Down Expand Up @@ -315,9 +320,7 @@ contract Gateway is IGateway, ReentrancyGuard {
}
}

function fund(SubnetID calldata subnetId) external payable signableOnly {
require(msg.value > crossMsgFee, "not enough gas to pay cross-message");

function fund(SubnetID calldata subnetId) external payable signableOnly hasFee {
CrossMsg memory crossMsg = CrossMsgHelper.createFundMsg(
subnetId,
msg.sender,
Expand All @@ -330,9 +333,7 @@ contract Gateway is IGateway, ReentrancyGuard {
distributeRewards(subnetId.getActor(), crossMsgFee);
}

function release() external payable signableOnly {
require(msg.value > crossMsgFee, "not enough gas to pay cross-message");

function release() external payable signableOnly hasFee {
uint256 releaseAmount = msg.value - crossMsgFee;

CrossMsg memory crossMsg = CrossMsgHelper.createReleaseMsg(
Expand All @@ -350,7 +351,7 @@ contract Gateway is IGateway, ReentrancyGuard {
function sendCross(
SubnetID memory destination,
CrossMsg memory crossMsg
) external payable signableOnly {
) external payable signableOnly hasFee {
require(
destination.route.length > 0,
"no destination for cross-message explicitly set"
Expand All @@ -367,7 +368,6 @@ contract Gateway is IGateway, ReentrancyGuard {
crossMsg.message.to.rawAddress != address(0),
"invalid to addr"
);
require(msg.value > crossMsgFee, "not enough gas to pay cross-message");

crossMsg.message.to = IPCAddress(
destination,
Expand Down Expand Up @@ -418,7 +418,7 @@ contract Gateway is IGateway, ReentrancyGuard {
}

function _commitTopDownMsg(CrossMsg memory crossMessage) internal {
(bool exist, Subnet storage subnet) = getSubnet(
(bool exist, Subnet storage subnet) = _getSubnet(
crossMessage.message.to.subnetId.down(networkName)
);

Expand Down Expand Up @@ -463,15 +463,15 @@ contract Gateway is IGateway, ReentrancyGuard {
nonce += 1;
}

function getSubnet(
function _getSubnet(
address actor
) internal view returns (bool found, Subnet storage subnet) {
SubnetID memory subnetId = networkName.createSubnetId(actor);

return getSubnet(subnetId);
return _getSubnet(subnetId);
}

function getSubnet(
function _getSubnet(
SubnetID memory subnetId
) internal view returns (bool found, Subnet storage subnet) {
subnet = subnets[subnetId.toHash()];
Expand Down

0 comments on commit 5e12e69

Please sign in to comment.