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

remove status and minStake #401

Merged
merged 1 commit into from
Dec 21, 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
427 changes: 203 additions & 224 deletions .storage-layouts/GatewayActorModifiers.json

Large diffs are not rendered by default.

427 changes: 203 additions & 224 deletions .storage-layouts/GatewayDiamond.json

Large diffs are not rendered by default.

304 changes: 170 additions & 134 deletions .storage-layouts/SubnetActorDiamond.json

Large diffs are not rendered by default.

304 changes: 170 additions & 134 deletions .storage-layouts/SubnetActorModifiers.json

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/GatewayDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contract GatewayDiamond {
struct ConstructorParams {
SubnetID networkName;
uint256 bottomUpCheckPeriod;
uint256 minCollateral;
// deprecated (for now): no `msgFee` currenlty charged for cross-net messages
uint256 msgFee;
uint8 majorityPercentage;
Expand All @@ -37,9 +36,6 @@ contract GatewayDiamond {
}

constructor(IDiamond.FacetCut[] memory _diamondCut, ConstructorParams memory params) {
if (params.minCollateral == 0) {
revert InvalidCollateral();
}
// The bottomUpCheckPeriod should be non-zero for now.
if (params.bottomUpCheckPeriod == 0) {
revert InvalidSubmissionPeriod();
Expand All @@ -66,7 +62,6 @@ contract GatewayDiamond {
s.crossMsgRelayerRewards = FEATURE_CROSSMSG_RELAYER_REWARDS;

s.networkName = params.networkName;
s.minStake = params.minCollateral;
s.bottomUpCheckPeriod = params.bottomUpCheckPeriod;
s.minCrossMsgFee = params.msgFee;
s.majorityPercentage = params.majorityPercentage;
Expand Down
13 changes: 0 additions & 13 deletions src/enums/Status.sol

This file was deleted.

5 changes: 0 additions & 5 deletions src/gateway/GatewayGetterFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ contract GatewayGetterFacet {
return s.totalSubnets;
}

/// @notice Returns the minimum stake required for instantiating a subnet.
function minStake() external view returns (uint256) {
return s.minStake;
}

/// @notice Returns the maximum number of messages per bottom-up batch.
function maxMsgsPerBottomUpBatch() external view returns (uint64) {
return s.maxMsgsPerBottomUpBatch;
Expand Down
11 changes: 0 additions & 11 deletions src/gateway/GatewayManagerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {GatewayActorModifiers} from "../lib/LibGatewayActorStorage.sol";
import {SubnetActorGetterFacet} from "../subnet/SubnetActorGetterFacet.sol";
import {BURNT_FUNDS_ACTOR} from "../constants/Constants.sol";
import {CrossMsg} from "../structs/CrossNet.sol";
import {Status} from "../enums/Status.sol";
import {FvmAddress} from "../structs/FvmAddress.sol";
import {SubnetID, Subnet, SupplySource} from "../structs/Subnet.sol";
import {Membership, SupplyKind} from "../structs/Subnet.sol";
Expand Down Expand Up @@ -50,7 +49,6 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard {

subnet.id = subnetId;
subnet.stake = collateral;
subnet.status = Status.Active;
subnet.genesisEpoch = block.number;
subnet.circSupply = genesisCircSupply;

Expand All @@ -72,12 +70,6 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard {
}

subnet.stake += msg.value;

if (subnet.status == Status.Inactive) {
if (subnet.stake >= s.minStake) {
subnet.status = Status.Active;
}
}
}

/// @notice release collateral for an existing subnet.
Expand All @@ -99,9 +91,6 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard {

subnet.stake -= amount;

if (subnet.stake < s.minStake) {
subnet.status = Status.Inactive;
}
payable(subnet.id.getActor()).sendValue(amount);
}

Expand Down
5 changes: 0 additions & 5 deletions src/gateway/router/BottomUpRouterFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {ISubnetActor} from "../../interfaces/ISubnetActor.sol";
import {GatewayActorModifiers} from "../../lib/LibGatewayActorStorage.sol";
import {BottomUpMsgBatch} from "../../structs/CrossNet.sol";
import {LibGateway} from "../../lib/LibGateway.sol";
import {Status} from "../../enums/Status.sol";
import {BatchNotCreated, BatchAlreadyExists, InvalidBatchEpoch, NotEnoughSubnetCircSupply, SubnetNotActive, SubnetNotFound, InvalidBatchSource, MaxMsgsPerBatchExceeded, BatchWithNoMessages, InvalidCrossMsgDstSubnet, NotRegisteredSubnet, InvalidCrossMsgNonce} from "../../errors/IPCErrors.sol";
import {Subnet} from "../../structs/Subnet.sol";
import {LibQuorum} from "../../lib/LibQuorum.sol";
Expand Down Expand Up @@ -45,10 +44,6 @@ contract BottomUpRouterFacet is GatewayActorModifiers {
if (!subnetExists) {
revert SubnetNotFound();
}
// cross-net messages can't be executed in inactive subnets.
if (subnet.status != Status.Active) {
revert SubnetNotActive();
}

uint256 totalValue;
uint256 totalFee;
Expand Down
5 changes: 0 additions & 5 deletions src/gateway/router/CheckpointingFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {GatewayActorModifiers} from "../../lib/LibGatewayActorStorage.sol";
import {BottomUpCheckpoint} from "../../structs/CrossNet.sol";
import {LibGateway} from "../../lib/LibGateway.sol";
import {LibQuorum} from "../../lib/LibQuorum.sol";
import {Status} from "../../enums/Status.sol";
import {Subnet} from "../../structs/Subnet.sol";
import {QuorumObjKind} from "../../structs/Quorum.sol";
import {Address} from "openzeppelin-contracts/utils/Address.sol";
Expand Down Expand Up @@ -37,10 +36,6 @@ contract CheckpointingFacet is GatewayActorModifiers {
if (!checkpoint.subnetID.equals(subnet.id)) {
revert InvalidSubnet();
}
// only active subnets can commit checkpoints
if (subnet.status != Status.Active) {
revert SubnetNotActive();
}

if (s.checkpointRelayerRewards) {
// slither-disable-next-line unused-return
Expand Down
2 changes: 0 additions & 2 deletions src/lib/LibGatewayActorStorage.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.19;

Check warning on line 2 in src/lib/LibGatewayActorStorage.sol

View workflow job for this annotation

GitHub Actions / Solhint check

Found more than One contract per file. 2 contracts found!

import {NotEnoughFee, NotSystemActor, NotEnoughFunds} from "../errors/IPCErrors.sol";
import {QuorumMap} from "../structs/Quorum.sol";
Expand Down Expand Up @@ -39,8 +39,6 @@
bytes32[] subnetKeys;
/// @notice path to the current network
SubnetID networkName;
/// @notice Minimum stake required to create a new subnet
uint256 minStake;
/// @notice minimum fee amount charged per cross message
uint256 minCrossMsgFee;
/// @notice majority percentage value (must be greater than or equal to 51)
Expand Down
2 changes: 0 additions & 2 deletions src/structs/Subnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.19;

import {SubnetID} from "./Subnet.sol";
import {FvmAddress} from "./FvmAddress.sol";
import {Status} from "../enums/Status.sol";
import {MaxPQ} from "../lib/priority/LibMaxPQ.sol";
import {MinPQ} from "../lib/priority/LibMinPQ.sol";

Expand All @@ -22,7 +21,6 @@ struct Subnet {
uint256 circSupply;
uint64 topDownNonce;
uint64 appliedBottomUpNonce;
Status status;
SubnetID id;
}

Expand Down
28 changes: 8 additions & 20 deletions test/IntegrationTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "../src/errors/IPCErrors.sol";

import {EMPTY_BYTES, METHOD_SEND} from "../src/constants/Constants.sol";
import {ConsensusType} from "../src/enums/ConsensusType.sol";
import {Status} from "../src/enums/Status.sol";
import {IDiamond} from "../src/interfaces/IDiamond.sol";
import {CrossMsg, BottomUpCheckpoint, StorableMsg, ParentFinality} from "../src/structs/CrossNet.sol";
import {FvmAddress} from "../src/structs/FvmAddress.sol";
Expand Down Expand Up @@ -126,7 +125,6 @@ contract TestGatewayActor is Test, TestParams {
networkName: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}),
bottomUpCheckPeriod: DEFAULT_CHECKPOINT_PERIOD,
msgFee: DEFAULT_CROSS_MSG_FEE,
minCollateral: DEFAULT_COLLATERAL_AMOUNT,
majorityPercentage: DEFAULT_MAJORITY_PERCENTAGE,
genesisValidators: new Validator[](0),
activeValidatorsLimit: DEFAULT_ACTIVE_VALIDATORS_LIMIT
Expand Down Expand Up @@ -653,7 +651,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor,

function fund(address funderAddress, uint256 fundAmount, SupplyKind mode) public {
// funding subnets is free, we do not need cross msg fee
(SubnetID memory subnetId, , uint256 nonceBefore, , uint256 circSupplyBefore, ) = getSubnet(address(saManager));
(SubnetID memory subnetId, , uint256 nonceBefore, , uint256 circSupplyBefore) = getSubnet(address(saManager));

uint256 expectedTopDownMsgsLength = gwGetter.getSubnetTopDownMsgsLength(subnetId) + 1;
uint256 expectedNonce = nonceBefore + 1;
Expand All @@ -667,7 +665,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor,
gwManager.fundWithToken(subnetId, FvmAddressHelper.from(funderAddress), fundAmount);
}

(, , uint256 nonce, , uint256 circSupply, ) = getSubnet(address(saManager));
(, , uint256 nonce, , uint256 circSupply) = getSubnet(address(saManager));

require(gwGetter.getSubnetTopDownMsgsLength(subnetId) == expectedTopDownMsgsLength, "unexpected lengths");

Expand Down Expand Up @@ -764,12 +762,12 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor,
function addStake(uint256 stakeAmount, address subnetAddress) public {
uint256 balanceBefore = subnetAddress.balance;

(, uint256 stakedBefore, , , , ) = getSubnet(subnetAddress);
(, uint256 stakedBefore, , , ) = getSubnet(subnetAddress);

gwManager.addStake{value: stakeAmount}();

uint256 balanceAfter = subnetAddress.balance;
(, uint256 stakedAfter, , , , ) = getSubnet(subnetAddress);
(, uint256 stakedAfter, , , ) = getSubnet(subnetAddress);

require(balanceAfter == balanceBefore - stakeAmount, "unexpected balance");
require(stakedAfter == stakedBefore + stakeAmount, "unexpected stake");
Expand All @@ -780,7 +778,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor,

manager.register{value: collateral}(0);

(SubnetID memory id, uint256 stake, uint256 topDownNonce, , uint256 circSupply, Status status) = getSubnetGW(
(SubnetID memory id, uint256 stake, uint256 topDownNonce, , uint256 circSupply) = getSubnetGW(
subnetAddress,
gw
);
Expand All @@ -794,7 +792,6 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor,
require(stake == collateral, "unexpected stake");
require(topDownNonce == 0, "unexpected nonce");
require(circSupply == 0, "unexpected circSupply");
require(status == Status.Active, "unexpected status");
}

function registerSubnet(uint256 collateral, address subnetAddress) public {
Expand All @@ -804,27 +801,18 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor,
function getSubnetGW(
address subnetAddress,
GatewayDiamond gw
) public returns (SubnetID memory, uint256, uint256, uint256, uint256, Status) {
) public returns (SubnetID memory, uint256, uint256, uint256, uint256) {
gwManager = GatewayManagerFacet(address(gw));
gwGetter = GatewayGetterFacet(address(gw));

SubnetID memory subnetId = gwGetter.getNetworkName().createSubnetId(subnetAddress);

Subnet memory subnet = gwGetter.subnets(subnetId.toHash());

return (
subnet.id,
subnet.stake,
subnet.topDownNonce,
subnet.appliedBottomUpNonce,
subnet.circSupply,
subnet.status
);
return (subnet.id, subnet.stake, subnet.topDownNonce, subnet.appliedBottomUpNonce, subnet.circSupply);
}

function getSubnet(
address subnetAddress
) public returns (SubnetID memory, uint256, uint256, uint256, uint256, Status) {
function getSubnet(address subnetAddress) public returns (SubnetID memory, uint256, uint256, uint256, uint256) {
return getSubnetGW(subnetAddress, gatewayDiamond);
}
}
Loading
Loading