mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user