mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Don't broadcast added blocks
Online validators should inherently have them. Offline validators will receive from the sync protocol. This does somewhat eliminate the class of nodes who would follow the blockchain (without validating it), yet that's fine for the performance benefit.
This commit is contained in:
parent
fea16df567
commit
bcc88c3e86
2 changed files with 4 additions and 25 deletions
|
@ -59,8 +59,7 @@ pub const ACCOUNT_MEMPOOL_LIMIT: u32 = 50;
|
||||||
pub const BLOCK_SIZE_LIMIT: usize = 3_001_000;
|
pub const BLOCK_SIZE_LIMIT: usize = 3_001_000;
|
||||||
|
|
||||||
pub(crate) const TENDERMINT_MESSAGE: u8 = 0;
|
pub(crate) const TENDERMINT_MESSAGE: u8 = 0;
|
||||||
pub(crate) const BLOCK_MESSAGE: u8 = 1;
|
pub(crate) const TRANSACTION_MESSAGE: u8 = 2; // TODO: Normalize to 1
|
||||||
pub(crate) const TRANSACTION_MESSAGE: u8 = 2;
|
|
||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
@ -336,9 +335,6 @@ impl<D: Db, T: TransactionTrait, P: P2p> Tributary<D, T, P> {
|
||||||
|
|
||||||
// Return true if the message should be rebroadcasted.
|
// Return true if the message should be rebroadcasted.
|
||||||
pub async fn handle_message(&self, msg: &[u8]) -> bool {
|
pub async fn handle_message(&self, msg: &[u8]) -> bool {
|
||||||
// Acquire the lock now to prevent sync_block from being run at the same time
|
|
||||||
let mut sync_block = self.synced_block_result.write().await;
|
|
||||||
|
|
||||||
match msg.first() {
|
match msg.first() {
|
||||||
Some(&TRANSACTION_MESSAGE) => {
|
Some(&TRANSACTION_MESSAGE) => {
|
||||||
let Ok(tx) = Transaction::read::<&[u8]>(&mut &msg[1 ..]) else {
|
let Ok(tx) = Transaction::read::<&[u8]>(&mut &msg[1 ..]) else {
|
||||||
|
@ -370,19 +366,6 @@ impl<D: Db, T: TransactionTrait, P: P2p> Tributary<D, T, P> {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(&BLOCK_MESSAGE) => {
|
|
||||||
let mut msg_ref = &msg[1 ..];
|
|
||||||
let Ok(block) = Block::<T>::read(&mut msg_ref) else {
|
|
||||||
log::error!("received invalid block message");
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
let commit = msg[(msg.len() - msg_ref.len()) ..].to_vec();
|
|
||||||
if self.sync_block_internal(block, commit, &mut sync_block).await {
|
|
||||||
log::debug!("synced block over p2p net instead of building the commit ourselves");
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ use tendermint::{
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
TENDERMINT_MESSAGE, TRANSACTION_MESSAGE, BLOCK_MESSAGE, ReadWrite,
|
TENDERMINT_MESSAGE, TRANSACTION_MESSAGE, ReadWrite,
|
||||||
transaction::Transaction as TransactionTrait, Transaction, BlockHeader, Block, BlockError,
|
transaction::Transaction as TransactionTrait, Transaction, BlockHeader, Block, BlockError,
|
||||||
Blockchain, P2p,
|
Blockchain, P2p,
|
||||||
};
|
};
|
||||||
|
@ -414,12 +414,7 @@ impl<D: Db, T: TransactionTrait, P: P2p> Network for TendermintNetwork<D, T, P>
|
||||||
);
|
);
|
||||||
match block_res {
|
match block_res {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
// If we successfully added this block, broadcast it
|
// If we successfully added this block, break
|
||||||
// TODO: Move this under the coordinator once we set up on new block notifications?
|
|
||||||
let mut msg = serialized_block.0;
|
|
||||||
msg.insert(0, BLOCK_MESSAGE);
|
|
||||||
msg.extend(encoded_commit);
|
|
||||||
self.p2p.broadcast(self.genesis, msg).await;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(BlockError::NonLocalProvided(hash)) => {
|
Err(BlockError::NonLocalProvided(hash)) => {
|
||||||
|
@ -428,6 +423,7 @@ impl<D: Db, T: TransactionTrait, P: P2p> Network for TendermintNetwork<D, T, P>
|
||||||
hex::encode(hash),
|
hex::encode(hash),
|
||||||
hex::encode(self.genesis)
|
hex::encode(self.genesis)
|
||||||
);
|
);
|
||||||
|
tokio::time::sleep(core::time::Duration::from_secs(5)).await;
|
||||||
}
|
}
|
||||||
_ => return invalid_block(),
|
_ => return invalid_block(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue