Skip to content

Commit 91b72cf

Browse files
authored
Merge pull request #166 from filecoin-project/feature/contracts-update
feat: Add storage snapshot data to Oracle contract,PowerVoting, adding F4 tasks to the contract
2 parents 055f949 + 5981c1f commit 91b72cf

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

power-oracle-contracts/src/Oracle.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
3737
// oracle node allow list
3838
mapping(address => bool) public nodeAllowList;
3939

40+
// snapshot allow list
41+
mapping(address => bool) public snapshotAllowList;
42+
4043
// address status map, key: voter address value: block height
4144
mapping(address => uint256) public voterAddressToBlockHeight;
4245

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

73+
// date to cid
74+
mapping(string => string) public dateToCid;
75+
7076
/**
7177
* @dev Modifier that allows a function to be called only by addresses in the node allow list.
7278
*/
@@ -77,6 +83,13 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
7783
_;
7884
}
7985

86+
modifier onlyInSnapshotAllowList(){
87+
if (!snapshotAllowList[msg.sender]) {
88+
revert PermissionError("Not in snapshot allow list error.");
89+
}
90+
_;
91+
}
92+
8093
/**
8194
* @dev Modifier that ensures the provided address is non-zero.
8295
* @param addr The address to check.
@@ -258,6 +271,15 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
258271
nodeAllowList[nodeAddress] = allow;
259272
}
260273

274+
/**
275+
* @notice Updates the snapshot allow list by adding or removing a snapshot address.
276+
* @param snapshotAddress Address of the snapshot to be added or removed.
277+
* @param allow Boolean indicating whether to allow (true) or disallow (false) the snapshot address.
278+
*/
279+
function updateSnapshotAllowList(address snapshotAddress, bool allow) external override onlyOwner nonZeroAddress(snapshotAddress) {
280+
snapshotAllowList[snapshotAddress] = allow;
281+
}
282+
261283
/**
262284
* @notice Retrieves the list of voter addresses.
263285
* @return An array containing the addresses of all voters.
@@ -275,6 +297,16 @@ contract Oracle is IOracle, Ownable2StepUpgradeable, UUPSUpgradeable {
275297
return voterToInfo[voter];
276298
}
277299

300+
/**
301+
* @notice Adds a snapshot for a specific date with its associated IPFS CID.
302+
* @param date The date associated with the snapshot.
303+
* @param cid The IPFS CID corresponding to the snapshot.
304+
* @dev Only addresses in the snapshot allow list can call this function.
305+
*/
306+
function addSnapshot(string calldata date, string calldata cid) external override onlyInSnapshotAllowList {
307+
dateToCid[date] = cid;
308+
}
309+
278310
/**
279311
* @notice Updates the miner IDs associated with a voter based on their actor IDs.
280312
* @param voterAddress The address of the voter.

power-oracle-contracts/src/interfaces/IOracle.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ interface IOracle is IOracleError {
9393
*/
9494
function updateNodeAllowList(address nodeAddress, bool allow) external;
9595

96+
/**
97+
* @notice Updates the snapshot allow list by adding or removing a snapshot address.
98+
* @param snapshotAddress Address of the snapshot to be added or removed.
99+
* @param allow Boolean indicating whether to allow (true) or disallow (false) the snapshot address.
100+
*/
101+
function updateSnapshotAllowList(address snapshotAddress, bool allow) external;
102+
96103
/**
97104
* @notice Removes a voter along with associated task information.
98105
* @param voterAddress Address of the voter to be removed.
@@ -111,6 +118,14 @@ interface IOracle is IOracleError {
111118
*/
112119
function getVoterInfo(address voter) external view returns(VoterInfo memory);
113120

121+
/**
122+
* @notice Adds a snapshot by associating a date with a CID (Content Identifier).
123+
* @param date The representing the date of the snapshot.
124+
* @param cid The IPFS CID (Content Identifier) for storing the snapshot data.
125+
* @dev The CID is stored on the blockchain and linked to the provided date.
126+
*/
127+
function addSnapshot(string calldata date, string calldata cid) external;
128+
114129
/**
115130
* @notice Event emitted when a delegate is created.
116131
* @param voterAddress The address of the voter who is delegating.

powervoting-contracts/src/PowerVoting-filecoin.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ contract PowerVoting is IPowerVoting, Ownable2StepUpgradeable, UUPSUpgradeable {
344344
proposal.voterInfoCid,
345345
proposal.voters.values()
346346
);
347-
}
347+
}
348348

349349
/**
350350
* @notice Get the list of IDs of all approved proposals.
@@ -398,7 +398,6 @@ contract PowerVoting is IPowerVoting, Ownable2StepUpgradeable, UUPSUpgradeable {
398398
if(proposal.expTime <= block.timestamp){
399399
revert TimeError("Proposal expiration time reached.");
400400
}
401-
_addF4Task();
402401
// increment votesCount
403402
uint256 vid = ++proposal.votesCount;
404403
// use votesCount as vote id
@@ -421,6 +420,14 @@ contract PowerVoting is IPowerVoting, Ownable2StepUpgradeable, UUPSUpgradeable {
421420
}
422421

423422
/**
423+
* @notice Adds a new F4 task.
424+
* @dev This function is a wrapper to call the internal _addF4Task function.
425+
*/
426+
function addF4Task() override external {
427+
_addF4Task();
428+
}
429+
430+
/**Ï
424431
* @notice Adds an F4 task for the caller if necessary.
425432
* @dev This function is called internally to check whether the caller needs to have an F4 task added.
426433
*/

powervoting-contracts/src/interfaces/IPowerVoting-filecoin.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,10 @@ interface IPowerVoting is IPowerVotingEvent, IPowerVotingError {
102102
* @param minerIds An array containing the miner IDs to be added.
103103
*/
104104
function addMinerId(uint64[] memory minerIds) external;
105+
106+
/**
107+
* @notice Adds a new F4 task.
108+
* @dev This function should be implemented to trigger the addition of an F4 task.
109+
*/
110+
function addF4Task() external;
105111
}

0 commit comments

Comments
 (0)