Skip to content
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
9 changes: 9 additions & 0 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions cumulus/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ pub struct BuildNetworkParams<
pub spawn_handle: SpawnTaskHandle,
pub import_queue: IQ,
pub sybil_resistance_level: CollatorSybilResistance,
pub metrics: sc_network::NotificationMetrics,
}

/// Build the network service, the network status sinks and an RPC sender.
Expand All @@ -475,6 +476,7 @@ pub async fn build_network<'a, Block, Client, RCInterface, IQ, Network>(
relay_chain_interface,
import_queue,
sybil_resistance_level,
metrics,
}: BuildNetworkParams<'a, Block, Client, Network, RCInterface, IQ>,
) -> sc_service::error::Result<(
Arc<dyn NetworkService>,
Expand Down Expand Up @@ -533,9 +535,6 @@ where
Box::new(block_announce_validator) as Box<_>
},
};
let metrics = Network::register_notification_metrics(
parachain_config.prometheus_config.as_ref().map(|config| &config.registry),
);

sc_service::build_network(sc_service::BuildNetworkParams {
config: parachain_config,
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/people/people-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sp-keyring = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
sp-statement-store = { workspace = true }
sp-storage = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }
Expand Down Expand Up @@ -141,6 +142,7 @@ std = [
"sp-offchain/std",
"sp-runtime/std",
"sp-session/std",
"sp-statement-store/std",
"sp-storage/std",
"sp-transaction-pool/std",
"sp-version/std",
Expand Down
37 changes: 37 additions & 0 deletions cumulus/parachains/runtimes/people/people-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ use sp_runtime::{
ApplyExtrinsicResult,
};
pub use sp_runtime::{MultiAddress, Perbill, Permill, RuntimeDebug};
use sp_statement_store::{
runtime_api::{InvalidStatement, StatementSource, ValidStatement},
SignatureVerificationResult, Statement,
};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
Expand Down Expand Up @@ -1128,6 +1132,39 @@ impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl sp_statement_store::runtime_api::ValidateStatement<Block> for Runtime {
fn validate_statement(
_source: StatementSource,
statement: Statement,
) -> Result<ValidStatement, InvalidStatement> {
let account = match statement.verify_signature() {
SignatureVerificationResult::Valid(account) => account.into(),
SignatureVerificationResult::Invalid => {
log::debug!("Bad statement signature.");
return Err(InvalidStatement::BadProof)
},
SignatureVerificationResult::NoSignature => {
log::debug!("Missing statement signature.");
return Err(InvalidStatement::NoProof)
},
};

// For now just allow validators to store some statements.
// In the future we will allow people.
if pallet_session::Validators::<Runtime>::get().contains(&account) {
Ok(ValidStatement {
max_count: 2,
max_size: 1024,
})
} else {
Ok(ValidStatement {
max_count: 0,
max_size: 0,
})
}
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
5 changes: 5 additions & 0 deletions cumulus/polkadot-omni-node/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ sc-client-db = { workspace = true, default-features = true }
sc-consensus = { workspace = true, default-features = true }
sc-consensus-manual-seal = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true }
sc-keystore = { workspace = true, default-features = true }
sc-network = { workspace = true, default-features = true }
sc-network-statement = { workspace = true, default-features = true }
sc-network-sync = { workspace = true, default-features = true }
sc-offchain = { workspace = true, default-features = true }
sc-rpc = { workspace = true, default-features = true }
sc-runtime-utilities = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = false }
sc-statement-store = { workspace = true, default-features = true }
sc-sysinfo = { workspace = true, default-features = true }
sc-telemetry = { workspace = true, default-features = true }
sc-tracing = { workspace = true, default-features = true }
Expand All @@ -71,6 +75,7 @@ sp-keystore = { workspace = true, default-features = true }
sp-offchain = { workspace = true, default-features = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true, default-features = true }
sp-statement-store = { workspace = true, default-features = true }
sp-storage = { workspace = true, default-features = true }
sp-timestamp = { workspace = true, default-features = true }
sp-transaction-pool = { workspace = true, default-features = true }
Expand Down
8 changes: 8 additions & 0 deletions cumulus/polkadot-omni-node/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ pub struct Cli<Config: CliConfig> {
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,

/// Enable the statement store.
///
/// The statement store is a store for statements validated using the runtime API
/// `validate_statement`. It should be enabled for chains that provide this runtime API.
#[arg(long)]
pub enable_statement_store: bool,

#[arg(skip)]
pub(crate) _phantom: PhantomData<Config>,
}
Expand Down Expand Up @@ -232,6 +239,7 @@ impl<Config: CliConfig> Cli<Config> {
.unwrap_or(self.authoring),
export_pov: self.export_pov_to_path.clone(),
max_pov_percentage: self.run.experimental_max_pov_percentage,
enable_statement_store: self.enable_statement_store,
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions cumulus/polkadot-omni-node/lib/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod command;
pub mod rpc;
pub mod runtime;
pub mod spec;
pub(crate) mod statement_store;
pub mod types;

use crate::cli::AuthoringPolicy;
Expand All @@ -38,6 +39,7 @@ use sp_runtime::{
OpaqueExtrinsic,
};
use sp_session::SessionKeys;
use sp_statement_store::runtime_api::ValidateStatement;
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use std::{fmt::Debug, path::PathBuf, str::FromStr};

Expand Down Expand Up @@ -70,6 +72,7 @@ pub trait NodeRuntimeApi<Block: BlockT>:
+ OffchainWorkerApi<Block>
+ CollectCollationInfo<Block>
+ GetCoreSelectorApi<Block>
+ ValidateStatement<Block>
+ RelayParentOffsetApi<Block>
+ Sized
{
Expand All @@ -85,6 +88,7 @@ impl<T, Block: BlockT> NodeRuntimeApi<Block> for T where
+ GetCoreSelectorApi<Block>
+ RelayParentOffsetApi<Block>
+ CollectCollationInfo<Block>
+ ValidateStatement<Block>
{
}

Expand Down Expand Up @@ -118,4 +122,7 @@ pub struct NodeExtraArgs {
/// The maximum percentage of the maximum PoV size that the collator can use.
/// It will be removed once <https://github.com/paritytech/polkadot-sdk/issues/6020> is fixed.
pub max_pov_percentage: Option<u32>,

/// If true then the statement store will be enabled.
pub enable_statement_store: bool,
}
13 changes: 11 additions & 2 deletions cumulus/polkadot-omni-node/lib/src/common/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use crate::common::{
ConstructNodeRuntimeApi,
};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_rpc::dev::{Dev, DevApiServer};
use sc_rpc::{
dev::{Dev, DevApiServer},
statement::{StatementApiServer, StatementStore},
};
use sp_runtime::traits::Block as BlockT;
use std::{marker::PhantomData, sync::Arc};
use substrate_frame_rpc_system::{System, SystemApiServer};
Expand All @@ -32,11 +35,12 @@ use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer
/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpsee::RpcModule<()>;

pub(crate) trait BuildRpcExtensions<Client, Backend, Pool> {
pub(crate) trait BuildRpcExtensions<Client, Backend, Pool, StatementStore> {
fn build_rpc_extensions(
client: Arc<Client>,
backend: Arc<Backend>,
pool: Arc<Pool>,
statement_store: Option<Arc<StatementStore>>,
) -> sc_service::error::Result<RpcExtension>;
}

Expand All @@ -47,6 +51,7 @@ impl<Block: BlockT, RuntimeApi>
ParachainClient<Block, RuntimeApi>,
ParachainBackend<Block>,
sc_transaction_pool::TransactionPoolHandle<Block, ParachainClient<Block, RuntimeApi>>,
sc_statement_store::Store,
> for BuildParachainRpcExtensions<Block, RuntimeApi>
where
RuntimeApi:
Expand All @@ -60,13 +65,17 @@ where
pool: Arc<
sc_transaction_pool::TransactionPoolHandle<Block, ParachainClient<Block, RuntimeApi>>,
>,
statement_store: Option<Arc<sc_statement_store::Store>>,
) -> sc_service::error::Result<RpcExtension> {
let build = || -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>> {
let mut module = RpcExtension::new(());

module.merge(System::new(client.clone(), pool).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(StateMigration::new(client.clone(), backend).into_rpc())?;
if let Some(statement_store) = statement_store {
module.merge(StatementStore::new(statement_store).into_rpc())?;
}
module.merge(Dev::new(client).into_rpc())?;

Ok(module)
Expand Down
44 changes: 42 additions & 2 deletions cumulus/polkadot-omni-node/lib/src/common/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use crate::common::{
command::NodeCommandRunner,
rpc::BuildRpcExtensions,
statement_store::{build_statement_store, new_statement_handler_proto},
types::{
ParachainBackend, ParachainBlockImport, ParachainClient, ParachainHostFunctions,
ParachainService,
Expand All @@ -40,6 +41,7 @@ use sc_consensus::DefaultImportQueue;
use sc_executor::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY};
use sc_network::{config::FullNetworkConfiguration, NetworkBackend, NetworkBlock};
use sc_service::{Configuration, ImportQueue, PartialComponents, TaskManager};
use sc_statement_store::Store;
use sc_sysinfo::HwBench;
use sc_telemetry::{TelemetryHandle, TelemetryWorker};
use sc_tracing::tracing::Instrument;
Expand Down Expand Up @@ -239,6 +241,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
ParachainClient<Self::Block, Self::RuntimeApi>,
ParachainBackend<Self::Block>,
TransactionPoolHandle<Self::Block, ParachainClient<Self::Block, Self::RuntimeApi>>,
Store,
>;

type StartConsensus: StartConsensus<
Expand Down Expand Up @@ -292,11 +295,19 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
let prometheus_registry = parachain_config.prometheus_registry().cloned();
let transaction_pool = params.transaction_pool.clone();
let import_queue_service = params.import_queue.service();
let net_config = FullNetworkConfiguration::<_, _, Net>::new(
let mut net_config = FullNetworkConfiguration::<_, _, Net>::new(
&parachain_config.network,
prometheus_registry.clone(),
);

let metrics = Net::register_notification_metrics(
parachain_config.prometheus_config.as_ref().map(|config| &config.registry),
);

let statement_handler_proto = node_extra_args.enable_statement_store.then(|| {
new_statement_handler_proto(&*client, &parachain_config, &metrics, &mut net_config)
});

let (network, system_rpc_tx, tx_handler_controller, sync_service) =
build_network(BuildNetworkParams {
parachain_config: &parachain_config,
Expand All @@ -308,10 +319,37 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
relay_chain_interface: relay_chain_interface.clone(),
import_queue: params.import_queue,
sybil_resistance_level: Self::SYBIL_RESISTANCE,
metrics,
})
.await?;

let statement_store = statement_handler_proto
.map(|statement_handler_proto| {
build_statement_store(
&parachain_config,
&mut task_manager,
client.clone(),
network.clone(),
sync_service.clone(),
params.keystore_container.local_keystore(),
statement_handler_proto,
)
})
.transpose()?;

if parachain_config.offchain_worker.enabled {
let custom_extensions = {
let statement_store = statement_store.clone();
move |_hash| {
if let Some(statement_store) = &statement_store {
vec![Box::new(statement_store.clone().as_statement_store_ext())
as Box<_>]
} else {
vec![]
}
}
};

let offchain_workers =
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
runtime_api_provider: client.clone(),
Expand All @@ -323,7 +361,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
network_provider: Arc::new(network.clone()),
is_validator: parachain_config.role.is_authority(),
enable_http_requests: true,
custom_extensions: move |_| vec![],
custom_extensions,
})?;
task_manager.spawn_handle().spawn(
"offchain-workers-runner",
Expand All @@ -336,12 +374,14 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
let client = client.clone();
let transaction_pool = transaction_pool.clone();
let backend_for_rpc = backend.clone();
let statement_store = statement_store.clone();

Box::new(move |_| {
Self::BuildRpcExtensions::build_rpc_extensions(
client.clone(),
backend_for_rpc.clone(),
transaction_pool.clone(),
statement_store.clone(),
)
})
};
Expand Down
Loading
Loading