Skip to content

Commit

Permalink
Merge pull request #2271 from blockstack/fix/2270
Browse files Browse the repository at this point in the history
Fix 2270
  • Loading branch information
jcnelson authored Jan 6, 2021
2 parents 404f87d + 6c1b2ed commit 7b02145
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions testnet/stacks-node/src/neon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ fn spawn_peer(
let _ = Relayer::setup_unconfirmed_state_readonly(&mut chainstate, &sortdb);
recv_unconfirmed_txs(&mut chainstate, unconfirmed_txs.clone());

let network_result = match this.run(
match this.run(
&sortdb,
&mut chainstate,
&mut mem_pool,
Expand All @@ -624,35 +624,37 @@ fn spawn_peer(
&handler_args,
&mut expected_attachments,
) {
Ok(res) => res,
Ok(network_result) => {
if num_p2p_state_machine_passes < network_result.num_state_machine_passes {
// p2p state-machine did a full pass. Notify anyone listening.
sync_comms.notify_p2p_state_pass();
num_p2p_state_machine_passes = network_result.num_state_machine_passes;
}

if num_inv_sync_passes < network_result.num_inv_sync_passes {
// inv-sync state-machine did a full pass. Notify anyone listening.
sync_comms.notify_inv_sync_pass();
num_inv_sync_passes = network_result.num_inv_sync_passes;
}

if network_result.has_data_to_store() {
results_with_data
.push_back(RelayerDirective::HandleNetResult(network_result));
}

// only do this on the Ok() path, even if we're mining, because an error in
// network dispatching is likely due to resource exhaustion
if mblock_deadline < get_epoch_time_ms() {
results_with_data.push_back(RelayerDirective::RunMicroblockTenure);
mblock_deadline =
get_epoch_time_ms() + (config.node.microblock_frequency as u128);
}
}
Err(e) => {
error!("P2P: Failed to process network dispatch: {:?}", &e);
panic!();
}
};

if num_p2p_state_machine_passes < network_result.num_state_machine_passes {
// p2p state-machine did a full pass. Notify anyone listening.
sync_comms.notify_p2p_state_pass();
num_p2p_state_machine_passes = network_result.num_state_machine_passes;
}

if num_inv_sync_passes < network_result.num_inv_sync_passes {
// inv-sync state-machine did a full pass. Notify anyone listening.
sync_comms.notify_inv_sync_pass();
num_inv_sync_passes = network_result.num_inv_sync_passes;
}

if network_result.has_data_to_store() {
results_with_data.push_back(RelayerDirective::HandleNetResult(network_result));
}

if mblock_deadline < get_epoch_time_ms() {
results_with_data.push_back(RelayerDirective::RunMicroblockTenure);
mblock_deadline =
get_epoch_time_ms() + (config.node.microblock_frequency as u128);
}

while let Some(next_result) = results_with_data.pop_front() {
// have blocks, microblocks, and/or transactions (don't care about anything else),
// or a directive to mine microblocks
Expand Down

0 comments on commit 7b02145

Please sign in to comment.