-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Contract state problem #2181
Comments
It also is a side-effect of #2119, we need some stable binary format for manifests now. |
neo/src/neo/IO/Json/JObject.cs Line 12 in 32513ed
We use |
That's an implementation detail that is not easy to reproduce, ordinary JSON libraries following JSON specification just don't provide this guarantee. |
We might also solve it by storing manifest in the NEF itself (of course, in non-JSON format), it's auto-generated anyway and NEF is not really usable without it. And I think it's important to fix it before preview5 (#2171). |
Just to reiterate, it's a problem of |
NEO follows the writing order of JSON text. |
It basically means that we're inventing some NEO-specific version of JSON which is not really productive. If JSON doesn't provide some characteristics we need it just doesn't fit here and we need to use something different. JSON is good for data exchange between different systems so let's use it this way, we can have manifest parameter in JSON format for contract deployment/update (any toolchain can easily generate it), but we shouldn't store it in the DB this way if we care about state reproducibility. Any other implementation will have the same problem, no one is writing project-specific JSON libraries, there are lots of them already available following the same basic standard. And they can have lots of variations in their output (hi, #2050 and let's say I have some |
Summary or problem description
Since #766 contract's manifest is stored along with other data in
ContractState
. We use JSON marshalling for manifest serialisation, but JSON specification does not guarantee that the order of the key-value pairs is strictly preserved during JSONisation. So there are two problems connected with that:Problem 1: Regular contracts deployment/updates. In ContractMenedgment's Deploy method we perform the following steps:
So there's a chance that Neo nodes (C# and Go) will have different ContractStates after Step 3 due to ambiguous manifest JSONisation. This problem affects storage dumps and stateroots.
Problem 2: Native contracts deployment. We don't have binary manifests for native contracts, so during native contracts deployment we just marshall native manifests (here) to put them into the storage. As a result, we've faced with the state difference for the genesis block during Neo-Go node testing.
Do you have any solution you want to propose?
The first problem can be solved by preserving the original (binary) manifest while storing ContractState. Then all Neo nodes will have the same manifests and the same ContractStates.
The second problem is a bit more complicated. We don't have binary manifest representation for native contracts, so we can't synchronize it between different nodes at the current moment. That's why it might be a good idea to replace the current manifest serialisation scheme by the new binary format where the order of fields is strictly defined. In this case, we can use binary format to store ContractStates and leave the JSONised manifest for RPC.
Neo Version
Where in the software does this update applies to?
The text was updated successfully, but these errors were encountered: