Skip to content

Commit 293b82b

Browse files
committed
fix process_pending_htlc_forwards for swaps
1 parent 3f41bd2 commit 293b82b

File tree

11 files changed

+200
-174
lines changed

11 files changed

+200
-174
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
3131

3232
use bitcoin::ecdsa::Signature as BitcoinSignature;
3333
use bitcoin::secp256k1::{self, SecretKey, PublicKey, Secp256k1, ecdsa::Signature};
34+
use rgb_lib::ContractId;
3435

3536
use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
3637
use crate::ln::types::{PaymentHash, PaymentPreimage, ChannelId};
@@ -216,14 +217,14 @@ pub struct HTLCUpdate {
216217
pub(crate) payment_preimage: Option<PaymentPreimage>,
217218
pub(crate) source: HTLCSource,
218219
pub(crate) htlc_value_satoshis: Option<u64>,
219-
pub(crate) htlc_value_rgb: Option<u64>,
220+
pub(crate) htlc_rgb_payment: Option<(ContractId, u64)>,
220221
}
221222
impl_writeable_tlv_based!(HTLCUpdate, {
222223
(0, payment_hash, required),
223224
(1, htlc_value_satoshis, option),
224225
(2, source, required),
225226
(4, payment_preimage, option),
226-
(6, htlc_value_rgb, option),
227+
(6, htlc_rgb_payment, option),
227228
});
228229

229230
/// If an HTLC expires within this many blocks, don't try to claim it in a shared transaction,
@@ -429,7 +430,7 @@ enum OnchainEvent {
429430
source: HTLCSource,
430431
payment_hash: PaymentHash,
431432
htlc_value_satoshis: Option<u64>,
432-
htlc_value_rgb: Option<u64>,
433+
htlc_rgb_payment: Option<(ContractId, u64)>,
433434
/// None in the second case, above, ie when there is no relevant output in the commitment
434435
/// transaction which appeared on chain.
435436
commitment_tx_output_idx: Option<u32>,
@@ -511,7 +512,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
511512
(1, htlc_value_satoshis, option),
512513
(2, payment_hash, required),
513514
(3, commitment_tx_output_idx, option),
514-
(4, htlc_value_rgb, option),
515+
(4, htlc_rgb_payment, option),
515516
},
516517
(1, MaturingOutput) => {
517518
(0, descriptor, required),
@@ -1109,7 +1110,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
11091110
writer.write_all(&$htlc_output.cltv_expiry.to_be_bytes())?;
11101111
writer.write_all(&$htlc_output.payment_hash.0[..])?;
11111112
$htlc_output.transaction_output_index.write(writer)?;
1112-
$htlc_output.amount_rgb.write(writer)?;
1113+
$htlc_output.rgb_payment.write(writer)?;
11131114
}
11141115
}
11151116

