Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add storage snapshot data to Oracle contract,PowerVoting, adding F4 tasks to the contract #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions power-oracle-contracts/src/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
// oracle node allow list
mapping(address => bool) public nodeAllowList;

// snapshot allow list
mapping(address => bool) public snapshotAllowList;

// address status map, key: voter address value: block height
mapping(address => uint256) public voterAddressToBlockHeight;

Expand Down Expand Up @@ -67,6 +70,9 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
// github account list
mapping(string => bool) public githubAccountList;

// date to cid
mapping(string => string) public dateToCid;

/**
* @dev Modifier that allows a function to be called only by addresses in the node allow list.
*/
Expand All @@ -77,6 +83,13 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
_;
}

modifier onlyInSnapshotAllowList(){
if (!snapshotAllowList[msg.sender]) {
revert PermissionError("Not in snapshot allow list error.");
}
_;
}

/**
* @dev Modifier that ensures the provided address is non-zero.
* @param addr The address to check.
Expand Down Expand Up @@ -258,6 +271,15 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
nodeAllowList[nodeAddress] = allow;
}

/**
* @notice Updates the snapshot allow list by adding or removing a snapshot address.
* @param snapshotAddress Address of the snapshot to be added or removed.
* @param allow Boolean indicating whether to allow (true) or disallow (false) the snapshot address.
*/
function updateSnapshotAllowList(address snapshotAddress, bool allow) external override onlyOwner nonZeroAddress(snapshotAddress) {
snapshotAllowList[snapshotAddress] = allow;
}

/**
* @notice Retrieves the list of voter addresses.
* @return An array containing the addresses of all voters.
Expand All @@ -275,6 +297,16 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
return voterToInfo[voter];
}

/**
* @notice Adds a snapshot for a specific date with its associated IPFS CID.
* @param date The date associated with the snapshot.
* @param cid The IPFS CID corresponding to the snapshot.
* @dev Only addresses in the snapshot allow list can call this function.
*/
function addSnapshot(string calldata date, string calldata cid) external override onlyInSnapshotAllowList {
dateToCid[date] = cid;
}

/**
* @notice Updates the miner IDs associated with a voter based on their actor IDs.
* @param voterAddress The address of the voter.
Expand Down
15 changes: 15 additions & 0 deletions power-oracle-contracts/src/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ interface IOracle is IOracleError {
*/
function updateNodeAllowList(address nodeAddress, bool allow) external;

/**
* @notice Updates the snapshot allow list by adding or removing a snapshot address.
* @param snapshotAddress Address of the snapshot to be added or removed.
* @param allow Boolean indicating whether to allow (true) or disallow (false) the snapshot address.
*/
function updateSnapshotAllowList(address snapshotAddress, bool allow) external;

/**
* @notice Removes a voter along with associated task information.
* @param voterAddress Address of the voter to be removed.
Expand All @@ -111,6 +118,14 @@ interface IOracle is IOracleError {
*/
function getVoterInfo(address voter) external view returns(VoterInfo memory);

/**
* @notice Adds a snapshot by associating a date with a CID (Content Identifier).
* @param date The representing the date of the snapshot.
* @param cid The IPFS CID (Content Identifier) for storing the snapshot data.
* @dev The CID is stored on the blockchain and linked to the provided date.
*/
function addSnapshot(string calldata date, string calldata cid) external;

/**
* @notice Event emitted when a delegate is created.
* @param voterAddress The address of the voter who is delegating.
Expand Down
11 changes: 9 additions & 2 deletions powervoting-contracts/src/PowerVoting-filecoin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ contract PowerVoting is IPowerVoting, Ownable2StepUpgradeable, UUPSUpgradeable {
proposal.voterInfoCid,
proposal.voters.values()
);
}
}

/**
* @notice Get the list of IDs of all approved proposals.
Expand Down Expand Up @@ -398,7 +398,6 @@ contract PowerVoting is IPowerVoting, Ownable2StepUpgradeable, UUPSUpgradeable {
if(proposal.expTime <= block.timestamp){
revert TimeError("Proposal expiration time reached.");
}
_addF4Task();
// increment votesCount
uint256 vid = ++proposal.votesCount;
// use votesCount as vote id
Expand All @@ -421,6 +420,14 @@ contract PowerVoting is IPowerVoting, Ownable2StepUpgradeable, UUPSUpgradeable {
}

/**
* @notice Adds a new F4 task.
* @dev This function is a wrapper to call the internal _addF4Task function.
*/
function addF4Task() override external {
_addF4Task();
}

/**Ï
* @notice Adds an F4 task for the caller if necessary.
* @dev This function is called internally to check whether the caller needs to have an F4 task added.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ interface IPowerVoting is IPowerVotingEvent, IPowerVotingError {
* @param minerIds An array containing the miner IDs to be added.
*/
function addMinerId(uint64[] memory minerIds) external;

/**
* @notice Adds a new F4 task.
* @dev This function should be implemented to trigger the addition of an F4 task.
*/
function addF4Task() external;
}