1
+ use crate :: clock:: Clock ;
1
2
use crate :: {
2
3
LightningError , LightningNode , NodeInfo , PaymentOutcome , PaymentResult , SimulationError ,
3
4
} ;
@@ -8,7 +9,7 @@ use bitcoin::{Network, ScriptBuf, TxOut};
8
9
use lightning:: ln:: chan_utils:: make_funding_redeemscript;
9
10
use std:: collections:: { hash_map:: Entry , HashMap } ;
10
11
use std:: sync:: Arc ;
11
- use std:: time:: { SystemTime , UNIX_EPOCH } ;
12
+ use std:: time:: UNIX_EPOCH ;
12
13
use tokio_util:: task:: TaskTracker ;
13
14
14
15
use lightning:: ln:: features:: { ChannelFeatures , NodeFeatures } ;
@@ -729,8 +730,9 @@ pub async fn ln_node_from_graph(
729
730
/// announcements, which has the effect of adding the nodes in each channel to the graph, because LDK does not export
730
731
/// all of the fields required to apply node announcements. This means that we will not have node-level information
731
732
/// (such as features) available in the routing graph.
732
- pub fn populate_network_graph < ' a > (
733
+ pub fn populate_network_graph < ' a , C : Clock > (
733
734
channels : Vec < SimulatedChannel > ,
735
+ clock : C ,
734
736
) -> Result < NetworkGraph < & ' a WrappedLog > , LdkError > {
735
737
let graph = NetworkGraph :: new ( Network :: Regtest , & WrappedLog { } ) ;
736
738
@@ -763,16 +765,16 @@ pub fn populate_network_graph<'a>(
763
765
764
766
graph. update_channel_from_unsigned_announcement ( & announcement, & Some ( & utxo_validator) ) ?;
765
767
766
- // The least significant bit of the channel flag field represents the direction that the channel update
767
- // applies to. This value is interpreted as node_1 if it is zero, and node_2 otherwise.
768
+ // LDK only allows channel announcements up to 24h in the future. Use a fixed timestamp so that even if we've
769
+ // sped up our clock dramatically, we won't hit that limit.
770
+ let now = clock. now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_secs ( ) as u32 ;
768
771
for ( i, node) in [ channel. node_1 , channel. node_2 ] . iter ( ) . enumerate ( ) {
769
772
let update = UnsignedChannelUpdate {
770
773
chain_hash,
771
774
short_channel_id : channel. short_channel_id . into ( ) ,
772
- timestamp : SystemTime :: now ( )
773
- . duration_since ( UNIX_EPOCH )
774
- . unwrap ( )
775
- . as_secs ( ) as u32 ,
775
+ timestamp : now,
776
+ // The least significant bit of the channel flag field represents the direction that the channel update
777
+ // applies to. This value is interpreted as node_1 if it is zero, and node_2 otherwise.
776
778
flags : i as u8 ,
777
779
cltv_expiry_delta : node. policy . cltv_expiry_delta as u16 ,
778
780
htlc_minimum_msat : node. policy . min_htlc_size_msat ,
@@ -1089,6 +1091,7 @@ impl UtxoLookup for UtxoValidator {
1089
1091
#[ cfg( test) ]
1090
1092
mod tests {
1091
1093
use super :: * ;
1094
+ use crate :: clock:: SystemClock ;
1092
1095
use crate :: test_utils:: get_random_keypair;
1093
1096
use bitcoin:: secp256k1:: PublicKey ;
1094
1097
use lightning:: routing:: router:: Route ;
@@ -1480,7 +1483,7 @@ mod tests {
1480
1483
let mock = MockNetwork :: new ( ) ;
1481
1484
let sim_network = Arc :: new ( Mutex :: new ( mock) ) ;
1482
1485
let channels = create_simulated_channels ( 5 , 300000000 ) ;
1483
- let graph = populate_network_graph ( channels. clone ( ) ) . unwrap ( ) ;
1486
+ let graph = populate_network_graph ( channels. clone ( ) , SystemClock { } ) . unwrap ( ) ;
1484
1487
1485
1488
// Create a simulated node for the first channel in our network.
1486
1489
let pk = channels[ 0 ] . node_1 . policy . pubkey ;
@@ -1572,7 +1575,8 @@ mod tests {
1572
1575
async fn new ( capacity : u64 ) -> Self {
1573
1576
let ( shutdown, _listener) = triggered:: trigger ( ) ;
1574
1577
let channels = create_simulated_channels ( 3 , capacity) ;
1575
- let routing_graph = Arc :: new ( populate_network_graph ( channels. clone ( ) ) . unwrap ( ) ) ;
1578
+ let routing_graph =
1579
+ Arc :: new ( populate_network_graph ( channels. clone ( ) , SystemClock { } ) . unwrap ( ) ) ;
1576
1580
1577
1581
let scorer = ProbabilisticScorer :: new (
1578
1582
ProbabilisticScoringDecayParameters :: default ( ) ,
0 commit comments