mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 20:59: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:
@@ -12,7 +12,7 @@ use sc_consensus::{BlockCheckParams, BlockImportParams, ImportResult, BlockImpor
|
||||
|
||||
use sc_client_api::{Backend, Finalizer};
|
||||
|
||||
use crate::tendermint::TendermintImport;
|
||||
use crate::{tendermint::TendermintImport, Announce};
|
||||
|
||||
#[async_trait]
|
||||
impl<
|
||||
@@ -22,7 +22,8 @@ impl<
|
||||
I: Send + Sync + BlockImport<B, Transaction = TransactionFor<C, B>> + 'static,
|
||||
CIDP: CreateInherentDataProviders<B, ()> + 'static,
|
||||
E: Send + Sync + Environment<B> + 'static,
|
||||
> BlockImport<B> for TendermintImport<B, Be, C, I, CIDP, E>
|
||||
A: Announce<B>,
|
||||
> BlockImport<B> for TendermintImport<B, Be, C, I, CIDP, E, A>
|
||||
where
|
||||
I::Error: Into<Error>,
|
||||
TransactionFor<C, B>: Send + Sync + 'static,
|
||||
|
||||
@@ -21,7 +21,7 @@ use substrate_prometheus_endpoint::Registry;
|
||||
|
||||
use tendermint_machine::{ext::BlockNumber, TendermintMachine};
|
||||
|
||||
use crate::tendermint::TendermintImport;
|
||||
use crate::{tendermint::TendermintImport, Announce};
|
||||
|
||||
pub type TendermintImportQueue<Block, Transaction> = BasicQueue<Block, Transaction>;
|
||||
|
||||
@@ -78,9 +78,11 @@ pub fn import_queue<
|
||||
I: Send + Sync + BlockImport<B, Transaction = TransactionFor<C, B>> + 'static,
|
||||
CIDP: CreateInherentDataProviders<B, ()> + 'static,
|
||||
E: Send + Sync + Environment<B> + 'static,
|
||||
A: Announce<B>,
|
||||
>(
|
||||
client: Arc<C>,
|
||||
inner: I,
|
||||
announce: A,
|
||||
providers: Arc<CIDP>,
|
||||
env: E,
|
||||
spawner: &impl sp_core::traits::SpawnEssentialNamed,
|
||||
@@ -90,7 +92,7 @@ where
|
||||
I::Error: Into<Error>,
|
||||
TransactionFor<C, B>: Send + Sync + 'static,
|
||||
{
|
||||
let import = TendermintImport::new(client, inner, providers, env);
|
||||
let import = TendermintImport::new(client, inner, announce, providers, env);
|
||||
|
||||
let authority = {
|
||||
let machine_clone = import.machine.clone();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::{sync::Arc, future::Future};
|
||||
|
||||
use sp_runtime::traits::Block as BlockTrait;
|
||||
use sp_api::TransactionFor;
|
||||
|
||||
use sc_executor::{NativeVersion, NativeExecutionDispatch, NativeElseWasmExecutor};
|
||||
@@ -43,15 +44,21 @@ impl NativeExecutionDispatch for ExecutorDispatch {
|
||||
|
||||
pub type FullClient = TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
||||
|
||||
pub fn import_queue(
|
||||
pub trait Announce<B: BlockTrait>: Send + Sync + Clone + 'static {
|
||||
fn announce(&self, hash: B::Hash);
|
||||
}
|
||||
|
||||
pub fn import_queue<A: Announce<Block>>(
|
||||
task_manager: &TaskManager,
|
||||
client: Arc<FullClient>,
|
||||
announce: A,
|
||||
pool: Arc<FullPool<Block, FullClient>>,
|
||||
registry: Option<&Registry>,
|
||||
) -> (impl Future<Output = ()>, TendermintImportQueue<Block, TransactionFor<FullClient, Block>>) {
|
||||
import_queue::import_queue(
|
||||
client.clone(),
|
||||
client.clone(),
|
||||
announce,
|
||||
Arc::new(|_, _| async { Ok(sp_timestamp::InherentDataProvider::from_system_time()) }),
|
||||
sc_basic_authorship::ProposerFactory::new(
|
||||
task_manager.spawn_handle(),
|
||||
|
||||
@@ -36,6 +36,7 @@ use crate::{
|
||||
signature_scheme::TendermintSigner,
|
||||
weights::TendermintWeights,
|
||||
import_queue::{ImportFuture, TendermintImportQueue},
|
||||
Announce,
|
||||
};
|
||||
|
||||
pub(crate) struct TendermintImport<
|
||||
@@ -45,6 +46,7 @@ pub(crate) struct TendermintImport<
|
||||
I: Send + Sync + BlockImport<B, Transaction = TransactionFor<C, B>> + 'static,
|
||||
CIDP: CreateInherentDataProviders<B, ()> + 'static,
|
||||
E: Send + Sync + Environment<B> + 'static,
|
||||
A: Announce<B>,
|
||||
> where
|
||||
TransactionFor<C, B>: Send + Sync + 'static,
|
||||
{
|
||||
@@ -56,6 +58,7 @@ pub(crate) struct TendermintImport<
|
||||
|
||||
pub(crate) client: Arc<C>,
|
||||
pub(crate) inner: Arc<AsyncRwLock<I>>,
|
||||
announce: A,
|
||||
providers: Arc<CIDP>,
|
||||
|
||||
env: Arc<AsyncRwLock<E>>,
|
||||
@@ -69,7 +72,8 @@ impl<
|
||||
I: Send + Sync + BlockImport<B, Transaction = TransactionFor<C, B>> + 'static,
|
||||
CIDP: CreateInherentDataProviders<B, ()> + 'static,
|
||||
E: Send + Sync + Environment<B> + 'static,
|
||||
> Clone for TendermintImport<B, Be, C, I, CIDP, E>
|
||||
A: Announce<B>,
|
||||
> Clone for TendermintImport<B, Be, C, I, CIDP, E, A>
|
||||
where
|
||||
TransactionFor<C, B>: Send + Sync + 'static,
|
||||
{
|
||||
@@ -83,6 +87,7 @@ where
|
||||
|
||||
client: self.client.clone(),
|
||||
inner: self.inner.clone(),
|
||||
announce: self.announce.clone(),
|
||||
providers: self.providers.clone(),
|
||||
|
||||
env: self.env.clone(),
|
||||
@@ -98,16 +103,18 @@ impl<
|
||||
I: Send + Sync + BlockImport<B, Transaction = TransactionFor<C, B>> + 'static,
|
||||
CIDP: CreateInherentDataProviders<B, ()> + 'static,
|
||||
E: Send + Sync + Environment<B> + 'static,
|
||||
> TendermintImport<B, Be, C, I, CIDP, E>
|
||||
A: Announce<B>,
|
||||
> TendermintImport<B, Be, C, I, CIDP, E, A>
|
||||
where
|
||||
TransactionFor<C, B>: Send + Sync + 'static,
|
||||
{
|
||||
pub(crate) fn new(
|
||||
client: Arc<C>,
|
||||
inner: I,
|
||||
announce: A,
|
||||
providers: Arc<CIDP>,
|
||||
env: E,
|
||||
) -> TendermintImport<B, Be, C, I, CIDP, E> {
|
||||
) -> TendermintImport<B, Be, C, I, CIDP, E, A> {
|
||||
TendermintImport {
|
||||
_block: PhantomData,
|
||||
_backend: PhantomData,
|
||||
@@ -117,6 +124,7 @@ where
|
||||
|
||||
client,
|
||||
inner: Arc::new(AsyncRwLock::new(inner)),
|
||||
announce,
|
||||
providers,
|
||||
|
||||
env: Arc::new(AsyncRwLock::new(env)),
|
||||
@@ -281,7 +289,8 @@ impl<
|
||||
I: Send + Sync + BlockImport<B, Transaction = TransactionFor<C, B>> + 'static,
|
||||
CIDP: CreateInherentDataProviders<B, ()> + 'static,
|
||||
E: Send + Sync + Environment<B> + 'static,
|
||||
> Network for TendermintImport<B, Be, C, I, CIDP, E>
|
||||
A: Announce<B>,
|
||||
> Network for TendermintImport<B, Be, C, I, CIDP, E, A>
|
||||
where
|
||||
TransactionFor<C, B>: Send + Sync + 'static,
|
||||
{
|
||||
@@ -361,6 +370,7 @@ where
|
||||
.finalize_block(BlockId::Hash(hash), Some(justification), true)
|
||||
.map_err(|_| Error::InvalidJustification)
|
||||
.unwrap();
|
||||
self.announce.announce(hash);
|
||||
|
||||
self.get_proposal(block.header()).await
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use sc_consensus::{BlockImportParams, Verifier, BlockImport};
|
||||
|
||||
use sc_client_api::{Backend, Finalizer};
|
||||
|
||||
use crate::tendermint::TendermintImport;
|
||||
use crate::{tendermint::TendermintImport, Announce};
|
||||
|
||||
#[async_trait]
|
||||
impl<
|
||||
@@ -20,7 +20,8 @@ impl<
|
||||
I: Send + Sync + BlockImport<B, Transaction = TransactionFor<C, B>> + 'static,
|
||||
CIDP: CreateInherentDataProviders<B, ()> + 'static,
|
||||
E: Send + Sync + Environment<B> + 'static,
|
||||
> Verifier<B> for TendermintImport<B, Be, C, I, CIDP, E>
|
||||
A: Announce<B>,
|
||||
> Verifier<B> for TendermintImport<B, Be, C, I, CIDP, E, A>
|
||||
where
|
||||
TransactionFor<C, B>: Send + Sync + 'static,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user