Skip to content
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
2 changes: 1 addition & 1 deletion src/v0.8/core/filplus/Filplus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ contract Filplus is Initializable, UUPSUpgradeable, IFilplus, RolesModifiers {
}

///@notice Returns the election time for auditors.
function auditorsElectionTime() external view returns (uint64) {
function datasetRuleAuditorsElectionTime() external view returns (uint64) {
return rules.datasetRuleAuditorsElectionTime;
}

Expand Down
24 changes: 18 additions & 6 deletions src/v0.8/core/finance/escrow/EscrowChallengeAuditCollateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ contract EscrowChallengeAuditCollateral is EscrowBase {
uint64 _matchingId,
address _payer,
address _token
) public view override onlyRole(roles, RolesType.DATASWAP_CONTRACT) returns (uint256 amount) {
)
public
view
override
onlyRole(roles, RolesType.DATASWAP_CONTRACT)
returns (uint256 amount)
{
(, , uint256 current, ) = roles.finance().getAccountEscrow(
_datasetId,
_matchingId,
Expand Down Expand Up @@ -93,7 +99,7 @@ contract EscrowChallengeAuditCollateral is EscrowBase {
_payer,
_token,
FinanceType.Type.EscrowChallengeAuditCollateral
);
);
}

/// @dev Internal function to get payment amount.
Expand All @@ -114,7 +120,7 @@ contract EscrowChallengeAuditCollateral is EscrowBase {
_payer,
_token,
FinanceType.Type.EscrowChallengeAuditCollateral
);
);
}

/// @dev Internal function to check if a refund is applicable.
Expand All @@ -124,9 +130,15 @@ contract EscrowChallengeAuditCollateral is EscrowBase {
uint64 _datasetId,
uint64 /*_matchingId*/
) internal view override returns (bool refund) {
//TODO: refund when reject without dispute
// return (roles.datasets().getDatasetState(_datasetId) ==
// DatasetType.State.Approved);
DatasetType.State state = roles.datasets().getDatasetState(_datasetId);
if (
state == DatasetType.State.Approved ||
state == DatasetType.State.Rejected
) {
return true;
} else {
//TODO: refund when reject without dispute
}
}

