Skip to content

Commit 4d45ce5

Browse files
committed
post rebase fixes
1 parent 63f26af commit 4d45ce5

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

lightning/src/events/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,10 @@ pub enum Event {
776776
///
777777
/// The caveat described above the `fee_earned_msat` field applies here as well.
778778
outbound_amount_forwarded_msat: Option<u64>,
779-
/// The rgb amount forwarded.
779+
/// The rgb amount forwarded outbound.
780780
outbound_amount_forwarded_rgb: Option<u64>,
781+
/// The rgb amount forwarded inbound.
782+
inbound_amount_forwarded_rgb: Option<u64>,
781783
},
782784
/// Used to indicate that a channel with the given `channel_id` is being opened and pending
783785
/// confirmation on-chain.
@@ -1058,7 +1060,7 @@ impl Writeable for Event {
10581060
}
10591061
&Event::PaymentForwarded {
10601062
fee_earned_msat, prev_channel_id, claim_from_onchain_tx,
1061-
next_channel_id, outbound_amount_forwarded_msat, outbound_amount_forwarded_rgb,
1063+
next_channel_id, outbound_amount_forwarded_msat, outbound_amount_forwarded_rgb, inbound_amount_forwarded_rgb,
10621064
} => {
10631065
7u8.write(writer)?;
10641066
write_tlv_fields!(writer, {
@@ -1068,6 +1070,7 @@ impl Writeable for Event {
10681070
(3, next_channel_id, option),
10691071
(5, outbound_amount_forwarded_msat, option),
10701072
(6, outbound_amount_forwarded_rgb, option),
1073+
(7, inbound_amount_forwarded_rgb, option),
10711074
});
10721075
},
10731076
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
@@ -1373,17 +1376,19 @@ impl MaybeReadable for Event {
13731376
let mut next_channel_id = None;
13741377
let mut outbound_amount_forwarded_msat = None;
13751378
let mut outbound_amount_forwarded_rgb = None;
1379+
let mut inbound_amount_forwarded_rgb = None;
13761380
read_tlv_fields!(reader, {
13771381
(0, fee_earned_msat, option),
13781382
(1, prev_channel_id, option),
13791383
(2, claim_from_onchain_tx, required),
13801384
(3, next_channel_id, option),
13811385
(5, outbound_amount_forwarded_msat, option),
13821386
(6, outbound_amount_forwarded_rgb, option),
1387+
(7, inbound_amount_forwarded_rgb, option),
13831388
});
13841389
Ok(Some(Event::PaymentForwarded {
13851390
fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
1386-
outbound_amount_forwarded_msat, outbound_amount_forwarded_rgb,
1391+
outbound_amount_forwarded_msat, outbound_amount_forwarded_rgb, inbound_amount_forwarded_rgb,
13871392
}))
13881393
};
13891394
f()

lightning/src/ln/channelmanager.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub(super) struct PendingHTLCInfo {
151151
/// The fee being skimmed off the top of this HTLC. If this is a forward, it'll be the fee we are
152152
/// skimming. If we're receiving this HTLC, it's the fee that our counterparty skimmed.
153153
pub(super) skimmed_fee_msat: Option<u64>,
154-
pub(super) amount_rgb: Option<u64>,
154+
pub(super) ingoing_amount_rgb: Option<u64>,
155155
pub(super) outgoing_amount_rgb: Option<u64>,
156156
}
157157

@@ -179,6 +179,7 @@ pub(super) struct PendingAddHTLCInfo {
179179
// Note that this may be an outbound SCID alias for the associated channel.
180180
prev_short_channel_id: u64,
181181
prev_htlc_id: u64,
182+
prev_htlc_value_rgb: Option<u64>,
182183
prev_funding_outpoint: OutPoint,
183184
prev_user_channel_id: u128,
184185
}
@@ -198,6 +199,7 @@ pub(crate) struct HTLCPreviousHopData {
198199
short_channel_id: u64,
199200
user_channel_id: Option<u128>,
200201
htlc_id: u64,
202+
htlc_value_rgb: Option<u64>,
201203
incoming_packet_shared_secret: [u8; 32],
202204
phantom_shared_secret: Option<[u8; 32]>,
203205

@@ -2957,15 +2959,15 @@ where
29572959
outgoing_amt_msat: amt_to_forward,
29582960
outgoing_cltv_value,
29592961
skimmed_fee_msat: None,
2960-
amount_rgb: msg.amount_rgb,
2962+
ingoing_amount_rgb: msg.amount_rgb,
29612963
outgoing_amount_rgb,
29622964
})
29632965
}
29642966

