@@ -15,6 +15,7 @@ use crate::blinded_path::message::{
15
15
} ;
16
16
use crate :: blinded_path:: payment:: BlindedPaymentPath ;
17
17
use crate :: chain;
18
+ use crate :: chain:: transaction:: TransactionData ;
18
19
use crate :: ln:: channelmanager:: PaymentId ;
19
20
use crate :: ln:: inbound_payment;
20
21
use crate :: offers:: invoice:: { Bolt12Invoice , DerivedSigningPubkey , InvoiceBuilder } ;
@@ -29,13 +30,14 @@ use crate::onion_message::messenger::{Destination, MessageRouter, MessageSendIns
29
30
use crate :: onion_message:: offers:: OffersMessage ;
30
31
use crate :: sign:: EntropySource ;
31
32
use crate :: sync:: Mutex ;
33
+ use bitcoin:: block:: Header ;
32
34
use bitcoin:: constants:: ChainHash ;
33
35
use bitcoin:: secp256k1:: { PublicKey , Secp256k1 } ;
34
36
use bitcoin:: { secp256k1, Network } ;
35
37
use types:: payment:: PaymentHash ;
36
38
37
39
use core:: ops:: Deref ;
38
- use core:: sync:: atomic:: AtomicUsize ;
40
+ use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
39
41
use core:: time:: Duration ;
40
42
41
43
#[ cfg( feature = "dnssec" ) ]
@@ -164,4 +166,37 @@ where
164
166
pub fn get_our_node_id ( & self ) -> PublicKey {
165
167
self . our_network_pubkey
166
168
}
169
+
170
+ fn best_block_updated ( & self , header : & Header ) {
171
+ macro_rules! max_time {
172
+ ( $timestamp: expr) => {
173
+ loop {
174
+ // Update $timestamp to be the max of its current value and the block
175
+ // timestamp. This should keep us close to the current time without relying on
176
+ // having an explicit local time source.
177
+ // Just in case we end up in a race, we loop until we either successfully
178
+ // update $timestamp or decide we don't need to.
179
+ let old_serial = $timestamp. load( Ordering :: Acquire ) ;
180
+ if old_serial >= header. time as usize { break ; }
181
+ if $timestamp. compare_exchange( old_serial, header. time as usize , Ordering :: AcqRel , Ordering :: Relaxed ) . is_ok( ) {
182
+ break ;
183
+ }
184
+ }
185
+ }
186
+ }
187
+
188
+ max_time ! ( self . highest_seen_timestamp) ;
189
+ }
167
190
}
191
+
192
+ impl < ES : Deref , MR : Deref > chain:: Listen for OffersMessageFlow < ES , MR >
193
+ where
194
+ ES :: Target : EntropySource ,
195
+ MR :: Target : MessageRouter ,
196
+ {
197
+ fn filtered_block_connected ( & self , header : & Header , _txdata : & TransactionData , _height : u32 ) {
198
+ self . best_block_updated ( header) ;
199
+ }
200
+
201
+ fn block_disconnected ( & self , _header : & Header , _height : u32 ) { }
202
+ }
0 commit comments