Commit 17f2e022 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update

parent eba42bd4
...@@ -18,15 +18,15 @@ contract Witness is IWitness, Ownable { ...@@ -18,15 +18,15 @@ contract Witness is IWitness, Ownable {
uint256 public lastMerkleRootUpdate; // 上次 merkle root 更新时间 uint256 public lastMerkleRootUpdate; // 上次 merkle root 更新时间
// 记录每天每个 merkle root 提交次数 2023-01-01 -> hash(merkleRoot, merkleSumRoot) -> 1 // 记录每天每个 merkle root 提交次数 2023-01-01 -> hash(merkleRoot, merkleSumRoot) -> 1
mapping(string => mapping(bytes32 => uint256)) public dailyMerkleRootSubmitCountMap; mapping(uint256 => mapping(bytes32 => uint256)) public dailyMerkleRootSubmitCountMap;
// 记录每天每个 witness 是否已提交过 // 记录每天每个 witness 是否已提交过
mapping(string => mapping(address => bool)) public dailyMerkleRootSubmittedMap; mapping(uint256 => mapping(address => bool)) public dailyMerkleRootSubmittedMap;
// 记录每天已验证的 merkle root (已超过生效阈值) // 记录每天已验证的 merkle root (已超过生效阈值)
mapping(string => bool) public dailyMerkleRootVerifiedMap; mapping(uint256 => bool) public dailyMerkleRootVerifiedMap;
// 记录每天的 merkle root // 记录每天的 merkle root
mapping(string => bytes32) public dailyMerkleRootMap; mapping(uint256 => bytes32) public dailyMerkleRootMap;
// 记录每天的 merkle sum root // 记录每天的 merkle sum root
mapping(string => bytes32) public dailyMerkleSumRootMap; mapping(uint256 => bytes32) public dailyMerkleSumRootMap;
uint256 public dailyDistribution; uint256 public dailyDistribution;
...@@ -39,7 +39,7 @@ contract Witness is IWitness, Ownable { ...@@ -39,7 +39,7 @@ contract Witness is IWitness, Ownable {
_; _;
} }
event MerkleRootChanged(string date, bytes32 merkleRoot, bytes32 merkleSumRoot); event MerkleRootChanged(uint256 date, bytes32 merkleRoot, bytes32 merkleSumRoot);
event MerkleRootThresholdChanged(uint256 merkleRootThreshold); event MerkleRootThresholdChanged(uint256 merkleRootThreshold);
event MerkleRootSubmitted(address indexed addr, bytes32 merkleRoot, bytes32 merkleSumRoot, uint256 indexed count, uint256 indexed dailySubmitCount); event MerkleRootSubmitted(address indexed addr, bytes32 merkleRoot, bytes32 merkleSumRoot, uint256 indexed count, uint256 indexed dailySubmitCount);
event DailyDistributionChanged(uint256 dailyDistribution); event DailyDistributionChanged(uint256 dailyDistribution);
...@@ -49,7 +49,11 @@ contract Witness is IWitness, Ownable { ...@@ -49,7 +49,11 @@ contract Witness is IWitness, Ownable {
return merkleRoot; return merkleRoot;
} }
function submitMerkleRoot(string calldata _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) public onlyWitness { function getWorkloadDistribution(uint256 dailyWorkload) view public returns (uint256) {
return dailyDistribution / dailyWorkload;
}
function submitMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) public onlyWitness {
require(dailyMerkleRootSubmitCount <= witnessSet.length(), "Too many submissions"); require(dailyMerkleRootSubmitCount <= witnessSet.length(), "Too many submissions");
require(!dailyMerkleRootSubmittedMap[_date][msg.sender], "Already submitted"); require(!dailyMerkleRootSubmittedMap[_date][msg.sender], "Already submitted");
// check already verified // check already verified
...@@ -73,7 +77,7 @@ contract Witness is IWitness, Ownable { ...@@ -73,7 +77,7 @@ contract Witness is IWitness, Ownable {
emit MerkleRootSubmitted(msg.sender, _merkleRoot, _merkleSumRoot, dailyMerkleRootSubmitCountMap[_date][rootHash], dailyMerkleRootSubmitCount); emit MerkleRootSubmitted(msg.sender, _merkleRoot, _merkleSumRoot, dailyMerkleRootSubmitCountMap[_date][rootHash], dailyMerkleRootSubmitCount);
} }
function _setMerkleRoot(string calldata _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) internal { function _setMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) internal {
merkleRoot = _merkleRoot; merkleRoot = _merkleRoot;
merkleSumRoot = merkleSumRoot; merkleSumRoot = merkleSumRoot;
dailyMerkleRootMap[_date] = _merkleRoot; dailyMerkleRootMap[_date] = _merkleRoot;
......
...@@ -4,7 +4,7 @@ pragma solidity ^0.8.20; ...@@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
interface IWitness { interface IWitness {
function getMerkleRoot() external returns (bytes32); function getMerkleRoot() external returns (bytes32);
function submitMerkleRoot(string calldata _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) external; function submitMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) external;
function getDailyDistribution() external view returns (uint256); function getDailyDistribution() external view returns (uint256);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment