Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Introduce first groundwork for Wasm executor (#27)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
gavofyork authored and rphmeier committed Jan 8, 2018
1 parent 723fb71 commit b38b633
Show file tree
Hide file tree
Showing 44 changed files with 1,087 additions and 611 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target/
**/*.rs.bk
*.swp
runtime/**/target/
**/._*
20 changes: 17 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ members = [
"candidate-agreement",
"client",
"collator",
"contracts",
"executor",
"primitives",
"rpc",
"rpc_servers",
"serializer",
"state_machine",
"validator",
]
exclude = [
"runtime"
]
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ env_logger = "0.4"
error-chain = "0.11"
log = "0.3"
polkadot-client = { path = "../client", version = "0.1" }
polkadot-contracts = { path = "../contracts", version = "0.1" }
polkadot-executor = { path = "../executor", version = "0.1" }
polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-rpc-servers = { path = "../rpc_servers", version = "0.1" }
4 changes: 2 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

extern crate env_logger;
extern crate polkadot_client as client;
extern crate polkadot_contracts as contracts;
extern crate polkadot_executor as executor;
extern crate polkadot_primitives as primitives;
extern crate polkadot_rpc_servers as rpc;

Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where

// Create client
let blockchain = DummyBlockchain;
let executor = contracts::executor();
let executor = executor::executor();
let client = client::Client::new(blockchain, executor);

let address = "127.0.0.1:9933".parse().unwrap();
Expand Down
26 changes: 18 additions & 8 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extern crate error_chain;

pub mod error;

use primitives::{block, Address, H256};
use primitives::contract::{CallData, OutData, StorageData};
use primitives::{block};
use primitives::contract::{CallData, StorageKey, StorageData};
use state_machine::backend::Backend;

use self::error::ResultExt;
Expand All @@ -44,6 +44,14 @@ pub trait Blockchain {
fn header(&self, hash: &block::HeaderHash) -> Result<Option<block::Header>, Self::Error>;
}

/// Information regarding the result of a call.
pub struct CallResult {
/// The data that was returned from the call.
pub return_data: Vec<u8>,
/// The changes made to the state by the call.
pub changes: state_machine::OverlayedChanges,
}

/// Polkadot Client
#[derive(Debug)]
pub struct Client<B, E> {
Expand Down Expand Up @@ -72,25 +80,27 @@ impl<B, E> Client<B, E> where
}

/// Return single storage entry of contract under given address in state in a block of given hash.
pub fn storage(&self, hash: &block::HeaderHash, address: &Address, key: &H256) -> error::Result<StorageData> {
pub fn storage(&self, hash: &block::HeaderHash, key: &StorageKey) -> error::Result<StorageData> {
self.state_at(hash)?
.storage(address, key)
.storage(&key.0)
.map(|x| StorageData(x.to_vec()))
.chain_err(|| error::ErrorKind::Backend)
}

/// Execute a call to a contract on top of state in a block of given hash.
pub fn call(&self, hash: &block::HeaderHash, address: &Address, method: &str, call_data: &CallData) -> error::Result<OutData> {
///
/// No changes are made.
pub fn call(&self, hash: &block::HeaderHash, method: &str, call_data: &CallData) -> error::Result<CallResult> {
let state = self.state_at(hash)?;
let mut changes = state_machine::OverlayedChanges::default();

Ok(state_machine::execute(
let _ = state_machine::execute(
&state,
&mut changes,
&self.executor,
address,
method,
call_data,
)?)
)?;
Ok(CallResult { return_data: vec![], changes })
}
}
38 changes: 0 additions & 38 deletions contracts/src/auth.rs

This file was deleted.

64 changes: 0 additions & 64 deletions contracts/src/balances.rs

This file was deleted.

Loading

0 comments on commit b38b633

Please sign in to comment.