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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
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
3 changes: 0 additions & 3 deletions src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,6 @@ use util::errors::APIError;
use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::Hash;

use std::time::Instant;

use ln::functional_test_utils::*;

#[test]
Expand DownExpand Up@@ -1495,7 +1493,6 @@ fn test_monitor_update_on_pending_forwards() {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
nodes[0].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[0].node.process_pending_htlc_forwards();
expect_payment_received!(nodes[0], payment_hash_2, 1000000);

Expand Down
9 changes: 2 additions & 7 deletions src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ use util::config::{UserConfig,ChannelConfig};
use std;
use std::default::Default;
use std::{cmp,mem};
use std::time::Instant;
use std::sync::{Arc};

#[cfg(test)]
Expand DownExpand Up@@ -133,14 +132,13 @@ struct OutboundHTLCOutput {

/// See AwaitingRemoteRevoke ChannelState for more info
enum HTLCUpdateAwaitingACK {
AddHTLC {
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to be sure, timeout here is only relevant if you are last peer in the payment route, don't have the preimage and can initiate the canceling walk back?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And furthermore, I've a doubt where the cltv_expiry field of AddHTLC should be used in our API, I mean we have fail_htlc_backwards, which is public but how API consumer is leaded to be aware of delay ?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

These are HTLCs which we accepted for relay but which we have not yet added to the outbound channel (as we were waiting for a remote revoke_and_ack at the time we received them, or were otherwise unable to forward them). AFAIR, we will never fail these HTLCs backwards as the ChannelMonitor isn't even aware of them at this time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay gotcha, not implemented yet, it's going with other TODO in Channel::update_add_htlc, need to pass height in process_pending_htlc_forwards I guess

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we can just fail them backwards if they're still waiting to be forwarded as the CLTV starts to get close in a hook from block_connected.

// always outbound
amount_msat: u64,
cltv_expiry: u32,
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
time_created: Instant, //TODO: Some kind of timeout thing-a-majig
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand DownExpand Up@@ -3252,7 +3250,6 @@ impl Channel {
cltv_expiry: cltv_expiry,
source,
onion_routing_packet: onion_routing_packet,
time_created: Instant::now(),
});
return Ok(None);
}
Expand DownExpand Up@@ -3622,14 +3619,13 @@ impl Writeable for Channel {
(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, time_created: _ } => {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
// time_created is not serialized - we re-init the timeout upon deserialization
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand DownExpand Up@@ -3796,7 +3792,6 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
time_created: Instant::now(),
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down
17 changes: 3 additions & 14 deletions src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ use std::collections::{HashMap, hash_map, HashSet};
use std::io::Cursor;
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Instant,Duration};
use std::time::Duration;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
Expand DownExpand Up@@ -247,7 +247,6 @@ pub(super) enum RAACommitmentOrder {
pub(super) struct ChannelHolder {
pub(super) by_id: HashMap<[u8; 32], Channel>,
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
pub(super) next_forward: Instant,
/// short channel id -> forward infos. Key of 0 means payments received
/// Note that while this is held in the same mutex as the channels themselves, no consistency
/// guarantees are made about the existence of a channel with the short id here, nor the short
Expand All@@ -266,7 +265,6 @@ pub(super) struct ChannelHolder {
pub(super) struct MutChannelHolder<'a> {
pub(super) by_id: &'a mut HashMap<[u8; 32], Channel>,
pub(super) short_to_id: &'a mut HashMap<u64, [u8; 32]>,
pub(super) next_forward: &'a mut Instant,
pub(super) forward_htlcs: &'a mut HashMap<u64, Vec<HTLCForwardInfo>>,
pub(super) claimable_htlcs: &'a mut HashMap<PaymentHash, Vec<(u64, HTLCPreviousHopData)>>,
pub(super) pending_msg_events: &'a mut Vec<events::MessageSendEvent>,
Expand All@@ -276,7 +274,6 @@ impl ChannelHolder {
MutChannelHolder {
by_id: &mut self.by_id,
short_to_id: &mut self.short_to_id,
next_forward: &mut self.next_forward,
forward_htlcs: &mut self.forward_htlcs,
claimable_htlcs: &mut self.claimable_htlcs,
pending_msg_events: &mut self.pending_msg_events,
Expand DownExpand Up@@ -549,7 +546,6 @@ impl ChannelManager {
channel_state: Mutex::new(ChannelHolder{
by_id: HashMap::new(),
short_to_id: HashMap::new(),
next_forward: Instant::now(),
forward_htlcs: HashMap::new(),
claimable_htlcs: HashMap::new(),
pending_msg_events: Vec::new(),
Expand DownExpand Up@@ -1184,10 +1180,6 @@ impl ChannelManager {
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = channel_state_lock.borrow_parts();

if cfg!(not(feature = "fuzztarget")) && Instant::now() < *channel_state.next_forward {
return;
}

for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
if short_chan_id != 0 {
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
Expand DownExpand Up@@ -1467,8 +1459,7 @@ impl ChannelManager {

let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state_lock.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
Expand DownExpand Up@@ -2077,8 +2068,7 @@ impl ChannelManager {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
forward_event = Some(Instant::now() + Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
channel_state.next_forward = forward_event.unwrap();
forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
Expand DownExpand Up@@ -3087,7 +3077,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
channel_state: Mutex::new(ChannelHolder {
by_id,
short_to_id,
next_forward: Instant::now(),
forward_htlcs,
claimable_htlcs,
pending_msg_events: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::mem;

pub const CHAN_CONFIRM_DEPTH: u32 = 100;
Expand DownExpand Up@@ -536,8 +535,6 @@ macro_rules! expect_pending_htlcs_forwardable {
Event::PendingHTLCsForwardable { .. } => { },
_ => panic!("Unexpected event"),
};
let node_ref: &Node = &$node;
node_ref.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
4 changes: 0 additions & 4 deletions src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::mem;

use ln::functional_test_utils::*;
Expand DownExpand Up@@ -2460,7 +2459,6 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
_ => panic!("Unexpected event"),
};
}
nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
nodes[1].node.process_pending_htlc_forwards();
check_added_monitors!(nodes[1], 1);

Expand DownExpand Up@@ -2813,7 +2811,6 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));

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

let events_2 = nodes[1].node.get_and_clear_pending_events();
Expand DownExpand Up@@ -4463,7 +4460,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
macro_rules! expect_htlc_forward {
($node: expr) => {{
expect_event!($node, Event::PendingHTLCsForwardable);
$node.node.channel_state.lock().unwrap().next_forward = Instant::now();
$node.node.process_pending_htlc_forwards();
}}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/events.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ use bitcoin::blockdata::script::Script;

use secp256k1::key::PublicKey;

use std::time::Instant;
use std::time::Duration;

/// An Event which you should probably take some action in response to.
pub enum Event {
Expand DownExpand Up@@ -92,8 +92,8 @@ pub enum Event {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
/// The earliest time at which process_pending_htlc_forwards should be called.
time_forwardable: Instant,
/// The amount of time that should be waited prior to calling process_pending_htlc_forwards
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
Expand Down