Skip to content

Commit 3b2aee7

Browse files
wip
1 parent bbeccad commit 3b2aee7

File tree

4 files changed

+99
-41
lines changed

4 files changed

+99
-41
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,7 @@ where
22752275
Some((update_add, commitment_signed, monitor_update)) => {
22762276
let update_err = self.chain_monitor.update_channel(chan.get().get_funding_txo().unwrap(), monitor_update);
22772277
let chan_id = chan.get().channel_id();
2278+
println!("VMW: monitor update in send_payment_along_path: {:?}", update_err);
22782279
match (update_err,
22792280
handle_monitor_update_res!(self, update_err, chan,
22802281
RAACommitmentOrder::CommitmentFirst, false, true))

lightning/src/ln/outbound_payment.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,14 @@ impl OutboundPayments {
416416

417417
log_trace!(logger, "Attempting to send payment with id {} and hash {} over route {}", log_bytes!(payment_id.0), log_bytes!(payment_hash.0), log_route!(route));
418418
let onion_session_privs = self.add_new_pending_payment(payment_hash, *payment_secret, payment_id, &route, retry_strategy, keys_manager, best_block_height)?;
419-
match self.send_payment_internal(&route, payment_hash, payment_secret, None, payment_id, None, onion_session_privs, keys_manager, best_block_height, &send_payment_along_path) {
419+
let res = self.send_payment_internal(&route, payment_hash, payment_secret, None, payment_id, None, onion_session_privs, keys_manager, best_block_height, &send_payment_along_path);
420+
println!("VMW: res of send payment internal: {:?}", res);
421+
match res {
420422
Err(PaymentSendFailure::AllFailedResendSafe(_)) => {
421423
self.retry_payment(payment_id, route_params, router, first_hops, inflight_htlcs, keys_manager, best_block_height, &send_payment_along_path)
422424
},
423425
Err(PaymentSendFailure::PartialFailure { failed_paths_retry, .. }) => {
426+
println!("VMW: got partial failure on send_payment");
424427
if let Some(retry) = failed_paths_retry {
425428
// Some paths were sent, even if we failed to send the full MPP value our recipient may
426429
// misbehave and claim the funds, at which point we have to consider the payment sent, so
@@ -483,6 +486,7 @@ impl OutboundPayments {
483486
F: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
484487
u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
485488
{
489+
println!("VMW: retrying payment");
486490
#[cfg(feature = "std")] {
487491
if has_expired(&route_params) {
488492
return Err(PaymentSendFailure::ParameterError(APIError::APIMisuseError {

lightning/src/ln/payment_tests.rs

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ use crate::chain::channelmonitor::{ANTI_REORG_DELAY, LATENCY_GRACE_PERIOD_BLOCKS
1616
use crate::chain::transaction::OutPoint;
1717
use crate::chain::keysinterface::{EntropySource, KeysInterface};
1818
use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS;
19-
use crate::ln::channelmanager::{self, BREAKDOWN_TIMEOUT, ChannelManager, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, IDEMPOTENCY_TIMEOUT_TICKS, Retry};
19+
use crate::ln::channelmanager::{self, BREAKDOWN_TIMEOUT, ChannelManager, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, IDEMPOTENCY_TIMEOUT_TICKS};
2020
use crate::ln::features::InvoiceFeatures;
2121
use crate::ln::msgs;
2222
use crate::ln::msgs::ChannelMessageHandler;
23+
use crate::ln::outbound_payment::Retry;
2324
use crate::routing::gossip::RoutingFees;
24-
use crate::routing::router::{get_route, PaymentParameters, RouteHint, RouteHintHop, RouteParameters};
25+
use crate::routing::router::{get_route, PaymentParameters, Route, RouteHint, RouteHintHop, RouteHop, RouteParameters};
2526
use crate::util::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider};
2627
use crate::util::test_utils;
2728
use crate::util::errors::APIError;
@@ -1758,22 +1759,22 @@ fn do_automatic_retries(test: AutoRetry) {
17581759
#[test]
17591760
fn auto_retry_partial_failure() {
17601761
// Test that we'll retry appropriately on send partial failure and retry partial failure.
1761-
let chanmon_cfgs = create_chanmon_cfgs(4);
1762-
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
1763-
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
1764-
let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs);
1762+
let chanmon_cfgs = create_chanmon_cfgs(2);
1763+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1764+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
1765+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
17651766

17661767
let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
1767-
let (chan_2_ann, _, chan_2_id, _) = create_announced_chan_between_nodes(&nodes, 0, 2, channelmanager::provided_init_features(), channelmanager::provided_init_features());
1768-
let chan_3_id = create_announced_chan_between_nodes(&nodes, 1, 3, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
1769-
let chan_4_id = create_announced_chan_between_nodes(&nodes, 2, 3, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
1768+
let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
1769+
let chan_3_id = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
1770+
let chan_4_id = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
17701771

17711772

17721773
// This amount should force the router to split across nodes[0]'s two channels.
1773-
let amt_msat = 18_000_000;
1774+
let amt_msat = 20_000;
17741775

17751776
// Marshall data to send the payment
1776-
let (_, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[3], amt_msat);
1777+
let (_, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], amt_msat);
17771778
#[cfg(feature = "std")]
17781779
let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
17791780
#[cfg(not(feature = "std"))]
@@ -1782,7 +1783,7 @@ fn auto_retry_partial_failure() {
17821783
invoice_features.set_variable_length_onion_required();
17831784
invoice_features.set_payment_secret_required();
17841785
invoice_features.set_basic_mpp_optional();
1785-
let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id())
1786+
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id())
17861787
.with_expiry_time(payment_expiry_secs as u64)
17871788
.with_features(invoice_features);
17881789
let route_params = RouteParameters {
@@ -1791,34 +1792,85 @@ fn auto_retry_partial_failure() {
17911792
final_cltv_expiry_delta: TEST_FINAL_CLTV,
17921793
};
17931794

1794-
// Ensure the first monitor update (for the initial send path 0 -> 1 -> 3) succeeds, but the
1795-
// second (for the initial send path 0 -> 2 -> 3) fails.
1795+
// Ensure the first monitor update (for the initial send path1 over chan_1) succeeds, but the
1796+
// second (for the initial send path2 over chan_2) fails.
17961797
chanmon_cfgs[0].persister.set_next_update_ret(ChannelMonitorUpdateStatus::Completed);
17971798
chanmon_cfgs[0].persister.set_next_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
1798-
// Ensure third monitor update (for the retry0's path 0 -> 1 -> 3) succeeds, but the fourth (for
1799-
// the retry0's path 0 -> 2 -> 3) fails, and monitor updates succeed after that.
1799+
// Ensure third monitor update (for the retry1's path1 over chan_1) succeeds, but the fourth (for
1800+
// the retry1's path2 over chan_3) fails, and monitor updates succeed after that.
18001801
chanmon_cfgs[0].persister.set_next_update_ret(ChannelMonitorUpdateStatus::Completed);
18011802
chanmon_cfgs[0].persister.set_next_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
1802-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
1803+
chanmon_cfgs[0].persister.set_next_update_ret(ChannelMonitorUpdateStatus::Completed);
18031804

1804-
// Configure the initial send, retry0 and retry1's paths.
1805+
// Configure the initial send, retry1 and retry2's paths.
1806+
let send_route = Route {
1807+
paths: vec![
1808+
vec![RouteHop {
1809+
pubkey: nodes[1].node.get_our_node_id(),
1810+
node_features: channelmanager::provided_node_features(),
1811+
short_channel_id: chan_1_id,
1812+
channel_features: channelmanager::provided_channel_features(),
1813+
fee_msat: amt_msat / 2,
1814+
cltv_expiry_delta: 100,
1815+
}],
1816+
vec![RouteHop {
1817+
pubkey: nodes[1].node.get_our_node_id(),
1818+
node_features: channelmanager::provided_node_features(),
1819+
short_channel_id: chan_2_id,
1820+
channel_features: channelmanager::provided_channel_features(),
1821+
fee_msat: amt_msat / 2,
1822+
cltv_expiry_delta: 100,
1823+
}],
1824+
],
1825+
payment_params: Some(PaymentParameters::from_node_id(nodes[1].node.get_our_node_id())),
1826+
};
1827+
let retry_1_route = Route {
1828+
paths: vec![
1829+
vec![RouteHop {
1830+
pubkey: nodes[1].node.get_our_node_id(),
1831+
node_features: channelmanager::provided_node_features(),
1832+
short_channel_id: chan_1_id,
1833+
channel_features: channelmanager::provided_channel_features(),
1834+
fee_msat: amt_msat / 4,
1835+
cltv_expiry_delta: 100,
1836+
}],
1837+
vec![RouteHop {
1838+
pubkey: nodes[1].node.get_our_node_id(),
1839+
node_features: channelmanager::provided_node_features(),
1840+
short_channel_id: chan_3_id,
1841+
channel_features: channelmanager::provided_channel_features(),
1842+
fee_msat: amt_msat / 4,
1843+
cltv_expiry_delta: 100,
1844+
}],
1845+
],
1846+
payment_params: Some(PaymentParameters::from_node_id(nodes[1].node.get_our_node_id())),
1847+
};
1848+
let retry_2_route = Route {
1849+
paths: vec![
1850+
vec![RouteHop {
1851+
pubkey: nodes[1].node.get_our_node_id(),
1852+
node_features: channelmanager::provided_node_features(),
1853+
short_channel_id: chan_1_id,
1854+
channel_features: channelmanager::provided_channel_features(),
1855+
fee_msat: amt_msat / 4,
1856+
cltv_expiry_delta: 100,
1857+
}],
1858+
],
1859+
payment_params: Some(PaymentParameters::from_node_id(nodes[1].node.get_our_node_id())),
1860+
};
1861+
nodes[0].router.expect_find_route(Ok(send_route));
1862+
nodes[0].router.expect_find_route(Ok(retry_1_route));
1863+
nodes[0].router.expect_find_route(Ok(retry_2_route));
18051864

18061865
// Send a payment that will partially fail on send, then partially fail on retry, then succeed.
1807-
match nodes[0].node.send_payment_with_retry(payment_hash, &Some(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(1)) {
1808-
Err(PaymentSendFailure::PartialFailure { results, ..}) => {
1809-
assert_eq!(results[0], Ok(()));
1810-
assert_eq!(results[1], Err(APIError::ChannelUnavailable {
1811-
err: "ChannelMonitor storage failure".to_owned(),
1812-
}));
1813-
},
1814-
_ => panic!("Unexpected result"),
1815-
}
1866+
nodes[0].node.send_payment_with_retry(payment_hash, &Some(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(3)).unwrap();
18161867

18171868
// Pass the first part of the payment along the path.
1818-
check_added_monitors!(nodes[0], 1);
1869+
check_added_monitors!(nodes[0], 5); // three outbound channel updates succeeded, two PermFailed
18191870
let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
1871+
println!("VMW: msg events: {:?}", msg_events);
18201872
assert_eq!(msg_events.len(), 1);
1821-
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], amt_msat, payment_hash, Some(payment_secret), msg_events.pop().unwrap(), true, None);
1873+
pass_along_path(&nodes[0], &[&nodes[1]], amt_msat, payment_hash, Some(payment_secret), msg_events.pop().unwrap(), true, None);
18221874

18231875
//
18241876
}

lightning/src/util/test_utils.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::chain::keysinterface;
2020
use crate::ln::channelmanager;
2121
use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
2222
use crate::ln::{msgs, wire};
23+
use crate::ln::msgs::LightningError;
2324
use crate::ln::script::ShutdownScript;
2425
use crate::routing::gossip::NetworkGraph;
2526
use crate::routing::router::{find_route, InFlightHtlcs, Route, RouteHop, RouteParameters, Router, ScorerAccountingForInFlightHtlcs};
@@ -75,21 +76,17 @@ impl chaininterface::FeeEstimator for TestFeeEstimator {
7576

7677
pub struct TestRouter<'a> {
7778
pub network_graph: Arc<NetworkGraph<&'a TestLogger>>,
78-
pub next_routes: Mutex<VecDeque<Route>>,
79+
pub next_routes: Mutex<VecDeque<Result<Route, LightningError>>>,
7980
}
8081

8182
impl<'a> TestRouter<'a> {
8283
pub fn new(network_graph: Arc<NetworkGraph<&'a TestLogger>>) -> Self {
83-
Self {
84-
network_graph,
85-
next_routes: Mutex::new(VecDeque::new()),
86-
}
84+
Self { network_graph, next_routes: Mutex::new(VecDeque::new()), }
8785
}
88-
}
8986

90-
impl<'a> TestRouter<'a> {
91-
pub fn new(network_graph: Arc<NetworkGraph<&'a TestLogger>>) -> Self {
92-
Self { network_graph }
87+
pub fn expect_find_route(&self, result: Result<Route, LightningError>) {
88+
let mut expected_routes = self.next_routes.lock().unwrap();
89+
expected_routes.push_back(result);
9390
}
9491
}
9592

@@ -98,8 +95,12 @@ impl<'a> Router for TestRouter<'a> {
9895
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
9996
inflight_htlcs: &InFlightHtlcs
10097
) -> Result<Route, msgs::LightningError> {
101-
if let Some(route) = self.next_routes.lock().unwrap().pop_front() {
102-
return Ok(route)
98+
println!("VMW: in testrouter find_route");
99+
if let Some(find_route_res) = self.next_routes.lock().unwrap().pop_front() {
100+
if let Ok(ref res) = find_route_res {
101+
println!("VMW: returning route: {:?}", res.paths);
102+
}
103+
return find_route_res
103104
}
104105
let logger = TestLogger::new();
105106
find_route(

0 commit comments

Comments
 (0)