Skip to content

Commit 3883432

Browse files
committed
Frontier RPC tests
1 parent 088f2c9 commit 3883432

File tree

7 files changed

+146
-0
lines changed

7 files changed

+146
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Frontier RPC Tests
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
12+
13+
jobs:
14+
tests:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout the source code
18+
uses: actions/checkout@v4
19+
20+
- name: Install deps
21+
run: sudo apt -y install protobuf-compiler
22+
23+
- name: Install & display rust toolchain
24+
run: rustup show
25+
26+
- name: Check targets are installed correctly
27+
run: rustup target list --installed
28+
29+
- name: Build astar-collator
30+
run: cargo build --release --features manual-seal
31+
32+
- name: Clone frontier tests
33+
run: git clone -b tests-for-astar https://github.com/AstarNetwork/frontier.git --depth 1
34+
35+
- name: Setup node
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: 18.x
39+
cache: 'npm'
40+
cache-dependency-path: frontier/ts-tests/package-lock.json
41+
42+
- name: Install dependencies
43+
working-directory: frontier/ts-tests
44+
run: npm install --frozen
45+
46+
- name: Run frontier RPC tests
47+
working-directory: frontier/ts-tests
48+
run: npm run test
49+
env:
50+
BINARY_PATH: ${{ github.workspace }}/target/release/astar-collator

Cargo.lock

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ sc-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch
132132
sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
133133
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
134134
sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
135+
sc-consensus-manual-seal = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
135136
sc-network = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
136137
sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
137138
sc-offchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }

bin/collator/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ sc-consensus = { workspace = true }
5656
sc-consensus-aura = { workspace = true }
5757
sc-consensus-babe = { workspace = true }
5858
sc-consensus-grandpa = { workspace = true }
59+
sc-consensus-manual-seal = { workspace = true, optional = true }
5960
sc-executor = { workspace = true }
6061
sc-network = { workspace = true }
6162
sc-network-sync = { workspace = true }
@@ -173,3 +174,6 @@ evm-tracing = [
173174
"moonbeam-rpc-trace",
174175
"moonbeam-rpc-txpool",
175176
]
177+
manual-seal = [
178+
"sc-consensus-manual-seal"
179+
]

bin/collator/src/local/service.rs

+40
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ pub fn new_partial(
139139
let frontier_block_import =
140140
FrontierBlockImport::new(grandpa_block_import.clone(), client.clone());
141141
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
142+
143+
#[cfg(feature = "manual-seal")]
144+
let import_queue = sc_consensus_manual_seal::import_queue(
145+
Box::new(client.clone()),
146+
&task_manager.spawn_essential_handle(),
147+
config.prometheus_registry(),
148+
);
149+
150+
#[cfg(not(feature = "manual-seal"))]
142151
let import_queue = sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _>(
143152
ImportQueueParams {
144153
block_import: frontier_block_import.clone(),
@@ -366,6 +375,8 @@ pub fn start_node(
366375
block_data_cache: block_data_cache.clone(),
367376
overrides: overrides.clone(),
368377
enable_evm_rpc: true, // enable EVM RPC for dev node by default
378+
#[cfg(feature = "manual-seal")]
379+
command_sink: None
369380
};
370381

371382
crate::rpc::create_full(
@@ -626,6 +637,10 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
626637
prometheus_registry.clone(),
627638
));
628639

640+
// Channel for the rpc handler to communicate with the authorship task.
641+
#[cfg(feature = "manual-seal")]
642+
let (command_sink, commands_stream) = futures::channel::mpsc::channel(1024);
643+
629644
let rpc_extensions_builder = {
630645
let client = client.clone();
631646
let network = network.clone();
@@ -649,6 +664,8 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
649664
block_data_cache: block_data_cache.clone(),
650665
overrides: overrides.clone(),
651666
enable_evm_rpc: true, // enable EVM RPC for dev node by default
667+
#[cfg(feature = "manual-seal")]
668+
command_sink: Some(command_sink.clone()),
652669
};
653670

654671
crate::rpc::create_full(deps, subscription, pubsub_notification_sinks.clone())
@@ -682,6 +699,29 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
682699

683700
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
684701

702+
#[cfg(feature = "manual-seal")]
703+
let aura = sc_consensus_manual_seal::run_manual_seal(sc_consensus_manual_seal::ManualSealParams {
704+
block_import,
705+
env: proposer_factory,
706+
client: client.clone(),
707+
pool: transaction_pool.clone(),
708+
commands_stream,
709+
select_chain,
710+
consensus_data_provider: Some(Box::new(sc_consensus_manual_seal::consensus::aura::AuraConsensusDataProvider::new(client.clone()))),
711+
create_inherent_data_providers: move |_, ()| {
712+
async move {
713+
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
714+
let slot =
715+
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
716+
*timestamp,
717+
slot_duration.clone(),
718+
);
719+
Ok((slot, timestamp))
720+
}
721+
},
722+
});
723+
724+
#[cfg(not(feature = "manual-seal"))]
685725
let aura = sc_consensus_aura::start_aura::<AuraPair, _, _, _, _, _, _, _, _, _, _>(
686726
StartAuraParams {
687727
slot_duration,

bin/collator/src/parachain/service.rs

+4
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ where
492492
block_data_cache: block_data_cache.clone(),
493493
overrides: overrides.clone(),
494494
enable_evm_rpc: additional_config.enable_evm_rpc,
495+
#[cfg(feature = "manual-seal")]
496+
command_sink: None,
495497
};
496498

497499
crate::rpc::create_full(deps, subscription, pubsub_notification_sinks.clone())
@@ -834,6 +836,8 @@ where
834836
block_data_cache: block_data_cache.clone(),
835837
overrides: overrides.clone(),
836838
enable_evm_rpc: additional_config.enable_evm_rpc,
839+
#[cfg(feature = "manual-seal")]
840+
command_sink: None,
837841
};
838842

839843
crate::rpc::create_full(

bin/collator/src/rpc.rs

+11
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ pub struct FullDeps<C, P, A: ChainApi> {
134134
pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
135135
/// Enable EVM RPC servers
136136
pub enable_evm_rpc: bool,
137+
/// Command sink for manual sealing
138+
#[cfg(feature = "manual-seal")]
139+
pub command_sink: Option<futures::channel::mpsc::Sender<sc_consensus_manual_seal::EngineCommand<Hash>>>,
137140
}
138141

139142
/// Instantiate all RPC extensions and Tracing RPC.
@@ -291,12 +294,20 @@ where
291294
overrides,
292295
block_data_cache,
293296
enable_evm_rpc,
297+
#[cfg(feature = "manual-seal")]
298+
command_sink,
294299
} = deps;
295300

296301
io.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
297302
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
298303
io.merge(sc_rpc::dev::Dev::new(client.clone(), deny_unsafe).into_rpc())?;
299304

305+
#[cfg(feature = "manual-seal")]
306+
if let Some(command_sink) = command_sink {
307+
use sc_consensus_manual_seal::rpc::ManualSealApiServer;
308+
io.merge(sc_consensus_manual_seal::rpc::ManualSeal::new(command_sink).into_rpc())?;
309+
}
310+
300311
if !enable_evm_rpc {
301312
return Ok(io);
302313
}

0 commit comments

Comments
 (0)