Skip to content

Commit

Permalink
squashed commits from paritytech#4639
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed Jun 19, 2024
1 parent 1bbb680 commit 486fbd0
Show file tree
Hide file tree
Showing 91 changed files with 74,604 additions and 1,249 deletions.
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cumulus/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,13 @@ pub struct BuildNetworkParams<
IQ,
> where
Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,
<Block as BlockT>::Hash: std::marker::Unpin,
{
pub parachain_config: &'a Configuration,
pub net_config:
sc_network::config::FullNetworkConfiguration<Block, <Block as BlockT>::Hash, Network>,
pub client: Arc<Client>,
pub transaction_pool: Arc<sc_transaction_pool::FullPool<Block, Client>>,
pub transaction_pool: Arc<sc_transaction_pool::TransactionPoolImpl<Block, Client>>,
pub para_id: ParaId,
pub relay_chain_interface: RCInterface,
pub spawn_handle: SpawnTaskHandle,
Expand Down Expand Up @@ -446,6 +447,7 @@ pub async fn build_network<'a, Block, Client, RCInterface, IQ, Network>(
)>
where
Block: BlockT,
<Block as BlockT>::Hash: std::marker::Unpin,
Client: UsageProvider<Block>
+ HeaderBackend<Block>
+ sp_consensus::block_validation::Chain<Block>
Expand Down
6 changes: 3 additions & 3 deletions cumulus/polkadot-parachain/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
pub type RpcExtension = jsonrpsee::RpcModule<()>;

