Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Split prefunded `Channel` into `Inbound`/`Outbound` channels by dunxen · Pull Request #2077 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Split prefunded `Channel` into `Inbound`/`Outbound` channels by dunxen · Pull Request #2077 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Split prefunded `Channel` into `Inbound`/`Outbound` channels by dunxen · Pull Request #2077 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Split prefunded `Channel` into `Inbound`/`Outbound` channels by dunxen · Pull Request #2077 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Split prefunded `Channel` into `Inbound`/`Outbound` channels by dunxen · Pull Request #2077 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Split prefunded `Channel` into `Inbound`/`Outbound` channels by dunxen · Pull Request #2077 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Split prefunded `Channel` into `Inbound`/`Outbound` channels by dunxen · Pull Request #2077 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
883afb3
Move `Channel` fields into `ChannelContext` struct
dunxen Mar 7, 2023
1503ebb
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util…
dunxen Jun 7, 2023
1ee0a66
Move `Channel::get_update_time_counter` and some other methods
dunxen Jun 7, 2023
ede8324
Move `Channel::channel_id` and some other methods to `ChannelContext`…
dunxen Jun 7, 2023
497aeb0
Move `Channel::build_commitment_transaction` to `ChannelContext` impl
dunxen Jun 7, 2023
0d739ee
Move `Channel::build_holder_transaction_keys` and some other methods
dunxen Jun 7, 2023
3ff94fa
Move `Channel::get_feerate_sat_per_1000_weight` and other methods
dunxen Jun 7, 2023
2774aa2
Prepare some methods for upcoming moves to `ChannelContext`
dunxen Jun 13, 2023
ed6a5bb
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
dunxen Jun 13, 2023
08ee72b
Move `Channel::commit_tx_fee_msat` to file-level utilities
dunxen Jun 13, 2023
9f4e714
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext`…
dunxen Jun 13, 2023
60706d6
Move `Channel::get_available_balances` to `ChannelContext` impl
dunxen Jun 13, 2023
25c1ad8
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_chann…
dunxen Jun 7, 2023
e3f0c55
Make `ChannelManager::issue_channel_close_events` take a `ChannelCont…
dunxen Jun 13, 2023
1012526
Move channel constants up
dunxen Mar 30, 2023
883e056
Introduce `InboundV1Channel` & `OutboundV1Channel`
dunxen Apr 5, 2023
e6c2f04
Move outbound channel constructor into `OutboundV1Channel` impl
dunxen Jun 7, 2023
baadeb7
Move inbound channel constructor into `InboundV1Channel` impl
dunxen Jun 7, 2023
2ea27e0
Move `Channel::force_shutdown` to `ChannelContext` impl
dunxen Jun 13, 2023
4ad67cf
Refactor channel map update macros for use with `ChannelContext`
dunxen Jun 7, 2023
4b1e286
Create and use methods for counting channels
dunxen Jun 7, 2023
4a0cd5c
Move outbound channel methods into `OutboundV1Channel`'s impl
dunxen Jun 7, 2023
637e03a
Move inbound channel methods into `InboundV1Channel`'s impl
dunxen Jun 7, 2023
8f93e2d
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
dunxen Jun 7, 2023
d957f36
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
dunxen Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1456,12 +1456,12 @@ fn monitor_failed_no_reestablish_response() {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}
{
let mut node_1_per_peer_lock;
let mut node_1_peer_state_lock;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).announcement_sigs_state = AnnouncementSigsState::PeerReceived;
get_channel_ref!(nodes[1], nodes[0], node_1_per_peer_lock, node_1_peer_state_lock, channel_id).context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
}

// Route the payment and deliver the initial commitment_signed (with a monitor update failure
Expand Down
6,950 changes: 3,522 additions & 3,428 deletions lightning/src/ln/channel.rs

Large diffs are not rendered by default.

731 changes: 439 additions & 292 deletions lightning/src/ln/channelmanager.rs

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -783,14 +783,36 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
macro_rules! get_outbound_v1_channel_ref {
($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.outbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_inbound_v1_channel_ref {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but this was added two commits ago, removed in the previous, and added back here.

($node: expr, $counterparty_node: expr, $per_peer_state_lock: ident, $peer_state_lock: ident, $channel_id: expr) => {
{
$per_peer_state_lock = $node.node.per_peer_state.read().unwrap();
$peer_state_lock = $per_peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
$peer_state_lock.inbound_v1_channel_by_id.get_mut(&$channel_id).unwrap()
}
}
}

#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.get_feerate_sat_per_1000_weight()
chan.context.get_feerate_sat_per_1000_weight()
}
}
}
Expand All@@ -802,7 +824,7 @@ macro_rules! get_opt_anchors {
let mut per_peer_state_lock;
let mut peer_state_lock;
let chan = get_channel_ref!($node, $counterparty_node, per_peer_state_lock, peer_state_lock, $channel_id);
chan.opt_anchors()
chan.context.opt_anchors()
}
}
}
Expand DownExpand Up@@ -2237,10 +2259,10 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
let peer_state = per_peer_state.get(&$prev_node.node.get_our_node_id())
.unwrap().lock().unwrap();
let channel = peer_state.channel_by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap();
if let Some(prev_config) = channel.prev_config() {
if let Some(prev_config) = channel.context.prev_config() {
prev_config.forwarding_fee_base_msat
} else {
channel.config().forwarding_fee_base_msat
channel.context.config().forwarding_fee_base_msat
}
};
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
Expand Down
80 changes: 43 additions & 37 deletions lightning/src/ln/functional_tests.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,7 @@ fn test_onion_failure() {
let short_channel_id = channels[1].0.contents.short_channel_id;
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap().channel_by_id.get(&channels[1].2).unwrap()
.get_counterparty_htlc_minimum_msat() - 1;
.context.get_counterparty_htlc_minimum_msat() - 1;
let mut bogus_route = route.clone();
let route_len = bogus_route.paths[0].hops.len();
bogus_route.paths[0].hops[route_len-1].fee_msat = amt_to_forward;
Expand Down
26 changes: 15 additions & 11 deletions lightning/src/ln/payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -607,9 +607,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id())
.unwrap().lock().unwrap();
let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap();
let mut new_config = channel.config();
let mut new_config = channel.context.config();
new_config.forwarding_fee_base_msat += 100_000;
channel.update_config(&new_config);
channel.context.update_config(&new_config);
new_route.paths[0].hops[0].fee_msat += 100_000;
}

Expand DownExpand Up@@ -1409,7 +1409,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1421,7 +1421,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, None);
Expand All@@ -1446,7 +1446,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
// First hop accounts for expected 1000 msat fee
assert_eq!(chan_1_used_liquidity, Some(501000));
Expand All@@ -1459,7 +1459,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);

assert_eq!(chan_2_used_liquidity, Some(500000));
Expand All@@ -1485,7 +1485,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel_1.get_short_channel_id().unwrap()
channel_1.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_1_used_liquidity, None);
}
Expand All@@ -1497,7 +1497,7 @@ fn test_trivial_inflight_htlc_tracking(){
let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[2].node.get_our_node_id()),
channel_2.get_short_channel_id().unwrap()
channel_2.context.get_short_channel_id().unwrap()
);
assert_eq!(chan_2_used_liquidity, None);
}
Expand DownExpand Up@@ -1538,7 +1538,7 @@ fn test_holding_cell_inflight_htlcs() {
let used_liquidity = inflight_htlcs.used_liquidity_msat(
&NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
&NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
channel.get_short_channel_id().unwrap()
channel.context.get_short_channel_id().unwrap()
);

assert_eq!(used_liquidity, Some(2000000));
Expand DownExpand Up@@ -1635,7 +1635,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

// Check for unknown channel id error.
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });

if test == InterceptTest::Fail {
// Ensure we can fail the intercepted payment back.
Expand All@@ -1659,7 +1661,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
log_bytes!(temp_chan_id), nodes[2].node.get_our_node_id()) });
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);

// Open the just-in-time channel so the payment can then be forwarded.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
{
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).closing_fee_limits.as_mut().unwrap().1 *= 10;
get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context.closing_fee_limits.as_mut().unwrap().1 *= 10;
}
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed);
let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id());
Expand Down