1010// licenses.
1111
1212use crate :: routing:: gossip:: { NetworkGraph , NodeAlias , P2PGossipSync } ;
13+ use crate :: routing:: utxo:: UtxoResult ;
1314use crate :: types:: features:: { ChannelFeatures , NodeFeatures } ;
15+ use crate :: ln:: chan_utils:: make_funding_redeemscript;
1416use crate :: ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , MAX_VALUE_MSAT , NodeAnnouncement , RoutingMessageHandler , SocketAddress , UnsignedChannelAnnouncement , UnsignedChannelUpdate , UnsignedNodeAnnouncement } ;
1517use crate :: util:: test_utils;
1618use crate :: util:: ser:: Writeable ;
@@ -22,6 +24,7 @@ use bitcoin::hex::FromHex;
2224use bitcoin:: network:: Network ;
2325use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
2426use bitcoin:: secp256k1:: { Secp256k1 , All } ;
27+ use bitcoin:: { Amount , TxOut } ;
2528
2629#[ allow( unused) ]
2730use crate :: prelude:: * ;
@@ -58,19 +61,34 @@ pub(crate) fn channel_announcement(
5861}
5962
6063// Using the same keys for LN and BTC ids
61- pub ( crate ) fn add_channel (
64+ pub ( crate ) fn add_channel_skipping_utxo_update (
6265 gossip_sync : & P2PGossipSync < Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > ,
63- secp_ctx : & Secp256k1 < All > , node_1_privkey : & SecretKey , node_2_privkey : & SecretKey , features : ChannelFeatures , short_channel_id : u64
66+ secp_ctx : & Secp256k1 < All > , node_1_privkey : & SecretKey , node_2_privkey : & SecretKey , features : ChannelFeatures , short_channel_id : u64 ,
6467) {
6568 let valid_announcement =
6669 channel_announcement ( node_1_privkey, node_2_privkey, features, short_channel_id, secp_ctx) ;
67- let node_1_pubkey = PublicKey :: from_secret_key ( & secp_ctx, node_1_privkey) ;
70+
71+ let node_1_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & node_1_privkey) ;
6872 match gossip_sync. handle_channel_announcement ( Some ( node_1_pubkey) , & valid_announcement) {
6973 Ok ( res) => assert ! ( res) ,
70- _ => panic ! ( )
74+ Err ( e ) => panic ! ( "{:?}" , e ) ,
7175 } ;
7276}
7377
78+ pub ( crate ) fn add_channel (
79+ gossip_sync : & P2PGossipSync < Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > ,
80+ secp_ctx : & Secp256k1 < All > , node_1_privkey : & SecretKey , node_2_privkey : & SecretKey , features : ChannelFeatures , short_channel_id : u64 ,
81+ ) {
82+ gossip_sync. utxo_lookup . as_ref ( ) . map ( |checker| {
83+ let node_1_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & node_1_privkey) ;
84+ let node_2_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & node_2_privkey) ;
85+ let script_pubkey = make_funding_redeemscript ( & node_1_pubkey, & node_2_pubkey) . to_p2wsh ( ) ;
86+ * checker. utxo_ret . lock ( ) . unwrap ( ) =
87+ UtxoResult :: Sync ( Ok ( TxOut { value : Amount :: from_sat ( 21_000_000_0000_0000 ) , script_pubkey } ) ) ;
88+ } ) ;
89+ add_channel_skipping_utxo_update ( gossip_sync, secp_ctx, node_1_privkey, node_2_privkey, features, short_channel_id) ;
90+ }
91+
7492pub ( crate ) fn add_or_update_node (
7593 gossip_sync : & P2PGossipSync < Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , Arc < test_utils:: TestChainSource > , Arc < test_utils:: TestLogger > > ,
7694 secp_ctx : & Secp256k1 < All > , node_privkey : & SecretKey , features : NodeFeatures , timestamp : u32
@@ -197,18 +215,43 @@ pub(super) fn build_line_graph() -> (
197215 ( secp_ctx, network_graph, gossip_sync, chain_monitor, logger)
198216}
199217
218+ pub ( super ) fn build_graph_with_gossip_validation ( ) -> (
219+ Secp256k1 < All > ,
220+ sync:: Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > ,
221+ P2PGossipSync < sync:: Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , sync:: Arc < test_utils:: TestChainSource > , sync:: Arc < test_utils:: TestLogger > > ,
222+ sync:: Arc < test_utils:: TestChainSource > ,
223+ sync:: Arc < test_utils:: TestLogger > ,
224+ ) {
225+ do_build_graph ( true )
226+ }
227+
200228pub ( super ) fn build_graph ( ) -> (
201229 Secp256k1 < All > ,
202230 sync:: Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > ,
203231 P2PGossipSync < sync:: Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , sync:: Arc < test_utils:: TestChainSource > , sync:: Arc < test_utils:: TestLogger > > ,
204232 sync:: Arc < test_utils:: TestChainSource > ,
205233 sync:: Arc < test_utils:: TestLogger > ,
234+ ) {
235+ do_build_graph ( false )
236+ }
237+
238+ fn do_build_graph ( with_validation : bool ) -> (
239+ Secp256k1 < All > ,
240+ sync:: Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > ,
241+ P2PGossipSync < sync:: Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > , sync:: Arc < test_utils:: TestChainSource > , sync:: Arc < test_utils:: TestLogger > > ,
242+ sync:: Arc < test_utils:: TestChainSource > ,
243+ sync:: Arc < test_utils:: TestLogger > ,
206244) {
207245 let secp_ctx = Secp256k1 :: new ( ) ;
208246 let logger = Arc :: new ( test_utils:: TestLogger :: new ( ) ) ;
209247 let chain_monitor = Arc :: new ( test_utils:: TestChainSource :: new ( Network :: Testnet ) ) ;
210248 let network_graph = Arc :: new ( NetworkGraph :: new ( Network :: Testnet , Arc :: clone ( & logger) ) ) ;
211- let gossip_sync = P2PGossipSync :: new ( Arc :: clone ( & network_graph) , None , Arc :: clone ( & logger) ) ;
249+ let checker = if with_validation {
250+ Some ( Arc :: clone ( & chain_monitor) )
251+ } else {
252+ None
253+ } ;
254+ let gossip_sync = P2PGossipSync :: new ( Arc :: clone ( & network_graph) , checker, Arc :: clone ( & logger) ) ;
212255 // Build network from our_id to node6:
213256 //
214257 // -1(1)2- node0 -1(3)2-
0 commit comments