Skip to content

Commit

Permalink
refactor: use block.timestamp instead of block.number (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal authored Oct 1, 2024
1 parent 017298b commit 4d28a0e
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 137 deletions.
30 changes: 15 additions & 15 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ contract Oracle is IOracle {
using ValidatorLib for *;

/// @inheritdoc IOracle
mapping(bytes32 _requestId => uint128 _finalizedAt) public finalizedAt;
mapping(bytes32 _requestId => uint256 _finalizedAt) public finalizedAt;

/// @inheritdoc IOracle
mapping(bytes32 _id => uint128 _requestCreatedAt) public requestCreatedAt;
mapping(bytes32 _id => uint256 _requestCreatedAt) public requestCreatedAt;

/// @inheritdoc IOracle
mapping(bytes32 _id => uint128 _responseCreatedAt) public responseCreatedAt;
mapping(bytes32 _id => uint256 _responseCreatedAt) public responseCreatedAt;

/// @inheritdoc IOracle
mapping(bytes32 _id => uint128 _disputeCreatedAt) public disputeCreatedAt;
mapping(bytes32 _id => uint256 _disputeCreatedAt) public disputeCreatedAt;

/// @inheritdoc IOracle
mapping(bytes32 _responseId => bytes32 _disputeId) public disputeOf;
Expand Down Expand Up @@ -132,9 +132,9 @@ contract Oracle is IOracle {
_participants[_requestId] = abi.encodePacked(_participants[_requestId], _response.proposer);
IResponseModule(_request.responseModule).propose(_request, _response, msg.sender);
_responseIds[_requestId] = abi.encodePacked(_responseIds[_requestId], _responseId);
responseCreatedAt[_responseId] = uint128(block.number);
responseCreatedAt[_responseId] = block.timestamp;

emit ResponseProposed(_requestId, _responseId, _response, block.number);
emit ResponseProposed(_requestId, _responseId, _response);
}

/// @inheritdoc IOracle
Expand Down Expand Up @@ -171,11 +171,11 @@ contract Oracle is IOracle {
_participants[_requestId] = abi.encodePacked(_participants[_requestId], msg.sender);
disputeStatus[_disputeId] = DisputeStatus.Active;
disputeOf[_responseId] = _disputeId;
disputeCreatedAt[_disputeId] = uint128(block.number);
disputeCreatedAt[_disputeId] = block.timestamp;

IDisputeModule(_request.disputeModule).disputeResponse(_request, _response, _dispute);

emit ResponseDisputed(_responseId, _disputeId, _dispute, block.number);
emit ResponseDisputed(_responseId, _disputeId, _dispute);
}

/// @inheritdoc IOracle
Expand All @@ -200,7 +200,7 @@ contract Oracle is IOracle {
// Notify the dispute module about the escalation
IDisputeModule(_request.disputeModule).onDisputeStatusChange(_disputeId, _request, _response, _dispute);

emit DisputeEscalated(msg.sender, _disputeId, block.number);
emit DisputeEscalated(msg.sender, _disputeId);

if (address(_request.resolutionModule) != address(0)) {
// Initiate the resolution
Expand Down Expand Up @@ -232,7 +232,7 @@ contract Oracle is IOracle {

IResolutionModule(_request.resolutionModule).resolveDispute(_disputeId, _request, _response, _dispute);

emit DisputeResolved(_disputeId, _dispute, msg.sender, block.number);
emit DisputeResolved(_disputeId, _dispute, msg.sender);
}

/// @inheritdoc IOracle
Expand All @@ -258,7 +258,7 @@ contract Oracle is IOracle {
disputeStatus[_disputeId] = _status;
IDisputeModule(_request.disputeModule).onDisputeStatusChange(_disputeId, _request, _response, _dispute);

emit DisputeStatusUpdated(_disputeId, _dispute, _status, block.number);
emit DisputeStatusUpdated(_disputeId, _dispute, _status);
}

/**
Expand Down Expand Up @@ -332,7 +332,7 @@ contract Oracle is IOracle {
revert Oracle_AlreadyFinalized(_requestId);
}

finalizedAt[_requestId] = uint128(block.number);
finalizedAt[_requestId] = block.timestamp;

if (address(_request.finalityModule) != address(0)) {
IFinalityModule(_request.finalityModule).finalizeRequest(_request, _response, msg.sender);
Expand All @@ -346,7 +346,7 @@ contract Oracle is IOracle {
IResponseModule(_request.responseModule).finalizeRequest(_request, _response, msg.sender);
IRequestModule(_request.requestModule).finalizeRequest(_request, _response, msg.sender);

emit OracleRequestFinalized(_requestId, _responseId, msg.sender, block.number);
emit OracleRequestFinalized(_requestId, _responseId, msg.sender);
}

/**
Expand Down Expand Up @@ -430,7 +430,7 @@ contract Oracle is IOracle {

_requestId = ValidatorLib._getId(_request);
nonceToRequestId[_requestNonce] = _requestId;
requestCreatedAt[_requestId] = uint128(block.number);
requestCreatedAt[_requestId] = block.timestamp;

// solhint-disable-next-line func-named-parameters
_allowedModules[_requestId] = abi.encodePacked(
Expand All @@ -444,6 +444,6 @@ contract Oracle is IOracle {
_participants[_requestId] = abi.encodePacked(_participants[_requestId], msg.sender);
IRequestModule(_request.requestModule).createRequest(_requestId, _request.requestModuleData, msg.sender);

emit RequestCreated(_requestId, _request, _ipfsHash, block.number);
emit RequestCreated(_requestId, _request, _ipfsHash);
}
}
51 changes: 19 additions & 32 deletions solidity/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,55 @@ interface IOracle {
* @param _requestId The id of the created request
* @param _request The request that has been created
* @param _ipfsHash The hashed IPFS CID of the metadata json
* @param _blockNumber The current block number
*/
event RequestCreated(bytes32 indexed _requestId, Request _request, bytes32 _ipfsHash, uint256 _blockNumber);
event RequestCreated(bytes32 indexed _requestId, Request _request, bytes32 _ipfsHash);

/**
* @notice Emitted when a response is proposed
* @param _requestId The id of the request
* @param _responseId The id of the proposed response
* @param _response The response that has been proposed
* @param _blockNumber The current block number
*/
event ResponseProposed(
bytes32 indexed _requestId, bytes32 indexed _responseId, Response _response, uint256 _blockNumber
);
event ResponseProposed(bytes32 indexed _requestId, bytes32 indexed _responseId, Response _response);

/**
* @notice Emitted when a response is disputed
* @param _responseId The id of the response being disputed
* @param _disputeId The id of the dispute
* @param _dispute The dispute that has been created
* @param _blockNumber The current block number
*/
event ResponseDisputed(
bytes32 indexed _responseId, bytes32 indexed _disputeId, Dispute _dispute, uint256 _blockNumber
);
event ResponseDisputed(bytes32 indexed _responseId, bytes32 indexed _disputeId, Dispute _dispute);

/**
* @notice Emitted when a request is finalized
* @param _requestId The id of the request being finalized
* @param _responseId The id of the final response, may be empty
* @param _caller The address of the user who finalized the request
* @param _blockNumber The current block number
*/
event OracleRequestFinalized(
bytes32 indexed _requestId, bytes32 indexed _responseId, address indexed _caller, uint256 _blockNumber
);
event OracleRequestFinalized(bytes32 indexed _requestId, bytes32 indexed _responseId, address indexed _caller);

/**
* @notice Emitted when a dispute is escalated
* @param _caller The address of the user who escalated the dispute
* @param _disputeId The id of the dispute being escalated
* @param _blockNumber The block number of the escalation
*/
event DisputeEscalated(address indexed _caller, bytes32 indexed _disputeId, uint256 _blockNumber);
event DisputeEscalated(address indexed _caller, bytes32 indexed _disputeId);

/**
* @notice Emitted when a dispute's status changes
* @param _disputeId The id of the dispute
* @param _dispute The dispute that is being updated
* @param _status The new dispute status
* @param _blockNumber The block number of the status update
*/
event DisputeStatusUpdated(bytes32 indexed _disputeId, Dispute _dispute, DisputeStatus _status, uint256 _blockNumber);
event DisputeStatusUpdated(bytes32 indexed _disputeId, Dispute _dispute, DisputeStatus _status);

/**
* @notice Emitted when a dispute is resolved
* @param _disputeId The id of the dispute being resolved
* @param _dispute The dispute that is being updated
* @param _caller The address of the user who resolved the dispute
* @param _blockNumber The block number of the dispute resolution
*/
event DisputeResolved(bytes32 indexed _disputeId, Dispute _dispute, address indexed _caller, uint256 _blockNumber);
event DisputeResolved(bytes32 indexed _disputeId, Dispute _dispute, address indexed _caller);

/*///////////////////////////////////////////////////////////////
ERRORS
Expand Down Expand Up @@ -301,36 +288,36 @@ interface IOracle {
function finalizedResponseId(bytes32 _requestId) external view returns (bytes32 _finalizedResponseId);

/**
* @notice The number of the block at which a request was created
* @notice The block's timestamp at which a request was created
*
* @param _id The request id
* @return _requestCreatedAt The block number
* @return _requestCreatedAt The block's timestamp
*/
function requestCreatedAt(bytes32 _id) external view returns (uint128 _requestCreatedAt);
function requestCreatedAt(bytes32 _id) external view returns (uint256 _requestCreatedAt);

/**
* @notice The number of the block at which a response was created
* @notice The block's timestamp at which a response was created
*
* @param _id The response id
* @return _responseCreatedAt The block number
* @return _responseCreatedAt The block's timestamp
*/
function responseCreatedAt(bytes32 _id) external view returns (uint128 _responseCreatedAt);
function responseCreatedAt(bytes32 _id) external view returns (uint256 _responseCreatedAt);

/**
* @notice The number of the block at which a dispute was created
* @notice The block's timestamp at which a dispute was created
*
* @param _id The dispute id
* @return _disputeCreatedAt The block number
* @return _disputeCreatedAt The block's timestamp
*/
function disputeCreatedAt(bytes32 _id) external view returns (uint128 _disputeCreatedAt);
function disputeCreatedAt(bytes32 _id) external view returns (uint256 _disputeCreatedAt);

/**
* @notice The number of the block at which a request was finalized
* @notice The block's timestamp at which a request was finalized
*
* @param _requestId The request id
* @return _finalizedAt The block number
* @return _finalizedAt The block's timestamp
*/
function finalizedAt(bytes32 _requestId) external view returns (uint128 _finalizedAt);
function finalizedAt(bytes32 _requestId) external view returns (uint256 _finalizedAt);

/*///////////////////////////////////////////////////////////////
LOGIC
Expand Down
7 changes: 1 addition & 6 deletions solidity/interfaces/modules/dispute/IDisputeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ interface IDisputeModule is IModule {
* @param _responseId The id of the response disputed
* @param _disputeId The id of the dispute
* @param _dispute The dispute that is being created
* @param _blockNumber The current block number
*/
event ResponseDisputed(
bytes32 indexed _requestId,
bytes32 indexed _responseId,
bytes32 indexed _disputeId,
IOracle.Dispute _dispute,
uint256 _blockNumber
bytes32 indexed _requestId, bytes32 indexed _responseId, bytes32 indexed _disputeId, IOracle.Dispute _dispute
);

/**
Expand Down
Loading

0 comments on commit 4d28a0e

Please sign in to comment.