Skip to content

Commit ed418cb

Browse files
feat: add listResourceConstraints view and fix clearConstraint
1 parent fa4b4e4 commit ed418cb

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

ArbGasInfo.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
pragma solidity >=0.4.21 <0.9.0;
66

7+
import {ArbResourceConstraintsTypes} from "./ArbResourceConstraintsTypes.sol";
8+
79
/// @title Provides insight into the cost of using the chain.
810
/// @notice These methods have been adjusted to account for Nitro's heavy use of calldata compression.
911
/// Of note to end-users, we no longer make a distinction between non-zero and zero-valued calldata bytes.
@@ -116,4 +118,11 @@ interface ArbGasInfo {
116118
/// @notice Returns the L1 pricing surplus as of the last update (may be negative).
117119
/// @notice Available in ArbOS version 20 and above
118120
function getLastL1PricingSurplus() external view returns (int256);
121+
122+
/// @notice Lists all resource constraints currently configured in ArbOS.
123+
/// @notice Available on ArbOS version 50 and above
124+
function listResourceConstraints()
125+
external
126+
view
127+
returns (ArbResourceConstraintsTypes.ResourceConstraint[] memory constraints);
119128
}

ArbOwner.sol

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
pragma solidity >=0.4.21 <0.9.0;
66

7+
import {ArbResourceConstraintsTypes} from "./ArbResourceConstraintsTypes.sol";
8+
79
/**
810
* @title Provides owners with tools for managing the rollup.
911
* @notice Calls by non-owners will always revert.
@@ -256,30 +258,22 @@ interface ArbOwner {
256258
bool enable
257259
) external;
258260

259-
/// @notice A pair representing a resource kind and its weight in constraint calculations.
260-
/// @param resource the resource kind (see Nitro documentation for list of resources)
261-
/// @param weight the relative weight of this resource in the constraint
262-
struct ResourceWeight {
263-
uint8 resource;
264-
uint64 weight;
265-
}
266-
267261
/// @notice Adds or updates a resource constraint
268262
/// @notice Available on ArbOS version 50 and above
269-
/// @param resources an array of (resource, weight) pairs
263+
/// @param resources an array of resourceweight pairs (see Nitro documentation for the list of resources)
270264
/// @param periodSecs the time window for the constraint
271265
/// @param targetPerSec allowed usage per second across weighted resources
272266
function setResourceConstraint(
273-
ResourceWeight[] calldata resources,
267+
ArbResourceConstraintsTypes.ResourceWeight[] calldata resources,
274268
uint32 periodSecs,
275269
uint64 targetPerSec
276270
) external;
277271

278272
/// @notice Removes a resource constraint
279273
/// @notice Available on ArbOS version 50 and above
280-
/// @param resource the resource kind (see Nitro documentation for the list of resources)
274+
/// @param resources the list of resource kinds to be removed (see Nitro documentation for the list of resources)
281275
/// @param periodSecs the time window for the constraint
282-
function clearConstraint(uint8 resource, uint32 periodSecs) external;
276+
function clearConstraint(uint8[] calldata resources, uint32 periodSecs) external;
283277

284278
/// Emitted when a successful call is made to this precompile
285279
event OwnerActs(bytes4 indexed method, address indexed owner, bytes data);

ArbResourceConstraintsTypes.sol

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2025, Offchain Labs, Inc.
2+
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
3+
// SPDX-License-Identifier: BUSL-1.1
4+
5+
pragma solidity >=0.4.21 <0.9.0;
6+
7+
/// @title ArbResourceConstraintsTypes
8+
/// @notice Resource constraints type definitions used by ArbOwner and ArbOwnerPublic precompiles.
9+
library ArbResourceConstraintsTypes {
10+
/// @notice A pair representing a resource kind and its weight in constraint calculations.
11+
struct ResourceWeight {
12+
uint8 resource;
13+
uint64 weight;
14+
}
15+
16+
/// @notice A constraint describing limits for a set of weighted resources.
17+
struct ResourceConstraint {
18+
ResourceWeight[] resources;
19+
uint32 periodSecs;
20+
uint64 targetPerSec;
21+
uint64 backlog;
22+
}
23+
}

0 commit comments

Comments
 (0)