mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-24 11:36:18 +00:00
Don't import justifications multiple times
Also don't broadcast blocks which were solely proposed.
This commit is contained in:
parent
9b0dca06d0
commit
4206ed3b18
2 changed files with 28 additions and 4 deletions
|
@ -36,9 +36,9 @@ where
|
|||
async fn import_justification(
|
||||
&mut self,
|
||||
hash: B::Hash,
|
||||
_: <B::Header as Header>::Number,
|
||||
number: <B::Header as Header>::Number,
|
||||
justification: Justification,
|
||||
) -> Result<(), Error> {
|
||||
self.import_justification_actual(hash, justification)
|
||||
self.import_justification_actual(number, hash, justification)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
marker::PhantomData,
|
||||
sync::{Arc, RwLock},
|
||||
cmp::Ordering,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
|
@ -274,9 +275,23 @@ where
|
|||
|
||||
pub(crate) fn import_justification_actual(
|
||||
&mut self,
|
||||
number: <B::Header as Header>::Number,
|
||||
hash: B::Hash,
|
||||
justification: Justification,
|
||||
) -> 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
|
||||
.client
|
||||
|
@ -337,7 +352,10 @@ where
|
|||
let (header, body) = block.clone().deconstruct();
|
||||
*self.importing_block.write().unwrap() = Some(hash);
|
||||
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 {
|
||||
hash,
|
||||
header: Some(header),
|
||||
|
@ -361,7 +379,13 @@ where
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue