Skip to content

Commit

Permalink
feat: update node for v0.9.40 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshvarma committed May 31, 2023
1 parent 358e69d commit b4ea96a
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 69 deletions.
1 change: 1 addition & 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 @@ -81,6 +81,7 @@ sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch =
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sc-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sc-network-sync = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
Expand Down
3 changes: 2 additions & 1 deletion bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ sc-client-db = { workspace = true }
sc-consensus = { workspace = true }
sc-consensus-aura = { workspace = true }
sc-consensus-babe = { workspace = true }
sc-consensus-grandpa = { workspace = true }
sc-executor = { workspace = true }
sc-finality-grandpa = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
sc-offchain = { workspace = true }
sc-rpc = { workspace = true }
sc-service = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions bin/collator/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ pub fn run() -> Result<()> {
parachain::build_import_queue,
)?;
let aux_revert = Box::new(|client, _, blocks| {
sc_finality_grandpa::revert(client, blocks)?;
sc_consensus_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
Expand All @@ -433,7 +433,7 @@ pub fn run() -> Result<()> {
parachain::build_import_queue,
)?;
let aux_revert = Box::new(|client, _, blocks| {
sc_finality_grandpa::revert(client, blocks)?;
sc_consensus_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
Expand All @@ -450,7 +450,7 @@ pub fn run() -> Result<()> {
parachain::build_import_queue,
)?;
let aux_revert = Box::new(|client, _, blocks| {
sc_finality_grandpa::revert(client, blocks)?;
sc_consensus_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
Expand Down
84 changes: 61 additions & 23 deletions bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
use futures::StreamExt;
use sc_client_api::{BlockBackend, BlockchainEvents};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
use sc_consensus_grandpa::SharedVoterState;
use sc_executor::NativeElseWasmExecutor;
use sc_finality_grandpa::SharedVoterState;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
Expand Down Expand Up @@ -69,15 +69,15 @@ pub fn new_partial(
(
FrontierBlockImport<
Block,
sc_finality_grandpa::GrandpaBlockImport<
sc_consensus_grandpa::GrandpaBlockImport<
FullBackend,
Block,
FullClient,
FullSelectChain,
>,
FullClient,
>,
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
sc_consensus_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
Option<Telemetry>,
Arc<fc_db::Backend<Block>>,
),
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn new_partial(
task_manager.spawn_essential_handle(),
client.clone(),
);
let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import(
let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import(
client.clone(),
&(client.clone() as Arc<_>),
select_chain.clone(),
Expand Down Expand Up @@ -200,7 +200,7 @@ pub fn start_node(
other: (block_import, grandpa_link, mut telemetry, frontier_backend),
} = new_partial(&config)?;

let protocol_name = sc_finality_grandpa::protocol_standard_name(
let protocol_name = sc_consensus_grandpa::protocol_standard_name(
&client
.block_hash(0)
.ok()
Expand All @@ -209,7 +209,7 @@ pub fn start_node(
&config.chain_spec,
);

let (network, system_rpc_tx, tx_handler_controller, network_starter) =
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand All @@ -233,6 +233,15 @@ pub fn start_node(
let fee_history_cache: FeeHistoryCache = Arc::new(std::sync::Mutex::new(BTreeMap::new()));
let overrides = fc_storage::overrides_handle(client.clone());

// Sinks for pubsub notifications.
// Everytime a new subscription is created, a new mpsc channel is added to the sink pool.
// The MappingSyncWorker sends through the channel on block import and the subscription emits a notification to the subscriber on receiving a message through this channel.
// This way we avoid race conditions when using native substrate block import notification stream.
let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
> = Default::default();
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);

let ethapi_cmd = evm_tracing_config.ethapi.clone();
let tracing_requesters =
if ethapi_cmd.contains(&EthApiCmd::Debug) || ethapi_cmd.contains(&EthApiCmd::Trace) {
Expand Down Expand Up @@ -269,6 +278,8 @@ pub fn start_node(
3,
0,
fc_mapping_sync::SyncStrategy::Parachain,
sync_service.clone(),
pubsub_notification_sinks.clone(),
)
.for_each(|()| futures::future::ready(())),
);
Expand Down Expand Up @@ -323,13 +334,16 @@ pub fn start_node(
trace_filter_max_count: evm_tracing_config.ethapi_trace_max_count,
enable_txpool: ethapi_cmd.contains(&EthApiCmd::TxPool),
};
let sync = sync_service.clone();
let pubsub_notification_sinks = pubsub_notification_sinks.clone();

Box::new(move |deny_unsafe, subscription| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
graph: transaction_pool.pool().clone(),
network: network.clone(),
sync: sync.clone(),
is_authority,
deny_unsafe,
frontier_backend: frontier_backend.clone(),
Expand All @@ -341,8 +355,13 @@ pub fn start_node(
enable_evm_rpc: true, // enable EVM RPC for dev node by default
};

crate::rpc::create_full(deps, subscription, rpc_config.clone())
.map_err::<ServiceError, _>(Into::into)
crate::rpc::create_full(
deps,
subscription,
pubsub_notification_sinks.clone(),
rpc_config.clone(),
)
.map_err::<ServiceError, _>(Into::into)
})
};

Expand All @@ -356,6 +375,7 @@ pub fn start_node(
backend,
system_rpc_tx,
tx_handler_controller,
sync_service: sync_service.clone(),
config,
telemetry: telemetry.as_mut(),
})?;
Expand Down Expand Up @@ -392,8 +412,8 @@ pub fn start_node(
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
sync_oracle: network.clone(),
justification_sync_link: network.clone(),
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
max_block_proposal_slot_portion: None,
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand All @@ -416,7 +436,7 @@ pub fn start_node(
None
};

let grandpa_config = sc_finality_grandpa::Config {
let grandpa_config = sc_consensus_grandpa::Config {
// FIXME #1578 make this available through chainspec
gossip_duration: Duration::from_millis(333),
justification_period: 512,
Expand All @@ -435,11 +455,12 @@ pub fn start_node(
// and vote data availability than the observer. The observer has not
// been tested extensively yet and having most nodes in a network run it
// could lead to finality stalls.
let grandpa_config = sc_finality_grandpa::GrandpaParams {
let grandpa_config = sc_consensus_grandpa::GrandpaParams {
config: grandpa_config,
link: grandpa_link,
network,
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
sync: sync_service,
voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state: SharedVoterState::empty(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand All @@ -450,7 +471,7 @@ pub fn start_node(
task_manager.spawn_essential_handle().spawn_blocking(
"grandpa-voter",
None,
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?,
sc_consensus_grandpa::run_grandpa_voter(grandpa_config)?,
);
}

Expand All @@ -472,7 +493,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
other: (block_import, grandpa_link, mut telemetry, frontier_backend),
} = new_partial(&config)?;

let protocol_name = sc_finality_grandpa::protocol_standard_name(
let protocol_name = sc_consensus_grandpa::protocol_standard_name(
&client
.block_hash(0)
.ok()
Expand All @@ -481,7 +502,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
&config.chain_spec,
);

let (network, system_rpc_tx, tx_handler_controller, network_starter) =
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand All @@ -505,6 +526,15 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
let fee_history_cache: FeeHistoryCache = Arc::new(std::sync::Mutex::new(BTreeMap::new()));
let overrides = fc_storage::overrides_handle(client.clone());

// Sinks for pubsub notifications.
// Everytime a new subscription is created, a new mpsc channel is added to the sink pool.
// The MappingSyncWorker sends through the channel on block import and the subscription emits a notification to the subscriber on receiving a message through this channel.
// This way we avoid race conditions when using native substrate block import notification stream.
let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
> = Default::default();
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);

// Frontier offchain DB task. Essential.
// Maps emulated ethereum data to substrate native data.
task_manager.spawn_essential_handle().spawn(
Expand All @@ -520,6 +550,8 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
3,
0,
fc_mapping_sync::SyncStrategy::Parachain,
sync_service.clone(),
pubsub_notification_sinks.clone(),
)
.for_each(|()| futures::future::ready(())),
);
Expand Down Expand Up @@ -568,14 +600,17 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
let rpc_extensions_builder = {
let client = client.clone();
let network = network.clone();
let sync = sync_service.clone();
let transaction_pool = transaction_pool.clone();
let pubsub_notification_sinks = pubsub_notification_sinks.clone();

Box::new(move |deny_unsafe, subscription| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
graph: transaction_pool.pool().clone(),
network: network.clone(),
sync: sync.clone(),
is_authority,
deny_unsafe,
frontier_backend: frontier_backend.clone(),
Expand All @@ -587,7 +622,8 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
enable_evm_rpc: true, // enable EVM RPC for dev node by default
};

crate::rpc::create_full(deps, subscription).map_err::<ServiceError, _>(Into::into)
crate::rpc::create_full(deps, subscription, pubsub_notification_sinks.clone())
.map_err::<ServiceError, _>(Into::into)
})
};

Expand All @@ -601,6 +637,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
backend,
system_rpc_tx,
tx_handler_controller,
sync_service: sync_service.clone(),
config,
telemetry: telemetry.as_mut(),
})?;
Expand Down Expand Up @@ -637,8 +674,8 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
sync_oracle: network.clone(),
justification_sync_link: network.clone(),
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
max_block_proposal_slot_portion: None,
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand All @@ -661,7 +698,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
None
};

let grandpa_config = sc_finality_grandpa::Config {
let grandpa_config = sc_consensus_grandpa::Config {
// FIXME #1578 make this available through chainspec
gossip_duration: Duration::from_millis(333),
justification_period: 512,
Expand All @@ -680,11 +717,12 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
// and vote data availability than the observer. The observer has not
// been tested extensively yet and having most nodes in a network run it
// could lead to finality stalls.
let grandpa_config = sc_finality_grandpa::GrandpaParams {
let grandpa_config = sc_consensus_grandpa::GrandpaParams {
config: grandpa_config,
link: grandpa_link,
network,
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
sync: Arc::new(sync_service),
voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state: SharedVoterState::empty(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand All @@ -695,7 +733,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
task_manager.spawn_essential_handle().spawn_blocking(
"grandpa-voter",
None,
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?,
sc_consensus_grandpa::run_grandpa_voter(grandpa_config)?,
);
}

Expand Down
Loading

0 comments on commit b4ea96a

Please sign in to comment.