Skip to content

Commit

Permalink
Merge pull request #208 from contrun/network-actor-connected-peers
Browse files Browse the repository at this point in the history
Add a peer store to network actor
  • Loading branch information
quake authored Oct 23, 2024
2 parents 04653f9 + a7aac1a commit 19a57e9
Show file tree
Hide file tree
Showing 11 changed files with 527 additions and 267 deletions.
31 changes: 0 additions & 31 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use ckb_types::packed::{OutPoint, Script};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use std::collections::HashMap;
use tentacle::multiaddr::Multiaddr;
use tentacle::secio::PeerId;
use thiserror::Error;
use tracing::log::error;
use tracing::{debug, info, warn};
Expand Down Expand Up @@ -138,8 +136,6 @@ pub struct NetworkGraph<S> {
// Similar to the best_height, this is the last update time of the network graph.
// We assume that we have already synced the graph up to this time - ASSUME_MAX_MESSAGE_TIMESTAMP_GAP.
last_update_timestamp: u64,
// when we restarting a node, we will reconnect to these peers
connected_peer_addresses: HashMap<PeerId, Multiaddr>,
nodes: HashMap<Pubkey, NodeInfo>,
store: S,
chain_hash: Hash256,
Expand Down Expand Up @@ -172,7 +168,6 @@ where
last_update_timestamp: 0,
channels: HashMap::new(),
nodes: HashMap::new(),
connected_peer_addresses: HashMap::new(),
store,
chain_hash: get_chain_hash(),
};
Expand Down Expand Up @@ -212,9 +207,6 @@ where
}
self.nodes.insert(node.node_id, node.clone());
}
for (peer, addr) in self.store.get_connected_peer(None) {
self.connected_peer_addresses.insert(peer, addr);
}
}

pub fn get_best_height(&self) -> u64 {
Expand Down Expand Up @@ -421,25 +413,6 @@ where
self.chain_hash == chain_hash
}

pub fn add_connected_peer(&mut self, peer_id: &PeerId, address: Multiaddr) {
self.connected_peer_addresses
.insert(peer_id.clone(), address.clone());
self.store.insert_connected_peer(peer_id.clone(), address);
}

pub fn get_connected_peers(&self) -> Vec<(&PeerId, &Multiaddr)> {
self.connected_peer_addresses.iter().collect()
}

pub fn get_peers_to_sync_network_graph(&self) -> Vec<(&PeerId, &Multiaddr)> {
self.connected_peer_addresses.iter().take(3).collect()
}

pub fn remove_connected_peer(&mut self, peer_id: &PeerId) {
self.connected_peer_addresses.remove(peer_id);
self.store.remove_connected_peer(peer_id);
}

pub fn get_node_inbounds(
&self,
node_id: Pubkey,
Expand Down Expand Up @@ -479,7 +452,6 @@ where
pub fn reset(&mut self) {
self.channels.clear();
self.nodes.clear();
self.connected_peer_addresses.clear();
}

pub fn init_payment_session(&self, payment_request: SendPaymentCommand) -> PaymentSession {
Expand Down Expand Up @@ -808,9 +780,6 @@ pub trait NetworkGraphStateStore {
) -> (Vec<ChannelInfo>, JsonBytes);
fn insert_channel(&self, channel: ChannelInfo);
fn insert_node(&self, node: NodeInfo);
fn insert_connected_peer(&self, peer_id: PeerId, multiaddr: Multiaddr);
fn get_connected_peer(&self, peer_id: Option<PeerId>) -> Vec<(PeerId, Multiaddr)>;
fn remove_connected_peer(&self, peer_id: &PeerId);
fn get_payment_session(&self, payment_hash: Hash256) -> Option<PaymentSession>;
fn insert_payment_session(&self, session: PaymentSession);
}
Expand Down
Loading

0 comments on commit 19a57e9

Please sign in to comment.