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
21 changes: 20 additions & 1 deletion src/v0.8/core/filplus/Filplus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ contract Filplus is Initializable, UUPSUpgradeable, IFilplus, RolesModifiers {
rules.proofAuditFee = 1000000000000000000;
rules.challengeAuditFee = rules.proofAuditFee;
rules.disputeAuditFee = rules.proofAuditFee;
rules.datasetRuleAuditorsElectionTime = 2880;

__UUPSUpgradeable_init();
}
Expand Down Expand Up @@ -310,6 +311,15 @@ contract Filplus is Initializable, UUPSUpgradeable, IFilplus, RolesModifiers {
emit FilplusEvents.SetDatacapCollateralMaxLockDays(_newValue);
}

///@notice Sets the election time for auditors.
///@param _blocks The number of blocks to set as the election time.
function setAuditorsElectionTime(
uint64 _blocks
) external onlyAddress(GOVERNANCE_ADDRESS) {
rules.datasetRuleAuditorsElectionTime = _blocks;
emit FilplusEvents.SetAuditorsElectionTime(_blocks);
}

// Public getter function to access datasetRuleMaxReplicasInCountries
function getDatasetRuleMaxReplicasInCountry(
uint16 _countryCode
Expand Down Expand Up @@ -363,7 +373,11 @@ contract Filplus is Initializable, UUPSUpgradeable, IFilplus, RolesModifiers {
}

/// @notice Returns the datacap collateral days when dataset approved
function getDatacapdatasetApprovedLockDays() external view returns (uint64) {
function getDatacapdatasetApprovedLockDays()
external
view
returns (uint64)
{
return rules.datacapdatasetApprovedLockDays;
}

Expand Down Expand Up @@ -508,6 +522,11 @@ contract Filplus is Initializable, UUPSUpgradeable, IFilplus, RolesModifiers {
return rules.datacapRulesMaxRemainingPercentageForNext;
}

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

/// @notice Check if the storage regions complies with filplus rules.
function isCompliantRuleMinRegionsPerDataset(
uint16[] memory _regions
Expand Down
27 changes: 12 additions & 15 deletions src/v0.8/interfaces/core/IFilplus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,27 @@ interface IFilplus {
function setChallengeProofsSubmiterCount(uint16 _newValue) external;

/// @notice Set the datacap collateral lock days when dataset approved complies with filplus rules.
function setDatacapdatasetApprovedLockDays(
uint64 _newValue
) external;
function setDatacapdatasetApprovedLockDays(uint64 _newValue) external;

/// @notice Set the datacap collateral lock max days complies with filplus rules.
function setDatacapCollateralMaxLockDays(
uint64 _newValue
) external;
function setDatacapCollateralMaxLockDays(uint64 _newValue) external;

/// @notice Set the challenge audit fee complies with filplus rules.
function setChallengeAuditFee(
uint256 _newValue
) external;
function setChallengeAuditFee(uint256 _newValue) external;

/// @notice Set the proof audit fee complies with filplus rules.
function setProofAuditFee(
uint256 _newValue
) external;
function setProofAuditFee(uint256 _newValue) external;

/// @notice Set the dispute audit fee complies with filplus rules.
function setDisputeAuditFee(
uint256 _newValue
) external;
function setDisputeAuditFee(uint256 _newValue) external;

/// @notice Set the challenge proofs price pre point complies with filplus rules.
function setChallengeProofsPricePrePoint(uint256 _newValue) external;

///@notice Sets the election time for auditors.
///@param _blocks The number of blocks to set as the election time.
function setAuditorsElectionTime(uint64 _blocks) external;

function getIncomeReleaseRule(
FinanceType.Type _type
)
Expand Down Expand Up @@ -245,6 +239,9 @@ interface IFilplus {
view
returns (uint8);

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

/// @notice Check if the storage area complies with filplus rules.
function isCompliantRuleGeolocation(
uint16[] memory _regions,
Expand Down
22 changes: 22 additions & 0 deletions src/v0.8/interfaces/module/IDatasetsChallenge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ 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;

///@notice Submit challenge proof for a dataset
/// Based on merkle proof challenge.
/// random challenge method is used to reduce the amount of data and calculation while ensuring algorithm security.
Expand Down Expand Up @@ -82,6 +88,22 @@ 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(
uint64 _datasetId
) external 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.
/// @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
) external view returns (uint64);

/// @notice Get the Roles contract.
/// @return Roles contract address.
function roles() external view returns (IRoles);
Expand Down
22 changes: 22 additions & 0 deletions src/v0.8/module/dataset/DatasetsChallenge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ 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 {}

///@notice Submit challenge proof for a dataset
/// Based on merkle proof challenge.
/// random challenge method is used to reduce the amount of data and calculation while ensuring algorithm security.
Expand Down Expand Up @@ -303,4 +309,20 @@ contract DatasetsChallenge is
1
)[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(
uint64 _datasetId
) external 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.
/// @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) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*******************************************************************************
* (c) 2023 Dataswap
*
* Licensed under the GNU General Public License, Version 3.0 or later (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/gpl-3.0.en.html *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.21;
import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol";
import {FinanceType} from "src/v0.8/types/FinanceType.sol";

contract DatasetAuditorElectionLIB {
///@notice Internal function to stake tokens.
///@param _candidates The storage array to store candidate addresses.
///@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(
address[] storage _candidates,
IRoles _roles,
uint64 _datasetId,
address _token
) internal {
(, , uint256 escrow, ) = _roles.finance().getAccountEscrow(
_datasetId,
0,
msg.sender,
_token,
FinanceType.Type.EscrowChallengeAuditCollateral
);

require(
escrow >= _roles.filplus().getProofAuditFee(),
"auditor escrow invalid"
);

// Add or update candidate
bool isNewCandidate = true;
for (uint256 i = 0; i < _candidates.length; i++) {
if (_candidates[i] == msg.sender) {
isNewCandidate = false;
break;
}
}

if (isNewCandidate) {
_candidates.push(msg.sender);
}
}

///@notice Internal function to elect winners based on staked amounts.
///@param _candidates The storage array containing candidate addresses.
///@param _roles The contract instance of IRoles.
///@param _datasetId The ID of the dataset.
///@param _token The address of the token used for staking.
///@param _numWinners The number of winners to be elected.
///@return winners An array containing the addresses of the elected winners.
function _electWinners(
address[] storage _candidates,
IRoles _roles,
uint64 _datasetId,
address _token,
uint256 _numWinners
) internal returns (address[] memory winners) {
require(
_numWinners > 0 && _numWinners <= _candidates.length,
"Invalid number of winners"
);

winners = new address[](_numWinners);

// Sort candidates by staked amount
for (uint256 i = 0; i < _candidates.length - 1; i++) {
for (uint256 j = 0; j < _candidates.length - i - 1; j++) {
(, , uint256 jEscrow, ) = _roles.finance().getAccountEscrow(
_datasetId,
0,
_candidates[j],
_token,
FinanceType.Type.EscrowChallengeAuditCollateral
);
(, , uint256 iEscrow, ) = _roles.finance().getAccountEscrow(
_datasetId,
0,
_candidates[i],
_token,
FinanceType.Type.EscrowChallengeAuditCollateral
);

if (jEscrow < iEscrow) {
(_candidates[j], _candidates[j + 1]) = (
_candidates[j + 1],
_candidates[j]
);
}
}
}

for (uint256 i = 0; i < winners.length; i++) {
winners[i] = _candidates[i];
}

return winners;
}

function isElectionFailed() internal returns (bool) {}
}
4 changes: 3 additions & 1 deletion src/v0.8/shared/events/FilplusEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ library FilplusEvents {
// Event emitted when datacap collateral lock days when dataset approved rule is set
event SetDatacapdatasetApprovedLockDays(uint64 _newValue);

// Event emitted when auditor elections time rule is set
event SetAuditorsElectionTime(uint64 _newValue);

// Event emitted when datacap collateral max lock days rule is set
event SetDatacapCollateralMaxLockDays(uint64 _newValue);

Expand All @@ -94,5 +97,4 @@ library FilplusEvents {

// Event emitted when dispute audit fee rule is set
event SetDisputeAuditFee(uint256 _newValue);

}
1 change: 1 addition & 0 deletions src/v0.8/types/DatasetType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ library DatasetType {
uint16 challengesCount;
mapping(address => ChallengeProof) challengeProofs; // Address of the auditor who submits challenges.
address[] auditors; // Records of auditors submitting verifications.
address[] candidates; // Records of candidates of auditors.
}

/// @notice The struct describes the storage requirements specified by the client.
Expand Down
3 changes: 2 additions & 1 deletion src/v0.8/types/FilplusType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ library FilplusType {
uint64 datasetRuleMinProofTimeout;
uint64 datasetRuleMinAuditTimeout;
uint64 datasetRuleRequirementTimeout;
uint64 datasetRuleAuditorsElectionTime; // The election time for auditors.
///@notice datacap rules
uint64 datacapRulesMaxAllocatedSizePerTime; // Maximum allocate datacap size per time.
uint8 datacapRulesMaxRemainingPercentageForNext; // Minimum completion percentage for the next allocation.
uint256 datacapPricePreByte; // The datacap price pre byte.
uint256 datacapChunkLandPricePreByte; // The datacap chunk land price pre byte.
uint256 challengeProofsPricePrePoint; // The challenge proofs price pre point.
uint16 challengeProofsSubmiterCount; // The challenge proofs submiter count.
uint64 datacapdatasetApprovedLockDays; // The datacap collateral days when dataset approved.
uint64 datacapdatasetApprovedLockDays; // The datacap collateral days when dataset approved.
uint64 datacapCollateralMaxLockDays; // The datacap collateral max lock days.
uint256 proofAuditFee; // The proof audit fee.
uint256 challengeAuditFee; // The challenge audit fee.
Expand Down