Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n 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;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1960,10 +1960,12 @@ impl Channel {
if !self.channel_outbound {
panic!("Cannot send fee from inbound channel");
}

if !self.is_usable() {
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
}
if !self.is_live() {
panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
}

if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
self.holding_cell_update_fee = Some(feerate_per_kw);
Expand Down
41 changes: 27 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,7 +449,10 @@ impl ChannelManager {
let channel_state = self.channel_state.lock().unwrap();
let mut res = Vec::with_capacity(channel_state.by_id.len());
for (channel_id, channel) in channel_state.by_id.iter() {
if channel.is_usable() {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
// really wanted anyway.
if channel.is_live() {
res.push(ChannelDetails {
channel_id: (*channel_id).clone(),
short_channel_id: channel.get_short_channel_id(),
Expand DownExpand Up@@ -997,7 +1000,7 @@ impl ChannelManager {
};

let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);

Ok(msgs::ChannelUpdate {
signature: sig,
Expand DownExpand Up@@ -1050,7 +1053,7 @@ impl ChannelManager {
let channel_state = channel_state_lock.borrow_parts();

let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
None => return Err(APIError::RouteError{err: "No channel available with first hop!"}),
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!"}),
Some(id) => id.clone(),
};

Expand All@@ -1060,12 +1063,12 @@ impl ChannelManager {
return Err(APIError::RouteError{err: "Node ID mismatch on first hop!"});
}
if !chan.is_live() {
return Err(APIError::RouteError{err: "Peer for first hop currently disconnected!"});
return Err(APIError::ChannelUnavailable{err: "Peer for first hop currently disconnected!"});
}
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, HTLCSource::OutboundRoute {
route: route.clone(),
session_priv: session_priv.clone(),
}, onion_packet).map_err(|he| APIError::RouteError{err: he.err})?
}, onion_packet).map_err(|he| APIError::ChannelUnavailable{err: he.err})?
};

let first_hop_node_id = route.hops.first().unwrap().pubkey;
Expand DownExpand Up@@ -1102,7 +1105,6 @@ impl ChannelManager {
/// May panic if the funding_txo is duplicative with some other channel (note that this should
/// be trivially prevented by using unique funding transaction keys per-channel).
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {

macro_rules! add_pending_event {
($event: expr) => {
{
Expand DownExpand Up@@ -1998,12 +2000,12 @@ impl ChannelManager {
match channel_state.by_id.get_mut(&channel_id) {
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
Some(chan) => {
if !chan.is_usable() {
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
}
if !chan.is_outbound() {
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
}
if !chan.is_live() {
return Err(APIError::ChannelUnavailable{err: "Channel is either not yet fully established or peer is currently disconnected"});
}
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
unimplemented!();
Expand DownExpand Up@@ -3025,7 +3027,7 @@ mod tests {

let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
};
}
Expand DownExpand Up@@ -3989,7 +3991,7 @@ mod tests {
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our max HTLC value in flight"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4025,7 +4027,7 @@ mod tests {
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
match err {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand All@@ -4050,7 +4052,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4106,7 +4108,7 @@ mod tests {
{
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
APIError::RouteError{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over our reserve value"),
_ => panic!("Unknown error variants"),
}
}
Expand DownExpand Up@@ -4935,6 +4937,10 @@ mod tests {
_ => panic!("Unexpected event"),
};

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();

Expand DownExpand Up@@ -5029,6 +5035,10 @@ mod tests {
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
}

nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// Channel should still work fine...
let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
Expand DownExpand Up@@ -5079,6 +5089,9 @@ mod tests {
_ => panic!("Unexpected event"),
}

reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
Expand Down
11 changes: 5 additions & 6 deletions src/util/errors.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,16 +20,15 @@ pub enum APIError {
/// The feerate which was too high.
feerate: u64
},

/// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
/// too-many-hops, etc).
RouteError {
/// A human-readable error message
err: &'static str
},


/// We were unable to complete the request since channel is disconnected or
/// shutdown in progress initiated by remote
/// We were unable to complete the request as the Channel required to do so is unable to
/// complete the request (or was not found). This can take many forms, including disconnected
/// peer, channel at capacity, channel shutting down, etc.
ChannelUnavailable {
/// A human-readable error message
err: &'static str
Expand Down