@@ -5,18 +5,21 @@ import {Passage} from "./Passage.sol";
5
5
6
6
/// @notice A contract deployed to Host chain that enables transactions from L1 to be sent on an L2.
7
7
contract Transactor {
8
- /// @notice The sum of `transact` calls in a block cannot use more than 30M gas.
9
- uint256 public constant PER_BLOCK_TRANSACT_GAS_LIMIT = 30_000_000 ;
10
-
11
- /// @notice Each `transact` call cannot use more than 5M gas.
12
- uint256 public constant PER_TRANSACT_GAS_LIMIT = 5_000_000 ;
13
-
14
8
/// @notice The chainId of rollup that Ether will be sent to by default when entering the rollup via fallback() or receive().
15
9
uint256 public immutable defaultRollupChainId;
16
10
11
+ /// @notice The address that is allowed to configure `transact` gas limits.
12
+ address public immutable gasAdmin;
13
+
17
14
/// @notice The address of the Passage contract, to enable transact + enter.
18
15
Passage public immutable passage;
19
16
17
+ /// @notice The sum of `transact` calls in a block cannot use more than this limit.
18
+ uint256 public perBlockGasLimit;
19
+
20
+ /// @notice Each `transact` call cannot use more than this limit.
21
+ uint256 public perTransactGasLimit;
22
+
20
23
/// @notice The total gas used by `transact` so far in this block.
21
24
/// rollupChainId => block number => `transasct` gasLimit used so far.
22
25
mapping (uint256 => mapping (uint256 => uint256 )) public transactGasUsed;
@@ -32,17 +35,37 @@ contract Transactor {
32
35
uint256 maxFeePerGas
33
36
);
34
37
38
+ /// @notice Emitted when the admin configures gas limits.
39
+ event GasConfigured (uint256 perBlock , uint256 perTransact );
40
+
35
41
/// @notice Thrown when attempting to use more then the current global `transact` gasLimit for the block.
36
42
error PerBlockTransactGasLimit ();
37
43
38
44
/// @notice Thrown when attempting to use too much gas per single `transact` call.
39
45
error PerTransactGasLimit ();
40
46
47
+ /// @notice Thrown when attempting to configure gas if not the admin.
48
+ error OnlyGasAdmin ();
49
+
41
50
/// @param _defaultRollupChainId - the chainId of the rollup that Ether will be sent to by default
42
51
/// when entering the rollup via fallback() or receive() fns.
43
- constructor (uint256 _defaultRollupChainId , Passage _passage ) {
52
+ constructor (
53
+ uint256 _defaultRollupChainId ,
54
+ address _gasAdmin ,
55
+ Passage _passage ,
56
+ uint256 _perBlockGasLimit ,
57
+ uint256 _perTransactGasLimit
58
+ ) {
44
59
defaultRollupChainId = _defaultRollupChainId;
60
+ gasAdmin = _gasAdmin;
45
61
passage = _passage;
62
+ _configureGas (_perBlockGasLimit, _perTransactGasLimit);
63
+ }
64
+
65
+ /// @notice Configure the `transact` gas limits.
66
+ function configureGas (uint256 perBlock , uint256 perTransact ) external {
67
+ if (msg .sender != gasAdmin) revert OnlyGasAdmin ();
68
+ _configureGas (perBlock, perTransact);
46
69
}
47
70
48
71
/// @notice Allows a special transaction to be sent to the rollup with sender == L1 msg.sender.
@@ -93,14 +116,21 @@ contract Transactor {
93
116
}
94
117
95
118
// ensure per-transact gas limit is respected
96
- if (gas > PER_TRANSACT_GAS_LIMIT ) revert PerTransactGasLimit ();
119
+ if (gas > perTransactGasLimit ) revert PerTransactGasLimit ();
97
120
98
121
// ensure global transact gas limit is respected
99
122
uint256 gasUsed = transactGasUsed[rollupChainId][block .number ];
100
- if (gasUsed + gas > PER_BLOCK_TRANSACT_GAS_LIMIT ) revert PerBlockTransactGasLimit ();
123
+ if (gasUsed + gas > perBlockGasLimit ) revert PerBlockTransactGasLimit ();
101
124
transactGasUsed[rollupChainId][block .number ] = gasUsed + gas;
102
125
103
126
// emit Transact event
104
127
emit Transact (rollupChainId, msg .sender , to, data, value, gas, maxFeePerGas);
105
128
}
129
+
130
+ /// @notice Helper to configure gas limits on deploy & via admin function
131
+ function _configureGas (uint256 perBlock , uint256 perTransact ) internal {
132
+ perBlockGasLimit = perBlock;
133
+ perTransactGasLimit = perTransact;
134
+ emit GasConfigured (perBlock, perTransact);
135
+ }
106
136
}
0 commit comments