mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 00:51:06 +00:00
Introduce first groundwork for Wasm executor (#27)
* Introduce first groundwork for Wasm executor. * Remove old Rust-runtime code. * Avoid commiting compled files. * Add runtime precompile. * Rename so module makes more sense. * Further renaming. * Ensure tests work. * Allow bringing in of externalities. - Add util functions/macros. - Add uncompacted runtime. - Add some external crates from pwasm-std for managing allocs/memory stuff. * Nice macros for imports. * Allow passing in of data through allocators. Make memcpy and malloc work. Basic allocator. * Can now pass in bytes to WasmExecutor. * Additional cleanup. * Switch usages of `OutData` to `u64` No need to be able to return bytes anymore. * convert to safe but extremely verbose type conversion. @rphmeier any more concise way of doing this? * Remove StaticExternalities distinction. * Remove another unused use. * Refactor wasm utils out * Remove extraneous copies that weren't really testing anything. * Try to use wasm 0.15 * Make it work! * Call-time externalities working. * Add basic externalities. * Fix grumbles and note unwraps to be sorted. * Test storage externality. Unforunately had to change signatures of externalities to avoid immutable function returning a reference. Not sure what to do about this... * Fix nits. * Compile collation logic. * Move back to refs. Yey. * Remove "object" id for storage access. * Fix test. * Fix up rest of tests. * remove unwrap. * Expose set/get code in externalities Also improve tests and add nice wrappers in rust-wasm. * Add validator set. * Introduce validator set into externalities and test. * Add another external function. * Remove code and validators; use storage for everything. * Introduce validators function. * Tests (and a fix) for the validators getter. * Allow calls into runtime to return data. * Remove unneeded trace. * Make runtime printing a bit nicer. * Create separate runtimes for testing and polkadot. * Remove commented code. * Use new path. * Refactor into shared support module. * Fix warning. * Remove unwraps. * Make macro a little less unhygenic. * Add wasm files.
This commit is contained in:
committed by
Robert Habermeier
parent
45c3e40a62
commit
a670208a33
@@ -17,8 +17,6 @@
|
||||
//! State machine backends. These manage the code and storage of contracts.
|
||||
|
||||
use std::{error, fmt};
|
||||
|
||||
use primitives::Address;
|
||||
use primitives::hash::H256;
|
||||
use triehash::sec_trie_root;
|
||||
|
||||
@@ -26,8 +24,6 @@ use super::{Update, MemoryState};
|
||||
|
||||
/// Output of a commit.
|
||||
pub struct Committed {
|
||||
/// Root of the code tree after changes committed.
|
||||
pub code_tree_root: H256,
|
||||
/// Root of the storage tree after changes committed.
|
||||
pub storage_tree_root: H256,
|
||||
}
|
||||
@@ -38,11 +34,8 @@ pub trait Backend {
|
||||
/// An error type when fetching data is not possible.
|
||||
type Error: super::Error;
|
||||
|
||||
/// Get code associated with specific address.
|
||||
fn code(&self, address: &Address) -> Result<&[u8], Self::Error>;
|
||||
|
||||
/// Get keyed storage associated with specific address.
|
||||
fn storage(&self, address: &Address, key: &H256) -> Result<&[u8], Self::Error>;
|
||||
fn storage(&self, key: &[u8]) -> Result<&[u8], Self::Error>;
|
||||
|
||||
/// Commit updates to the backend and get new state.
|
||||
fn commit<I>(&mut self, changes: I) -> Committed
|
||||
@@ -74,12 +67,8 @@ pub struct InMemory {
|
||||
impl Backend for InMemory {
|
||||
type Error = Void;
|
||||
|
||||
fn code(&self, address: &Address) -> Result<&[u8], Void> {
|
||||
Ok(self.inner.code(address).unwrap_or(&[]))
|
||||
}
|
||||
|
||||
fn storage(&self, address: &Address, key: &H256) -> Result<&[u8], Void> {
|
||||
Ok(self.inner.storage(address, key).unwrap_or(&[]))
|
||||
fn storage(&self, key: &[u8]) -> Result<&[u8], Void> {
|
||||
Ok(self.inner.storage(key).unwrap_or(&[]))
|
||||
}
|
||||
|
||||
fn commit<I>(&mut self, changes: I) -> Committed
|
||||
@@ -88,22 +77,13 @@ impl Backend for InMemory {
|
||||
self.inner.update(changes);
|
||||
|
||||
// fully recalculate trie roots.
|
||||
|
||||
let storage_roots = self.inner.storage.iter().map(|(addr, storage)| {
|
||||
let flat_trie = storage.iter().map(|(k, v)| (k.to_vec(), v.clone())).collect();
|
||||
(addr.to_vec(), sec_trie_root(flat_trie).to_vec())
|
||||
}).collect();
|
||||
|
||||
let storage_tree_root = H256(sec_trie_root(storage_roots).0);
|
||||
|
||||
let code_tree_root = sec_trie_root(
|
||||
self.inner.code.iter().map(|(k, v)| (k.to_vec(), v.clone())).collect()
|
||||
);
|
||||
|
||||
let code_tree_root = H256(code_tree_root.0);
|
||||
let storage_tree_root = H256(sec_trie_root(
|
||||
self.inner.storage.iter()
|
||||
.map(|(k, v)| (k.to_vec(), v.clone()))
|
||||
.collect()
|
||||
).0);
|
||||
|
||||
Committed {
|
||||
code_tree_root,
|
||||
storage_tree_root,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user