Bring substrate-demo up to date (#658)

* Updating substrate-demo

* Consenus fixes

* Reverted toolchain change

* Adjusted timeout formula

* Simplfied proposal creation

* Fixed tests

* Fixed a few small issues

* 2017->2018

* Style

* More style

* Renamed demo executable to substrate

* Style

* Fixed compilation after merge

* Style
This commit is contained in:
Arkadiy Paronyan
2018-09-10 17:54:32 +02:00
committed by Gav Wood
parent bcc26dd30a
commit fea750511e
41 changed files with 2940 additions and 312 deletions
+6 -4
View File
@@ -235,10 +235,12 @@ impl<B: Block, P: Proposer<B>> BftInstance<B, P>
{
fn round_timeout_duration(&self, round: usize) -> Duration {
const ROUND_INCREMENT_STEP: usize = 10000;
// 2^(min(6, x/8)) * 10
// Grows exponentially starting from 10 seconds, capped at 640 seconds.
const ROUND_INCREMENT_STEP: usize = 8;
let round = round / ROUND_INCREMENT_STEP;
let round = ::std::cmp::min(63, round) as u32;
let round = ::std::cmp::min(6, round) as u32;
let timeout = 1u64.checked_shl(round)
.unwrap_or_else(u64::max_value)
@@ -470,7 +472,7 @@ impl<B, P, I> BftService<B, P, I>
hash: None,
start_round: 0,
})),
round_timeout_multiplier: 4,
round_timeout_multiplier: 10,
key: key, // TODO: key changing over time.
factory,
}
@@ -866,7 +868,7 @@ mod tests {
hash: None,
start_round: 0,
})),
round_timeout_multiplier: 4,
round_timeout_multiplier: 10,
key: Arc::new(Keyring::One.into()),
factory: DummyFactory
}
+46 -1
View File
@@ -25,7 +25,7 @@ use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One,
use runtime_primitives::BuildStorage;
use primitives::{KeccakHasher, RlpCodec};
use primitives::storage::{StorageKey, StorageData};
use codec::Decode;
use codec::{Encode, Decode};
use state_machine::{
Ext, OverlayedChanges, Backend as StateBackend, CodeExecutor,
ExecutionStrategy, ExecutionManager, prove_read
@@ -316,6 +316,51 @@ impl<B, E, Block> Client<B, E, Block> where
block_builder::BlockBuilder::at_block(parent, &self)
}
/// Call a runtime function at given block.
pub fn call_api<A, R>(&self, at: &BlockId<Block>, function: &'static str, args: &A) -> error::Result<R>
where
A: Encode,
R: Decode,
{
let parent = at;
let header = <<Block as BlockT>::Header as HeaderT>::new(
self.block_number_from_id(&parent)?
.ok_or_else(|| error::ErrorKind::UnknownBlock(format!("{:?}", parent)))? + As::sa(1),
Default::default(),
Default::default(),
self.block_hash_from_id(&parent)?
.ok_or_else(|| error::ErrorKind::UnknownBlock(format!("{:?}", parent)))?,
Default::default()
);
self.state_at(&parent).and_then(|state| {
let mut overlay = Default::default();
let execution_manager = || ExecutionManager::Both(|wasm_result, native_result| {
warn!("Consensus error between wasm and native runtime execution at block {:?}", at);
warn!(" Function {:?}", function);
warn!(" Native result {:?}", native_result);
warn!(" Wasm result {:?}", wasm_result);
wasm_result
});
self.executor().call_at_state(
&state,
&mut overlay,
"initialise_block",
&header.encode(),
execution_manager()
)?;
let (r, _) = args.using_encoded(|input|
self.executor().call_at_state(
&state,
&mut overlay,
function,
input,
execution_manager()
))?;
Ok(R::decode(&mut &r[..])
.ok_or_else(|| error::Error::from(error::ErrorKind::CallResultDecode(function)))?)
})
}
/// Check a header's justification.
pub fn check_justification(
&self,
@@ -47,6 +47,17 @@ pub struct RemoteCallExecutor<B, F, H, C> {
_codec: PhantomData<C>,
}
impl<B, F, H, C> Clone for RemoteCallExecutor<B, F, H, C> {
fn clone(&self) -> Self {
RemoteCallExecutor {
blockchain: self.blockchain.clone(),
fetcher: self.fetcher.clone(),
_hasher: Default::default(),
_codec: Default::default(),
}
}
}
impl<B, F, H, C> RemoteCallExecutor<B, F, H, C> {
/// Creates new instance of remote call executor.
pub fn new(blockchain: Arc<B>, fetcher: Arc<F>) -> Self {
+1 -1
View File
@@ -85,4 +85,4 @@ pub mod keccak {
keccak256(x).into()
}
}
}
}
+1 -1
View File
@@ -423,4 +423,4 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
fn on_broadcasted(&self, propagations: HashMap<ComponentExHash<C>, Vec<String>>) {
self.pool.on_broadcasted(propagations)
}
}
}