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

Add some unit tests for network syncing #205

Merged
merged 14 commits into from
Oct 1, 2024
Merged
17 changes: 3 additions & 14 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5568,7 +5568,7 @@ mod tests {
},
hash_algorithm::HashAlgorithm,
network::{AcceptChannelCommand, OpenChannelCommand},
test_utils::NetworkNode,
test_utils::{init_tracing, NetworkNode},
types::{Hash256, LockTime, RemoveTlcFulfill, RemoveTlcReason},
NetworkActorCommand, NetworkActorMessage,
},
Expand All @@ -5583,22 +5583,11 @@ mod tests {
prelude::{AsTransactionBuilder, Builder, Entity, Pack},
};
use ractor::call;
use std::sync::Once;
use tracing_subscriber;

static INIT: Once = Once::new();

fn init_tracing() {
INIT.call_once(|| {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.pretty()
.init();
});
}

#[test]
fn test_per_commitment_point_and_secret_consistency() {
init_tracing();

let signer = InMemorySigner::generate_from_seed(&[1; 32]);
assert_eq!(
signer.get_commitment_point(0),
Expand Down
17 changes: 17 additions & 0 deletions src/fiber/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub const DEFAULT_AUTO_ANNOUNCE_NODE: bool = true;
/// The interval to reannounce NodeAnnouncement, in seconds.
pub const DEFAULT_ANNOUNCE_NODE_INTERVAL_SECONDS: u64 = 3600;

/// Whether to sync the network graph from the network. true means syncing.
pub const DEFAULT_SYNC_NETWORK_GRAPH: bool = true;

// See comment in `LdkConfig` for why do we need to specify both name and long,
// and prefix them with `ckb-`/`CKB_`.
#[derive(ClapSerde, Debug, Clone)]
Expand Down Expand Up @@ -168,6 +171,15 @@ pub struct FiberConfig {
help = "The interval to reannounce NodeAnnouncement, in seconds. 0 means never reannounce. [default: 3600 (1 hour)]"
)]
pub(crate) announce_node_interval_seconds: Option<u64>,

/// Whether to sync the network graph from the network. [default: true]
#[arg(
name = "FIBER_SYNC_NETWORK_GRAPH",
long = "fiber-sync-network-graph",
env,
help = "Whether to sync the network graph from the network. [default: true]"
)]
pub(crate) sync_network_graph: Option<bool>,
}

#[derive(PartialEq, Copy, Clone, Default)]
Expand Down Expand Up @@ -319,6 +331,11 @@ impl FiberConfig {
.into();
secio_kp.public_key()
}

pub fn sync_network_graph(&self) -> bool {
self.sync_network_graph
.unwrap_or(DEFAULT_SYNC_NETWORK_GRAPH)
}
}

// Basically ckb_sdk::types::NetworkType. But we added a `Mocknet` variant.
Expand Down
9 changes: 6 additions & 3 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ where

pub fn add_node(&mut self, node_info: NodeInfo) {
debug!("Adding node to network graph: {:?}", node_info);

let node_id = node_info.node_id;
if let Some(old_node) = self.nodes.get(&node_id) {
if old_node.anouncement_msg.version > node_info.anouncement_msg.version {
Expand Down Expand Up @@ -336,9 +337,11 @@ where
&& channel.funding_tx_block_number < end_block
}),
end_block,
contrun marked this conversation as resolved.
Show resolved Hide resolved
self.channels
.values()
.any(|channel| channel.funding_tx_block_number >= end_block),
self.channels.is_empty()
|| self
.channels
.values()
.any(|channel| channel.funding_tx_block_number >= end_block),
)
}

Expand Down
Loading
Loading