@@ -84,7 +84,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
84
84
mapping (bytes32 => CycleDataInfo) dataInfos;
85
85
86
86
SortedScoreList.List scoreList;
87
- uint256 totalAward ; // 记录这个cycle的总奖励
87
+ uint256 totalReward ; // 记录这个cycle的总奖励
88
88
}
89
89
90
90
struct CycleOutputInfo {
@@ -96,7 +96,6 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
96
96
uint256 _currectCycle;
97
97
mapping (uint256 => CycleInfo) _cycleInfos;
98
98
uint256 _startBlock;
99
- uint64 _minRankingScore;
100
99
101
100
struct SysConfig {
102
101
uint32 minDepositRatio;
@@ -126,7 +125,8 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
126
125
event SupplierReward (address supplier , bytes32 mixedHash , uint256 amount );
127
126
event SupplierPunished (address supplier , bytes32 mixedHash , uint256 amount );
128
127
event ShowDataProof (address supplier , bytes32 dataMixedHash , uint256 nonce_block );
129
- event WithdrawAward (bytes32 mixedHash , uint256 cycle );
128
+ event WithdrawReward (bytes32 mixedHash , uint256 cycle );
129
+ event CycleStart (uint256 cycleNumber , uint256 startReward );
130
130
131
131
function initialize (address _gwtToken , address _Foundation ) public initializer {
132
132
__PublicDataStorageUpgradable_init (_gwtToken, _Foundation);
@@ -191,6 +191,19 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
191
191
}
192
192
}
193
193
194
+ function _getRemainScore (uint256 length ) internal pure returns (uint16 ) {
195
+ uint16 [33 ] memory remainScores = [
196
+ 1600 , 1360 , 1180 , 1030 , 910 , 810 ,
197
+ 730 , 670 , 617 , 575 , 539 , 504 ,
198
+ 470 , 437 , 405 , 374 , 344 , 315 ,
199
+ 287 , 260 , 234 , 209 , 185 , 162 ,
200
+ 140 , 119 , 99 , 80 , 62 , 45 ,
201
+ 29 , 14 , 0
202
+ ];
203
+
204
+ return remainScores[length];
205
+ }
206
+
194
207
function _cycleNumber (uint256 blockNumber , uint256 startBlock ) internal view returns (uint256 ) {
195
208
uint cycleNumber = (blockNumber - startBlock) / sysConfig.blocksPerCycle;
196
209
if (cycleNumber * sysConfig.blocksPerCycle + startBlock < blockNumber) {
@@ -209,13 +222,19 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
209
222
CycleInfo storage cycleInfo = _cycleInfos[cycleNumber];
210
223
// 如果cycle的reward为0,说明这个周期还没有开始
211
224
// 开始一个周期:从上个周期的奖励中拿20%
212
- if (cycleInfo.totalAward == 0 ) {
213
- uint256 lastCycleReward = _cycleInfos[_currectCycle].totalAward ;
214
- // 0.05作为基金会收入
225
+ if (cycleInfo.totalReward == 0 ) {
226
+ uint256 lastCycleReward = _cycleInfos[_currectCycle].totalReward ;
227
+ // 5%作为基金会收入
215
228
uint256 fundationIncome = lastCycleReward * 5 / 100 ;
216
229
gwtToken.transfer (foundationAddress, fundationIncome);
217
- cycleInfo.totalAward = (lastCycleReward - (lastCycleReward * 4 / 5 ) - fundationIncome);
218
- _currectCycle = cycleNumber;
230
+ // 如果上一轮的获奖数据不足32个,剩余的奖金也滚动进此轮奖池
231
+ uint16 remainScore = _getRemainScore (_cycleInfos[_currectCycle].scoreList.length ());
232
+ uint256 remainReward = lastCycleReward * 4 * remainScore / totalRewardScore / 5 ;
233
+
234
+ cycleInfo.totalReward = lastCycleReward - (lastCycleReward * 4 / 5 ) - fundationIncome + remainReward;
235
+ _currectCycle = cycleNumber;
236
+
237
+ emit CycleStart (cycleNumber, cycleInfo.totalReward);
219
238
}
220
239
221
240
return cycleInfo;
@@ -224,7 +243,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
224
243
225
244
function _addCycleReward (uint256 amount ) private {
226
245
CycleInfo storage cycleInfo = _ensureCurrentCycleStart ();
227
- cycleInfo.totalAward += amount;
246
+ cycleInfo.totalReward += amount;
228
247
}
229
248
230
249
// 计算这些空间对应多少GWT,单位是wei
@@ -288,7 +307,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
288
307
}
289
308
290
309
function getCycleInfo (uint256 cycleNumber ) public view returns (CycleOutputInfo memory ) {
291
- return CycleOutputInfo (_cycleInfos[cycleNumber].totalAward , _cycleInfos[cycleNumber].scoreList.getSortedList ());
310
+ return CycleOutputInfo (_cycleInfos[cycleNumber].totalReward , _cycleInfos[cycleNumber].scoreList.getSortedList ());
292
311
}
293
312
294
313
function getPledgeInfo (address supplier ) public view returns (SupplierInfo memory ) {
@@ -456,7 +475,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
456
475
_updateLastSupplier (dataInfo, address (0 ), msg .sender );
457
476
458
477
//只有超过阈值才会更新排名,这个设定会导致用户不多的时候排名不满(强制性累积奖金)
459
- if (dataInfo.score > _minRankingScore ) {
478
+ if (dataInfo.score > sysConfig.minRankingScore ) {
460
479
if (cycleInfo.scoreList.maxlen () < sysConfig.topRewards) {
461
480
cycleInfo.scoreList.setMaxLen (sysConfig.topRewards);
462
481
}
@@ -523,9 +542,9 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
523
542
if (root_hash < proof.proofResult) {
524
543
_supplierInfos[proof.prover].lockedBalance -= proof.lockedAmount;
525
544
526
- uint256 awardFromPunish = proof.lockedAmount * 8 / 10 ;
527
- gwtToken.transfer (msg .sender , awardFromPunish );
528
- gwtToken.transfer (foundationAddress, proof.lockedAmount - awardFromPunish );
545
+ uint256 rewardFromPunish = proof.lockedAmount * 8 / 10 ;
546
+ gwtToken.transfer (msg .sender , rewardFromPunish );
547
+ gwtToken.transfer (foundationAddress, proof.lockedAmount - rewardFromPunish );
529
548
530
549
emit SupplierPunished (proof.prover, dataMixedHash, proof.lockedAmount);
531
550
emit SupplierBalanceChanged (proof.prover, _supplierInfos[proof.prover].avalibleBalance, _supplierInfos[proof.prover].lockedBalance);
@@ -552,43 +571,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
552
571
return IERCPublicDataContract (publicDataInfo.dataContract).getDataOwner (dataMixedHash);
553
572
}
554
573
555
- // return: 1: sponsor, 2- 6: last shower, 7: owner, 0: no one
556
- function _getWithdrawRole (address sender , bytes32 dataMixedHash , PublicData memory publicDataInfo , CycleDataInfo memory dataInfo ) internal view returns (uint8 ) {
557
- uint8 user = 0 ;
558
- if (sender == publicDataInfo.sponsor) {
559
- user |= 1 << 1 ;
560
- }
561
-
562
- if (sender == _getDataOwner (dataMixedHash, publicDataInfo)) {
563
- user |= 1 << 7 ;
564
- }
565
-
566
- for (uint8 i = 0 ; i < dataInfo.lastShowers.length ; i++ ) {
567
- if (dataInfo.lastShowers[i] == sender) {
568
- user |= uint8 (1 << (i+2 ));
569
- }
570
- }
571
-
572
- return user;
573
- }
574
-
575
- // sponsor拿50%, owner拿20%, 5个last shower平分30%
576
- function _calcuteReward (uint8 user , uint256 totalReward , uint256 last_shower_length ) internal pure returns (uint256 ) {
577
- uint reward = 0 ;
578
- if ((user >> 1 ) & 1 == 1 ) {
579
- reward += totalReward / 2 ;
580
- }
581
- if ((user >> 7 ) & 1 == 1 ) {
582
- reward += totalReward / 5 ;
583
- }
584
- if (user & 124 > 0 ) {
585
- reward += (totalReward - totalReward / 2 - totalReward / 5 ) / last_shower_length;
586
- }
587
-
588
- return reward;
589
- }
590
-
591
- function withdrawAward (uint256 cycleNumber , bytes32 dataMixedHash ) public {
574
+ function withdrawReward (uint256 cycleNumber , bytes32 dataMixedHash ) public {
592
575
// 判断这次的cycle已经结束
593
576
//require(_currectCycle > cycleNumber, "cycle not finish");
594
577
require (block .number > cycleNumber * sysConfig.blocksPerCycle + _startBlock, "cycle not finish " );
@@ -602,7 +585,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
602
585
require (dataInfo.score > 0 , "already withdraw " );
603
586
604
587
// 计算该得到多少奖励
605
- uint256 totalReward = cycleInfo.totalAward * 8 / 10 ;
588
+ uint256 totalReward = cycleInfo.totalReward * 8 / 10 ;
606
589
607
590
uint8 score = _getRewardScore (scoreListRanking);
608
591
// 如果数据总量不足32,那么多余的奖励沉淀在合约账户中
@@ -627,6 +610,6 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
627
610
628
611
// 更新积分
629
612
emit DataPointAdded (dataMixedHash, score);
630
- emit WithdrawAward (dataMixedHash, cycleNumber);
613
+ emit WithdrawReward (dataMixedHash, cycleNumber);
631
614
}
632
615
}
0 commit comments