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

State Machine: Abstract function execution #19

Merged
merged 12 commits into from
Nov 13, 2017
Merged

Conversation

rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Nov 12, 2017

Sub-calls all share the same prospective state. An error in any sub-call reverts all changes.

An in-memory storage backend is provided. This could also be implemented for disk or network-backed data.

Committing to a backend yields two updated trie roots:

  • code tree root is the root of a mapping address => code_hash.
  • storage tree root is the root of a mapping address => storage_root, where storage_root is the root of a storage tree for that account.

The motivation for separating these parts of the account record is that it will allow better light-client caching of contract code, although it also might become reasonable to combine them.

We might want an execute_static function at the root as well.

@rphmeier rphmeier added the A0-please_review Pull request needs code review. label Nov 12, 2017
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of style nitpicks and two questions:

  1. Arbitrary size storage
  2. Distinction between contract panic and backend error.


[dependencies]
polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-primitives = { path = "../primitives" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ditch version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge issue

use primitives::Address;
use primitives::hash::H256;

use triehash::sec_trie_root;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would keep it together with primitives. We might try to organize imports into 3 blocks:

<std imports>

<external libraries>

<internal>

discussed it some time ago with @debris and he likes it as well.

impl<'a, B: 'a, E: 'a> Externalities<E> for Ext<'a, B, E>
where B: Backend, E: Executor
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary line.

}

impl<'a, B: 'a, E: 'a> StaticExternalities<E> for Ext<'a, B, E>
where B: Backend, E: Executor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd prefer

impl ... for Ext<..> where
  B: Backend,
  E: Executor,
{

extern crate hashdb;
extern crate memorydb;
extern crate keccak_hash;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant line

fn set_storage(&mut self, key: H256, value: Vec<u8>);

/// Make a sub-call to another contract.
fn call(&mut self, address: &Address, method: &str, data: &CallData) -> Result<OutData, Self::Error>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line after method missing.

type Error = Error;

fn storage(&self, _key: &H256) -> Result<&[u8]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure we want to allow storage of data of arbitrary size?

call_data: &CallData,
) -> Result<OutData, Box<Error>> {
let code = match overlay.code(address) {
Some(x) => x.to_owned(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use bytes here to avoid allocation and copying.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will log it as a separate issue.

address: &Address,
method: &str,
call_data: &CallData,
) -> Result<OutData, Box<Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be able to distinguish between a backend failure (user's machine fault) and actual execution error (contract panic)?

The first should most likely kill the entire process and the latter should just indicate transaction failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, so I guess what needs returning is this same ext::Error<B, E> type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the executor error may still be a backend error (having wrapped it internally): https://github.com/paritytech/polkadot/pull/19/files#diff-e5f6b2fc846df5e06dad05931f099408L43

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it for now and figure out better error handling for that (we might need to add some bounds on Error type for both Executor and Externalities)

cli/Cargo.toml Outdated
@@ -8,3 +8,4 @@ description = "Polkadot node implementation in Rust."
clap = { version = "2.27", features = ["yaml"] }
env_logger = "0.4"
log = "0.3"
polkadot-state-machine = { path = "../state_machine" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to get it in the workspace :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should put it to top-level Cargo.toml

@5chdn 5chdn added M4-core and removed A0-please_review Pull request needs code review. labels Nov 13, 2017
@rphmeier
Copy link
Contributor Author

Arbitrary size storage only seems to complicate things for the paritydb (which will store a flattened version of the balances contract storage trie). Since we're not at the stage of integrating paritydb we might want to consider our strategy for integration before imposing restrictions on the storage formats.

cli/Cargo.toml Outdated
@@ -8,3 +8,4 @@ description = "Polkadot node implementation in Rust."
clap = { version = "2.27", features = ["yaml"] }
env_logger = "0.4"
log = "0.3"
polkadot-state-machine = { path = "../state_machine" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should put it to top-level Cargo.toml

address: &Address,
method: &str,
call_data: &CallData,
) -> Result<OutData, Box<Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it for now and figure out better error handling for that (we might need to add some bounds on Error type for both Executor and Externalities)

call_data: &CallData,
) -> Result<OutData, Box<Error>> {
let code = match overlay.code(address) {
Some(x) => x.to_owned(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will log it as a separate issue.

@rphmeier rphmeier merged commit 79a88a4 into master Nov 13, 2017
@rphmeier rphmeier deleted the rh-state-machine branch November 13, 2017 15:42
gilescope pushed a commit that referenced this pull request Dec 20, 2022
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants