1
+ use crate :: clock:: Clock ;
1
2
use crate :: {
2
3
LightningError , LightningNode , NodeInfo , PaymentOutcome , PaymentResult , SimulationError ,
3
4
} ;
@@ -9,7 +10,7 @@ use lightning::ln::chan_utils::make_funding_redeemscript;
9
10
use serde:: { Deserialize , Serialize } ;
10
11
use std:: collections:: { hash_map:: Entry , HashMap } ;
11
12
use std:: sync:: Arc ;
12
- use std:: time:: { SystemTime , UNIX_EPOCH } ;
13
+ use std:: time:: UNIX_EPOCH ;
13
14
use tokio_util:: task:: TaskTracker ;
14
15
15
16
use lightning:: ln:: features:: { ChannelFeatures , NodeFeatures } ;
@@ -737,8 +738,9 @@ pub async fn ln_node_from_graph(
737
738
/// announcements, which has the effect of adding the nodes in each channel to the graph, because LDK does not export
738
739
/// all of the fields required to apply node announcements. This means that we will not have node-level information
739
740
/// (such as features) available in the routing graph.
740
- pub fn populate_network_graph < ' a > (
741
+ pub fn populate_network_graph < ' a , C : Clock > (
741
742
channels : Vec < SimulatedChannel > ,
743
+ clock : Arc < C > ,
742
744
) -> Result < NetworkGraph < & ' a WrappedLog > , LdkError > {
743
745
let graph = NetworkGraph :: new ( Network :: Regtest , & WrappedLog { } ) ;
744
746
@@ -771,16 +773,16 @@ pub fn populate_network_graph<'a>(
771
773
772
774
graph. update_channel_from_unsigned_announcement ( & announcement, & Some ( & utxo_validator) ) ?;
773
775
774
- // The least significant bit of the channel flag field represents the direction that the channel update
775
- // applies to. This value is interpreted as node_1 if it is zero, and node_2 otherwise.
776
+ // LDK only allows channel announcements up to 24h in the future. Use a fixed timestamp so that even if we've
777
+ // sped up our clock dramatically, we won't hit that limit.
778
+ let now = clock. now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_secs ( ) as u32 ;
776
779
for ( i, node) in [ channel. node_1 , channel. node_2 ] . iter ( ) . enumerate ( ) {
777
780
let update = UnsignedChannelUpdate {
778
781
chain_hash,
779
782
short_channel_id : channel. short_channel_id . into ( ) ,
780
- timestamp : SystemTime :: now ( )
781
- . duration_since ( UNIX_EPOCH )
782
- . unwrap ( )
783
- . as_secs ( ) as u32 ,
783
+ timestamp : now,
784
+ // The least significant bit of the channel flag field represents the direction that the channel update
785
+ // applies to. This value is interpreted as node_1 if it is zero, and node_2 otherwise.
784
786
flags : i as u8 ,
785
787
cltv_expiry_delta : node. policy . cltv_expiry_delta as u16 ,
786
788
htlc_minimum_msat : node. policy . min_htlc_size_msat ,
@@ -1097,6 +1099,7 @@ impl UtxoLookup for UtxoValidator {
1097
1099
#[ cfg( test) ]
1098
1100
mod tests {
1099
1101
use super :: * ;
1102
+ use crate :: clock:: SystemClock ;
1100
1103
use crate :: test_utils:: get_random_keypair;
1101
1104
use bitcoin:: secp256k1:: PublicKey ;
1102
1105
use lightning:: routing:: router:: Route ;
@@ -1488,7 +1491,7 @@ mod tests {
1488
1491
let mock = MockNetwork :: new ( ) ;
1489
1492
let sim_network = Arc :: new ( Mutex :: new ( mock) ) ;
1490
1493
let channels = create_simulated_channels ( 5 , 300000000 ) ;
1491
- let graph = populate_network_graph ( channels. clone ( ) ) . unwrap ( ) ;
1494
+ let graph = populate_network_graph ( channels. clone ( ) , Arc :: new ( SystemClock { } ) ) . unwrap ( ) ;
1492
1495
1493
1496
// Create a simulated node for the first channel in our network.
1494
1497
let pk = channels[ 0 ] . node_1 . policy . pubkey ;
@@ -1580,7 +1583,9 @@ mod tests {
1580
1583
async fn new ( capacity : u64 ) -> Self {
1581
1584
let ( shutdown, _listener) = triggered:: trigger ( ) ;
1582
1585
let channels = create_simulated_channels ( 3 , capacity) ;
1583
- let routing_graph = Arc :: new ( populate_network_graph ( channels. clone ( ) ) . unwrap ( ) ) ;
1586
+ let routing_graph = Arc :: new (
1587
+ populate_network_graph ( channels. clone ( ) , Arc :: new ( SystemClock { } ) ) . unwrap ( ) ,
1588
+ ) ;
1584
1589
1585
1590
let scorer = ProbabilisticScorer :: new (
1586
1591
ProbabilisticScoringDecayParameters :: default ( ) ,
0 commit comments