Announce blocks

By claiming File, they're not sent ovber the P2P network before they 
have a justification, as desired. Unfortunately, they never were. This 
works around that.
This commit is contained in:
Luke Parker
2022-10-22 07:36:13 -04:00
parent dee6993ac8
commit 8a682cd25c
8 changed files with 66 additions and 22 deletions

View File

@@ -1,11 +1,14 @@
use std::{sync::Arc, future::Future};
use std::{sync::{Arc, RwLock}, future::Future};
use sp_core::H256;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sc_executor::NativeElseWasmExecutor;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sc_network::{NetworkService, NetworkBlock};
use sc_telemetry::{Telemetry, TelemetryWorker};
use serai_runtime::{self, opaque::Block, RuntimeApi};
pub(crate) use serai_consensus::{ExecutorDispatch, FullClient};
pub(crate) use serai_consensus::{ExecutorDispatch, Announce, FullClient};
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = serai_consensus::TendermintSelectChain<Block, FullBackend>;
@@ -19,9 +22,24 @@ type PartialComponents = sc_service::PartialComponents<
Option<Telemetry>,
>;
#[derive(Clone)]
pub struct NetworkAnnounce(Arc<RwLock<Option<Arc<NetworkService<Block, H256>>>>>);
impl NetworkAnnounce {
fn new() -> NetworkAnnounce {
NetworkAnnounce(Arc::new(RwLock::new(None)))
}
}
impl Announce<Block> for NetworkAnnounce {
fn announce(&self, hash: H256) {
if let Some(network) = self.0.read().unwrap().as_ref() {
network.announce_block(hash, None);
}
}
}
pub fn new_partial(
config: &Configuration,
) -> Result<(impl Future<Output = ()>, PartialComponents), ServiceError> {
) -> Result<((NetworkAnnounce, impl Future<Output = ()>), PartialComponents), ServiceError> {
if config.keystore_remote.is_some() {
return Err(ServiceError::Other("Remote Keystores are not supported".to_string()));
}
@@ -65,9 +83,11 @@ pub fn new_partial(
client.clone(),
);
let announce = NetworkAnnounce::new();
let (authority, import_queue) = serai_consensus::import_queue(
&task_manager,
client.clone(),
announce.clone(),
transaction_pool.clone(),
config.prometheus_registry(),
);
@@ -75,7 +95,7 @@ pub fn new_partial(
let select_chain = serai_consensus::TendermintSelectChain::new(backend.clone());
Ok((
authority,
(announce, authority),
sc_service::PartialComponents {
client,
backend,
@@ -91,7 +111,7 @@ pub fn new_partial(
pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
let (
authority,
(announce, authority),
sc_service::PartialComponents {
client,
backend,
@@ -114,6 +134,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
block_announce_validator_builder: None,
warp_sync: None,
})?;
*announce.0.write().unwrap() = Some(network.clone());
if config.offchain_worker.enabled {
sc_service::build_offchain_workers(