Skip to content

Commit

Permalink
Merge pull request #314 from 0xPolygon/feat/sprint-size
Browse files Browse the repository at this point in the history
feat(gov): add `sprintSize`
  • Loading branch information
gretzke authored Jul 27, 2023
2 parents 74f026e + ae4bb4f commit f7a1fc9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
17 changes: 17 additions & 0 deletions contracts/child/NetworkParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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 &&
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions docs/child/NetworkParams.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/child/NetworkParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("NetworkParams", () => {
newCheckpointBlockInterval: 0,
newEpochSize: 0,
newEpochReward: 0,
newSprintSize: 0,
newMinValidatorSetSize: 0,
newMaxValidatorSetSize: 0,
newWithdrawalWaitPeriod: 0,
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion test/forge/child/validator/RewardPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion test/forge/child/validator/ValidatorSet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f7a1fc9

Please sign in to comment.