Fixed transaction propagation (#850)

This commit is contained in:
Arkadiy Paronyan
2018-09-30 17:48:41 +02:00
committed by Gav Wood
parent cad28aa283
commit a5a7dd2480
7 changed files with 39 additions and 6 deletions
+1
View File
@@ -1706,6 +1706,7 @@ dependencies = [
"rhododendron 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-io 0.1.0",
"sr-primitives 0.1.0",
"substrate-bft 0.1.0",
"substrate-client 0.1.0",
"substrate-keyring 0.1.0",
+2
View File
@@ -472,6 +472,8 @@ impl<B: BlockT, S: Specialization<B>, H: ExHashT> Protocol<B, S, H> {
for t in extrinsics {
if let Some(hash) = self.transaction_pool.import(&t) {
peer.known_extrinsics.insert(hash);
} else {
trace!(target: "sync", "Extrinsic rejected");
}
}
}
+2 -1
View File
@@ -158,7 +158,7 @@ impl<Components> Service<Components>
Components::build_transaction_pool(config.transaction_pool, client.clone())?
);
let transaction_pool_adapter = TransactionPoolAdapter::<Components> {
imports_external_transactions: !config.roles == Roles::LIGHT,
imports_external_transactions: !(config.roles == Roles::LIGHT),
pool: transaction_pool.clone(),
client: client.clone(),
};
@@ -404,6 +404,7 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
fn import(&self, transaction: &ComponentExtrinsic<C>) -> Option<ComponentExHash<C>> {
if !self.imports_external_transactions {
debug!("Transaction rejected");
return None;
}
+12 -3
View File
@@ -49,6 +49,7 @@ use service::{
use network::{NetworkConfiguration, NonReservedPeerMode, Protocol, SyncProvider, ManageNetwork};
use client::{BlockOrigin, JustifiedHeader};
use sr_primitives::traits::As;
use sr_primitives::generic::BlockId;
struct TestNet<F: ServiceFactory> {
runtime: Runtime,
@@ -212,10 +213,11 @@ pub fn connectivity<F: ServiceFactory>(spec: FactoryChainSpec<F>) {
}
}
pub fn sync<F, B>(spec: FactoryChainSpec<F>, block_factory: B)
pub fn sync<F, B, E>(spec: FactoryChainSpec<F>, block_factory: B, extrinsic_factory: E)
where
F: ServiceFactory,
B: Fn(&F::FullService) -> (JustifiedHeader<F::Block>, Option<Vec<FactoryExtrinsic<F>>>),
E: Fn(&F::FullService) -> FactoryExtrinsic<F>,
{
const NUM_NODES: u32 = 10;
const NUM_BLOCKS: usize = 512;
@@ -237,9 +239,16 @@ where
for (_, service) in network.full_nodes.iter().skip(1) {
service.network().add_reserved_peer(first_address.clone()).expect("Error adding reserved peer");
}
network.run_until_all_full(|_index, service| {
network.run_until_all_full(|_index, service|
service.client().info().unwrap().chain.best_number == As::sa(NUM_BLOCKS as u64)
});
);
info!("Checking extrinsic propagation");
let first_service = network.full_nodes[0].1.clone();
let best_block = BlockId::number(first_service.client().info().unwrap().chain.best_number);
first_service.transaction_pool().submit_one(&best_block, extrinsic_factory(&first_service)).unwrap();
network.run_until_all_full(|_index, service|
service.transaction_pool().all().len() == 1
);
}
pub fn consensus<F>(spec: FactoryChainSpec<F>, authorities: Vec<String>)
+1
View File
@@ -72,6 +72,7 @@ use version::NativeVersion;
pub use runtime_primitives::BuildStorage;
pub use consensus::Call as ConsensusCall;
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use runtime_primitives::{Permill, Perbill};
pub use timestamp::BlockPeriod;
pub use srml_support::StorageValue;
+1
View File
@@ -19,6 +19,7 @@ node-consensus = { path = "../consensus" }
node-network = { path = "../network" }
node-transaction-pool = { path = "../transaction-pool" }
sr-io = { path = "../../core/sr-io" }
sr-primitives = { path = "../../core/sr-primitives" }
substrate-primitives = { path = "../../core/primitives" }
substrate-network = { path = "../../core/network" }
substrate-client = { path = "../../core/client" }
+20 -2
View File
@@ -45,7 +45,8 @@ extern crate substrate_bft as bft;
extern crate substrate_test_client;
#[cfg(test)]
extern crate substrate_keyring as keyring;
#[cfg(test)]
extern crate sr_primitives as runtime_primitives;
pub mod chain_spec;
use std::sync::Arc;
@@ -213,12 +214,18 @@ mod tests {
use {service, service_test, Factory, chain_spec};
use consensus::{self, OfflineTracker};
use primitives::ed25519;
use runtime_primitives::traits::BlockNumberToHash;
use runtime_primitives::generic::Era;
use node_primitives::Block;
use bft::{Proposer, Environment};
use node_network::consensus::ConsensusNetwork;
use substrate_test_client::fake_justify;
use node_primitives::BlockId;
use keyring::Keyring;
use node_runtime::{UncheckedExtrinsic, Call, BalancesCall};
use node_primitives::UncheckedExtrinsic as OpaqueExtrinsic;
use codec::{Decode, Encode};
use node_runtime::RawAddress;
#[test]
fn test_connectivity() {
@@ -251,7 +258,18 @@ mod tests {
let justification = service.client().check_justification(block.header, justification).unwrap();
(justification, Some(block.extrinsics))
};
service_test::sync::<Factory, _>(chain_spec::integration_test_config(), block_factory);
let extrinsic_factory = |service: &<Factory as service::ServiceFactory>::FullService| {
let payload = (0, Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69)), Era::immortal(), service.client().genesis_hash());
let signature = alice.sign(&payload.encode()).into();
let id = alice.public().0.into();
let xt = UncheckedExtrinsic {
signature: Some((RawAddress::Id(id), signature, payload.0, Era::immortal())),
function: payload.1,
}.encode();
let v: Vec<u8> = Decode::decode(&mut xt.as_slice()).unwrap();
OpaqueExtrinsic(v)
};
service_test::sync::<Factory, _, _>(chain_spec::integration_test_config(), block_factory, extrinsic_factory);
}
#[test]