@@ -2649,7 +2650,7 @@ macro_rules! fail_unbroadcast_htlcs {
26492650
source: (**source).clone(),
26502651
payment_hash: htlc.payment_hash.clone(),
26512652
htlc_value_satoshis: Some(htlc.amount_msat / 1000),
2652-
htlc_value_rgb: htlc.amount_rgb,
2653+
htlc_rgb_payment: htlc.rgb_payment,
26532654
commitment_tx_output_idx: None,
26542655
},
26552656
};
@@ -4089,7 +4090,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40894090
// Produce actionable events from on-chain events having reached their threshold.
40904091
for entry in onchain_events_reaching_threshold_conf.drain(..) {
40914092
match entry.event {
4092-
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, htlc_value_rgb, commitment_tx_output_idx } => {
4093+
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, htlc_rgb_payment, commitment_tx_output_idx } => {
40934094
// Check for duplicate HTLC resolutions.
40944095
#[cfg(debug_assertions)]
40954096
{
@@ -4113,7 +4114,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
41134114
payment_preimage: None,
41144115
source: source.clone(),
41154116
htlc_value_satoshis,
4116-
htlc_value_rgb,
4117+
htlc_rgb_payment,
41174118
}));
41184119
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
41194120
commitment_tx_output_idx,
@@ -4410,7 +4411,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
44104411
if pending_htlc.payment_hash == $htlc_output.payment_hash && pending_htlc.amount_msat == $htlc_output.amount_msat {
44114412
if let &Some(ref source) = pending_source {
44124413
log_claim!("revoked counterparty commitment tx", false, pending_htlc, true);
4413-
payment_data = Some(((**source).clone(), $htlc_output.payment_hash, $htlc_output.amount_msat, $htlc_output.amount_rgb));
4414+
payment_data = Some(((**source).clone(), $htlc_output.payment_hash, $htlc_output.amount_msat, $htlc_output.rgb_payment));
44144415
break;
44154416
}
44164417
}
@@ -4429,7 +4430,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
44294430
// transaction. This implies we either learned a preimage, the HTLC
44304431
// has timed out, or we screwed up. In any case, we should now
44314432
// resolve the source HTLC with the original sender.
4432-
payment_data = Some(((*source).clone(), htlc_output.payment_hash, htlc_output.amount_msat, htlc_output.amount_rgb));
4433+
payment_data = Some(((*source).clone(), htlc_output.payment_hash, htlc_output.amount_msat, htlc_output.rgb_payment));
44334434
} else if !$holder_tx {
44344435
if let Some(current_counterparty_commitment_txid) = &self.current_counterparty_commitment_txid {
44354436
check_htlc_valid_counterparty!(htlc_output, self.counterparty_claimable_outpoints.get(current_counterparty_commitment_txid).unwrap());
@@ -4481,7 +4482,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
44814482

44824483
// Check that scan_commitment, above, decided there is some source worth relaying an
44834484
// HTLC resolution backwards to and figure out whether we learned a preimage from it.
4484-
if let Some((source, payment_hash, amount_msat, amount_rgb)) = payment_data {
4485+
if let Some((source, payment_hash, amount_msat, htlc_rgb_payment)) = payment_data {
44854486
if accepted_preimage_claim {
44864487
if !self.pending_monitor_events.iter().any(
44874488
|update| if let &MonitorEvent::HTLCEvent(ref upd) = update { upd.source == source } else { false }) {
@@ -4501,7 +4502,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45014502
payment_preimage: Some(payment_preimage),
45024503
payment_hash,
45034504
htlc_value_satoshis: Some(amount_msat / 1000),
4504-
htlc_value_rgb: amount_rgb,
4505+
htlc_rgb_payment,
45054506
}));
45064507
}
45074508
} else if offered_preimage_claim {
@@ -4525,7 +4526,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45254526
payment_preimage: Some(payment_preimage),
45264527
payment_hash,
45274528
htlc_value_satoshis: Some(amount_msat / 1000),
4528-
htlc_value_rgb: amount_rgb,
4529+
htlc_rgb_payment,
45294530
}));
45304531
}
45314532
} else {
@@ -4546,7 +4547,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45464547
event: OnchainEvent::HTLCUpdate {
45474548
source, payment_hash,
45484549
htlc_value_satoshis: Some(amount_msat / 1000),
4549-
htlc_value_rgb: amount_rgb,
4550+
htlc_rgb_payment,
45504551
commitment_tx_output_idx: Some(input.previous_output.vout),
45514552
},
45524553
};
@@ -4740,10 +4741,10 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
47404741
let cltv_expiry: u32 = Readable::read(reader)?;
47414742
let payment_hash: PaymentHash = Readable::read(reader)?;
47424743
let transaction_output_index: Option<u32> = Readable::read(reader)?;
4743-
let amount_rgb: Option<u64> = Readable::read(reader)?;
4744+
let rgb_payment: Option<(ContractId, u64)> = Readable::read(reader)?;
47444745

47454746
HTLCOutputInCommitment {
4746-
offered, amount_msat, cltv_expiry, payment_hash, transaction_output_index, amount_rgb
4747+
offered, amount_msat, cltv_expiry, payment_hash, transaction_output_index, rgb_payment
47474748
}
47484749
}
47494750
}

lightning/src/events/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
pub mod bump_transaction;
1818

1919
pub use bump_transaction::BumpTransactionEvent;
20+
use rgb_lib::ContractId;
2021

