mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
Don't import justifications multiple times
Also don't broadcast blocks which were solely proposed.
This commit is contained in:
@@ -36,9 +36,9 @@ where
|
|||||||
async fn import_justification(
|
async fn import_justification(
|
||||||
&mut self,
|
&mut self,
|
||||||
hash: B::Hash,
|
hash: B::Hash,
|
||||||
_: <B::Header as Header>::Number,
|
number: <B::Header as Header>::Number,
|
||||||
justification: Justification,
|
justification: Justification,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.import_justification_actual(hash, justification)
|
self.import_justification_actual(number, hash, justification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
|
cmp::Ordering,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -274,9 +275,23 @@ where
|
|||||||
|
|
||||||
pub(crate) fn import_justification_actual(
|
pub(crate) fn import_justification_actual(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
number: <B::Header as Header>::Number,
|
||||||
hash: B::Hash,
|
hash: B::Hash,
|
||||||
justification: Justification,
|
justification: Justification,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
let info = self.client.info();
|
||||||
|
match info.best_number.cmp(&number) {
|
||||||
|
Ordering::Greater => return Ok(()),
|
||||||
|
Ordering::Equal => {
|
||||||
|
if info.best_hash == hash {
|
||||||
|
return Ok(());
|
||||||
|
} else {
|
||||||
|
Err(Error::InvalidJustification)?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ordering::Less => (),
|
||||||
|
}
|
||||||
|
|
||||||
self.verify_justification(hash, &justification)?;
|
self.verify_justification(hash, &justification)?;
|
||||||
self
|
self
|
||||||
.client
|
.client
|
||||||
@@ -337,7 +352,10 @@ where
|
|||||||
let (header, body) = block.clone().deconstruct();
|
let (header, body) = block.clone().deconstruct();
|
||||||
*self.importing_block.write().unwrap() = Some(hash);
|
*self.importing_block.write().unwrap() = Some(hash);
|
||||||
self.queue.write().await.as_mut().unwrap().import_blocks(
|
self.queue.write().await.as_mut().unwrap().import_blocks(
|
||||||
BlockOrigin::NetworkBroadcast,
|
// We do not want this block, which hasn't been confirmed, to be broadcast over the net
|
||||||
|
// Substrate will generate notifications unless it's Genesis, which this isn't, InitialSync,
|
||||||
|
// which changes telemtry behavior, or File, which is... close enough
|
||||||
|
BlockOrigin::File,
|
||||||
vec![IncomingBlock {
|
vec![IncomingBlock {
|
||||||
hash,
|
hash,
|
||||||
header: Some(header),
|
header: Some(header),
|
||||||
@@ -361,7 +379,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn add_block(&mut self, block: B, commit: Commit<TendermintSigner>) -> B {
|
async fn add_block(&mut self, block: B, commit: Commit<TendermintSigner>) -> B {
|
||||||
self.import_justification_actual(block.hash(), (CONSENSUS_ID, commit.encode())).unwrap();
|
self
|
||||||
|
.import_justification_actual(
|
||||||
|
*block.header().number(),
|
||||||
|
block.hash(),
|
||||||
|
(CONSENSUS_ID, commit.encode()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
self.get_proposal(block.header()).await
|
self.get_proposal(block.header()).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user