-
Notifications
You must be signed in to change notification settings - Fork 653
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
Exclude contract code out of state witness & distribute separately #11099
Comments
For now, @tayfunelmas will continue making progress on building network message, but @Longarithm will pause and focus on #11124 until we have a clear evidence that including contract code in state witness does not work for MVP launch. Relevant discussion can be found here: link |
Does this issue in principle imply that the contract code would no longer be a part of The State (i.e. no longer stored in the trie, with all that entails), or is this only a partial step towards such a future and the remaining work would need to be documented as a separate issue? |
Adding a description of the implementation in the context of this issue below. Distributing contracts separately from state witnessThe current chunk state witness structure is inefficient due to a significant portion being consumed by contract code. This document describes an implementation for optimizing the state witness size. The changes described are guarded by the protocol feature In feature
Deploying a contract to an accountA contract is deployed and called through a Near account.
When the contract is deployed, it is also pre-compiled, and the compiled code is persisted on disk in the compiled-contract cache. When applying a function call to a pre-compiled contract, the implementation skips reading from the trie and directly invokes the compiled code from the cache. Calling a function from contractIn stateless validation, all accesses to the state by actions are recorded in the state witness, so that the chunk validators can validate the chunk by applying the same actions. Note that, not all chunk validators may contain the contract in their compiled-contract cache. Excluding contract code from state witnessWhen
Collecting contract accesses and deploymentsIn order to identify which contracts to distribute, we collect (1) the hashes of the contracts called by a
Both information is collected in the Sending contract updates to validatorsUpon finishing producing the new chunk, the chunk producer reconstructs NOTE: All the operations described in the rest of this document are performed in the
Handling contract accesses messages in chunk validatorsWhen a chunk validator receives A chunk producer receiving the Handling deployed code messages in other validatorsWhen a validator receives a |
Relevant discussion
Link
Issue
During stateless validation forknet test, we observed node crash with the following error
@Longarithm mentioned that
is due to missing contract doe from state witness.
From debug log, @staffik confirmed that it was likely the case and the crash was happening with different contracts, including
lockup-meta-pool.near
andpack.promotional.basketball.playible.near
@Longarithm 's understanding of how this can cause node crash is as follows:
Timeline
April 17
@Longarithm is preparing a quick patch to bypass the issue in Forknet for now, but we need a proper solution in place before MainNet launch
April 18
The team had discussion on the proper solution and concluded to separate contract out of state witness. When a chunk validator realizes that it does not have a contract code to validate incoming state witness, it will reactively request missing code to its peers. As a result, chunk miss may happen, but the chunk validator should be compiled contract code ready fur the future validation.
The project involves following works but not limited to:
The text was updated successfully, but these errors were encountered: