From bcc88c3e866cff2a2b0a75fa3403ef022c3b0d4d Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 18 Apr 2024 01:42:40 -0400 Subject: [PATCH] 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. --- coordinator/tributary/src/lib.rs | 19 +------------------ coordinator/tributary/src/tendermint/mod.rs | 10 +++------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/coordinator/tributary/src/lib.rs b/coordinator/tributary/src/lib.rs index 99deb588..dcf38c68 100644 --- a/coordinator/tributary/src/lib.rs +++ b/coordinator/tributary/src/lib.rs @@ -59,8 +59,7 @@ pub const ACCOUNT_MEMPOOL_LIMIT: u32 = 50; pub const BLOCK_SIZE_LIMIT: usize = 3_001_000; pub(crate) const TENDERMINT_MESSAGE: u8 = 0; -pub(crate) const BLOCK_MESSAGE: u8 = 1; -pub(crate) const TRANSACTION_MESSAGE: u8 = 2; +pub(crate) const TRANSACTION_MESSAGE: u8 = 2; // TODO: Normalize to 1 #[allow(clippy::large_enum_variant)] #[derive(Clone, PartialEq, Eq, Debug)] @@ -336,9 +335,6 @@ impl Tributary { // Return true if the message should be rebroadcasted. 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() { Some(&TRANSACTION_MESSAGE) => { let Ok(tx) = Transaction::read::<&[u8]>(&mut &msg[1 ..]) else { @@ -370,19 +366,6 @@ impl Tributary { false } - Some(&BLOCK_MESSAGE) => { - let mut msg_ref = &msg[1 ..]; - let Ok(block) = Block::::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, } } diff --git a/coordinator/tributary/src/tendermint/mod.rs b/coordinator/tributary/src/tendermint/mod.rs index df8f7219..dc249a35 100644 --- a/coordinator/tributary/src/tendermint/mod.rs +++ b/coordinator/tributary/src/tendermint/mod.rs @@ -41,7 +41,7 @@ use tendermint::{ use tokio::sync::RwLock; use crate::{ - TENDERMINT_MESSAGE, TRANSACTION_MESSAGE, BLOCK_MESSAGE, ReadWrite, + TENDERMINT_MESSAGE, TRANSACTION_MESSAGE, ReadWrite, transaction::Transaction as TransactionTrait, Transaction, BlockHeader, Block, BlockError, Blockchain, P2p, }; @@ -414,12 +414,7 @@ impl Network for TendermintNetwork ); match block_res { Ok(()) => { - // If we successfully added this block, broadcast it - // 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; + // If we successfully added this block, break break; } Err(BlockError::NonLocalProvided(hash)) => { @@ -428,6 +423,7 @@ impl Network for TendermintNetwork hex::encode(hash), hex::encode(self.genesis) ); + tokio::time::sleep(core::time::Duration::from_secs(5)).await; } _ => return invalid_block(), }