@@ -32,7 +32,7 @@ use ln::chan_utils;
32
32
use ln:: chan_utils:: { CounterpartyCommitmentSecrets , HTLCOutputInCommitment , LocalCommitmentTransaction , HTLCType } ;
33
33
use ln:: channelmanager:: { HTLCSource , PaymentPreimage , PaymentHash } ;
34
34
use ln:: onchaintx:: OnchainTxHandler ;
35
- use ln:: onchain_utils:: { InputDescriptors , PackageTemplate } ;
35
+ use ln:: onchain_utils:: { InputDescriptors , PackageTemplate , OnchainRequest , BumpStrategy } ;
36
36
use chain:: chaininterface:: { ChainListener , ChainWatchInterface , BroadcasterInterface , FeeEstimator } ;
37
37
use chain:: transaction:: OutPoint ;
38
38
use chain:: keysinterface:: { SpendableOutputDescriptor , ChannelKeys } ;
@@ -428,26 +428,6 @@ impl Readable for RemoteCommitmentTransaction {
428
428
}
429
429
}
430
430
431
- /// ClaimRequest is a descriptor structure to communicate between detection
432
- /// and reaction module. They are generated by ChannelMonitor while parsing
433
- /// onchain txn leaked from a channel and handed over to OnchainTxHandler which
434
- /// is responsible for opportunistic aggregation, selecting and enforcing
435
- /// bumping logic, building and signing transactions.
436
- pub ( crate ) struct ClaimRequest {
437
- // Block height before which claiming is exclusive to one party,
438
- // after reaching it, claiming may be contentious.
439
- pub ( crate ) absolute_timelock : u32 ,
440
- // Timeout tx must have nLocktime set which means aggregating multiple
441
- // ones must take the higher nLocktime among them to satisfy all of them.
442
- // Sadly it has few pitfalls, a) it takes longuer to get fund back b) CLTV_DELTA
443
- // of a sooner-HTLC could be swallowed by the highest nLocktime of the HTLC set.
444
- // Do simplify we mark them as non-aggregable.
445
- pub ( crate ) aggregable : bool ,
446
- // Template (list of outpoint and set of data needed to generate transaction digest
447
- // and satisfy witness program).
448
- pub ( crate ) package_template : PackageTemplate ,
449
- }
450
-
451
431
/// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it
452
432
/// once they mature to enough confirmations (ANTI_REORG_DELAY)
453
433
#[ derive( Clone , PartialEq ) ]
@@ -1351,7 +1331,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1351
1331
/// HTLC-Success/HTLC-Timeout transactions.
1352
1332
/// Return updates for HTLC pending in the channel and failed automatically by the broadcast of
1353
1333
/// revoked remote commitment tx
1354
- fn check_spend_remote_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , ( Txid , Vec < TxOut > ) ) where L :: Target : Logger {
1334
+ fn check_spend_remote_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < OnchainRequest > , ( Txid , Vec < TxOut > ) ) where L :: Target : Logger {
1355
1335
// Most secp and related errors trying to create keys means we have no hope of constructing
1356
1336
// a spend transaction...so we return no transactions to broadcast
1357
1337
let mut claimable_outpoints = Vec :: new ( ) ;
@@ -1384,7 +1364,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1384
1364
for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1385
1365
if outp. script_pubkey == revokeable_p2wsh {
1386
1366
let malleable_justice_tx = PackageTemplate :: build_malleable_justice_tx ( per_commitment_point, per_commitment_key, self . remote_tx_cache . remote_delayed_payment_base_key , self . remote_tx_cache . remote_htlc_base_key , InputDescriptors :: RevokedOutput , commitment_txid, idx as u32 , outp. value , None , self . remote_tx_cache . on_remote_tx_csv ) ;
1387
- claimable_outpoints. push ( ClaimRequest { absolute_timelock : height + self . remote_tx_cache . on_remote_tx_csv as u32 , aggregable : true , package_template : malleable_justice_tx} ) ;
1367
+ claimable_outpoints. push ( OnchainRequest { aggregation : true , bump_strategy : BumpStrategy :: RBF , feerate_previous : 0 , height_timer : None , absolute_timelock : height + self . remote_tx_cache . on_remote_tx_csv as u32 , height_original : height , content : malleable_justice_tx} ) ;
1388
1368
}
1389
1369
}
1390
1370
@@ -1397,7 +1377,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1397
1377
return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ; // Corrupted per_commitment_data, fuck this user
1398
1378
}
1399
1379
let malleable_justice_tx = PackageTemplate :: build_malleable_justice_tx ( per_commitment_point, per_commitment_key, self . remote_tx_cache . remote_delayed_payment_base_key , self . remote_tx_cache . remote_htlc_base_key , if htlc. offered { InputDescriptors :: RevokedOfferedHTLC } else { InputDescriptors :: RevokedReceivedHTLC } , commitment_txid, transaction_output_index, htlc. amount_msat / 1000 , Some ( htlc. clone ( ) ) , self . remote_tx_cache . on_remote_tx_csv ) ;
1400
- claimable_outpoints. push ( ClaimRequest { absolute_timelock : htlc. cltv_expiry , aggregable : true , package_template : malleable_justice_tx} ) ;
1380
+ claimable_outpoints. push ( OnchainRequest { aggregation : true , bump_strategy : BumpStrategy :: RBF , feerate_previous : 0 , height_timer : None , absolute_timelock : htlc. cltv_expiry , height_original : height , content : malleable_justice_tx} ) ;
1401
1381
}
1402
1382
}
1403
1383
}
@@ -1529,10 +1509,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1529
1509
return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ; // Corrupted per_commitment_data, fuck this user
1530
1510
}
1531
1511
let preimage = if htlc. offered { if let Some ( p) = self . payment_preimages . get ( & htlc. payment_hash ) { Some ( * p) } else { None } } else { None } ;
1532
- let aggregable = if !htlc. offered { false } else { true } ;
1533
1512
if preimage. is_some ( ) || !htlc. offered {
1534
1513
let remote_htlc_tx = PackageTemplate :: build_remote_htlc_tx ( * revocation_point, self . remote_tx_cache . remote_delayed_payment_base_key , self . remote_tx_cache . remote_htlc_base_key , preimage, htlc. clone ( ) , commitment_txid, transaction_output_index) ;
1535
- claimable_outpoints. push ( ClaimRequest { absolute_timelock : htlc. cltv_expiry , aggregable , package_template : remote_htlc_tx } ) ;
1514
+ claimable_outpoints. push ( OnchainRequest { aggregation : if !htlc . offered { false } else { true } , bump_strategy : BumpStrategy :: RBF , feerate_previous : 0 , height_timer : None , absolute_timelock : htlc. cltv_expiry , height_original : height , content : remote_htlc_tx } ) ;
1536
1515
}
1537
1516
}
1538
1517
}
@@ -1543,7 +1522,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1543
1522
}
1544
1523
1545
1524
/// Attempts to claim a remote HTLC-Success/HTLC-Timeout's outputs using the revocation key
1546
- 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 {
1525
+ fn check_spend_remote_htlc < L : Deref > ( & mut self , tx : & Transaction , commitment_number : u64 , height : u32 , logger : & L ) -> ( Vec < OnchainRequest > , Option < ( Txid , Vec < TxOut > ) > ) where L :: Target : Logger {
1547
1526
let htlc_txid = tx. txid ( ) ;
1548
1527
if tx. input . len ( ) != 1 || tx. output . len ( ) != 1 || tx. input [ 0 ] . witness . len ( ) != 5 {
1549
1528
return ( Vec :: new ( ) , None )
@@ -1564,11 +1543,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1564
1543
1565
1544
log_trace ! ( logger, "Remote HTLC broadcast {}:{}" , htlc_txid, 0 ) ;
1566
1545
let malleable_justice_tx = PackageTemplate :: build_malleable_justice_tx ( per_commitment_point, per_commitment_key, self . remote_tx_cache . remote_delayed_payment_base_key , self . remote_tx_cache . remote_htlc_base_key , InputDescriptors :: RevokedOutput , htlc_txid, 0 , tx. output [ 0 ] . value , None , self . remote_tx_cache . on_remote_tx_csv ) ;
1567
- let claimable_outpoints = vec ! ( ClaimRequest { absolute_timelock: height + self . remote_tx_cache. on_remote_tx_csv as u32 , aggregable : true , package_template : malleable_justice_tx } ) ;
1546
+ let claimable_outpoints = vec ! ( OnchainRequest { aggregation : true , bump_strategy : BumpStrategy :: RBF , feerate_previous : 0 , height_timer : None , absolute_timelock: height + self . remote_tx_cache. on_remote_tx_csv as u32 , height_original : height , content : malleable_justice_tx } ) ;
1568
1547
( claimable_outpoints, Some ( ( htlc_txid, tx. output . clone ( ) ) ) )
1569
1548
}
1570
1549
1571
- fn broadcast_by_local_state ( & self , commitment_tx : & Transaction , local_tx : & LocalSignedTx ) -> ( Vec < ClaimRequest > , Vec < TxOut > , Option < ( Script , PublicKey , PublicKey ) > ) {
1550
+ fn broadcast_by_local_state ( & self , commitment_tx : & Transaction , local_tx : & LocalSignedTx , height : u32 ) -> ( Vec < OnchainRequest > , Vec < TxOut > , Option < ( Script , PublicKey , PublicKey ) > ) {
1572
1551
let mut claim_requests = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1573
1552
let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1574
1553
@@ -1585,7 +1564,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1585
1564
continue ;
1586
1565
}
1587
1566
} else { None } , htlc. amount_msat , local_tx. txid , transaction_output_index) ;
1588
- claim_requests. push ( ClaimRequest { absolute_timelock : :: std :: u32 :: MAX , aggregable : false , package_template : local_htlc_tx } ) ;
1567
+ claim_requests. push ( OnchainRequest { aggregation : false , bump_strategy : BumpStrategy :: CPFP , feerate_previous : 0 , height_timer : None , absolute_timelock : height , height_original : height , content : local_htlc_tx } ) ;
1589
1568
watch_outputs. push ( commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ;
1590
1569
}
1591
1570
}
@@ -1596,7 +1575,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1596
1575
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
1597
1576
/// revoked using data in local_claimable_outpoints.
1598
1577
/// Should not be used if check_spend_revoked_transaction succeeds.
1599
- fn check_spend_local_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < ClaimRequest > , ( Txid , Vec < TxOut > ) ) where L :: Target : Logger {
1578
+ fn check_spend_local_transaction < L : Deref > ( & mut self , tx : & Transaction , height : u32 , logger : & L ) -> ( Vec < OnchainRequest > , ( Txid , Vec < TxOut > ) ) where L :: Target : Logger {
1600
1579
let commitment_txid = tx. txid ( ) ;
1601
1580
let mut claim_requests = Vec :: new ( ) ;
1602
1581
let mut watch_outputs = Vec :: new ( ) ;
@@ -1638,13 +1617,13 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1638
1617
if self . current_local_commitment_tx . txid == commitment_txid {
1639
1618
is_local_tx = true ;
1640
1619
log_trace ! ( logger, "Got latest local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1641
- let mut res = self . broadcast_by_local_state ( tx, & self . current_local_commitment_tx ) ;
1620
+ let mut res = self . broadcast_by_local_state ( tx, & self . current_local_commitment_tx , height ) ;
1642
1621
append_onchain_update ! ( res) ;
1643
1622
} else if let & Some ( ref local_tx) = & self . prev_local_signed_commitment_tx {
1644
1623
if local_tx. txid == commitment_txid {
1645
1624
is_local_tx = true ;
1646
1625
log_trace ! ( logger, "Got previous local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1647
- let mut res = self . broadcast_by_local_state ( tx, local_tx) ;
1626
+ let mut res = self . broadcast_by_local_state ( tx, local_tx, height ) ;
1648
1627
append_onchain_update ! ( res) ;
1649
1628
}
1650
1629
}
@@ -1799,11 +1778,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1799
1778
let should_broadcast = self . would_broadcast_at_height ( height, & logger) ;
1800
1779
if should_broadcast {
1801
1780
let local_commitment_tx = PackageTemplate :: build_local_commitment_tx ( self . funding_redeemscript . clone ( ) , self . funding_info . 0 . txid . clone ( ) , self . funding_info . 0 . index as u32 ) ;
1802
- claimable_outpoints. push ( ClaimRequest { absolute_timelock : height, aggregable : false , package_template : local_commitment_tx } ) ;
1781
+ claimable_outpoints. push ( OnchainRequest { aggregation : false , bump_strategy : BumpStrategy :: CPFP , feerate_previous : 0 , height_timer : None , absolute_timelock : height, height_original : height , content : local_commitment_tx } ) ;
1803
1782
}
1804
1783
if should_broadcast {
1805
1784
if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_local_tx ( & self . funding_redeemscript ) {
1806
- let ( mut new_outpoints, new_outputs, _) = self . broadcast_by_local_state ( & commitment_tx, & self . current_local_commitment_tx ) ;
1785
+ let ( mut new_outpoints, new_outputs, _) = self . broadcast_by_local_state ( & commitment_tx, & self . current_local_commitment_tx , height ) ;
1807
1786
if !new_outputs. is_empty ( ) {
1808
1787
watch_outputs. push ( ( self . current_local_commitment_tx . txid . clone ( ) , new_outputs) ) ;
1809
1788
}
0 commit comments