Skip to content
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

Add incentive for voter #1848

Merged
merged 88 commits into from
Nov 2, 2020
Merged

Conversation

Tommo-L
Copy link
Contributor

@Tommo-L Tommo-L commented Aug 18, 2020

The additional GAS allocation is as follows:

  • 10% will be distributed to all NEO holders according to the weight of NEO.
  • 5% divided equally among 21 members.._
  • 85% will be allocated to the voters who voted for the top 21 nodes. The voters who voted for a consensus node are assigned 2/28 of this part according to the voting weight, and the voters who voted for a committee member (non-consensus node) are assigned 1/28 of this part according to the voting weight. (Implemented by this PR)

@erikzhang erikzhang added this to the NEO 3.0 milestone Aug 18, 2020
@Tommo-L Tommo-L mentioned this pull request Aug 19, 2020
@Tommo-L Tommo-L marked this pull request as ready for review August 22, 2020 14:50
@Tommo-L
Copy link
Contributor Author

Tommo-L commented Aug 22, 2020

I'll add more ut later.

@cloud8little
Copy link
Contributor

cloud8little commented Aug 25, 2020

when sync with the latest block index=160,with pre-configured with four committee members.
protocol.json:

{
  "ProtocolConfiguration": {
    "Magic": 5195086,
    "MillisecondsPerBlock": 15000,
    "ValidatorsCount": 1,
    "StandbyCommittee": [
      "026a59b03f981a5dfded185472f4f19409cd229b5cfd11721e70f2b1d16079376a",
      "024fa7faf85240822cbf6b665f58fcdf6d03ed0e62d18bd2db22216682f2b53147",
      "0273a5ed740acaf17f11ba70d2a9b1c950e86dc320a6efd88d532d087f94fe275b",
      "027a4c687d168044dfb37ad32a51830f0c86b068084914f2373702393b1923ae5e" 
    ],
    "SeedList": [
"localhost:10011"
    ]
  }
}

corresponding to the committee member account:

  • Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj 10 gas
  • NQ5zGxfYWfu6KEpmcEgZquXRiKowW6ckXK 10 gas
  • NafiUTPg5zWyNmTJRhk9Q271UbKnRdZ9Z6 10 gas
  • Nb4z5KTAqgavWKZ7RemRS73RGkY8Qc68mm 10 gas

75a2c9c5ced7b767fa10ba9bec1981c
64b142e143d9bdcde092525beb09136
df69ea104bf1238b416d761fcf8a0ff
7f5e57d6a418281d9bdca01f262a64f

the consensus wallet asset as below:

neo> open wallet wallet_1.json
password: ********
neo> list asset
Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj
NEO: 0
GAS: 10

Ncu47NyTJLJPEFi859gmuqQ8fPPt1AVwHX
NEO: 100000000
GAS: 30000000

NQ9PeXXbNREmHTqyBjjhPKcpZp97kdj1PK
NEO: 0
GAS: 0

NU7NPQHYFLvZV13R5SmSD4u8sDHYsHE2Yj
NEO: 0
GAS: 0

Ne3rapDVHrT7aHdFBwcq42skzgc3hgrYzd
NEO: 0
GAS: 0

----------------------------------------------------
Total:   NEO: 100000000    GAS: 30000010

NEO hash: 0xde5f57d430d3dece511cf975a8d37848cb9e0525
GAS hash: 0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc
neo> show gas
Unclaimed gas: 80.5

Result
Finally four committee members reward totally 10gas * 4 = 40 gas, while there is total 161 blocks, which should be 161 blocks * 5 gas/block * 5% = 40.25 gas, right? @Tommo-L
while the unclaimed gas 80.5 is correct, which should be 161 blocks * 5 gas/block * 10% = 80.5

var pubkey = committee[engine.Snapshot.PersistingBlock.Index % ProtocolSettings.Default.CommitteeMembersCount];
var account = Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash();
GAS.Mint(engine, account, gasPerBlock * CommitteeRewardRatio / 100);

// Record the cumulative reward of the voters of each committee