/// Full client dependencies
pub struct FullDeps<C, P> {
pub struct FullDeps<C, P: ?Sized> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand All @@ -57,7 +57,7 @@ where
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
P: TransactionPool<Block = Block> + Sync + Send + 'static + ?Sized,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashingFor<Block>>,
{
Expand Down Expand Up @@ -91,7 +91,7 @@ where
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
P: TransactionPool<Block = Block> + Sync + Send + 'static + ?Sized,
{
use frame_rpc_system::{System, SystemApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
Expand Down
33 changes: 19 additions & 14 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub type Service<RuntimeApi> = PartialComponents<
ParachainBackend,
(),
sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>,
sc_transaction_pool::TransactionPoolImpl<Block, ParachainClient<RuntimeApi>>,
(ParachainBlockImport<RuntimeApi>, Option<Telemetry>, Option<TelemetryWorkerHandle>),
>;

Expand Down Expand Up @@ -154,13 +154,14 @@ where
telemetry
});

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);
let transaction_pool = sc_transaction_pool::Builder::new()
.with_options(config.transaction_pool.clone())
.build(
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);

let block_import = ParachainBlockImport::new(client.clone(), backend.clone());

Expand Down Expand Up @@ -214,7 +215,7 @@ where
DenyUnsafe,
Arc<ParachainClient<RuntimeApi>>,
Arc<ParachainBackend>,
Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
Arc<sc_transaction_pool::TransactionPoolImpl<Block, ParachainClient<RuntimeApi>>>,
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
+ 'static,
BIQ: FnOnce(
Expand All @@ -231,7 +232,7 @@ where
Option<TelemetryHandle>,
&TaskManager,
Arc<dyn RelayChainInterface>,
Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
Arc<sc_transaction_pool::TransactionPoolImpl<Block, ParachainClient<RuntimeApi>>>,
Arc<SyncingService<Block>>,
KeystorePtr,
Duration,
Expand Down Expand Up @@ -464,7 +465,7 @@ fn build_parachain_rpc_extensions<RuntimeApi>(
deny_unsafe: sc_rpc::DenyUnsafe,
client: Arc<ParachainClient<RuntimeApi>>,
backend: Arc<ParachainBackend>,
pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
pool: Arc<sc_transaction_pool::TransactionPoolImpl<Block, ParachainClient<RuntimeApi>>>,
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
where
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
Expand All @@ -482,7 +483,7 @@ fn build_contracts_rpc_extensions(
deny_unsafe: sc_rpc::DenyUnsafe,
client: Arc<ParachainClient<FakeRuntimeApi>>,
_backend: Arc<ParachainBackend>,
pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<FakeRuntimeApi>>>,
pool: Arc<sc_transaction_pool::TransactionPoolImpl<Block, ParachainClient<FakeRuntimeApi>>>,
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error> {
let deps = crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe };

Expand Down Expand Up @@ -866,7 +867,9 @@ fn start_relay_chain_consensus(
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
relay_chain_interface: Arc<dyn RelayChainInterface>,
transaction_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<FakeRuntimeApi>>>,
transaction_pool: Arc<
sc_transaction_pool::TransactionPoolImpl<Block, ParachainClient<FakeRuntimeApi>>,
>,
_sync_oracle: Arc<SyncingService<Block>>,
_keystore: KeystorePtr,
_relay_chain_slot_duration: Duration,
Expand Down Expand Up @@ -937,7 +940,9 @@ fn start_lookahead_aura_consensus(
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
relay_chain_interface: Arc<dyn RelayChainInterface>,
transaction_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<FakeRuntimeApi>>>,
transaction_pool: Arc<
sc_transaction_pool::TransactionPoolImpl<Block, ParachainClient<FakeRuntimeApi>>,
>,
sync_oracle: Arc<SyncingService<Block>>,
keystore: KeystorePtr,
relay_chain_slot_duration: Duration,
Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/service/benches/transaction_throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion, Throughpu
use cumulus_client_cli::get_raw_genesis_header;
use cumulus_test_runtime::{AccountId, BalancesCall, ExistentialDeposit, SudoCall};
use futures::{future, StreamExt};
use sc_transaction_pool_api::{TransactionPool as _, TransactionSource, TransactionStatus};
use sc_transaction_pool_api::{TransactionSource, TransactionStatus};
use sp_core::{crypto::Pair, sr25519};
use sp_runtime::OpaqueExtrinsic;

Expand Down
19 changes: 10 additions & 9 deletions cumulus/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub type Backend = TFullBackend<Block>;
pub type ParachainBlockImport = TParachainBlockImport<Block, Arc<Client>, Backend>;

/// Transaction pool type used by the test service
pub type TransactionPool = Arc<sc_transaction_pool::FullPool<Block, Client>>;
pub type TransactionPool = Arc<sc_transaction_pool::TransactionPoolImpl<Block, Client>>;

/// Recovery handle that fails regularly to simulate unavailable povs.
pub struct FailingRecoveryHandle {
Expand Down Expand Up @@ -177,7 +177,7 @@ pub type Service = PartialComponents<
Backend,
(),
sc_consensus::import_queue::BasicQueue<Block>,
sc_transaction_pool::FullPool<Block, Client>,
sc_transaction_pool::TransactionPoolImpl<Block, Client>,
ParachainBlockImport,
>;

Expand Down Expand Up @@ -212,13 +212,14 @@ pub fn new_partial(

let block_import = ParachainBlockImport::new(client.clone(), backend.clone());

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);
let transaction_pool = sc_transaction_pool::Builder::new()
.with_options(config.transaction_pool.clone())
.build(
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let import_queue = cumulus_client_consensus_aura::import_queue::<AuthorityPair, _, _, _, _, _>(
Expand Down
18 changes: 18 additions & 0 deletions cumulus/zombienet/tests/0008-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Allows to manually submit extrinsic to collator.
// Usage:
// zombienet-linux -p native spwan 0008-parachain-extrinsic-gets-finalized.toml
// node 0008-main.js <path-to-generated-tmpdir/zombie.json>

global.zombie = null

const fs = require('fs');
const test = require('./0008-transaction_gets_finalized.js');

if (process.argv.length == 2) {
console.error('Path to zombie.json (generated by zombienet-linux spawn command shall be given)!');
process.exit(1);
}

let networkInfo = JSON.parse(fs.readFileSync(process.argv[2]));

test.run("charlie", networkInfo).then(process.exit)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[relaychain]
default_image = "{{RELAY_IMAGE}}"
default_command = "polkadot"
chain = "rococo-local"

[[relaychain.nodes]]
name = "alice"
validator = true

[[relaychain.nodes]]
name = "bob"
validator = true

[[parachains]]
id = 2000
cumulus_based = true
chain = "asset-hub-rococo-local"

# run charlie as parachain collator
[[parachains.collators]]
name = "charlie"
validator = true
image = "{{POLKADOT_PARACHAIN_IMAGE}}"
command = "polkadot-parachain"
args = ["--force-authoring", "-ltxpool=trace"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Description: Block building
Network: ./0008-parachain_extrinsic_gets_finalized.toml
Creds: config

alice: reports node_roles is 4
bob: reports node_roles is 4
charlie: reports node_roles is 4

alice: reports peers count is at least 1
bob: reports peers count is at least 1

alice: reports block height is at least 5 within 60 seconds
bob: reports block height is at least 5 within 60 seconds
charlie: reports block height is at least 2 within 120 seconds

alice: count of log lines containing "error" is 0 within 2 seconds
bob: count of log lines containing "error" is 0 within 2 seconds
charlie: count of log lines containing "error" is 0 within 2 seconds

charlie: js-script ./0008-transaction_gets_finalized.js within 600 seconds
77 changes: 77 additions & 0 deletions cumulus/zombienet/tests/0008-transaction_gets_finalized.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//based on: https://polkadot.js.org/docs/api/examples/promise/transfer-events

const assert = require("assert");

async function run(nodeName, networkInfo, args) {
// console.log('xxxxxxxxxxx 1');
const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName];
// console.log('xxxxxxxxxxx 2');
// Create the API and wait until ready
var api = null;
var keyring = null;
if (zombie == null) {
const testKeyring = require('@polkadot/keyring/testing');
const { WsProvider, ApiPromise } = require('@polkadot/api');
const provider = new WsProvider(wsUri);
api = await ApiPromise.create({provider});
// Construct the keyring after the API (crypto has an async init)
keyring = testKeyring.createTestKeyring({ type: "sr25519" });
} else {
keyring = new zombie.Keyring({ type: "sr25519" });
// console.log('xxxxxxxxxxx 3');
api = await zombie.connect(wsUri, userDefinedTypes);
// console.log('xxxxxxxxxxx 4');
}


// Add Alice to our keyring with a hard-derivation path (empty phrase, so uses dev)
const alice = keyring.addFromUri('//Alice');
// console.log('xxxxxxxxxxx 5');

// Create a extrinsic:
const extrinsic = api.tx.system.remark("xxx");
// console.log('xxxxxxxxxxx 6');

let extrinsic_success_event = false;
try {
// console.log('xxxxxxxxxxx 7');
await new Promise( async (resolve, reject) => {
const unsubscribe = await extrinsic
.signAndSend(alice, { nonce: -1 }, ({ events = [], status }) => {
console.log('Extrinsic status:', status.type);

if (status.isInBlock) {
console.log('Included at block hash', status.asInBlock.toHex());
console.log('Events:');

events.forEach(({ event: { data, method, section }, phase }) => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());

if (section=="system" && method =="ExtrinsicSuccess") {
extrinsic_success_event = true;
}
});
} else if (status.isFinalized) {
console.log('Finalized block hash', status.asFinalized.toHex());
unsubscribe();
if (extrinsic_success_event) {
resolve();
} else {
reject("ExtrinsicSuccess has not been seen");
}
} else if (status.isError) {
unsubscribe();
reject("Extrinsic status.isError");
}

});
});
// console.log('xxxxxxxxxxx 8');
} catch (error) {
assert.fail("Transfer promise failed, error: " + error);
}

assert.ok("test passed");
}

module.exports = { run }
Loading

0 comments on commit 486fbd0

Please sign in to comment.