-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Prerequisites for validate_block in Cumulus
#1926
Conversation
validate_block for Cumulusvalidate_block in Cumulus
tomusdrw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
core/executor/src/wasm_executor.rs
Outdated
| memory.get(offset, length) | ||
| .map_err(|_| ErrorKind::Runtime.into()) | ||
| Ok(val) => { | ||
| match filter_result(val, &memory)? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outer block is not necessary anymore
|
will need |
core/test-runtime/src/lib.rs
Outdated
| /// Convert into a signed extrinsic. | ||
| #[cfg(feature = "std")] | ||
| pub fn into_signed_tx(self) -> Extrinsic { | ||
| let signature = keyring::Keyring::from_raw_public( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should just be keyring::Keyring::from_public(self.from). If you're type-running something's wrong.
|
@rphmeier you ok to sign off on this? |
|
Why do I need to increase the impl_version here? |
core/executor/src/wasm_executor.rs
Outdated
| |res, memory| { | ||
| if let Some(I64(r)) = res { | ||
| let offset = r as u32; | ||
| let length = (r >> 32) as usize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I wonder if this is correct. Can you check my logic?
risi64.- According to the reference, right shift is logical for unsinged values but arithmetic for signed values.
- So
0x8000_0000_0000_0000 >> 32is an arithmetic shift and will give you0xFFFF_FFFF_8000_0000.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomusdrw FYI. We both need to go back and learn shifting :D
core/sr-io/without_std.rs
Outdated
| type Target = T; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| unsafe { &(*self.0.as_ptr()).0 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a safe implementation, though.
// let STATIC_FN = ExchangeableFunction { ... };
let y = STATIC_FN.deref();
STATIC_FN.replace_implementation(...); // violates borrowing rules and introduces UB
y();There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically: it's only safe to use this struct if we can ensure that borrows through deref do not last longer than a single invocation of the internal value. The public API should ensure this. I'm not sure Deref is the right choice with that in mind. Maybe a fn with_inner<F: FnOnce(&T)>(&self, f: F).
| } | ||
|
|
||
| // WASM does not support threads, so this is safe; qed. | ||
| unsafe impl<T> Sync for ExchangeableFunction<T> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens when we have a native-linked runtime? and if we would do runtime calls in multiple threads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never compiled in native. Only for WASM.
core/sr-io/without_std.rs
Outdated
| /// # Returns | ||
| /// | ||
| /// Returns the original implementation wrapped in [`RestoreImplementation`]. | ||
| pub unsafe fn replace_implementation(&'static self, new_impl: T) -> RestoreImplementation<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention in the documentation why this is unsafe?
core/sr-io/without_std.rs
Outdated
| /// A function which implementation can be exchanged. | ||
| /// | ||
| /// Internally this works by swapping function pointers. | ||
| pub struct ExchangeableFunction<T>(Cell<(T, bool)>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention what is this bool stands for?
core/sr-io/without_std.rs
Outdated
| } | ||
|
|
||
| /// Restores a function implementation on drop. | ||
| pub struct RestoreImplementation<T: 'static>(&'static ExchangeableFunction<T>, Option<T>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you briefly describe what each member is? (In comments)
* Adds benchmark for direct/indirect wasm function calls * Store the benchmark function pointer in a `Cell` * Add some documentation * Make function implementations exchangeable * Add parachain stub * Add macro for registering the `validate_block` function * Make all functions replace-able by unimplemented * Some more refactoring * Adds tests for executing empty parachain block * Work on a new test with empty witness data * Don't exchange `ext_print_*` stuff * Some cleanup and one more function for `validate_block` * More tests and more functions * Fixes after merging master * Use `parity-codec` `derive` feature * CHange implementation of `wasm-nice-panic-message` * Move `parachain` stuff to cumulus * Updated wasm files * Integrate feedback * Switch to `ExchangeableFunction` struct * More fixes * Switch to Cell and panic on multiple replaces * Increase `impl_version` * Fix shifting * Make the API more verbose of `ExchangeableFunction` * Increase `impl_version`
Adds prerequisites for implementing
validate_blockin Cumulus.