Skip to content

Commit

Permalink
perf: storage reads improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
moebius committed Oct 26, 2023
1 parent 3eba7b9 commit bbc4698
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 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 @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -285,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 @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bbc4698

Please sign in to comment.