Skip to content

Commit

Permalink
Merge branch 'dev' into perf/storageless-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Oct 27, 2023
2 parents 2af1f01 + ec411b8 commit 7898b72
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
33 changes: 16 additions & 17 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract Oracle is IOracle {
uint256 public totalRequestCount;

/// @inheritdoc IOracle
function createRequest(NewRequest memory _request) external returns (bytes32 _requestId) {
function createRequest(NewRequest calldata _request) external returns (bytes32 _requestId) {
_requestId = _createRequest(_request);
}

Expand Down Expand Up @@ -230,8 +230,8 @@ contract Oracle is IOracle {

/// @inheritdoc IOracle
function deleteResponse(bytes32 _responseId) external {
Response memory _response = _responses[_responseId];
Request memory _request = _requests[_response.requestId];
Response storage _response = _responses[_responseId];
Request storage _request = _requests[_response.requestId];

if (disputeOf[_responseId] != bytes32(0)) {
revert Oracle_CannotDeleteWhileDisputing(_responseId);
Expand All @@ -241,11 +241,10 @@ contract Oracle is IOracle {
}

_request.responseModule.deleteResponse(_response.requestId, _responseId, msg.sender);

delete _responses[_responseId];
_responseIds[_response.requestId].remove(_responseId);

emit ResponseDeleted(_response.requestId, msg.sender, _responseId);
delete _responses[_responseId];
}

/// @inheritdoc IOracle
Expand All @@ -254,7 +253,7 @@ contract Oracle is IOracle {
bytes32 _responseId,
bytes calldata _moduleData
) external returns (bytes32 _disputeId) {
Request memory _request = _requests[_requestId];
Request storage _request = _requests[_requestId];
if (_request.finalizedAt != 0) {
revert Oracle_AlreadyFinalized(_requestId);
}
Expand Down Expand Up @@ -299,7 +298,7 @@ contract Oracle is IOracle {
// Change the dispute status
_dispute.status = DisputeStatus.Escalated;

Request memory _request = _requests[_dispute.requestId];
Request storage _request = _requests[_dispute.requestId];

// Notify the dispute module about the escalation
_request.disputeModule.disputeEscalated(_disputeId, _moduleData);
Expand All @@ -314,15 +313,15 @@ contract Oracle is IOracle {

/// @inheritdoc IOracle
function resolveDispute(bytes32 _disputeId, bytes calldata _moduleData) external {
Dispute memory _dispute = _disputes[_disputeId];
Dispute storage _dispute = _disputes[_disputeId];

if (_dispute.createdAt == 0) revert Oracle_InvalidDisputeId(_disputeId);
// Revert if the dispute is not active nor escalated
if (_dispute.status > DisputeStatus.Escalated) {
revert Oracle_CannotResolve(_disputeId);
}

Request memory _request = _requests[_dispute.requestId];
Request storage _request = _requests[_dispute.requestId];
if (address(_request.resolutionModule) == address(0)) {
revert Oracle_NoResolutionModule(_disputeId);
}
Expand All @@ -335,7 +334,7 @@ contract Oracle is IOracle {
/// @inheritdoc IOracle
function updateDisputeStatus(bytes32 _disputeId, DisputeStatus _status, bytes calldata _moduleData) external {
Dispute storage _dispute = _disputes[_disputeId];
Request memory _request = _requests[_dispute.requestId];
Request storage _request = _requests[_dispute.requestId];
if (msg.sender != address(_request.disputeModule) && msg.sender != address(_request.resolutionModule)) {
revert Oracle_NotDisputeOrResolutionModule(msg.sender);
}
Expand All @@ -347,7 +346,7 @@ contract Oracle is IOracle {

/// @inheritdoc IOracle
function allowedModule(bytes32 _requestId, address _module) external view returns (bool _allowedModule) {
Request memory _request = _requests[_requestId];
Request storage _request = _requests[_requestId];
_allowedModule = address(_request.requestModule) == _module || address(_request.responseModule) == _module
|| address(_request.disputeModule) == _module || address(_request.resolutionModule) == _module
|| address(_request.finalityModule) == _module;
Expand Down Expand Up @@ -397,7 +396,7 @@ contract Oracle is IOracle {
if (_request.finalizedAt != 0) {
revert Oracle_AlreadyFinalized(_requestId);
}
Response memory _response = _responses[_finalizedResponseId];
Response storage _response = _responses[_finalizedResponseId];
if (_response.requestId != _requestId) {
revert Oracle_InvalidFinalizedResponse(_finalizedResponseId);
}
Expand All @@ -407,7 +406,7 @@ contract Oracle is IOracle {
}

_finalizedResponses[_requestId] = _finalizedResponseId;
_request.finalizedAt = block.timestamp;
_request.finalizedAt = uint128(block.timestamp);
_finalize(_requestId, _request);
}

Expand Down Expand Up @@ -435,7 +434,7 @@ contract Oracle is IOracle {
}
}
}
_request.finalizedAt = block.timestamp;
_request.finalizedAt = uint128(block.timestamp);
_finalize(_requestId, _request);
}

Expand Down Expand Up @@ -463,7 +462,7 @@ contract Oracle is IOracle {
* @param _request The request to be created
* @return _requestId The id of the created request
*/
function _createRequest(NewRequest memory _request) internal returns (bytes32 _requestId) {
function _createRequest(NewRequest calldata _request) internal returns (bytes32 _requestId) {
uint256 _requestNonce = totalRequestCount++;
// bytes32 _requestHash = keccak256(
// abi.encodePacked(
Expand Down Expand Up @@ -509,8 +508,8 @@ contract Oracle is IOracle {
// resolutionModule: _request.resolutionModule,
// finalityModule: _request.finalityModule,
// requester: msg.sender,
// nonce: _requestNonce,
// createdAt: block.timestamp,
// nonce: uint96(_requestNonce),
// createdAt: uint128(block.timestamp),
// finalizedAt: 0
// });

Expand Down
8 changes: 4 additions & 4 deletions solidity/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ interface IOracle {
*/
struct Request {
bytes32 ipfsHash;
uint128 createdAt;
uint128 finalizedAt;
uint96 nonce;
address requester;
IRequestModule requestModule;
IResponseModule responseModule;
IDisputeModule disputeModule;
IResolutionModule resolutionModule;
IFinalityModule finalityModule;
address requester;
uint256 nonce;
uint256 createdAt;
uint256 finalizedAt;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/ResponseProposal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
// }

// function test_proposeResponse_finalizedRequest(bytes memory _responseData, uint256 _timestamp) public {
// vm.assume(_timestamp > _expectedDeadline + _baseDisputeWindow);
// _timestamp = bound(_timestamp, _expectedDeadline + _baseDisputeWindow, type(uint128).max);

// vm.prank(proposer);
// bytes32 _responseId = oracle.proposeResponse(_requestId, _responseData);
Expand Down
26 changes: 13 additions & 13 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -630,22 +630,22 @@
// // Mock and expect the responseModule propose call:
// _mockAndExpect(
// address(responseModule),
// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, _responseData, proposer)),
// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, proposer)),
// abi.encode(mockResponse)
// );

// // Test: propose the response
// vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_CannotTamperParticipant.selector));
// vm.prank(proposer);
// oracle.proposeResponse(_requestId, _responseData, _responseData);
// oracle.proposeResponse(_requestId, _responseData);

// // Change the proposer address
// mockResponse.proposer = proposer;

// // Mock and expect the responseModule propose call:
// _mockAndExpect(
// address(responseModule),
// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, _responseData, proposer)),
// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, proposer)),
// abi.encode(mockResponse)
// );

Expand All @@ -655,7 +655,7 @@

// // Test: propose the response
// vm.prank(proposer);
// bytes32 _actualResponseId = oracle.proposeResponse(_requestId, _responseData, _responseData);
// bytes32 _actualResponseId = oracle.proposeResponse(_requestId, _responseData);

// // Check: emits ResponseProposed event?
// vm.expectEmit(true, true, true, true);
Expand All @@ -664,7 +664,7 @@
// );

// vm.prank(proposer);
// bytes32 _secondResponseId = oracle.proposeResponse(_requestId, _responseData, _responseData);
// bytes32 _secondResponseId = oracle.proposeResponse(_requestId, _responseData);

// // Check: correct response id returned?
// assertEq(_actualResponseId, _responseId);
Expand All @@ -689,7 +689,7 @@
// assertEq(_responseIds[1], _secondResponseId);
// }

// function test_proposeResponseRevertsIfAlreadyFinalized(bytes calldata _responseData, uint256 _finalizedAt) public {
// function test_proposeResponseRevertsIfAlreadyFinalized(bytes calldata _responseData, uint128 _finalizedAt) public {
// vm.assume(_finalizedAt > 0);

// // Create mock request
Expand All @@ -702,7 +702,7 @@

// // Should revert with already finalized
// vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_AlreadyFinalized.selector, (_requestId)));
// oracle.proposeResponse(_requestId, _responseData, _responseData);
// oracle.proposeResponse(_requestId, _responseData);
// }
// }

Expand Down Expand Up @@ -730,12 +730,12 @@
// // Test: revert if called by a random dude (not dispute module)
// vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_NotDisputeModule.selector, _proposer));
// vm.prank(_proposer);
// oracle.proposeResponse(_proposer, _requestId, _responseData, _responseData);
// oracle.proposeResponse(_proposer, _requestId, _responseData);

// // Mock and expect the responseModule propose call:
// _mockAndExpect(
// address(responseModule),
// abi.encodeCall(IResponseModule.propose, (_requestId, _proposer, _responseData, _responseData, address(disputeModule))),
// abi.encodeCall(IResponseModule.propose, (_requestId, _proposer, _responseData, address(disputeModule))),
// abi.encode(mockResponse)
// );

Expand All @@ -745,7 +745,7 @@

// // Test: propose the response
// vm.prank(address(disputeModule));
// bytes32 _actualResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData, _responseData);
// bytes32 _actualResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData);

// // Check: emits ResponseProposed event?
// vm.expectEmit(true, true, true, true);
Expand All @@ -754,7 +754,7 @@
// );

// vm.prank(address(disputeModule));
// bytes32 _secondResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData, _responseData);
// bytes32 _secondResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData);

// // Check: correct response id returned?
// assertEq(_actualResponseId, _responseId);
Expand Down Expand Up @@ -793,12 +793,12 @@

// _mockAndExpect(
// address(responseModule),
// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, bytes('response'), bytes('response'), proposer)),
// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, bytes('response'), proposer)),
// abi.encode(mockResponse)
// );

// vm.prank(proposer);
// bytes32 _responseId = oracle.proposeResponse(_requestId, bytes('response'), bytes('response'));
// bytes32 _responseId = oracle.proposeResponse(_requestId, bytes('response'));

// _mockAndExpect(
// address(responseModule),
Expand Down

0 comments on commit 7898b72

Please sign in to comment.