From ae4bb4f18c258452e7ce2f33339fc7e5d6c0a215 Mon Sep 17 00:00:00 2001 From: Zero Ekkusu <94782988+ZeroEkkusu@users.noreply.github.com> Date: Thu, 27 Jul 2023 12:30:38 +0200 Subject: [PATCH] feat(gov): add `sprintSize` --- contracts/child/NetworkParams.sol | 17 +++++++ docs/child/NetworkParams.md | 49 +++++++++++++++++++ test/child/NetworkParams.test.ts | 22 +++++++++ test/forge/child/validator/RewardPool.t.sol | 2 +- test/forge/child/validator/ValidatorSet.t.sol | 4 +- 5 files changed, 92 insertions(+), 2 deletions(-) diff --git a/contracts/child/NetworkParams.sol b/contracts/child/NetworkParams.sol index 5caf5be1..7feed4fd 100644 --- a/contracts/child/NetworkParams.sol +++ b/contracts/child/NetworkParams.sol @@ -16,6 +16,7 @@ contract NetworkParams is Ownable2Step, Initializable { uint256 newCheckpointBlockInterval; // in blocks uint256 newEpochSize; // in blocks uint256 newEpochReward; // in wei + uint256 newSprintSize; // in blocks uint256 newMinValidatorSetSize; uint256 newMaxValidatorSetSize; uint256 newWithdrawalWaitPeriod; // in blocks @@ -29,6 +30,7 @@ contract NetworkParams is Ownable2Step, Initializable { uint256 public checkpointBlockInterval; // in blocks uint256 public epochSize; // in blocks uint256 public epochReward; // in wei + uint256 public sprintSize; // in blocks uint256 public minValidatorSetSize; uint256 public maxValidatorSetSize; uint256 public withdrawalWaitPeriod; // in blocks @@ -41,6 +43,7 @@ contract NetworkParams is Ownable2Step, Initializable { event NewCheckpointBlockInterval(uint256 indexed checkpointInterval); event NewEpochSize(uint256 indexed size); event NewEpochReward(uint256 indexed reward); + event NewSprintSize(uint256 indexed size); event NewMinValidatorSetSize(uint256 indexed minValidatorSet); event NewMaxValidatorSetSize(uint256 indexed maxValidatorSet); event NewWithdrawalWaitPeriod(uint256 indexed withdrawalPeriod); @@ -61,6 +64,7 @@ contract NetworkParams is Ownable2Step, Initializable { initParams.newCheckpointBlockInterval != 0 && initParams.newEpochSize != 0 && initParams.newEpochReward != 0 && + initParams.newSprintSize != 0 && initParams.newMinValidatorSetSize != 0 && initParams.newMaxValidatorSetSize != 0 && initParams.newWithdrawalWaitPeriod != 0 && @@ -74,6 +78,7 @@ contract NetworkParams is Ownable2Step, Initializable { checkpointBlockInterval = initParams.newCheckpointBlockInterval; epochSize = initParams.newEpochSize; epochReward = initParams.newEpochReward; + sprintSize = initParams.newSprintSize; minValidatorSetSize = initParams.newMinValidatorSetSize; maxValidatorSetSize = initParams.newMaxValidatorSetSize; withdrawalWaitPeriod = initParams.newWithdrawalWaitPeriod; @@ -121,6 +126,18 @@ contract NetworkParams is Ownable2Step, Initializable { emit NewEpochReward(newEpochReward); } + /** + * @notice function to set new sprint size + * @dev disallows setting of a zero value for sanity check purposes + * @param newSprintSize new sprint size + */ + function setNewSprintSize(uint256 newSprintSize) external onlyOwner { + require(newSprintSize != 0, "NetworkParams: INVALID_SPRINT_SIZE"); + sprintSize = newSprintSize; + + emit NewSprintSize(newSprintSize); + } + /** * @notice function to set new minimum validator set size * @dev disallows setting of a zero value for sanity check purposes diff --git a/docs/child/NetworkParams.md b/docs/child/NetworkParams.md index 3b5ccc1c..c04de440 100644 --- a/docs/child/NetworkParams.md +++ b/docs/child/NetworkParams.md @@ -346,6 +346,22 @@ function to set new proposal threshold |---|---|---| | newProposalThreshold | uint256 | new proposal threshold | +### setNewSprintSize + +```solidity +function setNewSprintSize(uint256 newSprintSize) external nonpayable +``` + +function to set new sprint size + +*disallows setting of a zero value for sanity check purposes* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newSprintSize | uint256 | new sprint size | + ### setNewVotingDelay ```solidity @@ -394,6 +410,23 @@ function to set new withdrawal wait period |---|---|---| | newWithdrawalWaitPeriod | uint256 | new withdrawal wait period | +### sprintSize + +```solidity +function sprintSize() external view returns (uint256) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + ### transferOwnership ```solidity @@ -609,6 +642,22 @@ event NewProposalThreshold(uint256 indexed proposalThreshold) |---|---|---| | proposalThreshold `indexed` | uint256 | undefined | +### NewSprintSize + +```solidity +event NewSprintSize(uint256 indexed size) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| size `indexed` | uint256 | undefined | + ### NewVotingDelay ```solidity diff --git a/test/child/NetworkParams.test.ts b/test/child/NetworkParams.test.ts index fb447b42..5bcb57e3 100644 --- a/test/child/NetworkParams.test.ts +++ b/test/child/NetworkParams.test.ts @@ -16,6 +16,7 @@ describe("NetworkParams", () => { newCheckpointBlockInterval: 0, newEpochSize: 0, newEpochReward: 0, + newSprintSize: 0, newMinValidatorSetSize: 0, newMaxValidatorSetSize: 0, newWithdrawalWaitPeriod: 0, @@ -39,6 +40,7 @@ describe("NetworkParams", () => { initParams.newCheckpointBlockInterval = 2 ** Math.floor(Math.random() * 5 + 10); initParams.newEpochSize = 2 ** Math.floor(Math.random() * 5 + 10); initParams.newEpochReward = ethers.utils.parseUnits(String(Math.floor(Math.random() * 20 + 1))); + initParams.newSprintSize = 2 ** Math.floor(Math.random() * 5 + 10); initParams.newMinValidatorSetSize = Math.floor(Math.random() * 20 + 5); initParams.newMaxValidatorSetSize = Math.floor(Math.random() * 20 + 5); initParams.newWithdrawalWaitPeriod = 2 ** Math.floor(Math.random() * 5 + 10); @@ -54,6 +56,7 @@ describe("NetworkParams", () => { expect(await networkParams.checkpointBlockInterval()).to.equal(initParams.newCheckpointBlockInterval); expect(await networkParams.epochSize()).to.equal(initParams.newEpochSize); expect(await networkParams.epochReward()).to.equal(initParams.newEpochReward); + expect(await networkParams.sprintSize()).to.equal(initParams.newSprintSize); expect(await networkParams.minValidatorSetSize()).to.equal(initParams.newMinValidatorSetSize); expect(await networkParams.maxValidatorSetSize()).to.equal(initParams.newMaxValidatorSetSize); expect(await networkParams.withdrawalWaitPeriod()).to.equal(initParams.newWithdrawalWaitPeriod); @@ -134,6 +137,25 @@ describe("NetworkParams", () => { expect(await networkParams.epochReward()).to.equal(initParams.newEpochReward); }); + it("set new sprint size fail: only owner", async () => { + await impersonateAccount(accounts[1].address); + await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); + const newNetworkParams = networkParams.connect(accounts[1]); + await expect(newNetworkParams.setNewSprintSize(1)).to.be.revertedWith("Ownable: caller is not the owner"); + await stopImpersonatingAccount(accounts[1].address); + }); + + it("set new sprint size fail: invalid input", async () => { + await expect(networkParams.setNewSprintSize(0)).to.be.revertedWith("NetworkParams: INVALID_SPRINT_SIZE"); + }); + + it("set new sprint size success", async () => { + initParams.newSprintSize = 10 ** Math.floor(Math.random() + 6); + await networkParams.setNewSprintSize(initParams.newSprintSize); + + expect(await networkParams.sprintSize()).to.equal(initParams.newSprintSize); + }); + it("set new min validator set size fail: only owner", async () => { await impersonateAccount(accounts[1].address); await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/forge/child/validator/RewardPool.t.sol b/test/forge/child/validator/RewardPool.t.sol index 652fccf5..424bdced 100644 --- a/test/forge/child/validator/RewardPool.t.sol +++ b/test/forge/child/validator/RewardPool.t.sol @@ -23,7 +23,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { networkParams = new NetworkParams(); - networkParams.initialize(NetworkParams.InitParams(address(1), 1, 1, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1)); + networkParams.initialize(NetworkParams.InitParams(address(1), 1, 64, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1)); token = new MockERC20(); validatorSet = new ValidatorSet(); diff --git a/test/forge/child/validator/ValidatorSet.t.sol b/test/forge/child/validator/ValidatorSet.t.sol index 24d9e4d7..55e1ae3c 100644 --- a/test/forge/child/validator/ValidatorSet.t.sol +++ b/test/forge/child/validator/ValidatorSet.t.sol @@ -24,7 +24,9 @@ abstract contract Uninitialized is Test { function setUp() public virtual { networkParams = new NetworkParams(); - networkParams.initialize(NetworkParams.InitParams(address(1), 1, 1, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1)); + networkParams.initialize( + NetworkParams.InitParams(address(1), 1, epochSize, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1) + ); stateSender = new L2StateSender(); validatorSet = new ValidatorSet();