@@ -16,7 +16,7 @@ use bitcoin::blockdata::transaction::Transaction;
16
16
use bitcoin:: blockdata:: transaction:: OutPoint as BitcoinOutPoint ;
17
17
use bitcoin:: blockdata:: script:: Script ;
18
18
19
- use bitcoin:: hash_types:: Txid ;
19
+ use bitcoin:: hash_types:: { Txid , BlockHash } ;
20
20
21
21
use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
22
22
use bitcoin:: secp256k1;
@@ -58,6 +58,7 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
58
58
struct OnchainEventEntry {
59
59
txid : Txid ,
60
60
height : u32 ,
61
+ block_hash : Option < BlockHash > , // Added as optional, will be filled in for any entry generated on 0.0.113 or after
61
62
event : OnchainEvent ,
62
63
}
63
64
@@ -92,6 +93,7 @@ impl Writeable for OnchainEventEntry {
92
93
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
93
94
write_tlv_fields ! ( writer, {
94
95
( 0 , self . txid, required) ,
96
+ ( 1 , self . block_hash, option) ,
95
97
( 2 , self . height, required) ,
96
98
( 4 , self . event, required) ,
97
99
} ) ;
@@ -103,14 +105,16 @@ impl MaybeReadable for OnchainEventEntry {
103
105
fn read < R : io:: Read > ( reader : & mut R ) -> Result < Option < Self > , DecodeError > {
104
106
let mut txid = Txid :: all_zeros ( ) ;
105
107
let mut height = 0 ;
108
+ let mut block_hash = None ;
106
109
let mut event = None ;
107
110
read_tlv_fields ! ( reader, {
108
111
( 0 , txid, required) ,
112
+ ( 1 , block_hash, option) ,
109
113
( 2 , height, required) ,
110
114
( 4 , event, ignorable) ,
111
115
} ) ;
112
116
if let Some ( ev) = event {
113
- Ok ( Some ( Self { txid, height, event : ev } ) )
117
+ Ok ( Some ( Self { txid, height, block_hash , event : ev } ) )
114
118
} else {
115
119
Ok ( None )
116
120
}
@@ -543,17 +547,22 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
543
547
544
548
/// Upon channelmonitor.block_connected(..) or upon provision of a preimage on the forward link
545
549
/// for this channel, provide new relevant on-chain transactions and/or new claim requests.
546
- /// Formerly this was named `block_connected`, but it is now also used for claiming an HTLC output
547
- /// if we receive a preimage after force-close.
548
- /// `conf_height` represents the height at which the transactions in `txn_matched` were
549
- /// confirmed. This does not need to equal the current blockchain tip height, which should be
550
- /// provided via `cur_height`, however it must never be higher than `cur_height`.
551
- pub ( crate ) fn update_claims_view < B : Deref , F : Deref , L : Deref > ( & mut self , txn_matched : & [ & Transaction ] , requests : Vec < PackageTemplate > , conf_height : u32 , cur_height : u32 , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L )
552
- where B :: Target : BroadcasterInterface ,
553
- F :: Target : FeeEstimator ,
554
- L :: Target : Logger ,
550
+ /// Together with `update_claims_view_from_matched_txn` this used to be named
551
+ /// `block_connected`, but it is now also used for claiming an HTLC output if we receive a
552
+ /// preimage after force-close.
553
+ ///
554
+ /// `conf_height` represents the height at which the request was generated. This
555
+ /// does not need to equal the current blockchain tip height, which should be provided via
556
+ /// `cur_height`, however it must never be higher than `cur_height`.
557
+ pub ( crate ) fn update_claims_view_from_requests < B : Deref , F : Deref , L : Deref > (
558
+ & mut self , requests : Vec < PackageTemplate > , conf_height : u32 , cur_height : u32 ,
559
+ broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L
560
+ ) where
561
+ B :: Target : BroadcasterInterface ,
562
+ F :: Target : FeeEstimator ,
563
+ L :: Target : Logger ,
555
564
{
556
- log_debug ! ( logger, "Updating claims view at height {} with {} matched transactions in block {} and {} claim requests" , cur_height, txn_matched . len ( ) , conf_height , requests. len( ) ) ;
565
+ log_debug ! ( logger, "Updating claims view at height {} with {} claim requests" , cur_height, requests. len( ) ) ;
557
566
let mut preprocessed_requests = Vec :: with_capacity ( requests. len ( ) ) ;
558
567
let mut aggregated_request = None ;
559
568
@@ -633,7 +642,25 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
633
642
self . pending_claim_requests . insert ( txid, req) ;
634
643
}
635
644
}
645
+ }
636
646
647
+ /// Upon channelmonitor.block_connected(..) or upon provision of a preimage on the forward link
648
+ /// for this channel, provide new relevant on-chain transactions and/or new claim requests.
649
+ /// Together with `update_claims_view_from_requests` this used to be named `block_connected`,
650
+ /// but it is now also used for claiming an HTLC output if we receive a preimage after force-close.
651
+ ///
652
+ /// `conf_height` represents the height at which the transactions in `txn_matched` were
653
+ /// confirmed. This does not need to equal the current blockchain tip height, which should be
654
+ /// provided via `cur_height`, however it must never be higher than `cur_height`.
655
+ pub ( crate ) fn update_claims_view_from_matched_txn < B : Deref , F : Deref , L : Deref > (
656
+ & mut self , txn_matched : & [ & Transaction ] , conf_height : u32 , conf_hash : BlockHash ,
657
+ cur_height : u32 , broadcaster : & B , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L
658
+ ) where
659
+ B :: Target : BroadcasterInterface ,
660
+ F :: Target : FeeEstimator ,
661
+ L :: Target : Logger ,
662
+ {
663
+ log_debug ! ( logger, "Updating claims view at height {} with {} matched transactions in block {}" , cur_height, txn_matched. len( ) , conf_height) ;
637
664
let mut bump_candidates = HashMap :: new ( ) ;
638
665
for tx in txn_matched {
639
666
// Scan all input to verify is one of the outpoint spent is of interest for us
@@ -661,6 +688,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
661
688
let entry = OnchainEventEntry {
662
689
txid: tx. txid( ) ,
663
690
height: conf_height,
691
+ block_hash: Some ( conf_hash) ,
664
692
event: OnchainEvent :: Claim { claim_request: first_claim_txid_height. 0 . clone( ) }
665
693
} ;
666
694
if !self . onchain_events_awaiting_threshold_conf. contains( & entry) {
@@ -701,6 +729,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
701
729
let entry = OnchainEventEntry {
702
730
txid : tx. txid ( ) ,
703
731
height : conf_height,
732
+ block_hash : Some ( conf_hash) ,
704
733
event : OnchainEvent :: ContentiousOutpoint { package } ,
705
734
} ;
706
735
if !self . onchain_events_awaiting_threshold_conf . contains ( & entry) {
@@ -860,12 +889,12 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
860
889
self . claimable_outpoints . get ( outpoint) . is_some ( )
861
890
}
862
891
863
- pub ( crate ) fn get_relevant_txids ( & self ) -> Vec < Txid > {
864
- let mut txids: Vec < Txid > = self . onchain_events_awaiting_threshold_conf
892
+ pub ( crate ) fn get_relevant_txids ( & self ) -> Vec < ( Txid , Option < BlockHash > ) > {
893
+ let mut txids: Vec < ( Txid , Option < BlockHash > ) > = self . onchain_events_awaiting_threshold_conf
865
894
. iter ( )
866
- . map ( |entry| entry. txid )
895
+ . map ( |entry| ( entry. txid , entry . block_hash ) )
867
896
. collect ( ) ;
868
- txids. sort_unstable ( ) ;
897
+ txids. sort_unstable_by_key ( | ( txid , _ ) | * txid ) ;
869
898
txids. dedup ( ) ;
870
899
txids
871
900
}
0 commit comments