29652967
fn construct_recv_pending_htlc_info(
29662968
&self, hop_data: msgs::InboundOnionPayload, shared_secret: [u8; 32], payment_hash: PaymentHash,
29672969
amt_msat: u64, cltv_expiry: u32, phantom_shared_secret: Option<[u8; 32]>, allow_underpay: bool,
2968-
counterparty_skimmed_fee_msat: Option<u64>, amount_rgb: Option<u64>
2970+
counterparty_skimmed_fee_msat: Option<u64>, ingoing_amount_rgb: Option<u64>
29692971
) -> Result<PendingHTLCInfo, InboundOnionErr> {
29702972
let (payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, outgoing_cltv_value, payment_metadata, rgb_amount_to_forward) = match hop_data {
29712973
msgs::InboundOnionPayload::Receive {
@@ -3021,7 +3023,7 @@ where
30213023
msg: "Upstream node sent less than we were supposed to receive in payment",
30223024
});
30233025
}
3024-
match (rgb_amount_to_forward, amount_rgb) {
3026+
match (rgb_amount_to_forward, ingoing_amount_rgb) {
30253027
(Some(_), None) | (None, Some(_)) => {
30263028
return Err(InboundOnionErr {
30273029
err_code: 19,
@@ -3092,8 +3094,8 @@ where
30923094
outgoing_amt_msat: onion_amt_msat,
30933095
outgoing_cltv_value,
30943096
skimmed_fee_msat: counterparty_skimmed_fee_msat,
3095-
amount_rgb,
3096-
outgoing_amount_rgb: amount_rgb,
3097+
ingoing_amount_rgb,
3098+
outgoing_amount_rgb: rgb_amount_to_forward,
30973099
})
30983100
}
30993101

@@ -4311,6 +4313,7 @@ where
43114313
user_channel_id: Some(payment.prev_user_channel_id),
43124314
outpoint: payment.prev_funding_outpoint,
43134315
htlc_id: payment.prev_htlc_id,
4316+
htlc_value_rgb: payment.prev_htlc_value_rgb,
43144317
incoming_packet_shared_secret: payment.forward_info.incoming_shared_secret,
43154318
phantom_shared_secret: None,
43164319
});
@@ -4344,10 +4347,10 @@ where
43444347
for forward_info in pending_forwards.drain(..) {
43454348
match forward_info {
43464349
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
4347-
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
4350+
prev_short_channel_id, prev_htlc_id, prev_htlc_value_rgb, prev_funding_outpoint, prev_user_channel_id,
43484351
forward_info: PendingHTLCInfo {
43494352
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
4350-
outgoing_cltv_value, amount_rgb, ..
4353+
outgoing_cltv_value, ingoing_amount_rgb, ..
43514354
}
43524355
}) => {
43534356
macro_rules! failure_handler {
@@ -4359,6 +4362,7 @@ where
43594362
user_channel_id: Some(prev_user_channel_id),
43604363
outpoint: prev_funding_outpoint,
43614364
htlc_id: prev_htlc_id,
4365+
htlc_value_rgb: prev_htlc_value_rgb,
43624366
incoming_packet_shared_secret: incoming_shared_secret,
43634367
phantom_shared_secret: $phantom_ss,
43644368
});
@@ -4415,7 +4419,7 @@ where
44154419
onion_utils::Hop::Receive(hop_data) => {
44164420
match self.construct_recv_pending_htlc_info(hop_data,
44174421
incoming_shared_secret, payment_hash, outgoing_amt_msat,
4418-
outgoing_cltv_value, Some(phantom_shared_secret), false, None, amount_rgb)
4422+
outgoing_cltv_value, Some(phantom_shared_secret), false, None, ingoing_amount_rgb)
44194423
{
44204424
Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id, vec![(info, prev_htlc_id)])),
44214425
Err(InboundOnionErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
@@ -4460,7 +4464,7 @@ where
44604464
for forward_info in pending_forwards.drain(..) {
44614465
match forward_info {
44624466
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
4463-
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
4467+
prev_short_channel_id, prev_htlc_id, prev_htlc_value_rgb, prev_funding_outpoint, prev_user_channel_id,
44644468
forward_info: PendingHTLCInfo {
44654469
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
44664470
routing: PendingHTLCRouting::Forward { onion_packet, .. }, skimmed_fee_msat, outgoing_amount_rgb, ..
@@ -4472,6 +4476,7 @@ where
44724476
user_channel_id: Some(prev_user_channel_id),
44734477
outpoint: prev_funding_outpoint,
44744478
htlc_id: prev_htlc_id,
4479+
htlc_value_rgb: prev_htlc_value_rgb,
44754480
incoming_packet_shared_secret: incoming_shared_secret,
44764481
// Phantom payments are only PendingHTLCRouting::Receive.
44774482
phantom_shared_secret: None,
@@ -4523,7 +4528,7 @@ where
45234528
'next_forwardable_htlc: for forward_info in pending_forwards.drain(..) {
45244529
match forward_info {
45254530
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
4526-
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
4531+
prev_short_channel_id, prev_htlc_id, prev_htlc_value_rgb, prev_funding_outpoint, prev_user_channel_id,
45274532
forward_info: PendingHTLCInfo {
45284533
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat,
45294534
skimmed_fee_msat, ..
@@ -4556,6 +4561,7 @@ where
45564561
user_channel_id: Some(prev_user_channel_id),
45574562
outpoint: prev_funding_outpoint,
45584563
htlc_id: prev_htlc_id,
4564+
htlc_value_rgb: prev_htlc_value_rgb,
45594565
incoming_packet_shared_secret: incoming_shared_secret,
45604566
phantom_shared_secret,
45614567
},
@@ -4586,6 +4592,7 @@ where
45864592
user_channel_id: $htlc.prev_hop.user_channel_id,
45874593
outpoint: prev_funding_outpoint,
45884594
htlc_id: $htlc.prev_hop.htlc_id,
4595+
htlc_value_rgb: $htlc.prev_hop.htlc_value_rgb,
45894596
incoming_packet_shared_secret: $htlc.prev_hop.incoming_packet_shared_secret,
45904597
phantom_shared_secret,
45914598
}), payment_hash,
@@ -5703,7 +5710,7 @@ where
57035710
}
57045711

57055712
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage,
5706-
forwarded_htlc_value_msat: Option<u64>, forwarded_htlc_rgb: Option<u64>, from_onchain: bool, startup_replay: bool,
5713+
forwarded_htlc_value_msat: Option<u64>, outbound_amount_forwarded_rgb: Option<u64>, from_onchain: bool, startup_replay: bool,
57075714
next_channel_counterparty_node_id: Option<PublicKey>, next_channel_outpoint: OutPoint
57085715
) {
57095716
match source {
@@ -5723,6 +5730,7 @@ where
57235730
},
57245731
HTLCSource::PreviousHopData(hop_data) => {
57255732
let prev_outpoint = hop_data.outpoint;
5733+
let inbound_amount_forwarded_rgb = hop_data.htlc_value_rgb;
57265734
let completed_blocker = RAAMonitorUpdateBlockingAction::from_prev_hop_data(&hop_data);
57275735
#[cfg(debug_assertions)]
57285736
let claiming_chan_funding_outpoint = hop_data.outpoint;
@@ -5809,7 +5817,8 @@ where
58095817
prev_channel_id: Some(prev_outpoint.to_channel_id()),
58105818
next_channel_id: Some(next_channel_outpoint.to_channel_id()),
58115819
outbound_amount_forwarded_msat: forwarded_htlc_value_msat,
5812-
outbound_amount_forwarded_rgb: forwarded_htlc_rgb,
5820+
outbound_amount_forwarded_rgb,
5821+
inbound_amount_forwarded_rgb,
58135822
},
58145823
downstream_counterparty_and_funding_outpoint: chan_to_release,
58155824
})
@@ -6803,10 +6812,11 @@ where
68036812

