This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Optional storage entries #75
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
acab9a3
Block builder (substrate)
gavofyork 9acd3f9
Fix wasm build
gavofyork ca5900f
Bulid on any block
gavofyork d11cfe1
Test for block builder.
gavofyork b973ccc
Block import tests for client.
gavofyork ec61865
Tidy ups
gavofyork cec06a7
Repotted client
gavofyork 38cd36a
Avoid pointless work
gavofyork 8b7abca
All backend stuff now manages optional storage.
gavofyork 9dba812
Native runtime-io now supports empty storage items.
gavofyork 0f591c6
Finish up the API transition.
gavofyork 79c6b4c
Merge branch 'master' into gav-optional-storage
gavofyork a802b7e
Build fix.
gavofyork 3928c1c
Fix tests.
gavofyork 002ab5f
Merge branch 'master' into gav-optional-storage
gavofyork 61db63f
Remerge in changes to client.
gavofyork 5d1a3a7
Final fixes.
gavofyork 212d370
Unrevert typos
gavofyork 780e549
Remove accidentally committed change
gavofyork e552875
Bring back zero copy
gavofyork 0a08196
Fix merge.
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Block builder (substrate)
- Loading branch information
commit acab9a333fb61b05fced8fb61b6d39bdab2eb57a
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright 2017 Parity Technologies (UK) Ltd. | ||
| // This file is part of Substrate. | ||
|
|
||
| // Substrate is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Substrate is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Utility struct to build a block. | ||
|
|
||
| use std::vec::Vec; | ||
| use codec::{Joiner, Slicable}; | ||
| use state_machine::{self, CodeExecutor}; | ||
| use primitives::{Header, Block}; | ||
| use primitives::block::Transaction; | ||
| use {backend, error, BlockId, BlockStatus, Client}; | ||
| use triehash::ordered_trie_root; | ||
|
|
||
| /// Utility for building new (valid) blocks from a stream of transactions. | ||
| pub struct BlockBuilder<B, E> where | ||
| B: backend::Backend, | ||
| E: CodeExecutor + Clone, | ||
| error::Error: From<<<B as backend::Backend>::State as state_machine::backend::Backend>::Error>, | ||
| { | ||
| header: Header, | ||
| transactions: Vec<Transaction>, | ||
| executor: E, | ||
| state: B::State, | ||
| changes: state_machine::OverlayedChanges, | ||
| } | ||
|
|
||
| impl<B, E> BlockBuilder<B, E> where | ||
| B: backend::Backend, | ||
| E: CodeExecutor + Clone, | ||
| error::Error: From<<<B as backend::Backend>::State as state_machine::backend::Backend>::Error>, | ||
| { | ||
| /// Create a new instance of builder from the given client. | ||
| pub fn new(client: &Client<B, E>) -> error::Result<Self> { | ||
| let best = (client.info().map(|i| i.chain.best_number)?..1) | ||
| .find(|&n| if let Ok(BlockStatus::InChain) = client.block_status(&BlockId::Number(n)) | ||
| { true } else { false }) | ||
| .unwrap_or(0); | ||
|
|
||
| Ok(BlockBuilder { | ||
| header: Header { | ||
| number: best + 1, | ||
| parent_hash: client.block_hash(best)?.expect("We already ascertained this is InChain before; qed"), | ||
| state_root: Default::default(), | ||
| transaction_root: Default::default(), | ||
| digest: Default::default(), | ||
| }, | ||
| transactions: Default::default(), | ||
| executor: client.clone_executor(), | ||
| state: client.state_at(&BlockId::Number(best))?, | ||
| changes: Default::default(), | ||
| }) | ||
| } | ||
|
|
||
| /// Push a transaction onto the block's list of transactions. This will ensure the transaction | ||
| /// can be validly executed (by executing it); if it is invalid, it'll be returned along with | ||
| /// the error. Otherwise, it will return a mutable reference to self (in order to chain). | ||
| pub fn push(&mut self, tx: Transaction) -> error::Result<()> { | ||
| let output = state_machine::execute(&self.state, &mut self.changes, &self.executor, "execute_transaction", | ||
| &vec![].and(&self.header).and(&tx))?; | ||
| self.header = Header::decode(&mut &output[..]).expect("Header came straight out of runtime do must be valid"); | ||
| self.transactions.push(tx); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Consume the builder to return a valid `Block` containing all pushed transactions. | ||
| pub fn bake(mut self) -> error::Result<Block> { | ||
| self.header.transaction_root = ordered_trie_root(self.transactions.iter().map(Slicable::encode)).0.into(); | ||
| let output = state_machine::execute(&self.state, &mut self.changes, &self.executor, "finalise_block", | ||
| &self.header.encode())?; | ||
| self.header = Header::decode(&mut &output[..]).expect("Header came straight out of runtime do must be valid"); | ||
|
||
| Ok(Block { | ||
| header: self.header, | ||
| transactions: self.transactions, | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
typo fix reverted