Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enable manual sealing of blocks when in dev mode #151

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
rustup target add ${{ matrix.architectures.target-tupl }} --toolchain ${{ needs.get-version.outputs.toolchain }}
rustup target add wasm32-unknown-unknown --toolchain ${{ needs.get-version.outputs.toolchain }}
- name: install deps
run: sudo apt-get install ${{ matrix.architectures.dependencies }}
run: sudo apt-get update && sudo apt-get install ${{ matrix.architectures.dependencies }}
- name: Install sccache
env:
TEMP: ${{ runner.temp }}
Expand Down
79 changes: 75 additions & 4 deletions 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 node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = '2021'
license = 'Apache-2.0'
repository = 'https://github.com/digicatapult/dscp-node/'
name = 'dscp-node'
version = '9.2.0'
version = '9.3.0'

[[bin]]
name = 'dscp-node'
Expand All @@ -18,6 +18,7 @@ targets = ['x86_64-unknown-linux-gnu']
clap = { version = "4.4.6", features = ["derive"] }
futures = { version = "0.3.27", features = ["thread-pool"] }
bs58 = "0.4.0"
async-trait = "0.1.57"

sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand All @@ -27,6 +28,7 @@ sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/sub
sc-keystore = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sc-consensus-manual-seal = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sc-consensus-babe-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand Down
4 changes: 4 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pub struct Cli {

#[clap(flatten)]
pub run: RunCmd,

/// Enable manual sealing of blocks, primarily for testing. Must be run with --dev
#[arg(long, requires = "dev")]
pub manual_seal: bool,
}

#[derive(Debug, clap::Subcommand)]
Expand Down
10 changes: 7 additions & 3 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder},
chain_spec,
cli::{Cli, Subcommand},
service,
service, test_service,
};
use dscp_node_runtime::{Block, EXISTENTIAL_DEPOSIT};
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
Expand Down Expand Up @@ -186,8 +186,12 @@ pub fn run() -> sc_cli::Result<()> {
.map_err(|lang_err| sc_cli::Error::Application(Box::new(lang_err))),
None => {
let runner = cli.create_runner(&cli.run)?;
runner
.run_node_until_exit(|config| async move { service::new_full(config).map_err(sc_cli::Error::Service) })
runner.run_node_until_exit(|config| async move {
match cli.manual_seal {
true => test_service::new_test(config).map_err(sc_cli::Error::Service),
false => service::new_full(config).map_err(sc_cli::Error::Service),
}
})
}
}
}
6 changes: 3 additions & 3 deletions node/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod chain_spec;
#[macro_use]
mod service;
mod benchmarking;
mod chain_spec;
mod cli;
mod command;
mod rpc;
mod service;
mod test_service;

fn main() -> sc_cli::Result<()> {
command::run()
Expand Down
45 changes: 44 additions & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::sync::Arc;

use futures::channel::mpsc::Sender;
use jsonrpsee::RpcModule;
use sc_consensus_babe::BabeWorkerHandle;
use sc_consensus_manual_seal::{rpc::ManualSeal, rpc::ManualSealApiServer, EngineCommand};
pub use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
Expand All @@ -10,7 +12,7 @@ use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi;

use dscp_node_runtime::{opaque::Block, AccountId, Balance, Index};
use dscp_node_runtime::{opaque::Block, AccountId, Balance, Hash, Index};
use sp_keystore::KeystorePtr;

/// Extra dependencies for BABE.
Expand Down Expand Up @@ -74,3 +76,44 @@ where

Ok(module)
}

/// Full client dependencies.
pub struct TestDeps<C, P> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
/// A command stream to send authoring commands to manual seal consensus engine
pub command_sink: Sender<EngineCommand<Hash>>,
}

// Instantiate all full RPC extensions.
pub fn create_test<C, P>(deps: TestDeps<C, P>) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};

let mut module = RpcModule::new(());
let TestDeps {
client,
pool,
deny_unsafe,
command_sink,
} = deps;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(ManualSeal::new(command_sink).into_rpc())?;

Ok(module)
}
Loading