2122
use crate::blinded_path::message::OffersContext;
2223
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext, PaymentContextRef};
@@ -1092,7 +1093,7 @@ pub enum Event {
10921093
/// Inbound assets, if any
10931094
inbound_rgb_amount: Option<u64>,
10941095
/// How much assets should be forwarded, if any
1095-
expected_outbound_rgb_amount: Option<u64>,
1096+
expected_outbound_rgb_payment: Option<(ContractId, u64)>,
10961097
/// Whether the intercept is a swap
10971098
is_swap: bool,
10981099
/// Previous short channel id
@@ -1541,7 +1542,7 @@ impl Writeable for Event {
15411542
(1, channel_id, option),
15421543
});
15431544
},
1544-
&Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, inbound_rgb_amount, expected_outbound_rgb_amount, intercept_id, is_swap, prev_short_channel_id } => {
1545+
&Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, inbound_rgb_amount, expected_outbound_rgb_payment, intercept_id, is_swap, prev_short_channel_id } => {
15451546
6u8.write(writer)?;
15461547
let intercept_scid = InterceptNextHop::FakeScid { requested_next_hop_scid };
15471548
write_tlv_fields!(writer, {
@@ -1551,7 +1552,7 @@ impl Writeable for Event {
15511552
(6, inbound_amount_msat, required),
15521553
(8, expected_outbound_amount_msat, required),
15531554
(10, inbound_rgb_amount, option),
1554-
(12, expected_outbound_rgb_amount, option),
1555+
(12, expected_outbound_rgb_payment, option),
15551556
(14, is_swap, required),
15561557
(16, prev_short_channel_id, required),
15571558
});
@@ -1908,7 +1909,7 @@ impl MaybeReadable for Event {
19081909
let mut inbound_amount_msat = 0;
19091910
let mut expected_outbound_amount_msat = 0;
19101911
let mut inbound_rgb_amount = None;
1911-
let mut expected_outbound_rgb_amount = None;
1912+
let mut expected_outbound_rgb_payment = None;
19121913
let mut is_swap = false;
19131914
let mut prev_short_channel_id = 0;
19141915
read_tlv_fields!(reader, {
@@ -1918,7 +1919,7 @@ impl MaybeReadable for Event {
19181919
(6, inbound_amount_msat, required),
19191920
(8, expected_outbound_amount_msat, required),
19201921
(10, inbound_rgb_amount, option),
1921-
(12, expected_outbound_rgb_amount, option),
1922+
(12, expected_outbound_rgb_payment, option),
19221923
(14, is_swap, required),
19231924
(16, prev_short_channel_id, required),
19241925
});
@@ -1931,7 +1932,7 @@ impl MaybeReadable for Event {
19311932
inbound_amount_msat,
19321933
expected_outbound_amount_msat,
19331934
inbound_rgb_amount,
1934-
expected_outbound_rgb_amount,
1935+
expected_outbound_rgb_payment,
19351936
intercept_id,
19361937
is_swap,
19371938
prev_short_channel_id,

lightning/src/ln/chan_utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use bitcoin::hashes::hash160::Hash as Hash160;
2424
use bitcoin::hashes::sha256::Hash as Sha256;
2525
use bitcoin::hashes::ripemd160::Hash as Ripemd160;
2626
use bitcoin::hash_types::Txid;
27+
use rgb_lib::ContractId;
2728

2829
use crate::chain::chaininterface::fee_for_weight;
2930
use crate::chain::package::WEIGHT_REVOKED_OUTPUT;
@@ -581,8 +582,8 @@ pub struct HTLCOutputInCommitment {
581582
/// below the dust limit (in which case no output appears in the commitment transaction and the
582583
/// value is spent to additional transaction fees).
583584
pub transaction_output_index: Option<u32>,
584-
/// The RGB amount allocated to the HTLC
585-
pub amount_rgb: Option<u64>,
585+
/// The RGB payment allocated to the HTLC
586+
pub rgb_payment: Option<(ContractId, u64)>,
586587
}
587588

588589
impl HTLCOutputInCommitment {
@@ -600,7 +601,7 @@ impl_writeable_tlv_based!(HTLCOutputInCommitment, {
600601
(4, cltv_expiry, required),
601602
(6, payment_hash, required),
602603
(8, transaction_output_index, option),
603-
(10, amount_rgb, option),
604+
(10, rgb_payment, option),
604605
});
605606

606607
#[inline]

0 commit comments

Comments
 (0)