Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: optimizations #7

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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 @@ -206,8 +206,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 @@ -217,16 +217,15 @@ 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
function disputeResponse(bytes32 _requestId, bytes32 _responseId) 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 @@ -271,7 +270,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);
Expand All @@ -286,15 +285,15 @@ contract Oracle is IOracle {

/// @inheritdoc IOracle
function resolveDispute(bytes32 _disputeId) 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 @@ -307,7 +306,7 @@ contract Oracle is IOracle {
/// @inheritdoc IOracle
function updateDisputeStatus(bytes32 _disputeId, DisputeStatus _status) 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 @@ -319,7 +318,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 @@ -369,7 +368,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 @@ -379,7 +378,7 @@ contract Oracle is IOracle {
}

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

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

Expand Down Expand Up @@ -435,7 +434,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++;
_requestId = keccak256(abi.encodePacked(msg.sender, address(this), _requestNonce));
_requestIds[_requestNonce] = _requestId;
Expand All @@ -448,8 +447,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 @@ -198,15 +198,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 @@ contract Integration_ResponseProposal is IntegrationBase {
}

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
2 changes: 1 addition & 1 deletion solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ contract Unit_ProposeResponse is BaseTest {
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 Down