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

[neox] Merge neox to master #1786

Closed
wants to merge 7 commits into from
Closed

[neox] Merge neox to master #1786

wants to merge 7 commits into from

Conversation

ZhangTao1596
Copy link
Contributor

MPT Integration Specification

introduction

As we have already merged MPT into neo, now it's time for us to integrate it with neo. In this article, I will clarify the detail of the solution in neox.

persistence

Using DataCache implemented by MPT, we can replace the Storage in snapshot as the contracts' storage.

SnapshotView

Field Type Description
Blocks StoreDataCache<UInt256, TrimmedBlock>
Transactions StoreDataCache<UInt256, TransactionState>
Contracts StoreDataCache<UInt160, ContractState>
HeaderHashList StoreDataCache<SerializableWrapper, HeaderHashList>
BlockHashIndex StoreMetaDataCache
HeaderHashIndex StoreMetaDataCache
ContractId StoreMetaDataCache
LocalStateRoot StoreDataCache<SerializableWrapper, HashIndexState> State root hash of every block calculated by local node
ValidatorsStateRoot StoreMetaDataCache State root verified by validators, only store the latest one
Storages MPTDataCache<StorageKey, StorageItem> Storage of contracts, implemented with MPT

consensus

Validators confirm state root of a block in next consensus.
Primary node proposal PrepareRequest with signature of previous block state root. Backup nodes verify the state root signature with their local state root and send their signatures in PrepareResponse if succeed.
As long as a validator collects M preparation messages, it can generate state root of last block.
Because state root is a determined value, validators just vote for right or not. Therefore validators can determine state root in one consensus turn.

PrepareRequest

Field Type Description
Timestamp ulong
Nonce ulong
TransactionHashes UInt256[]
StateRootSignature byte[] signature of previous block state root

PrepareResponse

Field Type Description
PreparationHash UInt256
StateRootSignature byte[] signature of previous block state root

network

State root defination and GetStateRoot message for state root sync.

StateRoot

Field Type Description
Version byte Version of state root caculate algorithm
Index uint Index of block which state root is calculated from
RootHash UInt256 State root hash
Witness Witness Verification script and invocation script

GetStateRoot

Field Type Description
Index uint The minimum index of the requested stateroot

ledger

​ When receiving the block, the node will calculate state root after the persist is completed, and it will check the state root cache for state root of the block that have been confirmed by the validators.
​ When receiving state root signed by validators, the node will check and verify it and compare it with local state root, update state height if they are equal.

ZhangTao1596 and others added 4 commits June 29, 2020 10:16
* don't use snapshot directly in plugin

* persistence and ut

* fix mpt

* precommit

* fix commit

* rm LocalRootHashIndex

* fix ut

* pre commit

* fix clone view

* change name

* rename

* abstract

* comment

* fix ReadOnlyView

* rm precommit

* rm HashState

* add MPTDataCache

* optimze

* optimize

* remove blank line

* StateRoot verify fee

* expose Root in MPTDataCache

* fix some and ut

* merge master

* master

* fix mpt ut

* fix Storages and name

* rename

* add comment

* proof prefix

* fix

* format

* format

* format

* add StateRoot ut

* reset mpt prefix

* rm GetMessage

* throw exception when no script hash in state root

* UpdateLocalStateRoot when Storages changed

* rename

Co-authored-by: Tommo-L <[email protected]>
* don't use snapshot directly in plugin

* recover

* consensus state root

* fix build error

* rename

* remerge

* rm GetMessage

* rename

* throw exception when no script hash in state root

* Clean double enter

* Clean big line

* format

* put root sig into request and response

* update consensus ut

