From d7d5f6fe7a1782a3b05b72f063d4683e25ffc763 Mon Sep 17 00:00:00 2001 From: jaoleal Date: Wed, 18 Dec 2024 16:07:03 -0300 Subject: [PATCH] Naming UtreexoNode Fields and Traits Impl now follow the respective position of the field --- .../src/electrum_protocol.rs | 4 +- .../src/p2p_wire/chain_selector.rs | 77 +++++++++--------- crates/floresta-wire/src/p2p_wire/node.rs | 48 +++++------ .../src/p2p_wire/running_node.rs | 79 ++++++++++++------- .../floresta-wire/src/p2p_wire/sync_node.rs | 19 ++--- .../src/p2p_wire/tests/sync_node.rs | 4 +- crates/floresta/examples/node.rs | 2 +- 7 files changed, 128 insertions(+), 105 deletions(-) diff --git a/crates/floresta-electrum/src/electrum_protocol.rs b/crates/floresta-electrum/src/electrum_protocol.rs index d61077a3..ae3e4e8d 100644 --- a/crates/floresta-electrum/src/electrum_protocol.rs +++ b/crates/floresta-electrum/src/electrum_protocol.rs @@ -1057,7 +1057,7 @@ mod test { user_agent: "floresta".to_string(), }; - let chain_provider: UtreexoNode>> = + let chain_provider: UtreexoNode>, RunningNode> = UtreexoNode::new( u_config, chain.clone(), @@ -1131,7 +1131,7 @@ mod test { /// blockchain.scripthash.listunspent * /// blockchain.scripthash.subscribe * /// blockchain.scripthash.unsubscribe * - /// blockchain.transaction.broadcast * + /// blockchain.transaction.broadcast * /// blockchain.transaction.get * /// blockchain.transaction.get_merkle * /// mempool.get_fee_histogram * diff --git a/crates/floresta-wire/src/p2p_wire/chain_selector.rs b/crates/floresta-wire/src/p2p_wire/chain_selector.rs index 9e8d158b..cb6ce445 100644 --- a/crates/floresta-wire/src/p2p_wire/chain_selector.rs +++ b/crates/floresta-wire/src/p2p_wire/chain_selector.rs @@ -123,7 +123,7 @@ impl NodeContext for ChainSelector { } } -impl UtreexoNode +impl UtreexoNode where WireError: From<::Error>, Chain: BlockchainInterface + UpdatableChainstate + 'static, @@ -156,7 +156,7 @@ where self.send_to_peer(peer, NodeRequest::Shutdown).await?; let peer = self.peers.get(&peer).unwrap(); - self.0.address_man.update_set_state( + self.common.address_man.update_set_state( peer.address_id as usize, AddressState::Banned(ChainSelector::BAN_TIME), ); @@ -164,7 +164,7 @@ where } let last = headers.last().unwrap().block_hash(); - self.1 + self.context .tip_cache .entry(peer) .and_modify(|e| *e = last) @@ -453,24 +453,24 @@ where /// has send all blocks they have. Once all peers have finished, we just pick the /// most PoW chain among all chains that we got async fn empty_headers_message(&mut self, peer: PeerId) -> Result<(), WireError> { - match self.1.state { + match self.context.state { ChainSelectorState::DownloadingHeaders => { info!("Finished downloading headers from peer={peer}, checking if our peers agree"); self.poke_peers().await?; - self.1.state = ChainSelectorState::LookingForForks(Instant::now()); - self.1.done_peers.insert(peer); + self.context.state = ChainSelectorState::LookingForForks(Instant::now()); + self.context.done_peers.insert(peer); } ChainSelectorState::LookingForForks(_) => { - self.1.done_peers.insert(peer); - for peer in self.0.peer_ids.iter() { + self.context.done_peers.insert(peer); + for peer in self.common.peer_ids.iter() { // at least one peer haven't finished - if !self.1.done_peers.contains(peer) { + if !self.context.done_peers.contains(peer) { return Ok(()); } } - if let Some(assume_utreexo) = self.0.config.assume_utreexo.as_ref() { - self.1.state = ChainSelectorState::Done; + if let Some(assume_utreexo) = self.common.config.assume_utreexo.as_ref() { + self.context.state = ChainSelectorState::Done; // already assumed the chain if self.chain.get_validation_index().unwrap() >= assume_utreexo.height { return Ok(()); @@ -496,7 +496,7 @@ where self.check_tips().await?; } - self.1.state = ChainSelectorState::Done; + self.context.state = ChainSelectorState::Done; } _ => {} } @@ -552,8 +552,8 @@ where } async fn ban_peers_on_tip(&mut self, tip: BlockHash) -> Result<(), WireError> { - for peer in self.0.peers.clone() { - if self.1.tip_cache.get(&peer.0).copied().eq(&Some(tip)) { + for peer in self.common.peers.clone() { + if self.context.tip_cache.get(&peer.0).copied().eq(&Some(tip)) { self.address_man.update_set_state( peer.1.address_id as usize, AddressState::Banned(ChainSelector::BAN_TIME), @@ -580,7 +580,7 @@ where self.chain.get_best_block()?.0 ); - self.1.state = ChainSelectorState::Done; + self.context.state = ChainSelectorState::Done; self.chain.mark_chain_as_assumed(acc, tips[0]).unwrap(); self.chain.toggle_ibd(false); } @@ -594,7 +594,7 @@ where } info!("chain close enough to tip, not asking for utreexo state"); - self.1.state = ChainSelectorState::Done; + self.context.state = ChainSelectorState::Done; Ok(()) } @@ -612,7 +612,7 @@ where self.send_to_peer(peer, NodeRequest::GetHeaders(locator)) .await?; - let peer = self.1.sync_peer; + let peer = self.context.sync_peer; self.inflight .insert(InflightRequests::Headers, (peer, Instant::now())); @@ -624,7 +624,7 @@ where /// If it does, we disconnect and ban this peer async fn check_for_timeout(&mut self) -> Result<(), WireError> { let (failed, mut peers) = self - .0 + .common .inflight .iter() .filter(|(_, (_, instant))| { @@ -635,11 +635,11 @@ where for request in failed { if let InflightRequests::Headers = request { - if self.1.state == ChainSelectorState::DownloadingHeaders { + if self.context.state == ChainSelectorState::DownloadingHeaders { let new_sync_peer = rand::random::() % self.peer_ids.len(); let new_sync_peer = *self.peer_ids.get(new_sync_peer).unwrap(); - self.1.sync_peer = new_sync_peer; - self.request_headers(self.chain.get_best_block()?.1, self.1.sync_peer) + self.context.sync_peer = new_sync_peer; + self.request_headers(self.chain.get_best_block()?.1, self.context.sync_peer) .await?; self.inflight .insert(InflightRequests::Headers, (new_sync_peer, Instant::now())); @@ -652,14 +652,14 @@ where peers.dedup(); for peer in peers { - self.0.peers.entry(peer).and_modify(|e| { + self.common.peers.entry(peer).and_modify(|e| { if e.state != PeerStatus::Awaiting { e.state = PeerStatus::Banned; } }); self.send_to_peer(peer, NodeRequest::Shutdown).await?; - self.0.peers.remove(&peer); + self.common.peers.remove(&peer); } Ok(()) @@ -673,7 +673,7 @@ where /// the most PoW one. async fn poke_peers(&self) -> Result<(), WireError> { let locator = self.chain.get_block_locator().unwrap(); - for peer in self.0.peer_ids.iter() { + for peer in self.common.peer_ids.iter() { let get_headers = NodeRequest::GetHeaders(locator.clone()); self.send_to_peer(*peer, get_headers).await?; } @@ -697,30 +697,33 @@ where ChainSelector ); - if let ChainSelectorState::LookingForForks(start) = self.1.state { + if let ChainSelectorState::LookingForForks(start) = self.context.state { if start.elapsed().as_secs() > 30 { - self.1.state = ChainSelectorState::LookingForForks(Instant::now()); + self.context.state = ChainSelectorState::LookingForForks(Instant::now()); self.poke_peers().await?; } } - if self.1.state == ChainSelectorState::CreatingConnections { + if self.context.state == ChainSelectorState::CreatingConnections { // If we have enough peers, try to download headers if !self.peer_ids.is_empty() { let new_sync_peer = rand::random::() % self.peer_ids.len(); - self.1.sync_peer = *self.peer_ids.get(new_sync_peer).unwrap(); + self.context.sync_peer = *self.peer_ids.get(new_sync_peer).unwrap(); try_and_log!( - self.request_headers(self.chain.get_best_block()?.1, self.1.sync_peer) - .await + self.request_headers( + self.chain.get_best_block()?.1, + self.context.sync_peer + ) + .await ); - self.1.state = ChainSelectorState::DownloadingHeaders; + self.context.state = ChainSelectorState::DownloadingHeaders; } } // We downloaded all headers in the most-pow chain, and all our peers agree // this is the most-pow chain, we're done! - if self.1.state == ChainSelectorState::Done { + if self.context.state == ChainSelectorState::Done { try_and_log!(self.chain.flush()); break; } @@ -740,12 +743,12 @@ where block: BlockHash, height: u32, ) -> Result { - for peer_id in self.0.peer_ids.iter() { + for peer_id in self.common.peer_ids.iter() { let peer = self.peers.get(peer_id).unwrap(); if peer.services.has(ServiceFlags::from(1 << 25)) { self.send_to_peer(*peer_id, NodeRequest::GetUtreexoState((block, height))) .await?; - self.0.inflight.insert( + self.common.inflight.insert( InflightRequests::UtreexoState(*peer_id), (*peer_id, Instant::now()), ); @@ -815,7 +818,7 @@ where PeerMessages::Ready(version) => { self.handle_peer_ready(peer, &version).await?; - if matches!(self.1.state, ChainSelectorState::LookingForForks(_)) { + if matches!(self.context.state, ChainSelectorState::LookingForForks(_)) { let locator = self.chain.get_block_locator().unwrap(); self.send_to_peer(peer, NodeRequest::GetHeaders(locator)) .await?; @@ -823,8 +826,8 @@ where } PeerMessages::Disconnected(idx) => { - if peer == self.1.sync_peer { - self.1.state = ChainSelectorState::CreatingConnections; + if peer == self.context.sync_peer { + self.context.state = ChainSelectorState::CreatingConnections; } self.handle_disconnection(peer, idx).await?; } diff --git a/crates/floresta-wire/src/p2p_wire/node.rs b/crates/floresta-wire/src/p2p_wire/node.rs index 543cd3e6..5ed07723 100644 --- a/crates/floresta-wire/src/p2p_wire/node.rs +++ b/crates/floresta-wire/src/p2p_wire/node.rs @@ -183,21 +183,21 @@ pub struct NodeCommon { pub(crate) network: Network, } -pub struct UtreexoNode( - pub(crate) NodeCommon, - pub(crate) Context, -); +pub struct UtreexoNode { + pub(crate) common: NodeCommon, + pub(crate) context: NodeModule, +} -impl Deref for UtreexoNode { +impl Deref for UtreexoNode { fn deref(&self) -> &Self::Target { - &self.0 + &self.common } type Target = NodeCommon; } -impl DerefMut for UtreexoNode { +impl DerefMut for UtreexoNode { fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 + &mut self.common } } @@ -208,7 +208,7 @@ pub enum PeerStatus { Banned, } -impl UtreexoNode +impl UtreexoNode where T: 'static + Default + NodeContext, WireError: From<::Error>, @@ -231,8 +231,8 @@ where }) .transpose()?; - Ok(UtreexoNode( - NodeCommon { + Ok(UtreexoNode { + common: NodeCommon { last_filter: chain.get_block_hash(0).unwrap(), block_filters, inflight: HashMap::new(), @@ -261,8 +261,8 @@ where fixed_peer, config, }, - T::default(), - )) + context: T::default(), + }) } fn get_port(network: Network) -> u16 { @@ -537,7 +537,7 @@ where version.id, version.user_agent, version.blocks, version.services ); - if let Some(peer_data) = self.0.peers.get_mut(&peer) { + if let Some(peer_data) = self.common.peers.get_mut(&peer) { // This peer doesn't have basic services, so we disconnect it if !version .services @@ -563,7 +563,7 @@ where peer_data.height = version.blocks; if peer_data.services.has(service_flags::UTREEXO.into()) { - self.0 + self.common .peer_by_service .entry(service_flags::UTREEXO.into()) .or_default() @@ -571,7 +571,7 @@ where } if peer_data.services.has(ServiceFlags::COMPACT_FILTERS) { - self.0 + self.common .peer_by_service .entry(ServiceFlags::COMPACT_FILTERS) .or_default() @@ -579,7 +579,7 @@ where } if peer_data.services.has(ServiceFlags::from(1 << 25)) { - self.0 + self.common .peer_by_service .entry(ServiceFlags::from(1 << 25)) .or_default() @@ -629,14 +629,14 @@ where peer_id: u32, factor: u32, ) -> Result<(), WireError> { - let Some(peer) = self.0.peers.get_mut(&peer_id) else { + let Some(peer) = self.common.peers.get_mut(&peer_id) else { return Ok(()); }; peer.banscore += factor; // This peer is misbehaving too often, ban it - let is_missbehaving = peer.banscore >= self.0.max_banscore; + let is_missbehaving = peer.banscore >= self.common.max_banscore; // extra peers should be banned immediately let is_extra = peer.kind == ConnectionKind::Extra; @@ -702,7 +702,7 @@ where } pub(crate) async fn init_peers(&mut self) -> Result<(), WireError> { - let anchors = self.0.address_man.start_addr_man( + let anchors = self.common.address_man.start_addr_man( self.datadir.clone(), self.get_default_port(), self.network, @@ -789,7 +789,7 @@ where // if we need utreexo peers, we can bypass our max outgoing peers limit in case // we don't have any utreexo peers let bypass = self - .1 + .context .get_required_services() .has(service_flags::UTREEXO.into()) && !self.has_utreexo_peers(); @@ -836,7 +836,7 @@ where } fn get_required_services(&self) -> ServiceFlags { - let required_services = self.1.get_required_services(); + let required_services = self.context.get_required_services(); // chain selector should prefer peers that support UTREEXO filters, as // more peers with this service will improve our security for PoW @@ -886,7 +886,7 @@ where // Don't connect to the same peer twice if self - .0 + .common .peers .iter() .any(|peers| peers.1.address == address.get_net_address()) @@ -1098,7 +1098,7 @@ mod tests { fn check_address_resolving(address: &str, port: u16, should_succeed: bool, description: &str) { let result = - UtreexoNode::::resolve_connect_host(address, port); + UtreexoNode::::resolve_connect_host(address, port); if should_succeed { assert!(result.is_ok(), "Failed: {}", description); } else { diff --git a/crates/floresta-wire/src/p2p_wire/running_node.rs b/crates/floresta-wire/src/p2p_wire/running_node.rs index f4075426..3cd60db6 100644 --- a/crates/floresta-wire/src/p2p_wire/running_node.rs +++ b/crates/floresta-wire/src/p2p_wire/running_node.rs @@ -72,7 +72,7 @@ impl NodeContext for RunningNode { } } -impl UtreexoNode +impl UtreexoNode where WireError: From<::Error>, Chain: BlockchainInterface + UpdatableChainstate + 'static, @@ -82,12 +82,12 @@ where /// multiple handles. It also doesn't require a mutable reference to the node, or any /// synchronization mechanism. pub fn get_handle(&self) -> Arc { - self.1.user_requests.clone() + self.context.user_requests.clone() } async fn handle_user_request(&mut self) -> Result<(), WireError> { let requests = self - .1 + .context .user_requests .requests .lock() @@ -110,7 +110,7 @@ where peers.push(self.get_peer_info(peer)); } let peers = peers.into_iter().flatten().collect(); - self.1.user_requests.send_answer( + self.context.user_requests.send_answer( UserRequest::GetPeerInfo, Some(NodeResponse::GetPeerInfo(peers)), ); @@ -147,7 +147,7 @@ where self.open_connection(ConnectionKind::Regular, 0, local_addr) .await; self.peer_id_count += 1; - self.1.user_requests.send_answer( + self.context.user_requests.send_answer( UserRequest::Connect((addr, port)), Some(NodeResponse::Connect(true)), ); @@ -184,7 +184,7 @@ where async fn check_for_timeout(&mut self) -> Result<(), WireError> { let timed_out = self - .0 + .common .inflight .iter() .filter(|(_, (_, instant))| { @@ -231,7 +231,7 @@ where .insert(InflightRequests::Headers, (peer, Instant::now())); } InflightRequests::UserRequest(req) => { - self.1.user_requests.send_answer(req, None); + self.context.user_requests.send_answer(req, None); } InflightRequests::Connect(peer) => { self.peers.remove(&peer); @@ -250,10 +250,16 @@ where } pub async fn catch_up(self, kill_signal: Arc>) -> Self { - let mut sync = UtreexoNode::(self.0, SyncNode::default()); + let mut sync = UtreexoNode:: { + context: SyncNode::default(), + common: self.common, + }; sync.run(kill_signal, |_| {}).await; - UtreexoNode(sync.0, self.1) + UtreexoNode { + common: sync.common, + context: self.context, + } } pub async fn run( @@ -265,27 +271,36 @@ where let startup_tip = self.chain.get_height().unwrap(); // Use this node state to Initial Block download - let mut ibd = UtreexoNode(self.0, ChainSelector::default()); - try_and_log!(UtreexoNode::::run(&mut ibd, kill_signal.clone()).await); + let mut ibd = UtreexoNode { + common: self.common, + context: ChainSelector::default(), + }; + try_and_log!(UtreexoNode::::run(&mut ibd, kill_signal.clone()).await); if *kill_signal.read().await { - self = UtreexoNode(ibd.0, self.1); + self = UtreexoNode { + common: ibd.common, + context: self.context, + }; self.shutdown().await; try_and_log!(stop_signal.send(())); return; } - self = UtreexoNode(ibd.0, self.1); + self = UtreexoNode { + common: ibd.common, + context: self.context, + }; // download all blocks from the network if self.config.backfill && startup_tip == 0 { - let end = self.0.chain.get_validation_index().unwrap(); + let end = self.common.chain.get_validation_index().unwrap(); let chain = self .chain .get_partial_chain(startup_tip, end, Stump::default()) .unwrap(); - let mut backfill = UtreexoNode::::new( + let mut backfill = UtreexoNode::::new( self.config.clone(), chain, self.mempool.clone(), @@ -294,7 +309,7 @@ where .expect("Failed to create backfill node"); // expect is fine here, because we already // validated this config before creating the RunningNode - UtreexoNode::::run( + UtreexoNode::::run( &mut backfill, kill_signal.clone(), |chain: &PartialChainState| { @@ -350,7 +365,7 @@ where // Rework our address database periodic_job!( self.address_man.rearrange_buckets(), - self.1.last_address_rearrange, + self.context.last_address_rearrange, ADDRESS_REARRANGE_INTERVAL, RunningNode, true @@ -373,7 +388,7 @@ where // Open new feeler connection periodically periodic_job!( self.open_feeler_connection().await, - self.1.last_feeler, + self.context.last_feeler, FEELER_INTERVAL, RunningNode ); @@ -526,8 +541,8 @@ where /// 6 blocks. fn get_peer_score(&self, peer: PeerId) -> u32 { let mut score = 0; - for block in self.1.last_invs.keys() { - if self.1.last_invs[block].1.contains(&peer) { + for block in self.context.last_invs.keys() { + if self.context.last_invs[block].1.contains(&peer) { score += 1; } } @@ -594,13 +609,13 @@ where block.block.block_hash() ); if block.udata.is_some() { - self.1.user_requests.send_answer( + self.context.user_requests.send_answer( UserRequest::UtreexoBlock(block.block.block_hash()), Some(NodeResponse::UtreexoBlock(block)), ); return Ok(()); } - self.1.user_requests.send_answer( + self.context.user_requests.send_answer( UserRequest::Block(block.block.block_hash()), Some(NodeResponse::Block(block.block)), ); @@ -728,7 +743,7 @@ where NodeNotification::FromPeer(peer, message) => match message { PeerMessages::NewBlock(block) => { debug!("We got an inv with block {block} requesting it"); - self.1 + self.context .last_invs .entry(block) .and_modify(|(when, peers)| { @@ -818,7 +833,7 @@ where PeerMessages::BlockFilter((hash, filter)) => { debug!("Got a block filter for block {hash} from peer {peer}"); - if let Some(filters) = self.0.block_filters.as_ref() { + if let Some(filters) = self.common.block_filters.as_ref() { let mut current_height = filters.get_height()?; let Some(this_height) = self.chain.get_block_height(&hash)? else { warn!("Filter for block {} received, but we don't have it", hash); @@ -826,21 +841,25 @@ where }; if current_height + 1 != this_height { - self.1.inflight_filters.insert(this_height, filter); + self.context.inflight_filters.insert(this_height, filter); return Ok(()); } filters.push_filter(filter, current_height + 1)?; current_height += 1; - while let Some(filter) = self.1.inflight_filters.remove(&(current_height)) { + while let Some(filter) = + self.context.inflight_filters.remove(&(current_height)) + { filters.push_filter(filter, current_height)?; current_height += 1; } filters.save_height(current_height)?; let current_hash = self.chain.get_block_hash(current_height)?; - if self.last_filter == current_hash && self.1.inflight_filters.is_empty() { + if self.last_filter == current_hash + && self.context.inflight_filters.is_empty() + { self.inflight.remove(&InflightRequests::GetFilters); self.download_filters().await?; } @@ -851,13 +870,13 @@ where Inventory::Block(block) | Inventory::WitnessBlock(block) | Inventory::CompactBlock(block) => { - self.1 + self.context .user_requests .send_answer(UserRequest::Block(block), None); } Inventory::WitnessTransaction(tx) | Inventory::Transaction(tx) => { - self.1 + self.context .user_requests .send_answer(UserRequest::MempoolTransaction(tx), None); } @@ -865,7 +884,7 @@ where }, PeerMessages::Transaction(tx) => { debug!("saw a mempool transaction with txid={}", tx.compute_txid()); - self.1.user_requests.send_answer( + self.context.user_requests.send_answer( UserRequest::MempoolTransaction(tx.compute_txid()), Some(NodeResponse::MempoolTransaction(tx)), ); diff --git a/crates/floresta-wire/src/p2p_wire/sync_node.rs b/crates/floresta-wire/src/p2p_wire/sync_node.rs index a41dbd53..322d5212 100644 --- a/crates/floresta-wire/src/p2p_wire/sync_node.rs +++ b/crates/floresta-wire/src/p2p_wire/sync_node.rs @@ -47,7 +47,7 @@ impl NodeContext for SyncNode { const MAX_INFLIGHT_REQUESTS: usize = 100; // double the default } -impl UtreexoNode +impl UtreexoNode where WireError: From<::Error>, Chain: BlockchainInterface + UpdatableChainstate + 'static, @@ -55,12 +55,12 @@ where async fn get_blocks_to_download(&mut self) { let mut blocks = Vec::with_capacity(10); for _ in 0..10 { - let next_block = self.1.last_block_requested + 1; + let next_block = self.context.last_block_requested + 1; let next_block = self.chain.get_block_hash(next_block); match next_block { Ok(next_block) => { blocks.push(next_block); - self.1.last_block_requested += 1; + self.context.last_block_requested += 1; } Err(_) => { break; @@ -72,7 +72,7 @@ where pub async fn run(&mut self, kill_signal: Arc>, done_cb: impl FnOnce(&Chain)) { info!("Starting sync node"); - self.1.last_block_requested = self.chain.get_validation_index().unwrap(); + self.context.last_block_requested = self.chain.get_validation_index().unwrap(); loop { while let Ok(Some(msg)) = timeout(Duration::from_secs(1), self.node_rx.recv()).await { @@ -97,11 +97,11 @@ where ); if Instant::now() - .duration_since(self.0.last_tip_update) + .duration_since(self.common.last_tip_update) .as_secs() > SyncNode::ASSUME_STALE { - self.1.last_block_requested = self.chain.get_validation_index().unwrap(); + self.context.last_block_requested = self.chain.get_validation_index().unwrap(); self.create_connection(ConnectionKind::Regular).await; self.last_tip_update = Instant::now(); continue; @@ -113,7 +113,7 @@ where continue; } - if self.chain.get_validation_index().unwrap() + 10 > self.1.last_block_requested { + if self.chain.get_validation_index().unwrap() + 10 > self.context.last_block_requested { if self.inflight.len() > 10 { continue; } @@ -126,7 +126,7 @@ where async fn handle_timeout(&mut self) { let to_remove = self - .0 + .common .inflight .iter() .filter(|(_, (_, instant))| instant.elapsed().as_secs() > SyncNode::REQUEST_TIMEOUT) @@ -263,7 +263,8 @@ where if !self.has_utreexo_peers() { warn!("No utreexo peers connected, trying to create a new one"); try_and_log!(self.maybe_open_connection().await); - self.1.last_block_requested = self.chain.get_validation_index().unwrap(); + self.context.last_block_requested = + self.chain.get_validation_index().unwrap(); self.inflight.clear(); } } diff --git a/crates/floresta-wire/src/p2p_wire/tests/sync_node.rs b/crates/floresta-wire/src/p2p_wire/tests/sync_node.rs index 881f95b3..9b706709 100644 --- a/crates/floresta-wire/src/p2p_wire/tests/sync_node.rs +++ b/crates/floresta-wire/src/p2p_wire/tests/sync_node.rs @@ -47,7 +47,7 @@ mod tests_utils { let config = get_node_config(datadir, network, pow_fraud_proofs); - let mut node = UtreexoNode::>>::new( + let mut node = UtreexoNode::>, SyncNode>::new( config, chain.clone(), mempool, @@ -77,7 +77,7 @@ mod tests_utils { // FIXME: This doesn't look very safe, but we need to coerce a &mut reference of the node // to live for the static lifetime, or it can't be spawn-ed by tokio::task - let _node: &'static mut UtreexoNode>> = + let _node: &'static mut UtreexoNode>, SyncNode> = unsafe { std::mem::transmute(&mut **node) }; timeout(Duration::from_secs(100), _node.run(kill_signal, |_| {})) diff --git a/crates/floresta/examples/node.rs b/crates/floresta/examples/node.rs index 31cc60b6..bf6a907d 100644 --- a/crates/floresta/examples/node.rs +++ b/crates/floresta/examples/node.rs @@ -57,7 +57,7 @@ async fn main() { // Finally, we are using the chain state created above, the node will use it to determine // what blocks and headers to download, and hand them to it to validate. let config = UtreexoNodeConfig::default(); - let p2p: UtreexoNode>> = UtreexoNode::new( + let p2p: UtreexoNode>, RunningNode> = UtreexoNode::new( config, chain.clone(), Arc::new(RwLock::new(Mempool::new())),