68046813
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
68056814
let forward_htlcs_empty = forward_htlcs.is_empty();
6815+
let prev_htlc_value_rgb = forward_info.ingoing_amount_rgb;
68066816
match forward_htlcs.entry(scid) {
68076817
hash_map::Entry::Occupied(mut entry) => {
68086818
entry.get_mut().push(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
6809-
prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id, forward_info }));
6819+
prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_htlc_value_rgb, prev_user_channel_id, forward_info }));
68106820
},
68116821
hash_map::Entry::Vacant(entry) => {
68126822
if !is_our_scid && forward_info.incoming_amt_msat.is_some() &&
@@ -6824,13 +6834,13 @@ where
68246834
inbound_amount_msat: forward_info.incoming_amt_msat.unwrap(),
68256835
expected_outbound_amount_msat: forward_info.outgoing_amt_msat,
68266836
intercept_id,
6827-
inbound_rgb_amount: forward_info.amount_rgb,
6837+
inbound_rgb_amount: forward_info.ingoing_amount_rgb,
68286838
expected_outbound_rgb_amount: forward_info.outgoing_amount_rgb,
68296839
is_swap,
68306840
prev_short_channel_id,
68316841
}, None));
68326842
entry.insert(PendingAddHTLCInfo {
6833-
prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id, forward_info });
6843+
prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_htlc_value_rgb, prev_user_channel_id, forward_info });
68346844
},
68356845
hash_map::Entry::Occupied(_) => {
68366846
log_info!(self.logger, "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}", scid);
@@ -6839,6 +6849,7 @@ where
68396849
user_channel_id: Some(prev_user_channel_id),
68406850
outpoint: prev_funding_outpoint,
68416851
htlc_id: prev_htlc_id,
6852+
htlc_value_rgb: prev_htlc_value_rgb,
68426853
incoming_packet_shared_secret: forward_info.incoming_shared_secret,
68436854
phantom_shared_secret: None,
68446855
});
@@ -6856,7 +6867,7 @@ where
68566867
push_forward_event = true;
68576868
}
68586869
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
6859-
prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id, forward_info })));
6870+
prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_htlc_value_rgb, prev_user_channel_id, forward_info })));
68606871
}
68616872
}
68626873
}
@@ -8369,6 +8380,7 @@ where
83698380
short_channel_id: htlc.prev_short_channel_id,
83708381
user_channel_id: Some(htlc.prev_user_channel_id),
83718382
htlc_id: htlc.prev_htlc_id,
8383+
htlc_value_rgb: htlc.prev_htlc_value_rgb,
83728384
incoming_packet_shared_secret: htlc.forward_info.incoming_shared_secret,
83738385
phantom_shared_secret: None,
83748386
outpoint: htlc.prev_funding_outpoint,
@@ -9334,7 +9346,7 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
93349346
(8, outgoing_cltv_value, required),
93359347
(9, incoming_amt_msat, option),
93369348
(10, skimmed_fee_msat, option),
9337-
(12, amount_rgb, required),
9349+
(12, ingoing_amount_rgb, required),
93389350
(14, outgoing_amount_rgb, required),
93399351
});
93409352

