From 5981c1fa5a165eda0f297bd2d1b76752ad796716 Mon Sep 17 00:00:00 2001 From: ZeXiang Date: Tue, 5 Nov 2024 18:13:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20storage=20snapshot=20data=20to=20?= =?UTF-8?q?Oracle=20contract=EF=BC=8CPowerVoting,=20adding=20F4=20tasks=20?= =?UTF-8?q?to=20the=20contract?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- power-oracle-contracts/src/Oracle.sol | 32 +++++++++++++++++++ .../src/interfaces/IOracle.sol | 15 +++++++++ .../src/PowerVoting-filecoin.sol | 11 +++++-- .../src/interfaces/IPowerVoting-filecoin.sol | 6 ++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/power-oracle-contracts/src/Oracle.sol b/power-oracle-contracts/src/Oracle.sol index 39d158c..a42771d 100755 --- a/power-oracle-contracts/src/Oracle.sol +++ b/power-oracle-contracts/src/Oracle.sol @@ -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; @@ -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. */ @@ -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. @@ -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. @@ -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. diff --git a/power-oracle-contracts/src/interfaces/IOracle.sol b/power-oracle-contracts/src/interfaces/IOracle.sol index e7cbf72..5b47526 100644 --- a/power-oracle-contracts/src/interfaces/IOracle.sol +++ b/power-oracle-contracts/src/interfaces/IOracle.sol @@ -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. @@ -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. diff --git a/powervoting-contracts/src/PowerVoting-filecoin.sol b/powervoting-contracts/src/PowerVoting-filecoin.sol index e717625..109629a 100644 --- a/powervoting-contracts/src/PowerVoting-filecoin.sol +++ b/powervoting-contracts/src/PowerVoting-filecoin.sol @@ -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. @@ -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 @@ -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. */ diff --git a/powervoting-contracts/src/interfaces/IPowerVoting-filecoin.sol b/powervoting-contracts/src/interfaces/IPowerVoting-filecoin.sol index 9a77d5d..867bc84 100644 --- a/powervoting-contracts/src/interfaces/IPowerVoting-filecoin.sol +++ b/powervoting-contracts/src/interfaces/IPowerVoting-filecoin.sol @@ -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; }