/// @dev Internal function to check if a payment is applicable.
Expand Down
2 changes: 1 addition & 1 deletion src/v0.8/interfaces/core/IFilplus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ interface IFilplus {
returns (uint8);

///@notice Returns the election time for auditors.
function auditorsElectionTime() external view returns (uint64);
function datasetRuleAuditorsElectionTime() external view returns (uint64);

/// @notice Check if the storage area complies with filplus rules.
function isCompliantRuleGeolocation(
Expand Down
27 changes: 21 additions & 6 deletions src/v0.8/interfaces/module/IDatasetsChallenge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ interface IDatasetsChallenge {
uint64 _datasetId
) external view returns (uint64);

///@notice Retrieves sorted auditor candidates for a specific dataset.
///@dev Retrieves a list of auditor candidates sorted based on certain criteria.
///@param _datasetId The ID of the dataset for which auditor candidates are retrieved.
///@return candidates An array containing the addresses of the sorted auditor candidates.
function getSortedAuditorCandidates(
/// @dev Retrieves auditor candidates for a given dataset ID.
/// @param _datasetId The ID of the dataset for which auditor candidates are requested.
/// @return candidates An array containing addresses of auditor candidates.
function getDatasetAuditorCandidates(
uint64 _datasetId
) external returns (address[] memory candidates);
) external view returns (address[] memory candidates);

/// @notice Retrieves the end height of the auditor election for a specific dataset.
/// @dev Retrieves the block height at which the auditor election for the specified dataset ends.
Expand All @@ -104,6 +103,22 @@ interface IDatasetsChallenge {
uint64 _datasetId
) external view returns (uint64);

/// @notice Retrieves the required collateral for challenge audits.
/// @return The amount of collateral required for challenge audits.
function getChallengeAuditCollateralRequirement()
external
view
returns (uint256);

/// @dev Checks whether the given account is a winner for a specific dataset ID.
/// @param _datasetId The ID of the dataset being checked.
/// @param _account The address of the account being checked for winner status.
/// @return A boolean indicating whether the account is a winner for the dataset ID.
function isWinner(
uint64 _datasetId,
address _account
) external returns (bool);

/// @notice Get the Roles contract.
/// @return Roles contract address.
function roles() external view returns (IRoles);
Expand Down
39 changes: 20 additions & 19 deletions src/v0.8/module/dataset/Datasets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ contract Datasets is
return _getImplementation();
}

/// @dev Claims the dataset escrow for a given dataset ID.
/// @param _datasetId The ID of the dataset for which the escrow is being claimed.
function _claimDatasetEscrow(uint64 _datasetId) internal {
roles.finance().claimEscrow(
_datasetId,
0,
FinanceType.FIL,
FinanceType.Type.EscrowChallengeCommission
);
roles.finance().claimEscrow(
_datasetId,
0,
FinanceType.FIL,
FinanceType.Type.EscrowChallengeAuditCollateral
);
}

///@notice Approve a dataset.
///@dev This function changes the state of the dataset to Approved and emits the DatasetApproved event.
function __approveDataset(
Expand All @@ -114,13 +131,7 @@ contract Datasets is

dataset._emitDatasetEvent(DatasetType.Event.Approved);

// Payment challenge commission
roles.finance().claimEscrow(
_datasetId,
0,
FinanceType.FIL,
FinanceType.Type.EscrowChallengeCommission
);
_claimDatasetEscrow(_datasetId);

emit DatasetsEvents.DatasetApproved(_datasetId);
}
Expand All @@ -139,12 +150,7 @@ contract Datasets is

dataset._emitDatasetEvent(DatasetType.Event.Rejected);

roles.finance().claimEscrow(
_datasetId,
0,
FinanceType.FIL,
FinanceType.Type.EscrowChallengeCommission
);
_claimDatasetEscrow(_datasetId);

uint64 mappingSize = roles.datasetsProof().getDatasetSize(
_datasetId,
Expand Down Expand Up @@ -438,12 +444,7 @@ contract Datasets is
DatasetType.Dataset storage dataset = datasets[_datasetId];
dataset._emitDatasetEvent(DatasetType.Event.WorkflowTimeout);

roles.finance().claimEscrow(
_datasetId,
0,
FinanceType.FIL,
FinanceType.Type.EscrowChallengeCommission
);
_claimDatasetEscrow(_datasetId);

uint64 mappingSize = roles.datasetsProof().getDatasetSize(
_datasetId,
Expand Down
94 changes: 86 additions & 8 deletions src/v0.8/module/dataset/DatasetsChallenge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import {DatasetsEvents} from "src/v0.8/shared/events/DatasetsEvents.sol";
import {DatasetsModifiers} from "src/v0.8/shared/modifiers/DatasetsModifiers.sol";
/// library
import {DatasetChallengeProofLIB} from "src/v0.8/module/dataset/library/challenge/DatasetChallengeProofLIB.sol";
import {DatasetAuditorElectionLIB} from "src/v0.8/module/dataset/library/challenge/DatasetAuditorElectionLIB.sol";

/// type
import {RolesType} from "src/v0.8/types/RolesType.sol";
import {DatasetType} from "src/v0.8/types/DatasetType.sol";
import {FinanceType} from "src/v0.8/types/FinanceType.sol";
import {GeolocationType} from "src/v0.8/types/GeolocationType.sol";

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Expand All @@ -46,6 +48,8 @@ contract DatasetsChallenge is
DatasetsModifiers
{
using DatasetChallengeProofLIB for DatasetType.DatasetChallengeProof;
using DatasetAuditorElectionLIB for DatasetType.DatasetAuditorElection;

mapping(uint64 => DatasetType.DatasetChallengeProof)
private datasetChallengeProofs; // Mapping of dataset ID to dataset details

Expand Down Expand Up @@ -84,7 +88,29 @@ contract DatasetsChallenge is
/// @dev Allows auditors to stake tokens for a specific dataset.
/// @param _datasetId The ID of the dataset for which auditors are staking tokens.
/// @param _amount The amount of tokens to stake.
function auditorStake(uint64 _datasetId, uint256 _amount) external {}
function auditorStake(uint64 _datasetId, uint256 _amount) external {
require(
uint64(block.number) < getAuditorElectionEndHeight(_datasetId),
"auditors election timeout"
);

roles.finance().__escrow(
_datasetId,
0,
msg.sender,
FinanceType.FIL,
FinanceType.Type.EscrowChallengeAuditCollateral,
_amount
);

DatasetType.DatasetChallengeProof
storage datasetChallengeProof = datasetChallengeProofs[_datasetId];
datasetChallengeProof.election._stake(
roles,
_datasetId,
FinanceType.FIL
);
}

///@notice Submit challenge proof for a dataset
/// Based on merkle proof challenge.
Expand All @@ -107,6 +133,9 @@ contract DatasetsChallenge is
roles.datasets().__reportDatasetWorkflowTimeout(_datasetId);
return;
}

require(isWinner(_datasetId, msg.sender), "Not an election winner");

DatasetType.DatasetChallengeProof
storage datasetChallengeProof = datasetChallengeProofs[_datasetId];
require(
Expand Down Expand Up @@ -310,19 +339,68 @@ contract DatasetsChallenge is
)[0];
}

///@notice Retrieves sorted auditor candidates for a specific dataset.
///@dev Retrieves a list of auditor candidates sorted based on certain criteria.
///@param _datasetId The ID of the dataset for which auditor candidates are retrieved.
///@return candidates An array containing the addresses of the sorted auditor candidates.
function getSortedAuditorCandidates(
/// @dev Retrieves auditor candidates for a given dataset ID.
/// @param _datasetId The ID of the dataset for which auditor candidates are requested.
/// @return candidates An array containing addresses of auditor candidates.
function getDatasetAuditorCandidates(
uint64 _datasetId
) external returns (address[] memory candidates) {}
) external view returns (address[] memory candidates) {
DatasetType.DatasetChallengeProof
storage datasetChallengeProof = datasetChallengeProofs[_datasetId];

candidates = datasetChallengeProof.election.candidates;
}

/// @notice Retrieves the end height of the auditor election for a specific dataset.
/// @dev Retrieves the block height at which the auditor election for the specified dataset ends.
/// @param _datasetId The ID of the dataset for which the end height of the auditor election is retrieved.
/// @return The end height of the auditor election.
function getAuditorElectionEndHeight(
uint64 _datasetId
) public view returns (uint64) {}
) public view returns (uint64) {
uint64 proofCompleteHeight = roles
.datasetsProof()
.getDatasetProofCompleteHeight(_datasetId);

return
proofCompleteHeight +
roles.filplus().datasetRuleAuditorsElectionTime();
}

/// @dev Retrieves the required collateral for challenge audits.
/// @return The amount of collateral required for challenge audits.
function getChallengeAuditCollateralRequirement()
public
view
returns (uint256)
{
return
DatasetAuditorElectionLIB._getChallengeAuditCollateralRequirement(
roles
);
}

/// @dev Checks whether the given account is a winner for a specific dataset ID.
/// @param _datasetId The ID of the dataset being checked.
/// @param _account The address of the account being checked for winner status.
/// @return A boolean indicating whether the account is a winner for the dataset ID.
function isWinner(
uint64 _datasetId,
address _account
) public returns (bool) {
require(
uint64(block.number) >= getAuditorElectionEndHeight(_datasetId),
"auditor election not completed"
);

DatasetType.DatasetChallengeProof
storage datasetChallengeProof = datasetChallengeProofs[_datasetId];

return
datasetChallengeProof.election._processTicketResult(
getAuditorElectionEndHeight(_datasetId),
_account,
getChallengeSubmissionCount(_datasetId)
);
}
}
Loading