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

Fix vote #1792

Merged
merged 5 commits into from
Jul 28, 2020
Merged

Fix vote #1792

merged 5 commits into from
Jul 28, 2020

Conversation

Tommo-L
Copy link
Contributor

@Tommo-L Tommo-L commented Jul 23, 2020

Close #1790

@cloud8little
Copy link
Contributor

Test passed:

  1. send wallet a.json with 100 neo/100 gas.
  2. vote for himself.
  3. send neo to another account successfully.
  4. register for himself to be a candidate.
  5. vote successful and get candidates.

82a98bf3a77ed98bbdd4dffb6984222
9a1b44c86a95ccce5dd04d59827c024

@superboyiii
Copy link
Member

@shargon Ready for merge?

@superboyiii superboyiii mentioned this pull request Jul 24, 2020
16 tasks
Copy link
Member

@erikzhang erikzhang left a comment

Choose a reason for hiding this comment

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

If state_account.VoteTo keeps the original value, then other changes should also be rolled back, otherwise transaction consistency cannot be guaranteed. Maybe Vote() shouldn't return bool, but should throw an exception when something goes wrong.

@cloud8little
Copy link
Contributor

Retesting.

@cloud8little
Copy link
Contributor

Test passed:

  1. Register a candidate not exist in the wallet.
NEO-CLI v3.0.0-preview2  -  NEO v3.0.0-preview2  -  NEO-VM v3.0.0-preview2

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

Ncu47NyTJLJPEFi859gmuqQ8fPPt1AVwHX
NEO: 100000000
GAS: 30000000

----------------------------------------------------
Total:   NEO: 100000000    GAS: 30000000

NEO hash: 0xde5f57d430d3dece511cf975a8d37848cb9e0525
GAS hash: 0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc
neo> register candidate Ncu47NyTJLJPEFi859gmuqQ8fPPt1AVwHX
Error: Missing the signature of 026a59b03f981a5dfded185472f4f19409cd229b5cfd11721e70f2b1d16079376a
  1. Register candidate
neo> list key
  Address: Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj
PublicKey: 026a59b03f981a5dfded185472f4f19409cd229b5cfd11721e70f2b1d16079376a

  Address: Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj
PublicKey: 026a59b03f981a5dfded185472f4f19409cd229b5cfd11721e70f2b1d16079376a

neo> send neo NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB 100
password: ********
TXID: 0x2c045472e8de39fe3d36101f2f98b0d2c94d6c47a4546d03bd2372243b2b6a3a
neo> send gas NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB 100
password: ********
TXID: 0xdca11fa586665dd4dd2bdb403414a59bee8bb5b1a8ea89f7b68212d3fd6f50e0
neo> open wallet a.json
password: *
neo> list asset
NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
NEO: 100
GAS: 100

----------------------------------------------------
Total:   NEO: 100    GAS: 100

NEO hash: 0xde5f57d430d3dece511cf975a8d37848cb9e0525
GAS hash: 0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc
neo> list key
  Address: NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
PublicKey: 02ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a03

neo> register candidate NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
Invoking script with: '0c2102ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a0311c00c11726567697374657243616e6469646174650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 0.0600775
Evaluation Stack: [{"type":"Any"}]

relay tx(no|yes): no
neo> register candidate NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
Invoking script with: '0c2102ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a0311c00c11726567697374657243616e6469646174650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 0.0600775
Evaluation Stack: [{"type":"Any"}]

relay tx(no|yes): yes
Signed and relayed transaction with hash=0x02d47d1558cd78280ddd7120558b69dd02900122a61443944d27926e5a46a470
neo> get candidates
Invoking script with: '10c00c0d67657443616e646964617465730c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 1.0100757

Candidates:
02ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a03      0
neo> list key
  Address: NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
PublicKey: 02ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a03
  1. Unregister candidate and get candidates
neo> unregister candidate Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj
error: The address 0x7646c5c571b77ab316815d05d1c2ede2e9ea3bb1 was not found in the wallet
neo> unregister candidate NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
Invoking script with: '0c2102ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a0311c00c13756e726567697374657243616e6469646174650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 0.0600775
Evaluation Stack: [{"type":"Any"}]

relay tx(no|yes): yes
Signed and relayed transaction with hash=0x0ae9442300662e26530ae0f6051d4181747f12f68dbd7345e972f11e22028875
neo> get candidate
error: Command not found
neo> get candidates
Invoking script with: '10c00c0d67657443616e646964617465730c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 1.0100757
  1. Unregister a non-candidate
neo> unregister candidate NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
Error: The candidate does not exist
  1. Vote a non-candidate and send neo to other account.
neo> vote NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB 02ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a03
Error: The candidate does not exist
neo> send neo Nc56Zrq72VN9Xr6wo3HyFn3oFZUvoYQJtj 1
password: *
TXID: 0x0606e732e534474d1a3949dde42304612b1cf8081cfe923957b783b41c2cdc94
neo> list asset
NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
NEO: 99
GAS: 99.7525614

----------------------------------------------------
Total:   NEO: 99    GAS: 99.7525614

NEO hash: 0xde5f57d430d3dece511cf975a8d37848cb9e0525
GAS hash: 0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc
  1. Then register candidate and vote to the candidate; get candidates and check the votes.
