let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
let logger = test_utils::TestLogger::new();
- let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
+ let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
// Now try to send a second payment which will fail to send
let (payment_preimage_2, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[1]);
let events_3 = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events_3.len(), 1);
match events_3[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(*payment_preimage, payment_preimage_1);
+ assert_eq!(*payment_hash, payment_hash_1);
},
_ => panic!("Unexpected event"),
}
let events_3 = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events_3.len(), 1);
match events_3[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(*payment_preimage, payment_preimage_1);
+ assert_eq!(*payment_hash, payment_hash_1);
},
_ => panic!("Unexpected event"),
}
let logger = test_utils::TestLogger::new();
// Forward a payment for B to claim
- let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
+ let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(*payment_preimage, payment_preimage_1);
+ assert_eq!(*payment_hash, payment_hash_1);
},
_ => panic!("Unexpected event"),
}
let logger = test_utils::TestLogger::new();
// Forward a payment for B to claim
- let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
+ let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
// Now start forwarding a second payment, skipping the last RAA so B is in AwaitingRAA
let (payment_preimage_2, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[1]);
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(*payment_preimage, payment_preimage_1);
+ assert_eq!(*payment_hash, payment_hash_1);
},
_ => panic!("Unexpected event"),
}
sessions.remove(&session_priv_bytes)
} else { false };
if found_payment {
+ let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
self.pending_events.lock().unwrap().push(
- events::Event::PaymentSent { payment_preimage }
+ events::Event::PaymentSent {
+ payment_preimage,
+ payment_hash: payment_hash
+ }
);
} else {
log_trace!(self.logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
// further events will be generated for subsequence path successes.
let events = nodes[0].node.get_and_clear_pending_events();
match events[0] {
- Event::PaymentSent { payment_preimage: ref preimage } => {
+ Event::PaymentSent { payment_preimage: ref preimage, payment_hash: ref hash } => {
assert_eq!(payment_preimage, *preimage);
+ assert_eq!(our_payment_hash, *hash);
},
_ => panic!("Unexpected event"),
}
macro_rules! expect_payment_sent {
($node: expr, $expected_payment_preimage: expr) => {
let events = $node.node.get_and_clear_pending_events();
+ let expected_payment_hash = PaymentHash(Sha256::hash(&$expected_payment_preimage.0).into_inner());
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!($expected_payment_preimage, *payment_preimage);
+ assert_eq!(expected_payment_hash, *payment_hash);
},
_ => panic!("Unexpected event"),
}
send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 8000000);
send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 8000000);
- let (our_payment_preimage, _payment_hash, _payment_secret) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2]), 3000000);
- let (our_payment_preimage_2, _payment_hash_2, _payment_secret_2) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2]), 3000000);
+ let (our_payment_preimage, payment_hash_1, _payment_secret) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2]), 3000000);
+ let (our_payment_preimage_2, payment_hash_2, _payment_secret_2) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2]), 3000000);
// Broadcast legit commitment tx from C on B's chain
// Broadcast HTLC Success transaction by C on received output from C's commitment tx on B's chain
let mut first_claimed = false;
for event in events {
match event {
- Event::PaymentSent { payment_preimage } => {
- if payment_preimage == our_payment_preimage {
+ Event::PaymentSent { payment_preimage, payment_hash } => {
+ if payment_preimage == our_payment_preimage && payment_hash == payment_hash_1 {
assert!(!first_claimed);
first_claimed = true;
} else {
assert_eq!(payment_preimage, our_payment_preimage_2);
+ assert_eq!(payment_hash, payment_hash_2);
}
},
_ => panic!("Unexpected event"),
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
- let payment_preimage_3 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).0;
+ let (payment_preimage_3, payment_hash_3, _) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000);
let payment_preimage_4 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).0;
let payment_hash_5 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).1;
let payment_hash_6 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).1;
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 2);
match events[0] {
- Event::PaymentSent { payment_preimage } => {
+ Event::PaymentSent { payment_preimage, payment_hash } => {
assert_eq!(payment_preimage, payment_preimage_3);
+ assert_eq!(payment_hash, payment_hash_3);
},
_ => panic!("Unexpected event"),
}
let events_4 = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events_4.len(), 1);
match events_4[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(payment_preimage_1, *payment_preimage);
+ assert_eq!(payment_hash_1, *payment_hash);
},
_ => panic!("Unexpected event"),
}
let events_4 = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events_4.len(), 1);
match events_4[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(payment_preimage_1, *payment_preimage);
+ assert_eq!(payment_hash_1, *payment_hash);
},
_ => panic!("Unexpected event"),
}
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
let logger = test_utils::TestLogger::new();
- let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
+ let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
// Now try to send a second payment which will fail to send
let (payment_preimage_2, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[1]);
let events_3 = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events_3.len(), 1);
match events_3[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(*payment_preimage, payment_preimage_1);
+ assert_eq!(*payment_hash, payment_hash_1);
},
_ => panic!("Unexpected event"),
}
let events = nodes[0].node.get_and_clear_pending_events();
match events[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(*payment_preimage, our_payment_preimage);
+ assert_eq!(*payment_hash, duplicate_payment_hash);
}
_ => panic!("Unexpected event"),
}
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
- let (our_payment_preimage, _, _) = route_payment(&nodes[0], &[&nodes[1]], if use_dust { 50000 } else { 3000000 });
+ let (our_payment_preimage, our_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], if use_dust { 50000 } else { 3000000 });
// Claim the payment, but don't deliver A's commitment_signed, resulting in the HTLC only being
// present in B's local commitment transaction, but none of A's commitment transactions.
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentSent { payment_preimage } => {
+ Event::PaymentSent { payment_preimage, payment_hash } => {
assert_eq!(payment_preimage, our_payment_preimage);
+ assert_eq!(payment_hash, our_payment_hash);
},
_ => panic!("Unexpected event"),
}
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(*payment_preimage, payment_preimage_1);
+ assert_eq!(*payment_hash, payment_hash_1);
}
_ => panic!("Unexpected event"),
}
use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor};
use chain::transaction::OutPoint;
use chain::{Confirm, Watch};
+use ln::PaymentHash;
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs};
use ln::features::InitFeatures;
use ln::msgs::{ChannelMessageHandler, ErrorAction};
use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::blockdata::script::Builder;
use bitcoin::blockdata::opcodes;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::Hash;
use bitcoin::hash_types::BlockHash;
use bitcoin::secp256k1::Secp256k1;
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
let logger = test_utils::TestLogger::new();
- let (our_payment_preimage, _, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000);
+ let (our_payment_preimage, our_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000);
nodes[0].node.close_channel(&chan_1.2).unwrap();
let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id());
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(our_payment_preimage, *payment_preimage);
+ assert_eq!(our_payment_hash, *payment_hash);
},
_ => panic!("Unexpected event"),
}
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
- let (our_payment_preimage, _, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000);
+ let (our_payment_preimage, our_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000);
nodes[1].node.close_channel(&chan_1.2).unwrap();
let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id());
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentSent { ref payment_preimage } => {
+ Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
assert_eq!(our_payment_preimage, *payment_preimage);
+ assert_eq!(our_payment_hash, *payment_hash);
},
_ => panic!("Unexpected event"),
}
use util::ser::{Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};
use bitcoin::blockdata::script::Script;
-
+use bitcoin::hashes::Hash;
+use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::secp256k1::key::PublicKey;
use io;
/// Note that this serves as a payment receipt, if you wish to have such a thing, you must
/// store it somehow!
payment_preimage: PaymentPreimage,
+ /// The hash which was given to [`ChannelManager::send_payment`].
+ ///
+ /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
+ payment_hash: PaymentHash,
},
/// Indicates an outbound payment we made failed. Probably some intermediary node dropped
/// something. You may wish to retry with a different route.
(8, payment_preimage, option),
});
},
- &Event::PaymentSent { ref payment_preimage } => {
+ &Event::PaymentSent { ref payment_preimage, ref payment_hash} => {
2u8.write(writer)?;
write_tlv_fields!(writer, {
(0, payment_preimage, required),
+ (1, payment_hash, required),
});
},
&Event::PaymentFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed,
2u8 => {
let f = || {
let mut payment_preimage = PaymentPreimage([0; 32]);
+ let mut payment_hash = None;
read_tlv_fields!(reader, {
(0, payment_preimage, required),
+ (1, payment_hash, option),
});
+ if payment_hash.is_none() {
+ payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()));
+ }
Ok(Some(Event::PaymentSent {
payment_preimage,
+ payment_hash: payment_hash.unwrap(),
}))
};
f()