-
Notifications
You must be signed in to change notification settings - Fork 1k
[N3] Flat rewards (21 first nodes) #4312
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
base: master-n3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,17 +164,17 @@ private BigInteger CalculateBonus(DataCache snapshot, NeoAccountState state, uin | |
| // Compute Neo holder reward | ||
|
|
||
| // In the unit of datoshi, 1 GAS = 10^8 datoshi | ||
| BigInteger sumNeoHold = 0; | ||
| BigInteger sumGasPerBlock = 0; | ||
| foreach (var (index, gasPerBlock) in GetSortedGasRecords(snapshot, end - 1)) | ||
| { | ||
| if (index > start) | ||
| { | ||
| sumNeoHold += gasPerBlock * (end - index); | ||
| sumGasPerBlock += gasPerBlock * (end - index); | ||
| end = index; | ||
| } | ||
| else | ||
| { | ||
| sumNeoHold += gasPerBlock * (end - start); | ||
| sumGasPerBlock += gasPerBlock * (end - start); | ||
| break; | ||
| } | ||
| } | ||
|
|
@@ -190,7 +190,7 @@ private BigInteger CalculateBonus(DataCache snapshot, NeoAccountState state, uin | |
| voteReward = state.Balance * (latestGasPerVote - state.LastGasPerVote) / VoteFactor; | ||
| } | ||
|
|
||
| return (state.Balance * sumNeoHold * NeoHolderRewardRatio / 100 / TotalAmount, voteReward); | ||
| return (state.Balance * sumGasPerBlock * NeoHolderRewardRatio / 100 / TotalAmount, voteReward); | ||
| } | ||
|
|
||
| private void CheckCandidate(DataCache snapshot, ECPoint pubkey, CandidateState candidate) | ||
|
|
@@ -272,18 +272,41 @@ internal override async ContractTask PostPersistAsync(ApplicationEngine engine) | |
|
|
||
| if (ShouldRefreshCommittee(engine.PersistingBlock.Index, m)) | ||
| { | ||
| BigInteger voterRewardOfEachCommittee = gasPerBlock * VoterRewardRatio * VoteFactor * m / (m + n) / 100; // Zoom in VoteFactor times, and the final calculation should be divided VoteFactor | ||
| var withFlatRewards = engine.IsHardforkEnabled(Hardfork.HF_Faun); | ||
| BigInteger voterRewardOfEachCommittee = | ||
| withFlatRewards ? | ||
| gasPerBlock * VoterRewardRatio * VoteFactor / 100 : // Total reward for voters when it's flat rewards | ||
| gasPerBlock * VoterRewardRatio * VoteFactor * m / (m + n) / 100; // Zoom in VoteFactor times, and the final calculation should be divided VoteFactor | ||
| var votersCount = (BigInteger)engine.SnapshotCache[_votersCount]; | ||
|
|
||
| if (withFlatRewards && votersCount.IsZero) | ||
| { | ||
| // Skip reward distribution when there are no voters | ||
| return; | ||
| } | ||
|
|
||
| for (index = 0; index < committee.Count; index++) | ||
| { | ||
| var (publicKey, votes) = committee[index]; | ||
| var factor = index < n ? 2 : 1; // The `voter` rewards of validator will double than other committee's | ||
| if (votes > 0) | ||
|
|
||
| if (withFlatRewards) | ||
| { | ||
| BigInteger voterSumRewardPerNEO = factor * voterRewardOfEachCommittee / votes; | ||
| BigInteger voterSumRewardPerNEO = voterRewardOfEachCommittee / votersCount; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another change apart of flat rewards, this also set a defined level among the committee itself
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now, @shargon, one main point to change here is not just this We should not consider |
||
| StorageKey voterRewardKey = CreateStorageKey(Prefix_VoterRewardPerCommittee, publicKey); | ||
| StorageItem lastRewardPerNeo = engine.SnapshotCache.GetAndChange(voterRewardKey, () => new StorageItem(BigInteger.Zero)); | ||
| lastRewardPerNeo.Add(voterSumRewardPerNEO); | ||
| } | ||
| else | ||
| { | ||
| if (votes > 0) | ||
| { | ||
| var factor = index < n ? 2 : 1; // The `voter` rewards of validator will double than other committee's | ||
| BigInteger voterSumRewardPerNEO = factor * voterRewardOfEachCommittee / votes; | ||
| StorageKey voterRewardKey = CreateStorageKey(Prefix_VoterRewardPerCommittee, publicKey); | ||
| StorageItem lastRewardPerNeo = engine.SnapshotCache.GetAndChange(voterRewardKey, () => new StorageItem(BigInteger.Zero)); | ||
| lastRewardPerNeo.Add(voterSumRewardPerNEO); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.