Don't include :code by default in storage proofs#5060
Conversation
…runtime-everytime
…runtime-everytime
| // backwards compatible. | ||
| // | ||
| // TODO: Remove when solved: https://github.com/paritytech/substrate/issues/5047 | ||
| let code_proof = self.read_proof( |
There was a problem hiding this comment.
@svyatonik here I'm currently forcing that the :code is still added to the proof.
| assert!( | ||
| backend.storage(&sp_core::storage::well_known_keys::CODE) | ||
| .unwrap_err() | ||
| .contains("Database missing expected key"), |
There was a problem hiding this comment.
Probably just leave .unwrap_err() - comparing strings seems a bit fragile?
There was a problem hiding this comment.
Actually I wanted to match on the error, however it is a string already. The full error message is much longer, but this part is the important one (as long as no one changes the display impl for the error, it should be fine).
…runtime-everytime
pepyakin
left a comment
There was a problem hiding this comment.
Looks great! A couple of nits
| where H::Out: Encode, | ||
| { | ||
| let code = backend.storage(well_known_keys::CODE) | ||
| .ok() |
| let code = backend.storage(well_known_keys::CODE) | ||
| .ok() | ||
| .flatten() | ||
| .ok_or_else(|| "`:code` not found")?; |
There was a problem hiding this comment.
nit: .ok_or can work here as well
| .ok_or_else(|| "`:code` not found")?; | |
| .ok_or("`:code` not found")?; |
Co-Authored-By: Sergei Pepyakin <sergei@parity.io>
…runtime-everytime
* Adds test to verify that the runtime currently is always contained in the proof * Start passing the runtime wasm code from the outside * Fix compilation * More build fixes * Make the test work as expected now :) * Last fixes * Fixes benchmarks * Review feedback * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Fix compilation Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
|
So now to make a call one is required to query code from storage and keep it in memory to avoid re-querying it each time? This just wastes memory. Why not just add filter to the proof recorder? |
That's not true. It was only extracted if the hash does not match the available instance. When there's matching version of compiled code or wasmi instance we don't need to keep original WASM bytecode in memory. |
Yeah okay, after checking again the code, I found the code that caches the I don't think that this wastes any more memory than the implementation before. We don't cache the code anywhere else as before.
This doesn't work, as you also can have legit accesses from the runtime to |
Does it? Whoever verifies the proof has the code anyway and they can just return it when it is queried from the proof storage. Is that right @svyatonik?
Needlessly fetching the code on each call is expensive. The executor decides when it actually needs the code and should use either externalities or some other interface to fetch it only when needed |
No - there's no code on light client and that's why tthe ":code" was a part of execution proof since very beginning. There's an issue to add code caching #5047 , mentioned in the PR description. |
I'm asking about parachain validation here. The proof is useless without the code. So if it is excluded from the proof whoever is verifying it must have the code from some other source already. That also means when you have "legit accesses from the runtime to :code" they can just use the code they already have and there's no need to include it in the proof. Is this technically correct? |
|
For parachain validation, the runtime code is part of the validation blob that is stored on the relay chain. So, we don't need |
…h#5060)" (paritytech#5136) This reverts commit a193a19.
* Adds test to verify that the runtime currently is always contained in the proof * Start passing the runtime wasm code from the outside * Fix compilation * More build fixes * Make the test work as expected now :) * Last fixes * Fixes benchmarks * Review feedback * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Fix compilation Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
* Don't include `:code` by default in storage proofs (#5060) * Adds test to verify that the runtime currently is always contained in the proof * Start passing the runtime wasm code from the outside * Fix compilation * More build fixes * Make the test work as expected now :) * Last fixes * Fixes benchmarks * Review feedback * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Fix compilation Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com> * Fix compilation and change the way `RuntimeCode` works * Fix tests * Switch to `Cow` Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org> Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
* Don't include `:code` by default in storage proofs (paritytech#5060) * Adds test to verify that the runtime currently is always contained in the proof * Start passing the runtime wasm code from the outside * Fix compilation * More build fixes * Make the test work as expected now :) * Last fixes * Fixes benchmarks * Review feedback * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Fix compilation Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com> * Fix compilation and change the way `RuntimeCode` works * Fix tests * Switch to `Cow` Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org> Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
* Adds test to verify that the runtime currently is always contained in the proof * Start passing the runtime wasm code from the outside * Fix compilation * More build fixes * Make the test work as expected now :) * Last fixes * Fixes benchmarks * Review feedback * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Fix compilation Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
…h#5060)" (paritytech#5136) This reverts commit a193a19.
* Don't include `:code` by default in storage proofs (paritytech#5060) * Adds test to verify that the runtime currently is always contained in the proof * Start passing the runtime wasm code from the outside * Fix compilation * More build fixes * Make the test work as expected now :) * Last fixes * Fixes benchmarks * Review feedback * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Fix compilation Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com> * Fix compilation and change the way `RuntimeCode` works * Fix tests * Switch to `Cow` Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org> Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
This pr changes the behavior of automatically including
:codein storage proofs. Before this pr, the:codewas extracted by the wasm-executor before executing a function in the runtime. Now, the runtime code is passed as a parameter from the outside. This makes it possible to extract the:codefrom the backend, before the storage recorder tracks all accesses to the backend (which resulted in inclusion of:codein the proof).However, the
execution_prooffunction ofClientstill adds the:codeto the proof, this is required by the light client, until #5047 is implemented.Closes: paritytech/cumulus#8