]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Verify gossip using our RpcClient and the new LDK verification impl
authorMatt Corallo <git@bluematt.me>
Sat, 30 Sep 2023 03:01:07 +0000 (03:01 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 15 Oct 2023 17:14:03 +0000 (17:14 +0000)
Cargo.toml
src/bitcoind_client.rs
src/main.rs

index adac61dae1a692c9701cae0d3ea040d36d53fd0b..d73ce6de274f3878edce7a3bd837304a55455244 100644 (file)
@@ -9,7 +9,7 @@ edition = "2018"
 
 [dependencies]
 lightning = { version = "0.0.117", features = ["max_level_trace"] }
-lightning-block-sync = { version = "0.0.117", features = [ "rpc-client" ] }
+lightning-block-sync = { version = "0.0.117", features = [ "rpc-client", "tokio" ] }
 lightning-invoice = { version = "0.25.0" }
 lightning-net-tokio = { version = "0.0.117" }
 lightning-persister = { version = "0.0.117" }
index 3a41bc6e1ac74bb44cc2fec9a665e5a33d9f8c56..9f28015cf5ed0326190ac88b79b67f736c8de4a0 100644 (file)
@@ -28,7 +28,7 @@ use std::sync::Arc;
 use std::time::Duration;
 
 pub struct BitcoindClient {
-       bitcoind_rpc_client: Arc<RpcClient>,
+       pub(crate) bitcoind_rpc_client: Arc<RpcClient>,
        host: String,
        port: u16,
        rpc_user: String,
index 97524e618d34665707cd6b62adb4342f3c4fe517..50edb22ed54449d47d1f168c252ab05ff0ff7a6a 100644 (file)
@@ -133,12 +133,23 @@ type ChainMonitor = chainmonitor::ChainMonitor<
        >,
 >;
 
+pub(crate) type GossipVerifier = lightning_block_sync::gossip::GossipVerifier<
+       lightning_block_sync::gossip::TokioSpawner,
+       Arc<lightning_block_sync::rpc::RpcClient>,
+       Arc<FilesystemLogger>,
+       SocketDescriptor,
+       Arc<ChannelManager>,
+       Arc<SimpleArcOnionMessenger<FilesystemLogger>>,
+       IgnoringMessageHandler,
+       Arc<KeysManager>,
+>;
+
 pub(crate) type PeerManager = SimpleArcPeerManager<
        SocketDescriptor,
        ChainMonitor,
        BitcoindClient,
        BitcoindClient,
-       Arc<BitcoindClient>,
+       GossipVerifier,
        FilesystemLogger,
 >;
 
@@ -733,11 +744,8 @@ async fn start_ldk() {
        }
 
        // Step 14: Optional: Initialize the P2PGossipSync
-       let gossip_sync = Arc::new(P2PGossipSync::new(
-               Arc::clone(&network_graph),
-               None::<Arc<BitcoindClient>>,
-               logger.clone(),
-       ));
+       let gossip_sync =
+               Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger)));
 
        // Step 15: Initialize the PeerManager
        let channel_manager: Arc<ChannelManager> = Arc::new(channel_manager);
@@ -766,6 +774,15 @@ async fn start_ldk() {
                Arc::clone(&keys_manager),
        ));
 
+       // Install a GossipVerifier in in the P2PGossipSync
+       let utxo_lookup = GossipVerifier::new(
+               Arc::clone(&bitcoind_client.bitcoind_rpc_client),
+               lightning_block_sync::gossip::TokioSpawner,
+               Arc::clone(&gossip_sync),
+               Arc::clone(&peer_manager),
+       );
+       gossip_sync.add_utxo_lookup(Some(utxo_lookup));
+
        // ## Running LDK
        // Step 16: Initialize networking