Skip to content

Commit

Permalink
feat: report number of *new* blocks, confirmed microblocks, and uncon…
Browse files Browse the repository at this point in the history
…firmed microblocks when processing a NetworkResult
  • Loading branch information
jcnelson committed Oct 21, 2022
1 parent 1f7b295 commit b1b0e2c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/net/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub struct RelayerStats {
pub struct ProcessedNetReceipts {
pub mempool_txs_added: Vec<StacksTransaction>,
pub processed_unconfirmed_state: ProcessedUnconfirmedState,
pub num_new_blocks: u64,
pub num_new_confirmed_microblocks: u64,
pub num_new_unconfirmed_microblocks: u64,
}

/// Private trait for keeping track of messages that can be relayed, so we can identify the peers
Expand Down Expand Up @@ -1608,8 +1611,16 @@ impl Relayer {
coord_comms: Option<&CoordinatorChannels>,
event_observer: Option<&dyn MemPoolEventDispatcher>,
) -> Result<ProcessedNetReceipts, net_error> {
let mut num_new_blocks = 0;
let mut num_new_confirmed_microblocks = 0;
let mut num_new_unconfirmed_microblocks = 0;
match Relayer::process_new_blocks(network_result, sortdb, chainstate, coord_comms) {
Ok((new_blocks, new_confirmed_microblocks, new_microblocks, bad_block_neighbors)) => {
// report quantities of new data in the receipts
num_new_blocks = new_blocks.len() as u64;
num_new_confirmed_microblocks = new_confirmed_microblocks.len() as u64;
num_new_unconfirmed_microblocks = new_microblocks.len() as u64;

// attempt to relay messages (note that this is all best-effort).
// punish bad peers
if bad_block_neighbors.len() > 0 {
Expand Down Expand Up @@ -1730,6 +1741,9 @@ impl Relayer {
let receipts = ProcessedNetReceipts {
mempool_txs_added,
processed_unconfirmed_state,
num_new_blocks,
num_new_confirmed_microblocks,
num_new_unconfirmed_microblocks,
};

Ok(receipts)
Expand Down

0 comments on commit b1b0e2c

Please sign in to comment.