Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire: hunt down some minor bugs on running_node #132

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/floresta-wire/src/p2p_wire/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ impl Default for RunningNode {
user_requests: Arc::new(NodeInterface {
requests: Mutex::new(Vec::new()),
}),
last_block_check: Instant::now(),
}
}
}
Expand Down Expand Up @@ -377,7 +376,7 @@ where
return Err(WireError::NoPeersAvailable);
}
for _ in 0..10 {
let idx = if required_services.has(ServiceFlags::from(1 << 24)) {
let idx = if required_services.has(ServiceFlags::UTREEXO) {
if self.utreexo_peers.is_empty() {
return Err(WireError::NoUtreexoPeersAvailable);
}
Expand Down
40 changes: 14 additions & 26 deletions crates/floresta-wire/src/p2p_wire/running_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub struct RunningNode {
pub(crate) last_rescan_request: RescanStatus,
pub(crate) last_feeler: Instant,
pub(crate) last_address_rearrange: Instant,
pub(crate) last_block_check: Instant,
pub(crate) user_requests: Arc<NodeInterface>,
}

Expand Down Expand Up @@ -110,22 +109,6 @@ where
);
}

/// In some edge cases, we may get a block header, but not the block itself. This
/// function checks if we have the block, and if not, requests it.
async fn ask_missed_block(&mut self) -> Result<(), WireError> {
let best_block = self.chain.get_best_block()?.0;
let validation_index = self.chain.get_validation_index()?;

if best_block == validation_index {
return Ok(());
}
for block in validation_index..=best_block {
let block = self.0.chain.get_block_hash(block)?;
self.request_blocks(vec![block]).await?;
}
Ok(())
}

async fn perform_user_request(&mut self, user_req: Vec<UserRequest>) {
for user_req in user_req {
let req = match user_req {
Expand Down Expand Up @@ -186,11 +169,16 @@ where
let (_, time) = self.inflight.get(request).unwrap();
if time.elapsed() > Duration::from_secs(RunningNode::REQUEST_TIMEOUT) {
timed_out.push(request.clone());
warn!("Request {:?} timed out", request);
}
}

for request in timed_out {
let Some((peer, _)) = self.inflight.remove(&request) else {
warn!(
"POSSIBLE BUG: Request {:?} timed out, but it wasn't in the inflight list",
request
);
continue;
};

Expand Down Expand Up @@ -281,7 +269,7 @@ where
// Then take the final state and run the node
self = UtreexoNode(ibd.0, self.1);
info!("starting running node...");

self.last_block_request = self.chain.get_validation_index().unwrap_or(0);
loop {
while let Ok(notification) =
timeout(Duration::from_millis(100), self.node_rx.recv()).await
Expand Down Expand Up @@ -377,13 +365,6 @@ where
);

// Check if we haven't missed any block
periodic_job!(
self.ask_missed_block().await,
self.1.last_block_check,
BLOCK_CHECK_INTERVAL,
RunningNode
);

if self.inflight.len() < 10 {
try_and_log!(self.ask_block().await);
}
Expand Down Expand Up @@ -522,9 +503,15 @@ where
let validation_index = self.chain.get_validation_index()?;
let mut next_block = self.chain.get_block_hash(validation_index + 1)?;

self.blocks.insert(block.block.block_hash(), (peer, block));
debug!(
"Block {} received, waiting for block {}",
block.block.block_hash(),
next_block
);

self.blocks.insert(block.block.block_hash(), (peer, block));
while let Some((peer, block)) = self.blocks.remove(&next_block) {
debug!("processing block {}", block.block.block_hash(),);
let (proof, del_hashes, inputs) = floresta_chain::proof_util::process_proof(
&block.udata.unwrap(),
&block.block.txdata,
Expand Down Expand Up @@ -586,6 +573,7 @@ where
Ok(_next_block) => next_block = _next_block,
Err(_) => break,
}
debug!("accepted block {}", block.block.block_hash());
}

// Remove confirmed transactions from the mempool.
Expand Down
Loading