diff --git a/solidity/contracts/Oracle.sol b/solidity/contracts/Oracle.sol index 9283cb9..7b46ea8 100644 --- a/solidity/contracts/Oracle.sol +++ b/solidity/contracts/Oracle.sol @@ -47,7 +47,7 @@ contract Oracle is IOracle, OracleAccessController { mapping(bytes32 _requestId => mapping(address _user => bool _isParticipant)) public isParticipant; /// @inheritdoc IOracle - uint256 public totalRequestCount; + uint256 public nextRequestNonce; /** * @notice The list of the response ids for each request @@ -72,15 +72,15 @@ contract Oracle is IOracle, OracleAccessController { /// @inheritdoc IOracle function listRequestIds(uint256 _startFrom, uint256 _batchSize) external view returns (bytes32[] memory _list) { - uint256 _totalRequestsCount = totalRequestCount; + uint256 _nextRequestNonce = nextRequestNonce; // If trying to collect non-existent ids only, return empty array - if (_startFrom > _totalRequestsCount) { + if (_startFrom >= _nextRequestNonce) { return _list; } - if (_batchSize > _totalRequestsCount - _startFrom) { - _batchSize = _totalRequestsCount - _startFrom; + if (_batchSize > _nextRequestNonce - _startFrom) { + _batchSize = _nextRequestNonce - _startFrom; } _list = new bytes32[](_batchSize); @@ -443,7 +443,8 @@ contract Oracle is IOracle, OracleAccessController { hasAccess(_request.accessModule, OracleTypehash.CREATE_TYPEHASH, abi.encode(_request), _accessControl) returns (bytes32 _requestId) { - uint256 _requestNonce = totalRequestCount++; + // we assign the next request nonce, then increment it by 1 + uint256 _requestNonce = nextRequestNonce++; if (_request.nonce == 0) _request.nonce = uint96(_requestNonce); diff --git a/solidity/interfaces/IOracle.sol b/solidity/interfaces/IOracle.sol index 6246de7..4096dc8 100644 --- a/solidity/interfaces/IOracle.sol +++ b/solidity/interfaces/IOracle.sol @@ -334,11 +334,11 @@ interface IOracle is IOracleAccessController { function isParticipant(bytes32 _requestId, address _user) external view returns (bool _isParticipant); /** - * @notice Returns the total number of requests stored in the oracle + * @notice Returns the next request nonce. * - * @return _count The total number of requests + * @return _nextNonce The next request nonce */ - function totalRequestCount() external view returns (uint256 _count); + function nextRequestNonce() external view returns (uint256 _nextNonce); /** * @notice Returns the list of request IDs diff --git a/solidity/test/integration/ResponseDispute.t.sol b/solidity/test/integration/ResponseDispute.t.sol index 5e1b76b..dc766ff 100644 --- a/solidity/test/integration/ResponseDispute.t.sol +++ b/solidity/test/integration/ResponseDispute.t.sol @@ -14,7 +14,7 @@ contract Integration_ResponseDispute is IntegrationBase { _expectedDeadline = block.timestamp + BLOCK_TIME * 600; _responseData = abi.encode('response'); - mockRequest.nonce = uint96(oracle.totalRequestCount()); + mockRequest.nonce = uint96(oracle.nextRequestNonce()); mockAccessControl.user = requester; _requestId = oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl); diff --git a/solidity/test/integration/ResponseProposal.t.sol b/solidity/test/integration/ResponseProposal.t.sol index 77f37fb..a8df9de 100644 --- a/solidity/test/integration/ResponseProposal.t.sol +++ b/solidity/test/integration/ResponseProposal.t.sol @@ -9,7 +9,7 @@ contract Integration_ResponseProposal is IntegrationBase { function setUp() public override { super.setUp(); - mockRequest.nonce = uint96(oracle.totalRequestCount()); + mockRequest.nonce = uint96(oracle.nextRequestNonce()); address _badRequester = makeAddr('badRequester'); mockAccessControl.user = _badRequester; diff --git a/solidity/test/unit/Oracle.t.sol b/solidity/test/unit/Oracle.t.sol index 6034398..3f38ffe 100644 --- a/solidity/test/unit/Oracle.t.sol +++ b/solidity/test/unit/Oracle.t.sol @@ -66,8 +66,8 @@ contract MockOracle is Oracle { disputeCreatedAt[_disputeId] = _disputeCreatedAt; } - function mock_setTotalRequestCount(uint256 _totalRequestCount) external { - totalRequestCount = _totalRequestCount; + function mock_setNextRequestNonce(uint256 _nextRequestNonce) external { + nextRequestNonce = _nextRequestNonce; } function mock_addResponseId(bytes32 _requestId, bytes32 _responseId) external { @@ -156,7 +156,7 @@ contract Oracle_Unit_CreateRequest is BaseTest { bytes calldata _resolutionData, bytes calldata _finalityData ) public setResolutionAndFinality(_useResolutionAndFinality) happyPath { - uint256 _initialNonce = oracle.totalRequestCount(); + uint256 _initialNonce = oracle.nextRequestNonce(); // Create the request mockRequest.requestModuleData = _requestData; @@ -165,7 +165,7 @@ contract Oracle_Unit_CreateRequest is BaseTest { mockRequest.resolutionModuleData = _resolutionData; mockRequest.finalityModuleData = _finalityData; mockRequest.requester = requester; - mockRequest.nonce = uint96(oracle.totalRequestCount()); + mockRequest.nonce = uint96(oracle.nextRequestNonce()); // Compute the associated request id bytes32 _theoreticalRequestId = _getId(mockRequest); @@ -200,7 +200,7 @@ contract Oracle_Unit_CreateRequest is BaseTest { assertEq(_requestId, _theoreticalRequestId); // Check: nonce incremented? - assertEq(oracle.totalRequestCount(), _initialNonce + 1); + assertEq(oracle.nextRequestNonce(), _initialNonce + 1); } /** @@ -235,7 +235,7 @@ contract Oracle_Unit_CreateRequest is BaseTest { * @notice Check that creating a request with a nonce that already exists reverts */ function test_createRequest_revertsIfInvalidNonce(uint256 _nonce) public happyPath { - vm.assume(_nonce != oracle.totalRequestCount()); + vm.assume(_nonce != oracle.nextRequestNonce()); // Set the nonce mockRequest.nonce = uint96(_nonce); @@ -273,7 +273,7 @@ contract Oracle_Unit_CreateRequests is BaseTest { bytes calldata _responseData, bytes calldata _disputeData ) public { - uint256 _initialNonce = oracle.totalRequestCount(); + uint256 _initialNonce = oracle.nextRequestNonce(); uint256 _requestsAmount = 5; IOracle.Request[] memory _requests = new IOracle.Request[](_requestsAmount); bytes32[] memory _precalculatedIds = new bytes32[](_requestsAmount); @@ -290,7 +290,7 @@ contract Oracle_Unit_CreateRequests is BaseTest { mockRequest.responseModuleData = _responseData; mockRequest.disputeModuleData = _disputeData; mockRequest.requester = requester; - mockRequest.nonce = uint96(oracle.totalRequestCount() + _i); + mockRequest.nonce = uint96(oracle.nextRequestNonce() + _i); bytes32 _theoreticalRequestId = _getId(mockRequest); _requests[_i] = mockRequest; @@ -329,7 +329,7 @@ contract Oracle_Unit_CreateRequests is BaseTest { assertEq(oracle.nonceToRequestId(_requests[_i].nonce), _requestsIds[_i]); } - uint256 _newNonce = oracle.totalRequestCount(); + uint256 _newNonce = oracle.nextRequestNonce(); assertEq(_newNonce, _initialNonce + _requestsAmount); } @@ -341,7 +341,7 @@ contract Oracle_Unit_CreateRequests is BaseTest { bytes calldata _responseData, bytes calldata _disputeData ) public { - uint256 _initialNonce = oracle.totalRequestCount(); + uint256 _initialNonce = oracle.nextRequestNonce(); uint256 _requestsAmount = 5; IOracle.Request[] memory _requests = new IOracle.Request[](_requestsAmount); bytes32[] memory _precalculatedIds = new bytes32[](_requestsAmount); @@ -369,7 +369,7 @@ contract Oracle_Unit_CreateRequests is BaseTest { oracle.mock_setAccessModuleApproved(requester, address(accessModule), true); oracle.createRequests(_requests, _ipfsHashes, _accessControls); - uint256 _newNonce = oracle.totalRequestCount(); + uint256 _newNonce = oracle.nextRequestNonce(); assertEq(_newNonce, _initialNonce + _requestsAmount); } } @@ -391,7 +391,7 @@ contract Oracle_Unit_ListRequestIds is BaseTest { oracle.mock_setRequestId(_i, _requestId); } - oracle.mock_setTotalRequestCount(_numberOfRequests); + oracle.mock_setNextRequestNonce(_numberOfRequests); // Test: fetching the requests bytes32[] memory _requestsIds = oracle.listRequestIds(0, _numberOfRequests); @@ -421,7 +421,7 @@ contract Oracle_Unit_ListRequestIds is BaseTest { oracle.mock_setRequestId(_i, _requestId); } - oracle.mock_setTotalRequestCount(_numberOfRequests); + oracle.mock_setNextRequestNonce(_numberOfRequests); // Test: fetching 1 extra request bytes32[] memory _requestsIds = oracle.listRequestIds(0, _numberOfRequests + 1);