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

Commit

Permalink
Merge branch 'master' into td-pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Apr 16, 2018
2 parents 2da7ac0 + d153954 commit 5265f7e
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
polkadot/runtime/wasm/target/
substrate/executor/wasm/target/
substrate/test-runtime/wasm/target/
substrate/pwasm-alloc/target/
substrate/pwasm-libc/target/
substrate/pwasm-alloc/Cargo.lock
substrate/pwasm-libc/Cargo.lock
demo/runtime/wasm/target/
**/._*
10 changes: 9 additions & 1 deletion polkadot/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,15 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
}

let polkadot_block = block_builder.bake();
info!("Proposing block [number: {}; extrinsics: [{}], parent_hash: {}]", polkadot_block.header.number, polkadot_block.extrinsics.len(), polkadot_block.header.parent_hash);
info!("Proposing block [number: {}; hash: {}; parent_hash: {}; extrinsics: [{}]]",
polkadot_block.header.number,
Hash::from(polkadot_block.header.blake2_256()),
polkadot_block.header.parent_hash,
polkadot_block.extrinsics.iter()
.map(|xt| format!("{}", Hash::from(xt.blake2_256())))
.collect::<Vec<_>>()
.join(", ")
);

let substrate_block = Slicable::decode(&mut polkadot_block.encode().as_slice())
.expect("polkadot blocks defined to serialize to substrate blocks correctly; qed");
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion polkadot/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn local_testnet_config() -> ChainConfig {
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: vec![],
intentions: initial_authorities.clone(),
transaction_fee: 1,
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
validator_count: 2,
Expand Down
3 changes: 3 additions & 0 deletions polkadot/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,16 @@ impl<'a, T: 'a + PolkadotApi> Ready<'a, T> {
impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready<VerifiedTransaction> for Ready<'a, T> {
fn is_ready(&mut self, xt: &VerifiedTransaction) -> Readiness {
let sender = xt.inner.signed;
trace!(target: "transaction-pool", "Checking readiness of {} (from {})", xt.hash, TransactionHash::from(sender));

// TODO: find a way to handle index error properly -- will need changes to
// transaction-pool trait.
let (api_handle, at_block) = (&self.api_handle, &self.at_block);
let next_index = self.known_indices.entry(sender)
.or_insert_with(|| api_handle.index(at_block, sender).ok().unwrap_or_else(u64::max_value));

trace!(target: "transaction-pool", "Next index for sender is {}; xt index is {}", next_index, xt.inner.index);

match xt.inner.index.cmp(&next_index) {
Ordering::Greater => Readiness::Future,
Ordering::Equal => Readiness::Ready,
Expand Down
12 changes: 10 additions & 2 deletions substrate/bft/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<D, S> Locked<D, S> {
enum LocalState {
Start,
Proposed,
Prepared,
Prepared(bool), // whether we thought it valid.
Committed,
VoteAdvance,
}
Expand Down Expand Up @@ -582,6 +582,7 @@ impl<C: Context> Strategy<C> {
Some(_) => {
// don't check validity if we are locked.
// this is necessary to preserve the liveness property.
self.local_state = LocalState::Prepared(true);
prepare_for = Some(digest);
}
None => {
Expand All @@ -591,6 +592,8 @@ impl<C: Context> Strategy<C> {

if let Async::Ready(valid) = res {
self.evaluating_proposal = None;
self.local_state = LocalState::Prepared(valid);

if valid {
prepare_for = Some(digest);
}
Expand All @@ -606,7 +609,6 @@ impl<C: Context> Strategy<C> {
).into();

self.import_and_send_message(message, context, sending);
self.local_state = LocalState::Prepared;
}

Ok(())
Expand Down Expand Up @@ -657,6 +659,12 @@ impl<C: Context> Strategy<C> {
// sent an AdvanceRound message yet, do so.
let mut attempt_advance = self.current_accumulator.advance_votes() > self.max_faulty;

// if we evaluated the proposal and it was bad, vote to advance round.
if let LocalState::Prepared(false) = self.local_state {
attempt_advance = true;
}

// if the timeout has fired, vote to advance round.
if let Async::Ready(_) = self.round_timeout.poll()? {
attempt_advance = true;
}
Expand Down
71 changes: 69 additions & 2 deletions substrate/bft/src/generic/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use super::*;

use std::collections::BTreeSet;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
Expand Down Expand Up @@ -117,6 +118,7 @@ struct TestContext {
node_count: usize,
current_round: Arc<AtomicUsize>,
timer: Timer,
evaluated: Mutex<BTreeSet<usize>>,
}

impl Context for TestContext {
Expand All @@ -137,7 +139,7 @@ impl Context for TestContext {
let proposal = {
let mut p = self.proposal.lock().unwrap();
let x = *p;
*p = (*p * 2) + 1;
*p += self.node_count;
x
};

Expand Down Expand Up @@ -175,6 +177,10 @@ impl Context for TestContext {
}

fn proposal_valid(&self, proposal: &Candidate) -> FutureResult<bool, Error> {
if !self.evaluated.lock().unwrap().insert(proposal.0) {
panic!("Evaluated proposal {:?} twice", proposal.0);
}

Ok(proposal.0 % 3 != 0).into_future()
}

Expand Down Expand Up @@ -230,6 +236,64 @@ fn consensus_completes_with_minimum_good() {
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
evaluated: Mutex::new(BTreeSet::new()),
node_count,
};

agree(
ctx,
node_count,
max_faulty,
rx.map_err(|_| Error),
tx.sink_map_err(|_| Error).with(move |t| Ok((i, t))),
)
})
.collect::<Vec<_>>();

let timeout = timeout_in(Duration::from_millis(500)).map_err(|_| Error);
let results = ::futures::future::join_all(nodes)
.map(Some)
.select(timeout.map(|_| None))
.wait()
.map(|(i, _)| i)
.map_err(|(e, _)| e)
.expect("to complete")
.expect("to not time out");

for result in &results {
assert_eq!(&result.justification.digest, &results[0].justification.digest);
}
}

#[test]
fn consensus_completes_with_minimum_good_all_initial_proposals_bad() {
let node_count = 10;
let max_faulty = 3;

let timer = tokio_timer::wheel().tick_duration(ROUND_DURATION).build();

let (network, net_send, net_recv) = Network::new(node_count);
network.route_on_thread();

let nodes = net_send
.into_iter()
.zip(net_recv)
.take(node_count - max_faulty)
.enumerate()
.map(|(i, (tx, rx))| {
// the first 5 proposals are going to be bad.
let proposal = if i < 5 {
i * 3 // proposals considered bad in the tests if they are % 3
} else {
(i * 3) + 1
};

let ctx = TestContext {
local_id: AuthorityId(i),
proposal: Mutex::new(proposal),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
evaluated: Mutex::new(BTreeSet::new()),
node_count,
};

Expand Down Expand Up @@ -279,6 +343,7 @@ fn consensus_does_not_complete_without_enough_nodes() {
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
evaluated: Mutex::new(BTreeSet::new()),
node_count,
};

Expand Down Expand Up @@ -335,6 +400,7 @@ fn threshold_plus_one_locked_on_proposal_only_one_with_candidate() {
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(locked_round + 1)),
timer: timer.clone(),
evaluated: Mutex::new(BTreeSet::new()),
node_count,
};
let mut agreement = agree(
Expand Down Expand Up @@ -367,7 +433,7 @@ fn threshold_plus_one_locked_on_proposal_only_one_with_candidate() {
})
.collect::<Vec<_>>();

let timeout = timeout_in(Duration::from_millis(500)).map_err(|_| Error);
let timeout = timeout_in(Duration::from_millis(1000)).map_err(|_| Error);
let results = ::futures::future::join_all(nodes)
.map(Some)
.select(timeout.map(|_| None))
Expand Down Expand Up @@ -404,6 +470,7 @@ fn consensus_completes_even_when_nodes_start_with_a_delay() {
proposal: Mutex::new(i),
current_round: Arc::new(AtomicUsize::new(0)),
timer: timer.clone(),
evaluated: Mutex::new(BTreeSet::new()),
node_count,
};

Expand Down
1 change: 1 addition & 0 deletions substrate/rpc-servers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub fn start_http(
http::ServerBuilder::new(io)
.threads(4)
.rest_api(http::RestApi::Unsecure)
.cors(http::DomainsValidation::Disabled)
.start_http(addr)
}

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 5265f7e

Please sign in to comment.