* Check Json.Serialize map keys (#1705)

* don't use snapshot directly in plugin

* recover

* consensus state root

* fix build error

* rename

* remerge

* rm GetMessage

* rename

* throw exception when no script hash in state root

* Clean double enter

* Clean big line

* format

* put root sig into request and response

* update consensus ut

* fix some

* fix some

* format

* comment

* fix

* requst in recovery

* StateRootSignature fixed size

* no need ?

* format

* Update ConsensusContext.cs

* Check sc.Complete

Co-authored-by: Shargon <[email protected]>
* network

* format

* add GetStateRootPayload

* recover ping

* rm state height in Update

* get state root of Blockchain.Height - 1

* rm Blockchain.State.cs
* cn state root verify and persist

* check state root cache

* remove mpt proof, move to plugin

* TryAdd optimization

* fix

* ..

* file name

* filename

* fix error

Co-authored-by: Shargon <[email protected]>
@roman-khimov
Copy link
Contributor

It's a bit disappointing to see #1526 being completely ignored. With all respect to the work done for neox, this design is fine for Neo 2, but we should do better for Neo 3. And it's not the code that's problematic, the code is fine, the problem is in the design of this feature and we either roll over all the problems of it from Neo 2 to Neo 3 or we make something better right from the genesis. I've thought that Neo 3 usually does the second.

ZhangTao1596 and others added 2 commits July 21, 2020 10:00
* Allow call from native contract (#1700)

* Fix MethodCallback (#1723)

* Fix #1714 (#1715)

* Add base64 SYSCALLs (#1717)

* Neo.VM.3.0.0-CI00230 (#1725)

* Allow to iterate buffer (#1726)

* Buffer iterator

* Rename

* Remove using

Co-authored-by: Erik Zhang <[email protected]>

* Update StorageContext.cs (#1728)

StorageContext needs to be public so it can be accessed by Neo Debugger

Co-authored-by: Erik Zhang <[email protected]>

* Fix return value check (#1730)

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

* Fix ContractEventDescriptor (#1733)

* fix enumerator (#1744)

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

* Change json fields to all lower case for consistency (#1736)

* Replace DataCache.Find by DataCache.Seek (#1740)

* replace DataCache.Find by DataCache.Seek

* fix order

* optimize

* Update ByteArrayComparer.cs

* Update ByteArrayComparer.cs

* Update DataCache.cs

* fix comments

* fix comments

* fix comments

* Update DataCache.cs

* Update DataCache.cs

* Reorder methods

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

* Add MaxVerificationGas (#1745)

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

* Create KeyBuilder (#1748)

* Speed up the initialization of ApplicationEngine. (#1749)

* Change nef checksum to double SHA256 (#1751)

* Change to double SHA256

* Clean code

* Revert change

* Clean code

* Fix checksum

* Update NefFile.cs

* Fix compile

* Clean code

Clean code
Fix checksum
Update NefFile.cs
Fix compile

* Optimize

* Optimize

* Fix

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

* Check witnesses on isStandard (#1754)

* Check witness on isStandard

* Add IsDeployed

* Add IsPayable

* Fix UT

* format

* Add coverage

* Remove IsPayable, IsDeployed

* Move NEP10 to manifest (#1729)

* NEP10 abi

* To lower case

* Move to Manifest

* Clean code

* Update ContractManifest.cs

* Update ContractManifest.cs

* Fix native contracts

Co-authored-by: Erik Zhang <[email protected]>

* Capture fault Exception (#1761)

* Capture faultException

* Update Wallet error

* Remove flag check

* Clean code

* Sender from signers (#1752)

* Sender from signers

* Remove co-

* Move signers outside attributes

* Fix UT and remove Signers class

* Fix UT

* Add FeeOnly scope

* Remove orderBy

* Remove _signersCache

* Fix Signers

* Fix WitnessScope

* Fix Sender

* Update TransactionAttributeType.cs

* Update Wallet.cs

* Fix Wallet

* Rename

* Update Wallet.cs

* Update Wallet.cs

* Partial UT fix

* More UT fixes

* Fix Sender's WitnessScope

* Fix Wallet

* Fix UT

* Explicit FeeOnly for DeployNativeContracts

* Same order as serialization

* Test FeeOnly

* dotnet format

* format

Co-authored-by: Erik Zhang <[email protected]>

* IApplicationEngineProvider (#1758)

* Remove the lock from SendersFeeMonitor and rename it to TransactionVerificationContext (#1756)

* Add EffectiveVoterTurnout (#1762)

* Remove AllowedTriggers from SYSCALLs (#1755)

* fix validatorscount (#1770)

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

* impl SeekInternal

Co-authored-by: Erik Zhang <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Luchuan <[email protected]>
Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: joeqian <[email protected]>
Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

Beautiful!
Congratulations to all the team for working hard on it,following historical discussions precisely.

After merging master I will take another review, in particular, on consensus.

* Allow call from native contract (#1700)

* Fix MethodCallback (#1723)

* Fix #1714 (#1715)

* Add base64 SYSCALLs (#1717)

* Neo.VM.3.0.0-CI00230 (#1725)

* Allow to iterate buffer (#1726)

* Buffer iterator

* Rename

* Remove using

Co-authored-by: Erik Zhang <[email protected]>

* Update StorageContext.cs (#1728)

StorageContext needs to be public so it can be accessed by Neo Debugger

Co-authored-by: Erik Zhang <[email protected]>

* Fix return value check (#1730)

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

* Fix ContractEventDescriptor (#1733)

* fix enumerator (#1744)

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

* Change json fields to all lower case for consistency (#1736)

* Replace DataCache.Find by DataCache.Seek (#1740)

* replace DataCache.Find by DataCache.Seek

* fix order

* optimize

* Update ByteArrayComparer.cs

* Update ByteArrayComparer.cs

* Update DataCache.cs

* fix comments

* fix comments

* fix comments

* Update DataCache.cs

* Update DataCache.cs

* Reorder methods

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

* Add MaxVerificationGas (#1745)

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

* Create KeyBuilder (#1748)

* Speed up the initialization of ApplicationEngine. (#1749)

* Change nef checksum to double SHA256 (#1751)

* Change to double SHA256

* Clean code

* Revert change

* Clean code

* Fix checksum

* Update NefFile.cs

* Fix compile

* Clean code

Clean code
Fix checksum
Update NefFile.cs
Fix compile

* Optimize

* Optimize

* Fix

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

* Check witnesses on isStandard (#1754)

* Check witness on isStandard

* Add IsDeployed

* Add IsPayable

* Fix UT

* format

* Add coverage

* Remove IsPayable, IsDeployed

* Move NEP10 to manifest (#1729)

* NEP10 abi

* To lower case

* Move to Manifest

* Clean code

* Update ContractManifest.cs

* Update ContractManifest.cs

* Fix native contracts

Co-authored-by: Erik Zhang <[email protected]>

* Capture fault Exception (#1761)

* Capture faultException

* Update Wallet error

* Remove flag check

* Clean code

* Sender from signers (#1752)

* Sender from signers

* Remove co-

* Move signers outside attributes

* Fix UT and remove Signers class

* Fix UT

* Add FeeOnly scope

* Remove orderBy

* Remove _signersCache

* Fix Signers

* Fix WitnessScope

* Fix Sender

* Update TransactionAttributeType.cs

* Update Wallet.cs

* Fix Wallet

* Rename

* Update Wallet.cs

* Update Wallet.cs

* Partial UT fix

* More UT fixes

* Fix Sender's WitnessScope

* Fix Wallet

* Fix UT

* Explicit FeeOnly for DeployNativeContracts

* Same order as serialization

* Test FeeOnly

* dotnet format

* format

Co-authored-by: Erik Zhang <[email protected]>

* IApplicationEngineProvider (#1758)

* Remove the lock from SendersFeeMonitor and rename it to TransactionVerificationContext (#1756)

* Add EffectiveVoterTurnout (#1762)

* Remove AllowedTriggers from SYSCALLs (#1755)

* fix validatorscount (#1770)

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

* workflows: use checkout action v2 (#1775)

* Update git workflow

* Update .github/workflows/main.yml

Co-authored-by: Erik Zhang <[email protected]>

Co-authored-by: Erik Zhang <[email protected]>

* Add cache to native contract executions V2 (#1766)

* cache v2

* More optimizations

* Policy contract optimization

* Remove interporable variable

* Two more

* Add Set

* Optimizations

* Optimize

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

* Optimize attributes (#1774)

* Add length before compression data (#1768)

* Add length before compression

* Optimize

* Fix UT

* Add UT

* Add UT

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

* Fix VerifyWitnesses (#1776)

* Ensure non predictable peers (#1739)

* Plugins from List to array

* Move false to init

* Fix UT

* Refactor

* Add Exception Message For CreateContract (#1787)

* Add Exception Message When Create Contract

* Add Exception Message

* Code optimization

* add UT

Co-authored-by: Shargon <[email protected]>
Co-authored-by: Qiao Jin <[email protected]>

Co-authored-by: Erik Zhang <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Harry Pierson <[email protected]>
Co-authored-by: Luchuan <[email protected]>
Co-authored-by: Tommo-L <[email protected]>
Co-authored-by: joeqian <[email protected]>
Co-authored-by: cloud8little <[email protected]>
Co-authored-by: Qiao Jin <[email protected]>
@ZhangTao1596
Copy link
Contributor Author

Move to #1793, because conficts and error.

@erikzhang erikzhang deleted the neox branch September 3, 2020 06:58
@erikzhang erikzhang restored the neox branch September 3, 2020 06:59
@erikzhang erikzhang deleted the neox branch November 25, 2020 15:23
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.

3 participants