Consensus message buffering and more (#114)

* CLI options and keystore integration

* Replace multiqueue with future::mpsc

* BFT gossip

* Revert to app_dirs

* generate_from_seed commented

* Refactor event loop

* Start consensus by timer

* Message buffering

* Minor fixes

* Work around duty-roster issue.

* some more minor fixes

* fix compilation

* more consistent formatting

* make bft input stream never conclude

* Minor fixes

* add timestamp module to executive

* more cleanups and logging

* Fixed message propagation
This commit is contained in:
Arkadiy Paronyan
2018-04-06 19:18:26 +02:00
committed by Gav Wood
parent 633b9f4c0b
commit b3dd4e74fd
34 changed files with 413 additions and 146 deletions
@@ -50,6 +50,13 @@ use runtime_support::StorageValue;
use primitives::traits::{self, Header, Zero, One, Checkable, Applyable, CheckEqual, Executable, MakePayment};
use codec::Slicable;
/// Compute the extrinsics root of a list of extrinsics.
pub fn extrinsics_root<H: Hashing, E: Slicable>(extrinsics: &[E]) -> H::Output {
let xts = extrinsics.iter().map(Slicable::encode).collect::<Vec<_>>();
let xts = xts.iter().map(Vec::as_slice).collect::<Vec<_>>();
H::enumerated_trie_root(&xts)
}
pub struct Executive<
System,
Block,
@@ -82,11 +89,9 @@ impl<
);
// check transaction trie root represents the transactions.
let txs = block.extrinsics().iter().map(Slicable::encode).collect::<Vec<_>>();
let txs = txs.iter().map(Vec::as_slice).collect::<Vec<_>>();
let txs_root = System::Hashing::enumerated_trie_root(&txs);
header.extrinsics_root().check_equal(&txs_root);
assert!(header.extrinsics_root() == &txs_root, "Transaction trie root must be valid.");
let xts_root = extrinsics_root::<System::Hashing, _>(&block.extrinsics());
header.extrinsics_root().check_equal(&xts_root);
assert!(header.extrinsics_root() == &xts_root, "Transaction trie root must be valid.");
}
/// Actually execute all transitioning for `block`.
@@ -164,7 +169,7 @@ impl<
fn post_finalise(header: &System::Header) {
// store the header hash in storage; we can't do it before otherwise there would be a
// cyclic dependency.
<system::Module<System>>::record_block_hash(header)
<system::Module<System>>::record_block_hash(header);
}
}
@@ -108,23 +108,27 @@ impl<T: Trait> Module<T> {
}
/// Records a particular block number and hash combination.
pub fn record_block_hash<H: traits::Header<Number = T::BlockNumber>>(header: &H) {
pub fn record_block_hash<H: traits::Header<Number = T::BlockNumber, Hash = T::Hash>>(header: &H) {
// store the header hash in storage; we can't do it before otherwise there would be a
// cyclic dependency.
<BlockHash<T>>::insert(header.number(), &T::Hashing::hash_of(header));
let h = T::Hashing::hash_of(header);
<BlockHash<T>>::insert(header.number(), &h);
Self::initialise(&(*header.number() + One::one()), &h, &Default::default());
}
/// Initializes the state following the determination of the genesis block.
pub fn initialise_genesis_state<H: traits::Header<Number = T::BlockNumber>>(header: &H) {
pub fn initialise_genesis_state<H: traits::Header<Number = T::BlockNumber, Hash = T::Hash>>(header: &H) {
Self::record_block_hash(header);
}
/// Calculate the current block's random seed.
fn calculate_random() -> T::Hash {
assert!(Self::block_number() > Zero::zero(), "Block number may never be zero");
(0..81)
.scan(
{ let mut n = Self::block_number().clone(); n -= T::BlockNumber::one(); n },
|c, _| { if *c > T::BlockNumber::zero() { *c -= T::BlockNumber::one() }; Some(c.clone())
Self::block_number() - One::one(),
|c, _| { if *c > Zero::zero() { *c -= One::one() }; Some(*c)
})
.map(Self::block_hash)
.triplet_mix()