@@ -191,8 +191,8 @@ impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync
191
191
let txn_outputs = monitor. block_connected ( txn_matched, height, & block_hash, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
192
192
193
193
for ( ref txid, ref outputs) in txn_outputs {
194
- for ( idx, output ) in outputs. iter ( ) . enumerate ( ) {
195
- self . chain_monitor . install_watch_outpoint ( ( txid. clone ( ) , idx as u32 ) , & output . script_pubkey ) ;
194
+ for ( idx, script ) in outputs. iter ( ) {
195
+ self . chain_monitor . install_watch_outpoint ( ( txid. clone ( ) , * idx) , & script . script_pubkey ) ;
196
196
}
197
197
}
198
198
}
@@ -241,8 +241,8 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys, T: De
241
241
self . chain_monitor . install_watch_tx ( & funding_txo. 0 . txid , & funding_txo. 1 ) ;
242
242
self . chain_monitor . install_watch_outpoint ( ( funding_txo. 0 . txid , funding_txo. 0 . index as u32 ) , & funding_txo. 1 ) ;
243
243
for ( txid, outputs) in monitor. get_outputs_to_watch ( ) . iter ( ) {
244
- for ( idx, script) in outputs. iter ( ) . enumerate ( ) {
245
- self . chain_monitor . install_watch_outpoint ( ( * txid, idx as u32 ) , script) ;
244
+ for ( idx, script) in outputs. iter ( ) {
245
+ self . chain_monitor . install_watch_outpoint ( ( * txid, * idx) , script) ;
246
246
}
247
247
}
248
248
}
@@ -789,7 +789,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
789
789
// interface knows about the TXOs that we want to be notified of spends of. We could probably
790
790
// be smart and derive them from the above storage fields, but its much simpler and more
791
791
// Obviously Correct (tm) if we just keep track of them explicitly.
792
- outputs_to_watch : HashMap < Txid , Vec < Script > > ,
792
+ outputs_to_watch : HashMap < Txid , Vec < ( u32 , Script ) > > ,
793
793
794
794
#[ cfg( test) ]
795
795
pub onchain_tx_handler : OnchainTxHandler < ChanSigner > ,
@@ -1095,10 +1095,11 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
1095
1095
}
1096
1096
1097
1097
( self . outputs_to_watch . len ( ) as u64 ) . write ( writer) ?;
1098
- for ( txid, output_scripts ) in self . outputs_to_watch . iter ( ) {
1098
+ for ( txid, idx_scripts ) in self . outputs_to_watch . iter ( ) {
1099
1099
txid. write ( writer) ?;
1100
- ( output_scripts. len ( ) as u64 ) . write ( writer) ?;
1101
- for script in output_scripts. iter ( ) {
1100
+ ( idx_scripts. len ( ) as u64 ) . write ( writer) ?;
1101
+ for ( idx, script) in idx_scripts. iter ( ) {
1102
+ idx. write ( writer) ?;
1102
1103
script. write ( writer) ?;
1103
1104
}
1104
1105
}
@@ -1417,7 +1418,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1417
1418
1418
1419
/// Gets a list of txids, with their output scripts (in the order they appear in the
1419
1420
/// transaction), which we must learn about spends of via block_connected().
1420
- pub fn get_outputs_to_watch ( & self ) -> & HashMap < Txid , Vec < Script > > {
1421
+ pub fn get_outputs_to_watch ( & self ) -> & HashMap < Txid , Vec < ( u32 , Script ) > > {
1421
1422
& self . outputs_to_watch
1422
1423
}
1423
1424
@@ -1478,7 +1479,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1478
1479
/// HTLC-Success/HTLC-Timeout transactions.
1479
1480
/// Return updates for HTLC pending in the channel and failed automatically by the broadcast of
1480
1481
/// revoked remote commitment tx
1481
- fn check_spend_remote_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , ( Txid , Vec < TxOut > ) ) where L :: Target : Logger {
1482
+ fn check_spend_remote_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , ( Txid , Vec < ( u32 , TxOut ) > ) ) where L :: Target : Logger {
1482
1483
// Most secp and related errors trying to create keys means we have no hope of constructing
1483
1484
// a spend transaction...so we return no transactions to broadcast
1484
1485
let mut claimable_outpoints = Vec :: new ( ) ;
@@ -1533,7 +1534,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1533
1534
if !claimable_outpoints. is_empty ( ) || per_commitment_option. is_some ( ) { // ie we're confident this is actually ours
1534
1535
// We're definitely a remote commitment transaction!
1535
1536
log_trace ! ( logger, "Got broadcast of revoked remote commitment transaction, going to generate general spend tx with {} inputs" , claimable_outpoints. len( ) ) ;
1536
- watch_outputs. append ( & mut tx. output . clone ( ) ) ;
1537
+ for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1538
+ watch_outputs. push ( ( idx as u32 , outp. clone ( ) ) ) ;
1539
+ }
1537
1540
self . remote_commitment_txn_on_chain . insert ( commitment_txid, ( commitment_number, tx. output . iter ( ) . map ( |output| { output. script_pubkey . clone ( ) } ) . collect ( ) ) ) ;
1538
1541
1539
1542
macro_rules! check_htlc_fails {
@@ -1580,7 +1583,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1580
1583
// already processed the block, resulting in the remote_commitment_txn_on_chain entry
1581
1584
// not being generated by the above conditional. Thus, to be safe, we go ahead and
1582
1585
// insert it here.
1583
- watch_outputs. append ( & mut tx. output . clone ( ) ) ;
1586
+ for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1587
+ watch_outputs. push ( ( idx as u32 , outp. clone ( ) ) ) ;
1588
+ }
1584
1589
self . remote_commitment_txn_on_chain . insert ( commitment_txid, ( commitment_number, tx. output . iter ( ) . map ( |output| { output. script_pubkey . clone ( ) } ) . collect ( ) ) ) ;
1585
1590
1586
1591
log_trace ! ( logger, "Got broadcast of non-revoked remote commitment transaction {}" , commitment_txid) ;
@@ -1670,7 +1675,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1670
1675
}
1671
1676
1672
1677
/// Attempts to claim a remote HTLC-Success/HTLC-Timeout's outputs using the revocation key
1673
- fn check_spend_remote_htlc < L : Deref > ( & mut self , tx : & Transaction , commitment_number : u64 , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , Option < ( Txid , Vec < TxOut > ) > ) where L :: Target : Logger {
1678
+ fn check_spend_remote_htlc < L : Deref > ( & mut self , tx : & Transaction , commitment_number : u64 , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , Option < ( Txid , Vec < ( u32 , TxOut ) > ) > ) where L :: Target : Logger {
1674
1679
let htlc_txid = tx. txid ( ) ;
1675
1680
if tx. input . len ( ) != 1 || tx. output . len ( ) != 1 || tx. input [ 0 ] . witness . len ( ) != 5 {
1676
1681
return ( Vec :: new ( ) , None )
@@ -1692,10 +1697,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1692
1697
log_trace ! ( logger, "Remote HTLC broadcast {}:{}" , htlc_txid, 0 ) ;
1693
1698
let witness_data = InputMaterial :: Revoked { per_commitment_point, remote_delayed_payment_base_key : self . remote_tx_cache . remote_delayed_payment_base_key , remote_htlc_base_key : self . remote_tx_cache . remote_htlc_base_key , per_commitment_key, input_descriptor : InputDescriptors :: RevokedOutput , amount : tx. output [ 0 ] . value , htlc : None , on_remote_tx_csv : self . remote_tx_cache . on_remote_tx_csv } ;
1694
1699
let claimable_outpoints = vec ! ( ClaimRequest { absolute_timelock: height + self . remote_tx_cache. on_remote_tx_csv as u32 , aggregable: true , outpoint: BitcoinOutPoint { txid: htlc_txid, vout: 0 } , witness_data } ) ;
1695
- ( claimable_outpoints, Some ( ( htlc_txid, tx. output . clone ( ) ) ) )
1700
+ let outputs = vec ! [ ( 0 , tx. output[ 0 ] . clone( ) ) ] ;
1701
+ ( claimable_outpoints, Some ( ( htlc_txid, outputs) ) )
1696
1702
}
1697
1703
1698
- fn broadcast_by_local_state ( & self , commitment_tx : & Transaction , local_tx : & LocalSignedTx ) -> ( Vec < ClaimRequest > , Vec < TxOut > , Option < ( Script , PublicKey , PublicKey ) > ) {
1704
+ fn broadcast_by_local_state ( & self , commitment_tx : & Transaction , local_tx : & LocalSignedTx ) -> ( Vec < ClaimRequest > , Vec < ( u32 , TxOut ) > , Option < ( Script , PublicKey , PublicKey ) > ) {
1699
1705
let mut claim_requests = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1700
1706
let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1701
1707
@@ -1716,7 +1722,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1716
1722
} else { None } ,
1717
1723
amount : htlc. amount_msat ,
1718
1724
} } ) ;
1719
- watch_outputs. push ( commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ;
1725
+ watch_outputs. push ( ( transaction_output_index , commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ) ;
1720
1726
}
1721
1727
}
1722
1728
@@ -1726,7 +1732,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1726
1732
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
1727
1733
/// revoked using data in local_claimable_outpoints.
1728
1734
/// Should not be used if check_spend_revoked_transaction succeeds.
1729
- fn check_spend_local_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , ( Txid , Vec < TxOut > ) ) where L :: Target : Logger {
1735
+ fn check_spend_local_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , ( Txid , Vec < ( u32 , TxOut ) > ) ) where L :: Target : Logger {
1730
1736
let commitment_txid = tx. txid ( ) ;
1731
1737
let mut claim_requests = Vec :: new ( ) ;
1732
1738
let mut watch_outputs = Vec :: new ( ) ;
@@ -1870,7 +1876,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1870
1876
/// Eventually this should be pub and, roughly, implement ChainListener, however this requires
1871
1877
/// &mut self, as well as returns new spendable outputs and outpoints to watch for spending of
1872
1878
/// on-chain.
1873
- fn block_connected < B : Deref , F : Deref , L : Deref > ( & mut self , txn_matched : & [ & Transaction ] , height : u32 , block_hash : & BlockHash , broadcaster : B , fee_estimator : F , logger : L ) -> Vec < ( Txid , Vec < TxOut > ) >
1879
+ fn block_connected < B : Deref , F : Deref , L : Deref > ( & mut self , txn_matched : & [ & Transaction ] , height : u32 , block_hash : & BlockHash , broadcaster : B , fee_estimator : F , logger : L ) -> Vec < ( Txid , Vec < ( u32 , TxOut ) > ) >
1874
1880
where B :: Target : BroadcasterInterface ,
1875
1881
F :: Target : FeeEstimator ,
1876
1882
L :: Target : Logger ,
@@ -1962,8 +1968,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1962
1968
self . onchain_tx_handler . block_connected ( txn_matched, claimable_outpoints, height, & * broadcaster, & * fee_estimator, & * logger) ;
1963
1969
1964
1970
self . last_block_hash = block_hash. clone ( ) ;
1965
- for & ( ref txid, ref output_scripts ) in watch_outputs. iter ( ) {
1966
- self . outputs_to_watch . insert ( txid. clone ( ) , output_scripts . iter ( ) . map ( |o| o . script_pubkey . clone ( ) ) . collect ( ) ) ;
1971
+ for & ( ref txid, ref idx_scripts ) in watch_outputs. iter ( ) {
1972
+ self . outputs_to_watch . insert ( txid. clone ( ) , idx_scripts . iter ( ) . map ( |o| ( o . 0 , o . 1 . script_pubkey . clone ( ) ) ) . collect ( ) ) ;
1967
1973
}
1968
1974
1969
1975
watch_outputs
@@ -2460,13 +2466,13 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2460
2466
}
2461
2467
2462
2468
let outputs_to_watch_len: u64 = Readable :: read ( reader) ?;
2463
- let mut outputs_to_watch = HashMap :: with_capacity ( cmp:: min ( outputs_to_watch_len as usize , MAX_ALLOC_SIZE / ( mem:: size_of :: < Txid > ( ) + mem:: size_of :: < Vec < Script > > ( ) ) ) ) ;
2469
+ let mut outputs_to_watch = HashMap :: with_capacity ( cmp:: min ( outputs_to_watch_len as usize , MAX_ALLOC_SIZE / ( mem:: size_of :: < Txid > ( ) + mem:: size_of :: < u32 > ( ) + mem :: size_of :: < Vec < Script > > ( ) ) ) ) ;
2464
2470
for _ in 0 ..outputs_to_watch_len {
2465
2471
let txid = Readable :: read ( reader) ?;
2466
2472
let outputs_len: u64 = Readable :: read ( reader) ?;
2467
- let mut outputs = Vec :: with_capacity ( cmp:: min ( outputs_len as usize , MAX_ALLOC_SIZE / mem:: size_of :: < Script > ( ) ) ) ;
2473
+ let mut outputs = Vec :: with_capacity ( cmp:: min ( outputs_len as usize , MAX_ALLOC_SIZE / ( mem:: size_of :: < u32 > ( ) + mem :: size_of :: < Script > ( ) ) ) ) ;
2468
2474
for _ in 0 ..outputs_len {
2469
- outputs. push ( Readable :: read ( reader) ?) ;
2475
+ outputs. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader ) ? ) ) ;
2470
2476
}
2471
2477
if let Some ( _) = outputs_to_watch. insert ( txid, outputs) {
2472
2478
return Err ( DecodeError :: InvalidValue ) ;
0 commit comments