var voterRewardPerCommittee = gasPerBlock * VoterRewardRatio / 100 / (ProtocolSettings.Default.CommitteeMembersCount + ProtocolSettings.Default.ValidatorsCount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validators are included inside the Committee, they will be rewarded twice as committee and as validator?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, as dictated in the description:

The voters who voted for a consensus node are assigned 2/28 of this part according to the voting weight, and the voters who voted for a committee member (non-consensus node) are assigned 1/28 of this part according to the voting weight. (Implemented by this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mainly used to ensure that the validators' votes are concentrated and not too scattered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but we've got rounding error even here:

> 500000000.0*85/100/(21+7)
=> 15178571.42857143

Then it only gets worse with votes/neo amount.

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Aug 25, 2020

while there is total 161 blocks, which should be 161 blocks * 5 gas/block * 5% = 40.25 gas, right? @Tommo-L

That's right. @cloud8little

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Aug 27, 2020

@erikzhang @Tommo-L will the genesis block(index=0) generate gas? if yes, will it also be used to reward the committees/neo holders? #1845 (comment)

Currently, the genesis block will only reward neo holders but not committee. I think it's okay. What do you think? And this is why

Finally four committee members reward totally 10gas * 4 = 40 gas, while there is total 161 blocks, which should be 161 blocks * 5 gas/block * 5% = 40.25 gas, right?

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tommo-L did you tested this lines ?
https://coveralls.io/builds/34525125/source?filename=src%2Fneo%2FSmartContract%2FNative%2FTokens%2FNeoToken.cs#L113

I am not sure if it could throw a Collection was modified exception when the entry was added in the same execution.

dictionary.Remove(key);
changeSet.Remove(key);

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Oct 29, 2020

I am not sure if it could throw a Collection was modified exception when the entry was added in the same execution.

It'll not happen. As Prefix_VoterRewardPerCommittee was added in PostPersist after CheckCandidate. I'll add ut for it.

shargon
shargon previously approved these changes Oct 29, 2020
Co-authored-by: Erik Zhang <erik@neo.org>
@Tommo-L
Copy link
Contributor Author

Tommo-L commented Nov 2, 2020

Merge?

@shargon shargon merged commit 5800cf2 into neo-project:master Nov 2, 2020
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Nov 16, 2020
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Nov 17, 2020
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Dec 3, 2020
ShawnYun pushed a commit to ShawnYun/neo that referenced this pull request Jan 8, 2021
* add reward key

* incentive for voter

* optimize

* optimize

* optimize

* fix CalculateBonus and add ut

* format

* Item2 -> Votes

* Move fields

* Fix GetCommitteeVotes()

* specify variable name

* Remove double ToArray

* fix ut

* remove

* fix

* fix

* remove useless code

* optimize

* fix

* format

* Add using to dispose enumerators

* Update NeoToken.cs

* Update NeoToken.cs

* fix

* fix CalculateBonus

* Usng asending order

* Update NeoToken.cs

* fix

* optimize findrange

* format

* optimize

* Update NeoToken.cs

* fix

* format

* Use GetCommitteeFromCache

* Ensure registered

* fix PostPersist

* Update NeoToken.cs

* cache committee votes

* cache committee

* Update src/neo/Ledger/StorageItem.cs

Co-authored-by: Erik Zhang <erik@neo.org>

* fix PostPersist

* fix ShouldRefreshCommittee & optimize PostPersist

* add CommitteeEpoch

* fix CalculateBonus

* fix PostPersist

* optimize CalculateBonus

* optimize PostPersist

* Update NeoToken.cs

* add comments for trigger github action

* Allow standby can be voted

* optimize

* rename local variable

* Optimize Unregister Candidate

* Revert

* add ut

* fix ut

* format

* Conflicts

* Update src/neo/SmartContract/Native/Tokens/NeoToken.cs

Co-authored-by: Erik Zhang <erik@neo.org>

Co-authored-by: Tommo-L <luchuan@neo.org>
Co-authored-by: Erik Zhang <erik@neo.org>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Shargon <shargon@gmail.com>
cloud8little pushed a commit to cloud8little/neo that referenced this pull request Jan 24, 2021
* add reward key

* incentive for voter

* optimize

* optimize

* optimize

* fix CalculateBonus and add ut

* format

* Item2 -> Votes

* Move fields

* Fix GetCommitteeVotes()

* specify variable name

* Remove double ToArray

* fix ut

* remove

* fix

* fix

* remove useless code

* optimize

* fix

* format

* Add using to dispose enumerators

* Update NeoToken.cs

* Update NeoToken.cs

* fix

* fix CalculateBonus

* Usng asending order

* Update NeoToken.cs

* fix

* optimize findrange

* format

* optimize

* Update NeoToken.cs

* fix

* format

* Use GetCommitteeFromCache

* Ensure registered

* fix PostPersist

* Update NeoToken.cs

* cache committee votes

* cache committee

* Update src/neo/Ledger/StorageItem.cs

Co-authored-by: Erik Zhang <erik@neo.org>

* fix PostPersist

* fix ShouldRefreshCommittee & optimize PostPersist

* add CommitteeEpoch

* fix CalculateBonus

* fix PostPersist

* optimize CalculateBonus

* optimize PostPersist

* Update NeoToken.cs

* add comments for trigger github action

* Allow standby can be voted

* optimize

* rename local variable

* Optimize Unregister Candidate

* Revert

* add ut

* fix ut

* format

* Conflicts

* Update src/neo/SmartContract/Native/Tokens/NeoToken.cs

Co-authored-by: Erik Zhang <erik@neo.org>

Co-authored-by: Tommo-L <luchuan@neo.org>
Co-authored-by: Erik Zhang <erik@neo.org>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Shargon <shargon@gmail.com>
ixje added a commit to CityOfZion/neo-mamba that referenced this pull request Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants