Skip to content

Commit

Permalink
Merge pull request #50 from darwinia-network/poc1-final
Browse files Browse the repository at this point in the history
Merge from poc1-final to develop for devnet setup
  • Loading branch information
hackfisher authored Jul 29, 2019
2 parents 4ec2fbe + a9e4230 commit 7390a7c
Show file tree
Hide file tree
Showing 41 changed files with 4,222 additions and 3,975 deletions.
999 changes: 550 additions & 449 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ members = [
"node/runtime",
"node/rpc-client",
"srml/staking",
"srml/token/ring",
"srml/token/kton",
"srml/kton",
"srml/support",
"srml/aura",
"srml/try",
"srml/reward",
]

exclude = ["node/runtime/wasm"]
Expand Down
3 changes: 2 additions & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tokio = "0.1.7"
futures = "0.1"
exit-future = "0.1"
cli = { package = "substrate-cli", git = 'https://github.com/paritytech/substrate.git' }
parity-codec = { version = "3.3" }
parity-codec = { version = "4.1.1" }
sr-io = { git = 'https://github.com/paritytech/substrate.git' }
client = { package = "substrate-client", git = 'https://github.com/paritytech/substrate.git' }
primitives = { package = "substrate-primitives", git = 'https://github.com/paritytech/substrate.git' }
Expand All @@ -39,6 +39,7 @@ timestamp = { package = "srml-timestamp", git = 'https://github.com/paritytech/s
rand = "0.6"
finality_tracker = { package = "srml-finality-tracker", git = 'https://github.com/paritytech/substrate.git', default-features = false }
srml-support = { git = 'https://github.com/paritytech/substrate.git', default-features = false }
contracts = { package = "srml-contracts", git = 'https://github.com/paritytech/substrate.git', default-features = false }

[dev-dependencies]
consensus-common = { package = "substrate-consensus-common", git = 'https://github.com/paritytech/substrate.git' }
Expand Down
817 changes: 305 additions & 512 deletions node/cli/src/chain_spec.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions node/cli/src/factory_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ impl RuntimeAdapter for FactoryState<Number> {
} else {
match self.round() {
0 =>
// if round is 0 all transactions will be done with master as a sender
// if round is 0 all transactions will be done with master as a sender
self.block_no(),
_ =>
// if round is e.g. 1 every sender account will be new and not yet have
// any transactions done
// if round is e.g. 1 every sender account will be new and not yet have
// any transactions done
0
}
}
Expand Down
35 changes: 10 additions & 25 deletions node/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,15 @@ pub enum ChainSpec {
FlamingFir,
/// Whatever the current runtime is with the "global testnet" defaults.
StagingTestnet,
/// darwinia poc-1 testnet, same with local testnet
Trilobita,
/// darwinia poc-1 testnet
Darwinia,
/// darwinia poc-1 testnet fir
DarwiniaFir
}

/// Custom subcommands.
#[derive(Clone, Debug, StructOpt)]
pub enum CustomSubcommands {
/// The custom factory subcommmand for manufacturing transactions.
#[structopt(
name = "factory",
about = "Manufactures num transactions from Alice to random accounts. \
name = "factory",
about = "Manufactures num transactions from Alice to random accounts. \
Only supported for development or local testnet."
)]
Factory(FactoryCmd),
Expand Down Expand Up @@ -124,21 +118,14 @@ impl ChainSpec {
ChainSpec::Development => chain_spec::development_config(),
ChainSpec::LocalTestnet => chain_spec::local_testnet_config(),
ChainSpec::StagingTestnet => chain_spec::staging_testnet_config(),
ChainSpec::Trilobita => chain_spec::trilobita_testnet_config(),
// latest
ChainSpec::Darwinia => chain_spec::trilobita_config(),
ChainSpec::DarwiniaFir => chain_spec::darwinia_fir_config()?,
})
}

pub(crate) fn from(s: &str) -> Option<Self> {
match s {
"dev" => Some(ChainSpec::Development),
"local" => Some(ChainSpec::LocalTestnet),
"darwinia" => Some(ChainSpec::Darwinia),
"" => Some(ChainSpec::DarwiniaFir),
"trilobita" => Some(ChainSpec::Trilobita),
"fir" | "flaming-fir" => Some(ChainSpec::FlamingFir),
"" | "fir" | "flaming-fir" => Some(ChainSpec::FlamingFir),
"staging" => Some(ChainSpec::StagingTestnet),
_ => None,
}
Expand All @@ -163,22 +150,21 @@ pub fn run<I, T, E>(args: I, exit: E, version: cli::VersionInfo) -> error::Resul
|exit, _cli_args, _custom_args, config| {
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" by Darwinia Network, 2017-2019");
info!(" by Parity Technologies, 2017-2019");
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {:?}", config.roles);
let runtime = RuntimeBuilder::new().name_prefix("main-tokio-").build()
.map_err(|e| format!("{:?}", e))?;
let executor = runtime.executor();
match config.roles {
ServiceRoles::LIGHT => run_until_exit(
runtime,
service::Factory::new_light(config, executor).map_err(|e| format!("{:?}", e))?,
service::Factory::new_light(config).map_err(|e| format!("{:?}", e))?,
exit
),
_ => run_until_exit(
runtime,
service::Factory::new_full(config, executor).map_err(|e| format!("{:?}", e))?,
service::Factory::new_full(config).map_err(|e| format!("{:?}", e))?,
exit
),
}.map_err(|e| format!("{:?}", e))
Expand Down Expand Up @@ -220,7 +206,7 @@ fn run_until_exit<T, C, E>(
e: E,
) -> error::Result<()>
where
T: Deref<Target=substrate_service::Service<C>>,
T: Deref<Target=substrate_service::Service<C>> + Future<Item = (), Error = ()> + Send + 'static,
C: substrate_service::Components,
E: IntoExit,
{
Expand All @@ -229,13 +215,12 @@ fn run_until_exit<T, C, E>(
let informant = cli::informant::build(&service);
runtime.executor().spawn(exit.until(informant).map(|_| ()));

let _ = runtime.block_on(e.into_exit());
exit_send.fire();

// we eagerly drop the service so that the internal exit future is fired,
// but we need to keep holding a reference to the global telemetry guard
let _telemetry = service.telemetry();
drop(service);

let _ = runtime.block_on(service.select(e.into_exit()));
exit_send.fire();

// TODO [andre]: timeout this future #1318
let _ = runtime.shutdown_on_idle().wait();
Expand Down
58 changes: 36 additions & 22 deletions node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use node_primitives::Block;
use node_runtime::{GenesisConfig, RuntimeApi};
use substrate_service::{
FactoryFullConfiguration, LightComponents, FullComponents, FullBackend,
FullClient, LightClient, LightBackend, FullExecutor, LightExecutor, TaskExecutor,
FullClient, LightClient, LightBackend, FullExecutor, LightExecutor,
error::{Error as ServiceError},
};
use transaction_pool::{self, txpool::{Pool as TransactionPool}};
Expand Down Expand Up @@ -76,10 +76,10 @@ construct_service_factory! {
Genesis = GenesisConfig,
Configuration = NodeConfig<Self>,
FullService = FullComponents<Self>
{ |config: FactoryFullConfiguration<Self>, executor: TaskExecutor|
FullComponents::<Factory>::new(config, executor) },
{ |config: FactoryFullConfiguration<Self>|
FullComponents::<Factory>::new(config) },
AuthoritySetup = {
|mut service: Self::FullService, executor: TaskExecutor, local_key: Option<Arc<ed25519::Pair>>| {
|mut service: Self::FullService, local_key: Option<Arc<ed25519::Pair>>| {
let (block_import, link_half) = service.config.custom.grandpa_import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");

Expand All @@ -104,7 +104,7 @@ construct_service_factory! {
service.config.custom.inherent_data_providers.clone(),
service.config.force_authoring,
)?;
executor.spawn(aura.select(service.on_exit()).then(|_| Ok(())));
service.spawn_task(Box::new(aura.select(service.on_exit()).then(|_| Ok(()))));

info!("Running Grandpa session as Authority {}", key.public());
}
Expand All @@ -125,18 +125,16 @@ construct_service_factory! {

match config.local_key {
None => {
executor.spawn(grandpa::run_grandpa_observer(
service.spawn_task(Box::new(grandpa::run_grandpa_observer(
config,
link_half,
service.network(),
service.on_exit(),
)?);
)?));
},
Some(_) => {
let telemetry_on_connect = TelemetryOnConnect {
on_exit: Box::new(service.on_exit()),
telemetry_connection_sinks: service.telemetry_on_connect_stream(),
executor: &executor,
};
let grandpa_config = grandpa::GrandpaParams {
config: config,
Expand All @@ -146,15 +144,15 @@ construct_service_factory! {
on_exit: service.on_exit(),
telemetry_on_connect: Some(telemetry_on_connect),
};
executor.spawn(grandpa::run_grandpa_voter(grandpa_config)?);
service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
},
}

Ok(service)
}
},
LightService = LightComponents<Self>
{ |config, executor| <LightComponents<Factory>>::new(config, executor) },
{ |config| <LightComponents<Factory>>::new(config) },
FullImportQueue = AuraImportQueue<Self::Block>
{ |config: &mut FactoryFullConfiguration<Self> , client: Arc<FullClient<Self>>, select_chain: Self::SelectChain| {
let slot_duration = SlotDuration::get_or_compute(&*client)?;
Expand Down Expand Up @@ -220,7 +218,7 @@ mod tests {
use consensus::CompatibleDigestItem;
use consensus_common::{Environment, Proposer, ImportBlock, BlockOrigin, ForkChoiceStrategy};
use node_primitives::DigestItem;
use node_runtime::{Call, BalancesCall, UncheckedExtrinsic};
use node_runtime::{BalancesCall, Call, COIN, UncheckedExtrinsic};
use parity_codec::{Compact, Encode, Decode};
use primitives::{
crypto::Pair as CryptoPair, ed25519::Pair, blake2_256,
Expand All @@ -231,6 +229,7 @@ mod tests {
use finality_tracker;
use keyring::{ed25519::Keyring as AuthorityKeyring, sr25519::Keyring as AccountKeyring};
use substrate_service::ServiceFactory;
use service_test::SyncService;
use crate::service::Factory;

#[cfg(feature = "rhd")]
Expand Down Expand Up @@ -266,8 +265,13 @@ mod tests {
auxiliary: Vec::new(),
}
};
let extrinsic_factory = |service: &<Factory as service::ServiceFactory>::FullService| {
let payload = (0, Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69.into())), Era::immortal(), service.client().genesis_hash());
let extrinsic_factory = |service: &SyncService<<Factory as service::ServiceFactory>::FullService>| {
let payload = (
0,
Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69.into())),
Era::immortal(),
service.client().genesis_hash()
);
let signature = alice.sign(&payload.encode()).into();
let id = alice.public().0.into();
let xt = UncheckedExtrinsic {
Expand All @@ -277,7 +281,11 @@ mod tests {
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);
service_test::sync::<Factory, _, _>(
chain_spec::integration_test_config(),
block_factory,
extrinsic_factory,
);
}

#[test]
Expand All @@ -287,9 +295,14 @@ mod tests {

let alice = Arc::new(AuthorityKeyring::Alice.pair());
let mut slot_num = 1u64;
let block_factory = |service: &<Factory as ServiceFactory>::FullService| {
let mut inherent_data = service.config.custom.inherent_data_providers
.create_inherent_data().unwrap();
let block_factory = |service: &SyncService<<Factory as ServiceFactory>::FullService>| {
let service = service.get();
let mut inherent_data = service
.config
.custom
.inherent_data_providers
.create_inherent_data()
.expect("Creates inherent data.");
inherent_data.replace_data(finality_tracker::INHERENT_IDENTIFIER, &1u64);
inherent_data.replace_data(timestamp::INHERENT_IDENTIFIER, &(slot_num * 10));

Expand All @@ -299,13 +312,14 @@ mod tests {
client: service.client(),
transaction_pool: service.transaction_pool(),
});

let mut digest = Digest::<H256>::default();
digest.push(<DigestItem as CompatibleDigestItem<Pair>>::aura_pre_digest(slot_num * 10 / 2));
let proposer = proposer_factory.init(&parent_header).unwrap();
let new_block = proposer.propose(
inherent_data,
digest,
::std::time::Duration::from_secs(1),
std::time::Duration::from_secs(1),
).expect("Error making test block");

let (new_header, new_body) = new_block.deconstruct();
Expand Down Expand Up @@ -335,11 +349,11 @@ mod tests {
let charlie = Arc::new(AccountKeyring::Charlie.pair());

let mut index = 0;
let extrinsic_factory = |service: &<Factory as ServiceFactory>::FullService| {
let amount = 1000;
let extrinsic_factory = |service: &SyncService<<Factory as ServiceFactory>::FullService>| {
let amount = 5 * COIN;
let to = AddressPublic::from_raw(bob.public().0);
let from = AddressPublic::from_raw(charlie.public().0);
let genesis_hash = service.client().block_hash(0).unwrap().unwrap();
let genesis_hash = service.get().client().block_hash(0).unwrap().unwrap();
let signer = charlie.clone();

let function = Call::Balances(BalancesCall::transfer(to.into(), amount));
Expand Down
2 changes: 1 addition & 1 deletion node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"

[dependencies]
trie-root = "0.12"
parity-codec = "3.3"
parity-codec = "4.1.1"
runtime_io = { package = "sr-io", git = 'https://github.com/paritytech/substrate.git' }
state_machine = { package = "substrate-state-machine", git = 'https://github.com/paritytech/substrate.git' }
substrate-executor = { git = 'https://github.com/paritytech/substrate.git' }
Expand Down
Loading

0 comments on commit 7390a7c

Please sign in to comment.