@@ -9418,6 +9430,7 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
94189430
(4, htlc_id, required),
94199431
(6, incoming_packet_shared_secret, required),
94209432
(7, user_channel_id, option),
9433+
(8, htlc_value_rgb, option),
94219434
});
94229435

94239436
impl Writeable for ClaimableHTLC {
@@ -9569,6 +9582,7 @@ impl_writeable_tlv_based!(PendingAddHTLCInfo, {
95699582
(2, prev_short_channel_id, required),
95709583
(4, prev_htlc_id, required),
95719584
(6, prev_funding_outpoint, required),
9585+
(8, prev_htlc_value_rgb, option),
95729586
});
95739587

95749588
impl_writeable_tlv_based_enum!(HTLCForwardInfo,

lightning/src/rgb_utils/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ pub struct RgbPaymentInfo {
8383
pub remote_rgb_amount: u64,
8484
/// Whether the RGB amount in route should be overridden
8585
pub override_route_amount: bool,
86+
/// Whether the payment is inbound
87+
pub inbound: bool,
8688
}
8789

8890
/// RGB transfer info
@@ -189,6 +191,7 @@ pub(crate) fn color_commitment<SP: Deref>(channel_context: &ChannelContext<SP>,
189191
local_rgb_amount: rgb_info.local_rgb_amount,
190192
remote_rgb_amount: rgb_info.remote_rgb_amount,
191193
override_route_amount: false,
194+
inbound: htlc.offered == counterparty,
192195
};
193196
let serialized_info = serde_json::to_string(&rgb_payment_info).expect("valid rgb payment info");
194197
fs::write(rgb_payment_info_path, serialized_info).expect("able to write rgb payment info file");
@@ -554,14 +557,15 @@ pub fn write_rgb_channel_info(path: &PathBuf, rgb_info: &RgbInfo) {
554557
}
555558

556559
/// Write RGB payment info to file
557-
pub fn write_rgb_payment_info_file(ldk_data_dir: &Path, payment_hash: &PaymentHash, contract_id: ContractId, amount_rgb: u64, override_route_amount: bool) {
560+
pub fn write_rgb_payment_info_file(ldk_data_dir: &Path, payment_hash: &PaymentHash, contract_id: ContractId, amount_rgb: u64, override_route_amount: bool, inbound: bool) {
558561
let rgb_payment_info_path = ldk_data_dir.join(hex::encode(payment_hash.0));
559562
let rgb_payment_info = RgbPaymentInfo {
560563
contract_id,
561564
amount: amount_rgb,
562565
local_rgb_amount: 0,
563566
remote_rgb_amount: 0,
564567
override_route_amount,
568+
inbound,
565569
};
566570
let serialized_info = serde_json::to_string(&rgb_payment_info).expect("valid rgb payment info");
567571
std::fs::write(rgb_payment_info_path, serialized_info).expect("able to write rgb payment info file");

0 commit comments

Comments
 (0)