Skip to content

Commit

Permalink
fix: πŸ› remove getChallengeAuditCollateralRequirement
Browse files Browse the repository at this point in the history
βœ… Closes: #349
  • Loading branch information
siriusyim committed Mar 22, 2024
1 parent 446b9fd commit 259d09d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 78 deletions.
15 changes: 3 additions & 12 deletions src/v0.8/interfaces/module/IDatasetsChallenge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol";

/// @title IDatasetsChallenge
interface IDatasetsChallenge {
/// @notice Stake function for auditors.
/// @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;
/// @dev Allows a user to nominate themselves as a candidate for dataset auditor election.
/// @param _datasetId The ID of the dataset for which the user is nominating themselves as a candidate.
function nominateAsDatasetAuditorCandidate(uint64 _datasetId) external;

///@notice Submit challenge proof for a dataset
/// Based on merkle proof challenge.
Expand Down Expand Up @@ -103,13 +101,6 @@ 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.
Expand Down
35 changes: 12 additions & 23 deletions src/v0.8/module/dataset/DatasetsChallenge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,22 @@ contract DatasetsChallenge is
return _getImplementation();
}

/// @notice Stake function for auditors.
/// @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 {
/// @dev Allows a user to nominate themselves as a candidate for dataset auditor election.
/// @param _datasetId The ID of the dataset for which the user is nominating themselves as a candidate.
function nominateAsDatasetAuditorCandidate(uint64 _datasetId) external {
require(
uint64(block.number) < getAuditorElectionEndHeight(_datasetId),
"auditors election timeout"
);

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

roles.finance().__escrow(
_datasetId,
0,
Expand All @@ -105,11 +111,7 @@ contract DatasetsChallenge is

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

///@notice Submit challenge proof for a dataset
Expand Down Expand Up @@ -369,19 +371,6 @@ contract DatasetsChallenge is
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,9 @@ import {DatasetType} from "src/v0.8/types/DatasetType.sol";
library DatasetAuditorElectionLIB {
///@notice Internal function to stake tokens.
///@param self The storage to store candidate.
///@param _roles The contract instance of IRoles.
///@param _datasetId The ID of the dataset.
///@param _token The address of the token to stake.
function _stake(
DatasetType.DatasetAuditorElection storage self,
IRoles _roles,
uint64 _datasetId,
address _token
function _nominateAsDatasetAuditorCandidate(
DatasetType.DatasetAuditorElection storage self
) internal {
(, , uint256 escrow, ) = _roles.finance().getAccountEscrow(
_datasetId,
0,
msg.sender,
_token,
FinanceType.Type.EscrowChallengeAuditCollateral
);

require(
escrow >= _getChallengeAuditCollateralRequirement(_roles),
"auditor escrow value invalid"
);

// Add or update candidate
bool isNewCandidate = true;
for (uint256 i = 0; i < self.candidates.length; i++) {
Expand Down Expand Up @@ -139,13 +120,4 @@ library DatasetAuditorElectionLIB {

return false;
}

/// @dev Retrieves the required collateral for challenge audits.
/// @param _roles The Roles contract instance.
/// @return The amount of collateral required for challenge audits.
function _getChallengeAuditCollateralRequirement(
IRoles _roles
) internal view returns (uint256) {
return _roles.filplus().finaceRuleDatasetProofCollateral() * 3;
}
}
5 changes: 1 addition & 4 deletions test/v0.8/helpers/module/dataset/DatasetsHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,7 @@ contract DatasetsHelpers is Test, IDatasetsHelpers {
caller,
FinanceType.FIL
);
uint256 amount = roles
.datasetsChallenge()
.getChallengeAuditCollateralRequirement();
roles.datasetsChallenge().auditorStake(_datasetId, amount);
roles.datasetsChallenge().nominateAsDatasetAuditorCandidate(_datasetId);
uint64 delayBlocks = roles
.datasetsChallenge()
.getAuditorElectionEndHeight(_datasetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ contract ResubmittDatasetChallengeProofsTestCaseWithSuccess is
address(199),
FinanceType.FIL
);
uint256 amount = datasetsChallenge
.getChallengeAuditCollateralRequirement();
datasetsChallenge.auditorStake(_id, amount);
datasetsChallenge.nominateAsDatasetAuditorCandidate(_id);
vm.stopPrank();
uint64 delayBlocks = datasetsChallenge.getAuditorElectionEndHeight(_id);
vm.roll(delayBlocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,10 @@ contract DatasetsTestSetup is Test {
_caller,
FinanceType.FIL
);
uint256 amount = _datasetsHelpers
_datasetsHelpers
.getRoles()
.datasetsChallenge()
.getChallengeAuditCollateralRequirement();
_datasetsHelpers.getRoles().datasetsChallenge().auditorStake(
id,
amount
);
.nominateAsDatasetAuditorCandidate(id);
vm.stopPrank();
uint64 delayBlocks = _datasetsHelpers
.getRoles()
Expand Down

0 comments on commit 259d09d

Please sign in to comment.