Skip to content

Commit 531d6c8

Browse files
committed
Change Event amt fields to amount_msat for clarity
1 parent 8a56702 commit 531d6c8

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
191191
let events_3 = nodes[1].node.get_and_clear_pending_events();
192192
assert_eq!(events_3.len(), 1);
193193
match events_3[0] {
194-
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
194+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
195195
assert_eq!(payment_hash_1, *payment_hash);
196-
assert_eq!(amt, 1000000);
196+
assert_eq!(amount_msat, 1_000_000);
197197
match &purpose {
198198
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
199199
assert!(payment_preimage.is_none());
@@ -559,9 +559,9 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
559559
let events_5 = nodes[1].node.get_and_clear_pending_events();
560560
assert_eq!(events_5.len(), 1);
561561
match events_5[0] {
562-
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
562+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
563563
assert_eq!(payment_hash_2, *payment_hash);
564-
assert_eq!(amt, 1000000);
564+
assert_eq!(amount_msat, 1_000_000);
565565
match &purpose {
566566
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
567567
assert!(payment_preimage.is_none());
@@ -676,9 +676,9 @@ fn test_monitor_update_fail_cs() {
676676
let events = nodes[1].node.get_and_clear_pending_events();
677677
assert_eq!(events.len(), 1);
678678
match events[0] {
679-
Event::PaymentReceived { payment_hash, ref purpose, amt } => {
679+
Event::PaymentReceived { payment_hash, ref purpose, amount_msat } => {
680680
assert_eq!(payment_hash, our_payment_hash);
681-
assert_eq!(amt, 1000000);
681+
assert_eq!(amount_msat, 1_000_000);
682682
match &purpose {
683683
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
684684
assert!(payment_preimage.is_none());
@@ -1650,9 +1650,9 @@ fn test_monitor_update_fail_claim() {
16501650
let events = nodes[0].node.get_and_clear_pending_events();
16511651
assert_eq!(events.len(), 2);
16521652
match events[0] {
1653-
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
1653+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
16541654
assert_eq!(payment_hash_2, *payment_hash);
1655-
assert_eq!(1_000_000, amt);
1655+
assert_eq!(1_000_000, amount_msat);
16561656
match &purpose {
16571657
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
16581658
assert!(payment_preimage.is_none());
@@ -1664,9 +1664,9 @@ fn test_monitor_update_fail_claim() {
16641664
_ => panic!("Unexpected event"),
16651665
}
16661666
match events[1] {
1667-
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
1667+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
16681668
assert_eq!(payment_hash_3, *payment_hash);
1669-
assert_eq!(1_000_000, amt);
1669+
assert_eq!(1_000_000, amount_msat);
16701670
match &purpose {
16711671
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
16721672
assert!(payment_preimage.is_none());

lightning/src/ln/channelmanager.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3184,7 +3184,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31843184
new_events.push(events::Event::PaymentReceived {
31853185
payment_hash,
31863186
purpose: purpose(),
3187-
amt: total_value,
3187+
amount_msat: total_value,
31883188
});
31893189
payment_received_generated = true;
31903190
} else {
@@ -3225,7 +3225,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32253225
e.insert((purpose.clone(), vec![claimable_htlc]));
32263226
new_events.push(events::Event::PaymentReceived {
32273227
payment_hash,
3228-
amt: amt_to_forward,
3228+
amount_msat: amt_to_forward,
32293229
purpose,
32303230
});
32313231
},
@@ -3908,7 +3908,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
39083908
self.pending_events.lock().unwrap().push(events::Event::PaymentClaimed {
39093909
payment_hash,
39103910
purpose: payment_purpose,
3911-
amt: claimable_amt_msat,
3911+
amount_msat: claimable_amt_msat,
39123912
});
39133913
}
39143914

@@ -6906,7 +6906,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
69066906
pending_events_read.push(events::Event::PaymentClaimed {
69076907
payment_hash,
69086908
purpose: payment_purpose,
6909-
amt: claimable_amt_msat,
6909+
amount_msat: claimable_amt_msat,
69106910
});
69116911
}
69126912
}

lightning/src/ln/functional_test_utils.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,9 @@ macro_rules! expect_payment_received {
12521252
let events = $node.node.get_and_clear_pending_events();
12531253
assert_eq!(events.len(), 1);
12541254
match events[0] {
1255-
$crate::util::events::Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
1255+
$crate::util::events::Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
12561256
assert_eq!($expected_payment_hash, *payment_hash);
1257-
assert_eq!($expected_recv_value, amt);
1257+
assert_eq!($expected_recv_value, amount_msat);
12581258
match purpose {
12591259
$crate::util::events::PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
12601260
assert_eq!(&$expected_payment_preimage, payment_preimage);
@@ -1275,9 +1275,9 @@ macro_rules! expect_payment_claimed {
12751275
let events = $node.node.get_and_clear_pending_events();
12761276
assert_eq!(events.len(), 1);
12771277
match events[0] {
1278-
$crate::util::events::Event::PaymentClaimed { ref payment_hash, amt, .. } => {
1278+
$crate::util::events::Event::PaymentClaimed { ref payment_hash, amount_msat, .. } => {
12791279
assert_eq!($expected_payment_hash, *payment_hash);
1280-
assert_eq!($expected_recv_value, amt);
1280+
assert_eq!($expected_recv_value, amount_msat);
12811281
},
12821282
_ => panic!("Unexpected event"),
12831283
}
@@ -1512,7 +1512,7 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
15121512
if payment_received_expected {
15131513
assert_eq!(events_2.len(), 1);
15141514
match events_2[0] {
1515-
Event::PaymentReceived { ref payment_hash, ref purpose, amt} => {
1515+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
15161516
assert_eq!(our_payment_hash, *payment_hash);
15171517
match &purpose {
15181518
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
@@ -1524,7 +1524,7 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
15241524
assert!(our_payment_secret.is_none());
15251525
},
15261526
}
1527-
assert_eq!(amt, recv_value);
1527+
assert_eq!(amount_msat, recv_value);
15281528
},
15291529
_ => panic!("Unexpected event"),
15301530
}

lightning/src/ln/functional_tests.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1954,9 +1954,9 @@ fn test_channel_reserve_holding_cell_htlcs() {
19541954
let events = nodes[2].node.get_and_clear_pending_events();
19551955
assert_eq!(events.len(), 2);
19561956
match events[0] {
1957-
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
1957+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
19581958
assert_eq!(our_payment_hash_21, *payment_hash);
1959-
assert_eq!(recv_value_21, amt);
1959+
assert_eq!(recv_value_21, amount_msat);
19601960
match &purpose {
19611961
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
19621962
assert!(payment_preimage.is_none());
@@ -1968,9 +1968,9 @@ fn test_channel_reserve_holding_cell_htlcs() {
19681968
_ => panic!("Unexpected event"),
19691969
}
19701970
match events[1] {
1971-
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
1971+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
19721972
assert_eq!(our_payment_hash_22, *payment_hash);
1973-
assert_eq!(recv_value_22, amt);
1973+
assert_eq!(recv_value_22, amount_msat);
19741974
match &purpose {
19751975
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
19761976
assert!(payment_preimage.is_none());
@@ -3709,9 +3709,9 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
37093709
let events_2 = nodes[1].node.get_and_clear_pending_events();
37103710
assert_eq!(events_2.len(), 1);
37113711
match events_2[0] {
3712-
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
3712+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
37133713
assert_eq!(payment_hash_1, *payment_hash);
3714-
assert_eq!(amt, 1000000);
3714+
assert_eq!(amount_msat, 1_000_000);
37153715
match &purpose {
37163716
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
37173717
assert!(payment_preimage.is_none());
@@ -10053,15 +10053,17 @@ fn do_test_partial_claim_before_restart(persist_both_monitors: bool) {
1005310053
// never finished processing.
1005410054
let events = nodes[3].node.get_and_clear_pending_events();
1005510055
assert_eq!(events.len(), if persist_both_monitors { 4 } else { 3 });
10056-
if let Event::PaymentReceived { amt: 15_000_000, .. } = events[0] { } else { panic!(); }
10056+
if let Event::PaymentReceived { amount_msat: 15_000_000, .. } = events[0] { } else { panic!(); }
1005710057
if let Event::ChannelClosed { reason: ClosureReason::OutdatedChannelManager, .. } = events[1] { } else { panic!(); }
1005810058
if persist_both_monitors {
1005910059
if let Event::ChannelClosed { reason: ClosureReason::OutdatedChannelManager, .. } = events[2] { } else { panic!(); }
1006010060
}
1006110061

1006210062
// On restart, we should also get a duplicate PaymentClaimed event as we persisted the
1006310063
// ChannelManager prior to handling the original one.
10064-
if let Event::PaymentClaimed { payment_hash: our_payment_hash, amt: 15_000_000, .. } = events[if persist_both_monitors { 3 } else { 2 }] {
10064+
if let Event::PaymentClaimed { payment_hash: our_payment_hash, amount_msat: 15_000_000, .. } =
10065+
events[if persist_both_monitors { 3 } else { 2 }]
10066+
{
1006510067
assert_eq!(payment_hash, our_payment_hash);
1006610068
} else { panic!(); }
1006710069

lightning/src/util/events.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub enum Event {
209209
/// not stop you from registering duplicate payment hashes for inbound payments.
210210
payment_hash: PaymentHash,
211211
/// The value, in thousandths of a satoshi, that this payment is for.
212-
amt: u64,
212+
amount_msat: u64,
213213
/// Information for claiming this received payment, based on whether the purpose of the
214214
/// payment is to pay an invoice or to send a spontaneous payment.
215215
purpose: PaymentPurpose,
@@ -233,7 +233,7 @@ pub enum Event {
233233
/// registering duplicate payment hashes for inbound payments.
234234
payment_hash: PaymentHash,
235235
/// The value, in thousandths of a satoshi, that this payment is for.
236-
amt: u64,
236+
amount_msat: u64,
237237
/// The purpose of this claimed payment, i.e. whether the payment was for an invoice or a
238238
/// spontaneous payment.
239239
purpose: PaymentPurpose,
@@ -508,7 +508,7 @@ impl Writeable for Event {
508508
// We never write out FundingGenerationReady events as, upon disconnection, peers
509509
// drop any channels which have not yet exchanged funding_signed.
510510
},
511-
&Event::PaymentReceived { ref payment_hash, ref amt, ref purpose } => {
511+
&Event::PaymentReceived { ref payment_hash, ref amount_msat, ref purpose } => {
512512
1u8.write(writer)?;
513513
let mut payment_secret = None;
514514
let payment_preimage;
@@ -524,7 +524,7 @@ impl Writeable for Event {
524524
write_tlv_fields!(writer, {
525525
(0, payment_hash, required),
526526
(2, payment_secret, option),
527-
(4, amt, required),
527+
(4, amount_msat, required),
528528
(6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
529529
(8, payment_preimage, option),
530530
});
@@ -617,12 +617,12 @@ impl Writeable for Event {
617617
// We never write the OpenChannelRequest events as, upon disconnection, peers
618618
// drop any channels which have not yet exchanged funding_signed.
619619
},
620-
&Event::PaymentClaimed { ref payment_hash, ref amt, ref purpose } => {
620+
&Event::PaymentClaimed { ref payment_hash, ref amount_msat, ref purpose } => {
621621
19u8.write(writer)?;
622622
write_tlv_fields!(writer, {
623623
(0, payment_hash, required),
624624
(2, purpose, required),
625-
(4, amt, required),
625+
(4, amount_msat, required),
626626
});
627627
},
628628
// Note that, going forward, all new events must only write data inside of
@@ -643,12 +643,12 @@ impl MaybeReadable for Event {
643643
let mut payment_hash = PaymentHash([0; 32]);
644644
let mut payment_preimage = None;
645645
let mut payment_secret = None;
646-
let mut amt = 0;
646+
let mut amount_msat = 0;
647647
let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
648648
read_tlv_fields!(reader, {
649649
(0, payment_hash, required),
650650
(2, payment_secret, option),
651-
(4, amt, required),
651+
(4, amount_msat, required),
652652
(6, _user_payment_id, option),
653653
(8, payment_preimage, option),
654654
});
@@ -662,7 +662,7 @@ impl MaybeReadable for Event {
662662
};
663663
Ok(Some(Event::PaymentReceived {
664664
payment_hash,
665-
amt,
665+
amount_msat,
666666
purpose,
667667
}))
668668
};
@@ -829,17 +829,17 @@ impl MaybeReadable for Event {
829829
let f = || {
830830
let mut payment_hash = PaymentHash([0; 32]);
831831
let mut purpose = None;
832-
let mut amt = 0;
832+
let mut amount_msat = 0;
833833
read_tlv_fields!(reader, {
834834
(0, payment_hash, required),
835835
(2, purpose, ignorable),
836-
(4, amt, required),
836+
(4, amount_msat, required),
837837
});
838838
if purpose.is_none() { return Ok(None); }
839839
Ok(Some(Event::PaymentClaimed {
840840
payment_hash,
841841
purpose: purpose.unwrap(),
842-
amt,
842+
amount_msat,
843843
}))
844844
};
845845
f()

0 commit comments

Comments
 (0)