Skip to content

Commit 89a7062

Browse files
committed
contracts: add envelope limits to policy
1 parent a1accc0 commit 89a7062

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed

contracts/solidity/Policy.sol

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ contract Policy is IPolicy, GovernanceVote, GovProxyUpgradeable {
1818
uint256 public baseFee;
1919
uint256 internal candidateLimit;
2020
uint256 public envelopeFee;
21+
uint256 public maxEnvelopesPerBlock;
22+
uint256 public maxEnvelopeGasLimit;
2123

2224
// Only for precompiled uups implementation in genesis file, need to be removed when upgrading the contract.
2325
// This override is added because "immutable __self" in UUPSUpgradeable is not avaliable in precompiled contract.
@@ -39,6 +41,15 @@ contract Policy is IPolicy, GovernanceVote, GovProxyUpgradeable {
3941
}
4042
}
4143

44+
// Only for Policy upgrading for the new Envelope transactions
45+
function setInitialEnvelopeLimits(
46+
uint256 _maxEnvelopesPerBlock,
47+
uint256 _maxEnvelopeGasLimit
48+
) external onlyAdmin {
49+
maxEnvelopesPerBlock = _maxEnvelopesPerBlock;
50+
maxEnvelopeGasLimit = _maxEnvelopeGasLimit;
51+
}
52+
4253
function addBlackList(
4354
address _addr
4455
)
@@ -148,4 +159,38 @@ contract Policy is IPolicy, GovernanceVote, GovProxyUpgradeable {
148159
envelopeFee = _fee;
149160
emit SetEnvelopeFee(_fee);
150161
}
162+
163+
function setMaxEnvelopesPerBlock(
164+
uint256 _number
165+
)
166+
external
167+
needVote(
168+
bytes32(
169+
// keccak256("setMaxEnvelopesPerBlock")
170+
0x468ff90b65b7330769fd5fa1950650ac15948bbbaaff84f86b3c11a5dc7842d1
171+
),
172+
keccak256(abi.encode(_number))
173+
)
174+
{
175+
if (_number <= 0) revert Errors.InvalidMaxEnvelopesPerBlock();
176+
maxEnvelopesPerBlock = _number;
177+
emit SetMaxEnvelopesPerBlock(_number);
178+
}
179+
180+
function setMaxEnvelopeGasLimit(
181+
uint256 _gaslimit
182+
)
183+
external
184+
needVote(
185+
bytes32(
186+
// keccak256("setMaxEnvelopeGasLimit")
187+
0xf48e9af07262cd1c77a4209ac59848c8bf3f8ec29817678aa7f1b67dd990501c
188+
),
189+
keccak256(abi.encode(_gaslimit))
190+
)
191+
{
192+
if (_gaslimit < 21000) revert Errors.InvalidMaxEnvelopeGasLimit();
193+
maxEnvelopeGasLimit = _gaslimit;
194+
emit SetMaxEnvelopeGasLimit(_gaslimit);
195+
}
151196
}

contracts/solidity/interfaces/IPolicy.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface IPolicy {
88
event SetBaseFee(uint256 baseFee);
99
event SetCandidateLimit(uint256 candidateLimit);
1010
event SetEnvelopeFee(uint256 envelopeFee);
11+
event SetMaxEnvelopesPerBlock(uint256 maxEnvelopesPerBlock);
12+
event SetMaxEnvelopeGasLimit(uint256 setMaxEnvelopeGasLimit);
1113

1214
// add an address to blacklist policy
1315
function addBlackList(address _addr) external;
@@ -35,4 +37,16 @@ interface IPolicy {
3537

3638
// return the value of candidate limit policy
3739
function getCandidateLimit() external view returns (uint256);
40+
41+
// set the maximum number of envelope transactions to be packed in each block
42+
function setMaxEnvelopesPerBlock(uint256 _number) external;
43+
44+
// get the value of envelope transaction number policy
45+
function maxEnvelopesPerBlock() external view returns (uint256);
46+
47+
// set the maximum value of envelope transaction gas limit
48+
function setMaxEnvelopeGasLimit(uint256 _gaslimit) external;
49+
50+
// get the value of envelope transaction gas limit policy
51+
function maxEnvelopeGasLimit() external view returns (uint256);
3852
}

contracts/solidity/libraries/Errors.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ library Errors {
2323
error InvalidBaseFee();
2424
error InvalidCandidateLimit();
2525
error InvalidEnvelopeFee();
26+
error InvalidMaxEnvelopesPerBlock();
27+
error InvalidMaxEnvelopeGasLimit();
2628

2729
// Governance Errors
2830
error SideCallNotAllowed();

privnet/four/genesis_privnet.json

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

privnet/seven/genesis_privnet.json

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

privnet/single/genesis_privnet.json

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)