Skip to content

Commit

Permalink
put transaction size threshold in const
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Nov 8, 2024
1 parent 9025b31 commit 420e3e5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions base_layer/core/src/mempool/service/inbound_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ use crate::{

pub const LOG_TARGET: &str = "c::mp::service::inbound_handlers";

/// Threshold of the protobuf encoded transaction bytes size to gossip a full transaction. If an encoded transaction is
/// greater than this, a notification of a new transaction is gossiped. This is selected to be slightly less than the
/// network default gossip message size of 64KiB.
const MEMPOOL_TRANSACTION_FULL_PROPAGATION_THRESHOLD_BYTES: usize = 62 * 1024;

/// The MempoolInboundHandlers is used to handle all received inbound mempool requests and transactions from remote
/// nodes.
#[derive(Clone)]
Expand Down Expand Up @@ -96,9 +101,16 @@ impl MempoolInboundHandlers {
if tx.body.outputs().len() + tx.body.inputs().len() < 4 && tx.body().kernels().len() < 4 {
let msg =
proto::common::Transaction::try_from(&*tx).map_err(MempoolServiceError::ConversionError)?;
// TODO: allow configuration of full vs reference byte size
let encoded_len = msg.encoded_len();
if encoded_len <= 64 * 1024 {
debug!(
target: LOG_TARGET,
"Transaction has {} input(s), {} output(s), and {} kernel(s). Encoded size = {}",
tx.body.inputs().len(),
tx.body.outputs().len(),
tx.body.kernels().len(),
encoded_len
);
if encoded_len <= MEMPOOL_TRANSACTION_FULL_PROPAGATION_THRESHOLD_BYTES {
debug!(target: LOG_TARGET, "Transaction is less than 64KiB when encoded ({encoded_len}). Gossiping full transaction.");
transaction_too_large_to_gossip = false;
// Gossip the full transaction
Expand Down

0 comments on commit 420e3e5

Please sign in to comment.