neo> register candidate NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB
Invoking script with: '0c2102ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a0311c00c11726567697374657243616e6469646174650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 0.0600775
Evaluation Stack: [{"type":"Any"}]

relay tx(no|yes): yes
Signed and relayed transaction with hash=0x9deab808316d09794e1f33f0c25d142787b0f850aebb52403b52005fabe55fd5

neo> vote NUzy2y33pa7DvUgnihxdqSPUTZi3Hb3DnB 02ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a03
Invoking script with: '0c2102ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a030c1463ab15dab11bfa8ebc0b3ca0e2bec6300b45e35d12c00c04766f74650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 5.0100793
Evaluation Stack: [{"type":"Any"}]

relay tx(no|yes): yes
Signed and relayed transaction with hash=0x5e737b6b0d9864823abaccd57812b6106a7ad3cb6773fb4e001d7b7d1659d081
neo> get candidates
Invoking script with: '10c00c0d67657443616e646964617465730c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 1.0100757

Candidates:
02ae840030e1e58d3c8b08568e13075372fb17c111fb5690fc3c26a7342abc2a03      99

@superboyiii
Copy link
Member

@erikzhang Could you review it again?

validator_new = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_Candidate).Add(voteTo))?.GetInteroperable<CandidateState>();
if (validator_new is null) return false;
if (!validator_new.Registered) return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not throw an exception?

Copy link
Member

Choose a reason for hiding this comment

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

Returning false can give the contract a chance to recover from the exception. Throwing an exception will directly terminate the virtual machine. we should try not to throw exceptions if the consistency can be guaranteed.

@cloud8little
Copy link
Contributor

Retest passed.

  1. vote when pubkey register
neo> vote Nb4z5KTAqgavWKZ7RemRS73RGkY8Qc68mm 0358c84fee21b68e568b1a43d1cf6bddf74cce08ad5f3b301f3ad6d3ad75a9a6dc
Invoking script with: '0c210358c84fee21b68e568b1a43d1cf6bddf74cce08ad5f3b301f3ad6d3ad75a9a6dc0c14a63e5f5deb760927fed26f64e40cabff2309329312c00c04766f74650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 5.0100793
Evaluation Stack: [{"type":"Boolean","value":true}]

relay tx(no|yes): yes
Signed and relayed transaction with hash=0x590578ebe8242810f28552a02d339ec9b5e54b3a553ed602df80fe49b9ea2be4
  1. vote before register, then send neo successfully to other accounts.
neo> vote Nb4z5KTAqgavWKZ7RemRS73RGkY8Qc68mm 027a4c687d168044dfb37ad32a51830f0c86b068084914f2373702393b1923ae5e
Invoking script with: '0c21027a4c687d168044dfb37ad32a51830f0c86b068084914f2373702393b1923ae5e0c14a63e5f5deb760927fed26f64e40cabff2309329312c00c04766f74650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b52'
VM State: HALT
Gas Consumed: 5.0100793
Evaluation Stack: [{"type":"Boolean","value":false}]

relay tx(no|yes): yes
Signed and relayed transaction with hash=0xdc4c34f6f537c5b11389425584269288f97eb04f2d69f52372833944b60ca85d

@superboyiii
Copy link
Member

Looks good now.

@superboyiii
Copy link
Member

@erikzhang Shall we merge?

@superboyiii
Copy link
Member

@shargon Need your merge.

@shargon shargon merged commit 90105ef into neo-project:preview3 Jul 28, 2020
erikzhang added a commit that referenced this pull request Aug 5, 2020
* Classes related to Neo.SmartContract types should not be internal (#1785)

* Classes related to Neo.SmartContract types should not be internal
Fixes #1782

* public callbacks + protected internal service methods

* Add AsReadOnly()

Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Shargon <[email protected]>

* Add AppEngine.ValidateCallFlags to be callable by subclasses (#1784)

* Update ApplicationEngine.cs

separate call flag validation into separate function so it can be called by ApplicationEngine subclasses. This is needed for the debugger, which overrides a few of the standard service implementations

* fix whitespace

* protected internal addGas

Co-authored-by: Harry Pierson <[email protected]>

* Fix vote (#1792)

* fix vote

* add ut

* throw exception

* fix

* fix ut

Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: erikzhang <[email protected]>

* preview3

* Update dependency

Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Luchuan <[email protected]>
Co-authored-by: Tommo-L <[email protected]>
cloud8little pushed a commit to cloud8little/neo that referenced this pull request Jan 24, 2021
* Classes related to Neo.SmartContract types should not be internal (neo-project#1785)

* Classes related to Neo.SmartContract types should not be internal
Fixes neo-project#1782

* public callbacks + protected internal service methods

* Add AsReadOnly()

Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Shargon <[email protected]>

* Add AppEngine.ValidateCallFlags to be callable by subclasses (neo-project#1784)

* Update ApplicationEngine.cs

separate call flag validation into separate function so it can be called by ApplicationEngine subclasses. This is needed for the debugger, which overrides a few of the standard service implementations

* fix whitespace

* protected internal addGas

Co-authored-by: Harry Pierson <[email protected]>

* Fix vote (neo-project#1792)

* fix vote

* add ut

* throw exception

* fix

* fix ut

Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: erikzhang <[email protected]>

* preview3

* Update dependency

Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Luchuan <[email protected]>
Co-authored-by: Tommo-L <[email protected]>
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.

6 participants