Skip to content

Commit

Permalink
Frontier RPC tests (#1249)
Browse files Browse the repository at this point in the history
* Frontier RPC tests

* fmt

* fmt

* fmt

* update gh action

* run only on push master
  • Loading branch information
ermalkaleci authored Jun 4, 2024
1 parent 111d18f commit ab95d31
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/frontier-rpc-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Frontier RPC Tests
on:
workflow_dispatch:
push:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v4

- name: Install deps
run: sudo apt -y install protobuf-compiler

- name: Install & display rust toolchain
run: rustup show

- name: Check targets are installed correctly
run: rustup target list --installed

- name: Build astar-collator
run: cargo build --release --locked --features manual-seal --bin astar-collator

- name: Clone frontier tests
run: git clone https://github.com/AstarNetwork/frontier-tests.git --depth 1

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'
cache-dependency-path: frontier-tests/package-lock.json

- name: Install dependencies
working-directory: frontier-tests
run: npm install --frozen

- name: Build contracts
working-directory: frontier-tests
run: npm run build

- name: Run frontier RPC tests
working-directory: frontier-tests
run: npm run test
env:
BINARY_PATH: ${{ github.workspace }}/target/release/astar-collator
36 changes: 36 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ sc-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch
sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
sc-consensus-manual-seal = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
sc-network = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
sc-offchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" }
Expand Down
4 changes: 4 additions & 0 deletions bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ sc-consensus = { workspace = true }
sc-consensus-aura = { workspace = true }
sc-consensus-babe = { workspace = true }
sc-consensus-grandpa = { workspace = true }
sc-consensus-manual-seal = { workspace = true, optional = true }
sc-executor = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
Expand Down Expand Up @@ -173,3 +174,6 @@ evm-tracing = [
"moonbeam-rpc-trace",
"moonbeam-rpc-txpool",
]
manual-seal = [
"sc-consensus-manual-seal",
]
44 changes: 44 additions & 0 deletions bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ pub fn new_partial(
let frontier_block_import =
FrontierBlockImport::new(grandpa_block_import.clone(), client.clone());
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;

#[cfg(feature = "manual-seal")]
let import_queue = sc_consensus_manual_seal::import_queue(
Box::new(client.clone()),
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
);

#[cfg(not(feature = "manual-seal"))]
let import_queue = sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _>(
ImportQueueParams {
block_import: frontier_block_import.clone(),
Expand Down Expand Up @@ -366,6 +375,8 @@ pub fn start_node(
block_data_cache: block_data_cache.clone(),
overrides: overrides.clone(),
enable_evm_rpc: true, // enable EVM RPC for dev node by default
#[cfg(feature = "manual-seal")]
command_sink: None,
};

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

// Channel for the rpc handler to communicate with the authorship task.
#[cfg(feature = "manual-seal")]
let (command_sink, commands_stream) = futures::channel::mpsc::channel(1024);

let rpc_extensions_builder = {
let client = client.clone();
let network = network.clone();
Expand All @@ -649,6 +664,8 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
block_data_cache: block_data_cache.clone(),
overrides: overrides.clone(),
enable_evm_rpc: true, // enable EVM RPC for dev node by default
#[cfg(feature = "manual-seal")]
command_sink: Some(command_sink.clone()),
};

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

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

#[cfg(feature = "manual-seal")]
let aura = sc_consensus_manual_seal::run_manual_seal(
sc_consensus_manual_seal::ManualSealParams {
block_import,
env: proposer_factory,
client: client.clone(),
pool: transaction_pool.clone(),
commands_stream,
select_chain,
consensus_data_provider: Some(Box::new(
sc_consensus_manual_seal::consensus::aura::AuraConsensusDataProvider::new(
client.clone(),
),
)),
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration.clone(),
);
Ok((slot, timestamp))
},
},
);

#[cfg(not(feature = "manual-seal"))]
let aura = sc_consensus_aura::start_aura::<AuraPair, _, _, _, _, _, _, _, _, _, _>(
StartAuraParams {
slot_duration,
Expand Down
4 changes: 4 additions & 0 deletions bin/collator/src/parachain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ where
block_data_cache: block_data_cache.clone(),
overrides: overrides.clone(),
enable_evm_rpc: additional_config.enable_evm_rpc,
#[cfg(feature = "manual-seal")]
command_sink: None,
};

crate::rpc::create_full(deps, subscription, pubsub_notification_sinks.clone())
Expand Down Expand Up @@ -834,6 +836,8 @@ where
block_data_cache: block_data_cache.clone(),
overrides: overrides.clone(),
enable_evm_rpc: additional_config.enable_evm_rpc,
#[cfg(feature = "manual-seal")]
command_sink: None,
};

crate::rpc::create_full(
Expand Down
12 changes: 12 additions & 0 deletions bin/collator/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ pub struct FullDeps<C, P, A: ChainApi> {
pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
/// Enable EVM RPC servers
pub enable_evm_rpc: bool,
/// Command sink for manual sealing
#[cfg(feature = "manual-seal")]
pub command_sink:
Option<futures::channel::mpsc::Sender<sc_consensus_manual_seal::EngineCommand<Hash>>>,
}

/// Instantiate all RPC extensions and Tracing RPC.
Expand Down Expand Up @@ -291,12 +295,20 @@ where
overrides,
block_data_cache,
enable_evm_rpc,
#[cfg(feature = "manual-seal")]
command_sink,
} = deps;

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

#[cfg(feature = "manual-seal")]
if let Some(command_sink) = command_sink {
use sc_consensus_manual_seal::rpc::ManualSealApiServer;
io.merge(sc_consensus_manual_seal::rpc::ManualSeal::new(command_sink).into_rpc())?;
}

if !enable_evm_rpc {
return Ok(io);
}
Expand Down

0 comments on commit ab95d31

Please sign in to comment.