From bbc46986be9d2a853a4fe062cd30abf0cd3b3d13 Mon Sep 17 00:00:00 2001 From: moebius <0xmoebius@tutanota.com> Date: Thu, 26 Oct 2023 11:41:28 -0300 Subject: [PATCH] perf: storage reads improvements --- solidity/contracts/Oracle.sol | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/solidity/contracts/Oracle.sol b/solidity/contracts/Oracle.sol index 7f3b5a3..03bfef2 100644 --- a/solidity/contracts/Oracle.sol +++ b/solidity/contracts/Oracle.sol @@ -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); } @@ -225,7 +225,7 @@ contract Oracle is IOracle { /// @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); } @@ -270,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); @@ -285,7 +285,7 @@ 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 @@ -293,7 +293,7 @@ contract Oracle is IOracle { 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); } @@ -306,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); } @@ -318,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; @@ -368,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); } @@ -434,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;