Merge branch 'master' of github.com:rust-bitcoin/rust-lightning into use-workspaces

This commit is contained in:
RJ Rybarczyk 2019-11-18 19:44:55 +00:00
commit 5305223495
13 changed files with 403 additions and 319 deletions

View file

@ -37,7 +37,7 @@ use lightning::ln::channelmonitor;
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate}; use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate};
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, ChannelManagerReadArgs}; use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, ChannelManagerReadArgs};
use lightning::ln::router::{Route, RouteHop}; use lightning::ln::router::{Route, RouteHop};
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, HandleError, UpdateAddHTLC, LocalFeatures}; use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, LightningError, UpdateAddHTLC, LocalFeatures};
use lightning::util::events; use lightning::util::events;
use lightning::util::logger::Logger; use lightning::util::logger::Logger;
use lightning::util::config::UserConfig; use lightning::util::config::UserConfig;
@ -193,7 +193,7 @@ pub fn do_test(data: &[u8]) {
config.channel_options.fee_proportional_millionths = 0; config.channel_options.fee_proportional_millionths = 0;
config.channel_options.announced_channel = true; config.channel_options.announced_channel = true;
config.peer_channel_config_limits.min_dust_limit_satoshis = 0; config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap(), (ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).unwrap(),
monitor) monitor)
} } } }
} }
@ -392,7 +392,7 @@ pub fn do_test(data: &[u8]) {
($res: expr) => { ($res: expr) => {
match $res { match $res {
Ok(()) => {}, Ok(()) => {},
Err(HandleError { action: Some(ErrorAction::IgnoreError), .. }) => { }, Err(LightningError { action: ErrorAction::IgnoreError, .. }) => { },
_ => { $res.unwrap() }, _ => { $res.unwrap() },
} }
} }

View file

@ -331,7 +331,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4)); config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4));
config.channel_options.announced_channel = get_slice!(1)[0] != 0; config.channel_options.announced_channel = get_slice!(1)[0] != 0;
config.peer_channel_config_limits.min_dust_limit_satoshis = 0; config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
let channelmanager = ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap(); let channelmanager = ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).unwrap();
let router = Arc::new(Router::new(PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret()), watch.clone(), Arc::clone(&logger))); let router = Arc::new(Router::new(PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret()), watch.clone(), Arc::clone(&logger)));
let peers = RefCell::new([false; 256]); let peers = RefCell::new([false; 256]);

View file

@ -190,7 +190,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
_ => panic!("Unexpected event"), _ => panic!("Unexpected event"),
} }
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::IgnoreError) }) = nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed) { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::IgnoreError }) = nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed) {
assert_eq!(err, "Previous monitor update failure prevented generation of RAA"); assert_eq!(err, "Previous monitor update failure prevented generation of RAA");
} else { panic!(); } } else { panic!(); }
} }
@ -485,7 +485,7 @@ fn test_monitor_update_fail_cs() {
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]).unwrap(); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]).unwrap();
*nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure); *nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure);
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send_event.commitment_msg).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send_event.commitment_msg).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[1], 1); check_added_monitors!(nodes[1], 1);
@ -515,7 +515,7 @@ fn test_monitor_update_fail_cs() {
assert_eq!(*node_id, nodes[0].node.get_our_node_id()); assert_eq!(*node_id, nodes[0].node.get_our_node_id());
*nodes[0].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure); *nodes[0].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure);
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[0], 1); check_added_monitors!(nodes[0], 1);
@ -565,7 +565,7 @@ fn test_monitor_update_fail_no_rebroadcast() {
let bs_raa = commitment_signed_dance!(nodes[1], nodes[0], send_event.commitment_msg, false, true, false, true); let bs_raa = commitment_signed_dance!(nodes[1], nodes[0], send_event.commitment_msg, false, true, false, true);
*nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure); *nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure);
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &bs_raa).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &bs_raa).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
@ -618,12 +618,12 @@ fn test_monitor_update_raa_while_paused() {
*nodes[0].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure); *nodes[0].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure);
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event_2.msgs[0]).unwrap(); nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event_2.msgs[0]).unwrap();
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_event_2.commitment_msg).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_event_2.commitment_msg).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[0], 1); check_added_monitors!(nodes[0], 1);
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa).unwrap_err() {
assert_eq!(err, "Previous monitor update failure prevented responses to RAA"); assert_eq!(err, "Previous monitor update failure prevented responses to RAA");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[0], 1); check_added_monitors!(nodes[0], 1);
@ -704,7 +704,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
// Now fail monitor updating. // Now fail monitor updating.
*nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure); *nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure);
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_revoke_and_ack).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_revoke_and_ack).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
@ -768,7 +768,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0)); send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0));
nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send_event.msgs[0]).unwrap(); nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send_event.msgs[0]).unwrap();
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::IgnoreError) }) = nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg) { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::IgnoreError }) = nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg) {
assert_eq!(err, "Previous monitor update failure prevented generation of RAA"); assert_eq!(err, "Previous monitor update failure prevented generation of RAA");
} else { panic!(); } } else { panic!(); }
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
@ -945,7 +945,7 @@ fn test_monitor_update_fail_reestablish() {
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish).unwrap(); nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish).unwrap();
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[1], 1); check_added_monitors!(nodes[1], 1);
@ -1033,12 +1033,12 @@ fn raa_no_response_awaiting_raa_state() {
// then restore channel monitor updates. // then restore channel monitor updates.
*nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure); *nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure);
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]).unwrap(); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]).unwrap();
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[1], 1); check_added_monitors!(nodes[1], 1);
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa).unwrap_err() {
assert_eq!(err, "Previous monitor update failure prevented responses to RAA"); assert_eq!(err, "Previous monitor update failure prevented responses to RAA");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[1], 1); check_added_monitors!(nodes[1], 1);
@ -1130,7 +1130,7 @@ fn claim_while_disconnected_monitor_update_fail() {
// update. // update.
*nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure); *nodes[1].chan_monitor.update_ret.lock().unwrap() = Err(ChannelMonitorUpdateErr::TemporaryFailure);
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[1], 1); check_added_monitors!(nodes[1], 1);
@ -1145,7 +1145,7 @@ fn claim_while_disconnected_monitor_update_fail() {
let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]).unwrap(); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]).unwrap();
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed).unwrap_err() {
assert_eq!(err, "Previous monitor update failure prevented generation of RAA"); assert_eq!(err, "Previous monitor update failure prevented generation of RAA");
} else { panic!(); } } else { panic!(); }
// Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC // Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC
@ -1235,7 +1235,7 @@ fn monitor_failed_no_reestablish_response() {
assert_eq!(events.len(), 1); assert_eq!(events.len(), 1);
let payment_event = SendEvent::from_event(events.pop().unwrap()); let payment_event = SendEvent::from_event(events.pop().unwrap());
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]).unwrap(); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]).unwrap();
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[1], 1); check_added_monitors!(nodes[1], 1);
@ -1327,7 +1327,7 @@ fn first_message_on_recv_ordering() {
// Deliver the final RAA for the first payment, which does not require a response. RAAs // Deliver the final RAA for the first payment, which does not require a response. RAAs
// generally require a commitment_signed, so the fact that we're expecting an opposite response // generally require a commitment_signed, so the fact that we're expecting an opposite response
// to the next message also tests resetting the delivery order. // to the next message also tests resetting the delivery order.
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa).unwrap_err() {
assert_eq!(err, "Failed to update ChannelMonitor"); assert_eq!(err, "Failed to update ChannelMonitor");
} else { panic!(); } } else { panic!(); }
check_added_monitors!(nodes[1], 1); check_added_monitors!(nodes[1], 1);
@ -1336,7 +1336,7 @@ fn first_message_on_recv_ordering() {
// RAA/CS response, which should be generated when we call test_restore_channel_monitor (with // RAA/CS response, which should be generated when we call test_restore_channel_monitor (with
// the appropriate HTLC acceptance). // the appropriate HTLC acceptance).
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]).unwrap(); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]).unwrap();
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg).unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg).unwrap_err() {
assert_eq!(err, "Previous monitor update failure prevented generation of RAA"); assert_eq!(err, "Previous monitor update failure prevented generation of RAA");
} else { panic!(); } } else { panic!(); }
@ -1597,7 +1597,7 @@ fn do_during_funding_monitor_fail(fail_on_generate: bool, restore_between_fails:
} }
let funding_signed_res = nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); let funding_signed_res = nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()));
if fail_on_signed || !restore_between_fails { if fail_on_signed || !restore_between_fails {
if let msgs::HandleError { err, action: Some(msgs::ErrorAction::IgnoreError) } = funding_signed_res.unwrap_err() { if let msgs::LightningError { err, action: msgs::ErrorAction::IgnoreError } = funding_signed_res.unwrap_err() {
if fail_on_generate && !restore_between_fails { if fail_on_generate && !restore_between_fails {
assert_eq!(err, "Previous monitor update failure prevented funding_signed from allowing funding broadcast"); assert_eq!(err, "Previous monitor update failure prevented funding_signed from allowing funding broadcast");
check_added_monitors!(nodes[0], 0); check_added_monitors!(nodes[0], 0);

View file

@ -33,7 +33,7 @@ use ln::router::Route;
use ln::msgs; use ln::msgs;
use ln::msgs::LocalFeatures; use ln::msgs::LocalFeatures;
use ln::onion_utils; use ln::onion_utils;
use ln::msgs::{ChannelMessageHandler, DecodeError, HandleError}; use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
use chain::keysinterface::KeysInterface; use chain::keysinterface::KeysInterface;
use util::config::UserConfig; use util::config::UserConfig;
use util::{byte_utils, events}; use util::{byte_utils, events};
@ -118,7 +118,7 @@ impl HTLCSource {
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug #[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
pub(super) enum HTLCFailReason { pub(super) enum HTLCFailReason {
ErrorPacket { LightningError {
err: msgs::OnionErrorPacket, err: msgs::OnionErrorPacket,
}, },
Reason { Reason {
@ -143,21 +143,21 @@ type ShutdownResult = (Vec<Transaction>, Vec<(HTLCSource, PaymentHash)>);
/// this struct and call handle_error!() on it. /// this struct and call handle_error!() on it.
struct MsgHandleErrInternal { struct MsgHandleErrInternal {
err: msgs::HandleError, err: msgs::LightningError,
shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>, shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
} }
impl MsgHandleErrInternal { impl MsgHandleErrInternal {
#[inline] #[inline]
fn send_err_msg_no_close(err: &'static str, channel_id: [u8; 32]) -> Self { fn send_err_msg_no_close(err: &'static str, channel_id: [u8; 32]) -> Self {
Self { Self {
err: HandleError { err: LightningError {
err, err,
action: Some(msgs::ErrorAction::SendErrorMessage { action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage { msg: msgs::ErrorMessage {
channel_id, channel_id,
data: err.to_string() data: err.to_string()
}, },
}), },
}, },
shutdown_finish: None, shutdown_finish: None,
} }
@ -165,28 +165,28 @@ impl MsgHandleErrInternal {
#[inline] #[inline]
fn ignore_no_close(err: &'static str) -> Self { fn ignore_no_close(err: &'static str) -> Self {
Self { Self {
err: HandleError { err: LightningError {
err, err,
action: Some(msgs::ErrorAction::IgnoreError), action: msgs::ErrorAction::IgnoreError,
}, },
shutdown_finish: None, shutdown_finish: None,
} }
} }
#[inline] #[inline]
fn from_no_close(err: msgs::HandleError) -> Self { fn from_no_close(err: msgs::LightningError) -> Self {
Self { err, shutdown_finish: None } Self { err, shutdown_finish: None }
} }
#[inline] #[inline]
fn from_finish_shutdown(err: &'static str, channel_id: [u8; 32], shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>) -> Self { fn from_finish_shutdown(err: &'static str, channel_id: [u8; 32], shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>) -> Self {
Self { Self {
err: HandleError { err: LightningError {
err, err,
action: Some(msgs::ErrorAction::SendErrorMessage { action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage { msg: msgs::ErrorMessage {
channel_id, channel_id,
data: err.to_string() data: err.to_string()
}, },
}), },
}, },
shutdown_finish: Some((shutdown_res, channel_update)), shutdown_finish: Some((shutdown_res, channel_update)),
} }
@ -195,27 +195,27 @@ impl MsgHandleErrInternal {
fn from_chan_no_close(err: ChannelError, channel_id: [u8; 32]) -> Self { fn from_chan_no_close(err: ChannelError, channel_id: [u8; 32]) -> Self {
Self { Self {
err: match err { err: match err {
ChannelError::Ignore(msg) => HandleError { ChannelError::Ignore(msg) => LightningError {
err: msg, err: msg,
action: Some(msgs::ErrorAction::IgnoreError), action: msgs::ErrorAction::IgnoreError,
}, },
ChannelError::Close(msg) => HandleError { ChannelError::Close(msg) => LightningError {
err: msg, err: msg,
action: Some(msgs::ErrorAction::SendErrorMessage { action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage { msg: msgs::ErrorMessage {
channel_id, channel_id,
data: msg.to_string() data: msg.to_string()
}, },
}), },
}, },
ChannelError::CloseDelayBroadcast { msg, .. } => HandleError { ChannelError::CloseDelayBroadcast { msg, .. } => LightningError {
err: msg, err: msg,
action: Some(msgs::ErrorAction::SendErrorMessage { action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage { msg: msgs::ErrorMessage {
channel_id, channel_id,
data: msg.to_string() data: msg.to_string()
}, },
}), },
}, },
}, },
shutdown_finish: None, shutdown_finish: None,
@ -585,7 +585,10 @@ impl ChannelManager {
/// Non-proportional fees are fixed according to our risk using the provided fee estimator. /// Non-proportional fees are fixed according to our risk using the provided fee estimator.
/// ///
/// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`! /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
pub fn new(network: Network, feeest: Arc<FeeEstimator>, monitor: Arc<ManyChannelMonitor>, chain_monitor: Arc<ChainWatchInterface>, tx_broadcaster: Arc<BroadcasterInterface>, logger: Arc<Logger>,keys_manager: Arc<KeysInterface>, config: UserConfig) -> Result<Arc<ChannelManager>, secp256k1::Error> { ///
/// User must provide the current blockchain height from which to track onchain channel
/// funding outpoints and send payments with reliable timelocks.
pub fn new(network: Network, feeest: Arc<FeeEstimator>, monitor: Arc<ManyChannelMonitor>, chain_monitor: Arc<ChainWatchInterface>, tx_broadcaster: Arc<BroadcasterInterface>, logger: Arc<Logger>,keys_manager: Arc<KeysInterface>, config: UserConfig, current_blockchain_height: usize) -> Result<Arc<ChannelManager>, secp256k1::Error> {
let secp_ctx = Secp256k1::new(); let secp_ctx = Secp256k1::new();
let res = Arc::new(ChannelManager { let res = Arc::new(ChannelManager {
@ -596,7 +599,7 @@ impl ChannelManager {
chain_monitor, chain_monitor,
tx_broadcaster, tx_broadcaster,
latest_block_height: AtomicUsize::new(0), //TODO: Get an init value latest_block_height: AtomicUsize::new(current_blockchain_height),
last_block_hash: Mutex::new(Default::default()), last_block_hash: Mutex::new(Default::default()),
secp_ctx, secp_ctx,
@ -1009,9 +1012,9 @@ impl ChannelManager {
/// only fails if the channel does not yet have an assigned short_id /// only fails if the channel does not yet have an assigned short_id
/// May be called with channel_state already locked! /// May be called with channel_state already locked!
fn get_channel_update(&self, chan: &Channel) -> Result<msgs::ChannelUpdate, HandleError> { fn get_channel_update(&self, chan: &Channel) -> Result<msgs::ChannelUpdate, LightningError> {
let short_channel_id = match chan.get_short_channel_id() { let short_channel_id = match chan.get_short_channel_id() {
None => return Err(HandleError{err: "Channel not yet established", action: None}), None => return Err(LightningError{err: "Channel not yet established", action: msgs::ErrorAction::IgnoreError}),
Some(id) => id, Some(id) => id,
}; };
@ -1140,7 +1143,7 @@ impl ChannelManager {
match handle_error!(self, err) { match handle_error!(self, err) {
Ok(_) => unreachable!(), Ok(_) => unreachable!(),
Err(e) => { Err(e) => {
if let Some(msgs::ErrorAction::IgnoreError) = e.action { if let msgs::ErrorAction::IgnoreError = e.action {
} else { } else {
log_error!(self, "Got bad keys: {}!", e.err); log_error!(self, "Got bad keys: {}!", e.err);
let mut channel_state = self.channel_state.lock().unwrap(); let mut channel_state = self.channel_state.lock().unwrap();
@ -1370,12 +1373,41 @@ impl ChannelManager {
let (commitment_msg, monitor) = match chan.get_mut().send_commitment() { let (commitment_msg, monitor) = match chan.get_mut().send_commitment() {
Ok(res) => res, Ok(res) => res,
Err(e) => { Err(e) => {
if let ChannelError::Ignore(_) = e { // We surely failed send_commitment due to bad keys, in that case
panic!("Stated return value requirements in send_commitment() were not met"); // close channel and then send error message to peer.
let their_node_id = chan.get().get_their_node_id();
let err: Result<(), _> = match e {
ChannelError::Ignore(_) => {
panic!("Stated return value requirements in send_commitment() were not met");
},
ChannelError::Close(msg) => {
log_trace!(self, "Closing channel {} due to Close-required error: {}", log_bytes!(chan.key()[..]), msg);
let (channel_id, mut channel) = chan.remove_entry();
if let Some(short_id) = channel.get_short_channel_id() {
channel_state.short_to_id.remove(&short_id);
}
Err(MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, channel.force_shutdown(), self.get_channel_update(&channel).ok()))
},
ChannelError::CloseDelayBroadcast { .. } => { panic!("Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here"); }
};
match handle_error!(self, err) {
Ok(_) => unreachable!(),
Err(e) => {
match e.action {
msgs::ErrorAction::IgnoreError => {},
_ => {
log_error!(self, "Got bad keys: {}!", e.err);
let mut channel_state = self.channel_state.lock().unwrap();
channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
node_id: their_node_id,
action: e.action,
});
},
}
continue;
},
} }
//TODO: Handle...this is bad! }
continue;
},
}; };
if let Err(e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) { if let Err(e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
handle_errors.push((chan.get().get_their_node_id(), handle_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true))); handle_errors.push((chan.get().get_their_node_id(), handle_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true)));
@ -1434,7 +1466,7 @@ impl ChannelManager {
match handle_error!(self, err) { match handle_error!(self, err) {
Ok(_) => {}, Ok(_) => {},
Err(e) => { Err(e) => {
if let Some(msgs::ErrorAction::IgnoreError) = e.action { if let msgs::ErrorAction::IgnoreError = e.action {
} else { } else {
let mut channel_state = self.channel_state.lock().unwrap(); let mut channel_state = self.channel_state.lock().unwrap();
channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError { channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
@ -1488,7 +1520,7 @@ impl ChannelManager {
log_trace!(self, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0)); log_trace!(self, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0));
mem::drop(channel_state_lock); mem::drop(channel_state_lock);
match &onion_error { match &onion_error {
&HTLCFailReason::ErrorPacket { ref err } => { &HTLCFailReason::LightningError { ref err } => {
#[cfg(test)] #[cfg(test)]
let (channel_update, payment_retryable, onion_error_code) = onion_utils::process_onion_failure(&self.secp_ctx, &self.logger, &source, err.data.clone()); let (channel_update, payment_retryable, onion_error_code) = onion_utils::process_onion_failure(&self.secp_ctx, &self.logger, &source, err.data.clone());
#[cfg(not(test))] #[cfg(not(test))]
@ -1541,8 +1573,8 @@ impl ChannelManager {
let packet = onion_utils::build_failure_packet(&incoming_packet_shared_secret, failure_code, &data[..]).encode(); let packet = onion_utils::build_failure_packet(&incoming_packet_shared_secret, failure_code, &data[..]).encode();
onion_utils::encrypt_failure_packet(&incoming_packet_shared_secret, &packet) onion_utils::encrypt_failure_packet(&incoming_packet_shared_secret, &packet)
}, },
HTLCFailReason::ErrorPacket { err } => { HTLCFailReason::LightningError { err } => {
log_trace!(self, "Failing HTLC with payment_hash {} backwards with pre-built ErrorPacket", log_bytes!(payment_hash.0)); log_trace!(self, "Failing HTLC with payment_hash {} backwards with pre-built LightningError", log_bytes!(payment_hash.0));
onion_utils::encrypt_failure_packet(&incoming_packet_shared_secret, &err.data) onion_utils::encrypt_failure_packet(&incoming_packet_shared_secret, &err.data)
} }
}; };
@ -1660,7 +1692,7 @@ impl ChannelManager {
match handle_error!(self, err) { match handle_error!(self, err) {
Ok(_) => {}, Ok(_) => {},
Err(e) => { Err(e) => {
if let Some(msgs::ErrorAction::IgnoreError) = e.action { if let msgs::ErrorAction::IgnoreError = e.action {
} else { } else {
let mut channel_state = self.channel_state.lock().unwrap(); let mut channel_state = self.channel_state.lock().unwrap();
channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError { channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
@ -2118,7 +2150,7 @@ impl ChannelManager {
//TODO: here and below MsgHandleErrInternal, #153 case //TODO: here and below MsgHandleErrInternal, #153 case
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id)); return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
} }
try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::ErrorPacket { err: msg.reason.clone() }), channel_state, chan); try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), channel_state, chan);
}, },
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id)) hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id))
} }
@ -2292,7 +2324,7 @@ impl ChannelManager {
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id)); return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
} }
if !chan.get().is_usable() { if !chan.get().is_usable() {
return Err(MsgHandleErrInternal::from_no_close(HandleError{err: "Got an announcement_signatures before we were ready for it", action: Some(msgs::ErrorAction::IgnoreError)})); return Err(MsgHandleErrInternal::from_no_close(LightningError{err: "Got an announcement_signatures before we were ready for it", action: msgs::ErrorAction::IgnoreError}));
} }
let our_node_id = self.get_our_node_id(); let our_node_id = self.get_our_node_id();
@ -2445,7 +2477,7 @@ impl ChannelManager {
match handle_error!(self, err) { match handle_error!(self, err) {
Ok(_) => unreachable!(), Ok(_) => unreachable!(),
Err(e) => { Err(e) => {
if let Some(msgs::ErrorAction::IgnoreError) = e.action { if let msgs::ErrorAction::IgnoreError = e.action {
} else { } else {
log_error!(self, "Got bad keys: {}!", e.err); log_error!(self, "Got bad keys: {}!", e.err);
let mut channel_state = self.channel_state.lock().unwrap(); let mut channel_state = self.channel_state.lock().unwrap();
@ -2538,7 +2570,7 @@ impl ChainListener for ChannelManager {
} else if let Err(e) = chan_res { } else if let Err(e) = chan_res {
pending_msg_events.push(events::MessageSendEvent::HandleError { pending_msg_events.push(events::MessageSendEvent::HandleError {
node_id: channel.get_their_node_id(), node_id: channel.get_their_node_id(),
action: Some(msgs::ErrorAction::SendErrorMessage { msg: e }), action: msgs::ErrorAction::SendErrorMessage { msg: e },
}); });
return false; return false;
} }
@ -2626,82 +2658,82 @@ impl ChainListener for ChannelManager {
impl ChannelMessageHandler for ChannelManager { impl ChannelMessageHandler for ChannelManager {
//TODO: Handle errors and close channel (or so) //TODO: Handle errors and close channel (or so)
fn handle_open_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &msgs::OpenChannel) -> Result<(), HandleError> { fn handle_open_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &msgs::OpenChannel) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_open_channel(their_node_id, their_local_features, msg)) handle_error!(self, self.internal_open_channel(their_node_id, their_local_features, msg))
} }
fn handle_accept_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &msgs::AcceptChannel) -> Result<(), HandleError> { fn handle_accept_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &msgs::AcceptChannel) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_accept_channel(their_node_id, their_local_features, msg)) handle_error!(self, self.internal_accept_channel(their_node_id, their_local_features, msg))
} }
fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &msgs::FundingCreated) -> Result<(), HandleError> { fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &msgs::FundingCreated) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_funding_created(their_node_id, msg)) handle_error!(self, self.internal_funding_created(their_node_id, msg))
} }
fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), HandleError> { fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_funding_signed(their_node_id, msg)) handle_error!(self, self.internal_funding_signed(their_node_id, msg))
} }
fn handle_funding_locked(&self, their_node_id: &PublicKey, msg: &msgs::FundingLocked) -> Result<(), HandleError> { fn handle_funding_locked(&self, their_node_id: &PublicKey, msg: &msgs::FundingLocked) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_funding_locked(their_node_id, msg)) handle_error!(self, self.internal_funding_locked(their_node_id, msg))
} }
fn handle_shutdown(&self, their_node_id: &PublicKey, msg: &msgs::Shutdown) -> Result<(), HandleError> { fn handle_shutdown(&self, their_node_id: &PublicKey, msg: &msgs::Shutdown) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_shutdown(their_node_id, msg)) handle_error!(self, self.internal_shutdown(their_node_id, msg))
} }
fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &msgs::ClosingSigned) -> Result<(), HandleError> { fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &msgs::ClosingSigned) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_closing_signed(their_node_id, msg)) handle_error!(self, self.internal_closing_signed(their_node_id, msg))
} }
fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateAddHTLC) -> Result<(), msgs::HandleError> { fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateAddHTLC) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_update_add_htlc(their_node_id, msg)) handle_error!(self, self.internal_update_add_htlc(their_node_id, msg))
} }
fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), HandleError> { fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_update_fulfill_htlc(their_node_id, msg)) handle_error!(self, self.internal_update_fulfill_htlc(their_node_id, msg))
} }
fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) -> Result<(), HandleError> { fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_update_fail_htlc(their_node_id, msg)) handle_error!(self, self.internal_update_fail_htlc(their_node_id, msg))
} }
fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), HandleError> { fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_update_fail_malformed_htlc(their_node_id, msg)) handle_error!(self, self.internal_update_fail_malformed_htlc(their_node_id, msg))
} }
fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &msgs::CommitmentSigned) -> Result<(), HandleError> { fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &msgs::CommitmentSigned) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_commitment_signed(their_node_id, msg)) handle_error!(self, self.internal_commitment_signed(their_node_id, msg))
} }
fn handle_revoke_and_ack(&self, their_node_id: &PublicKey, msg: &msgs::RevokeAndACK) -> Result<(), HandleError> { fn handle_revoke_and_ack(&self, their_node_id: &PublicKey, msg: &msgs::RevokeAndACK) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_revoke_and_ack(their_node_id, msg)) handle_error!(self, self.internal_revoke_and_ack(their_node_id, msg))
} }
fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFee) -> Result<(), HandleError> { fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFee) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_update_fee(their_node_id, msg)) handle_error!(self, self.internal_update_fee(their_node_id, msg))
} }
fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), HandleError> { fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_announcement_signatures(their_node_id, msg)) handle_error!(self, self.internal_announcement_signatures(their_node_id, msg))
} }
fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<(), HandleError> { fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<(), LightningError> {
let _ = self.total_consistency_lock.read().unwrap(); let _ = self.total_consistency_lock.read().unwrap();
handle_error!(self, self.internal_channel_reestablish(their_node_id, msg)) handle_error!(self, self.internal_channel_reestablish(their_node_id, msg))
} }
@ -2946,7 +2978,7 @@ impl<R: ::std::io::Read> Readable<R> for HTLCSource {
impl Writeable for HTLCFailReason { impl Writeable for HTLCFailReason {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> { fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
match self { match self {
&HTLCFailReason::ErrorPacket { ref err } => { &HTLCFailReason::LightningError { ref err } => {
0u8.write(writer)?; 0u8.write(writer)?;
err.write(writer)?; err.write(writer)?;
}, },
@ -2963,7 +2995,7 @@ impl Writeable for HTLCFailReason {
impl<R: ::std::io::Read> Readable<R> for HTLCFailReason { impl<R: ::std::io::Read> Readable<R> for HTLCFailReason {
fn read(reader: &mut R) -> Result<HTLCFailReason, DecodeError> { fn read(reader: &mut R) -> Result<HTLCFailReason, DecodeError> {
match <u8 as Readable<R>>::read(reader)? { match <u8 as Readable<R>>::read(reader)? {
0 => Ok(HTLCFailReason::ErrorPacket { err: Readable::read(reader)? }), 0 => Ok(HTLCFailReason::LightningError { err: Readable::read(reader)? }),
1 => Ok(HTLCFailReason::Reason { 1 => Ok(HTLCFailReason::Reason {
failure_code: Readable::read(reader)?, failure_code: Readable::read(reader)?,
data: Readable::read(reader)?, data: Readable::read(reader)?,

View file

@ -1643,46 +1643,48 @@ impl ChannelMonitor {
return (txn_to_broadcast, (commitment_txid, watch_outputs), spendable_outputs); // Corrupted per_commitment_data, fuck this user return (txn_to_broadcast, (commitment_txid, watch_outputs), spendable_outputs); // Corrupted per_commitment_data, fuck this user
} }
if let Some(payment_preimage) = self.payment_preimages.get(&htlc.payment_hash) { if let Some(payment_preimage) = self.payment_preimages.get(&htlc.payment_hash) {
let input = TxIn { if htlc.offered {
previous_output: BitcoinOutPoint { let input = TxIn {
txid: commitment_txid, previous_output: BitcoinOutPoint {
vout: transaction_output_index, txid: commitment_txid,
}, vout: transaction_output_index,
script_sig: Script::new(), },
sequence: idx as u32, // reset to 0xfffffffd in sign_input script_sig: Script::new(),
witness: Vec::new(), sequence: idx as u32, // reset to 0xfffffffd in sign_input
}; witness: Vec::new(),
if htlc.cltv_expiry > height + CLTV_SHARED_CLAIM_BUFFER {
inputs.push(input);
inputs_desc.push(if htlc.offered { InputDescriptors::OfferedHTLC } else { InputDescriptors::ReceivedHTLC });
inputs_info.push((payment_preimage, tx.output[transaction_output_index as usize].value, htlc.cltv_expiry));
total_value += tx.output[transaction_output_index as usize].value;
} else {
let mut single_htlc_tx = Transaction {
version: 2,
lock_time: 0,
input: vec![input],
output: vec!(TxOut {
script_pubkey: self.destination_script.clone(),
value: htlc.amount_msat / 1000,
}),
}; };
let predicted_weight = single_htlc_tx.get_weight() + Self::get_witnesses_weight(&[if htlc.offered { InputDescriptors::OfferedHTLC } else { InputDescriptors::ReceivedHTLC }]); if htlc.cltv_expiry > height + CLTV_SHARED_CLAIM_BUFFER {
let height_timer = Self::get_height_timer(height, htlc.cltv_expiry); inputs.push(input);
let mut used_feerate; inputs_desc.push(if htlc.offered { InputDescriptors::OfferedHTLC } else { InputDescriptors::ReceivedHTLC });
if subtract_high_prio_fee!(self, fee_estimator, single_htlc_tx.output[0].value, predicted_weight, tx.txid(), used_feerate) { inputs_info.push((payment_preimage, tx.output[transaction_output_index as usize].value, htlc.cltv_expiry));
let sighash_parts = bip143::SighashComponents::new(&single_htlc_tx); total_value += tx.output[transaction_output_index as usize].value;
let (redeemscript, htlc_key) = sign_input!(sighash_parts, single_htlc_tx.input[0], htlc.amount_msat / 1000, payment_preimage.0.to_vec()); } else {
assert!(predicted_weight >= single_htlc_tx.get_weight()); let mut single_htlc_tx = Transaction {
spendable_outputs.push(SpendableOutputDescriptor::StaticOutput { version: 2,
outpoint: BitcoinOutPoint { txid: single_htlc_tx.txid(), vout: 0 }, lock_time: 0,
output: single_htlc_tx.output[0].clone(), input: vec![input],
}); output: vec!(TxOut {
match self.our_claim_txn_waiting_first_conf.entry(single_htlc_tx.input[0].previous_output.clone()) { script_pubkey: self.destination_script.clone(),
hash_map::Entry::Occupied(_) => {}, value: htlc.amount_msat / 1000,
hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::RemoteHTLC { script: redeemscript, key: htlc_key, preimage: Some(*payment_preimage), amount: htlc.amount_msat / 1000 }, used_feerate, htlc.cltv_expiry, height)); } }),
};
let predicted_weight = single_htlc_tx.get_weight() + Self::get_witnesses_weight(&[if htlc.offered { InputDescriptors::OfferedHTLC } else { InputDescriptors::ReceivedHTLC }]);
let height_timer = Self::get_height_timer(height, htlc.cltv_expiry);
let mut used_feerate;
if subtract_high_prio_fee!(self, fee_estimator, single_htlc_tx.output[0].value, predicted_weight, tx.txid(), used_feerate) {
let sighash_parts = bip143::SighashComponents::new(&single_htlc_tx);
let (redeemscript, htlc_key) = sign_input!(sighash_parts, single_htlc_tx.input[0], htlc.amount_msat / 1000, payment_preimage.0.to_vec());
assert!(predicted_weight >= single_htlc_tx.get_weight());
spendable_outputs.push(SpendableOutputDescriptor::StaticOutput {
outpoint: BitcoinOutPoint { txid: single_htlc_tx.txid(), vout: 0 },
output: single_htlc_tx.output[0].clone(),
});
match self.our_claim_txn_waiting_first_conf.entry(single_htlc_tx.input[0].previous_output.clone()) {
hash_map::Entry::Occupied(_) => {},
hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::RemoteHTLC { script: redeemscript, key: htlc_key, preimage: Some(*payment_preimage), amount: htlc.amount_msat / 1000 }, used_feerate, htlc.cltv_expiry, height)); }
}
txn_to_broadcast.push(single_htlc_tx);
} }
txn_to_broadcast.push(single_htlc_tx);
} }
} }
} }
@ -1738,7 +1740,7 @@ impl ChannelMonitor {
output: outputs, output: outputs,
}; };
let mut predicted_weight = spend_tx.get_weight() + Self::get_witnesses_weight(&inputs_desc[..]); let predicted_weight = spend_tx.get_weight() + Self::get_witnesses_weight(&inputs_desc[..]);
let mut used_feerate; let mut used_feerate;
if !subtract_high_prio_fee!(self, fee_estimator, spend_tx.output[0].value, predicted_weight, tx.txid(), used_feerate) { if !subtract_high_prio_fee!(self, fee_estimator, spend_tx.output[0].value, predicted_weight, tx.txid(), used_feerate) {

View file

@ -844,7 +844,7 @@ pub fn create_network(node_count: usize, node_config: &[Option<UserConfig>]) ->
let mut default_config = UserConfig::new(); let mut default_config = UserConfig::new();
default_config.channel_options.announced_channel = true; default_config.channel_options.announced_channel = true;
default_config.peer_channel_config_limits.force_announced_channel_preference = false; default_config.peer_channel_config_limits.force_announced_channel_preference = false;
let node = ChannelManager::new(Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone(), if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }).unwrap(); let node = ChannelManager::new(Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone(), if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }, 0).unwrap();
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &keys_manager.get_node_secret()), chain_monitor.clone(), Arc::clone(&logger)); let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &keys_manager.get_node_secret()), chain_monitor.clone(), Arc::clone(&logger));
nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router, keys_manager, node_seed: seed, nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router, keys_manager, node_seed: seed,
network_payment_count: payment_count.clone(), network_payment_count: payment_count.clone(),

View file

@ -70,10 +70,10 @@ fn test_insane_channel_opens() {
// that supposedly makes the channel open message insane // that supposedly makes the channel open message insane
let insane_open_helper = |expected_error_str, message_mutator: fn(msgs::OpenChannel) -> msgs::OpenChannel| { let insane_open_helper = |expected_error_str, message_mutator: fn(msgs::OpenChannel) -> msgs::OpenChannel| {
match nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), LocalFeatures::new(), &message_mutator(open_channel_message.clone())) { match nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), LocalFeatures::new(), &message_mutator(open_channel_message.clone())) {
Err(msgs::HandleError{ err: error_str, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) => { Err(msgs::LightningError{ err: error_str, action: msgs::ErrorAction::SendErrorMessage {..}}) => {
assert_eq!(error_str, expected_error_str, "unexpected HandleError string (expected `{}`, actual `{}`)", expected_error_str, error_str) assert_eq!(error_str, expected_error_str, "unexpected LightningError string (expected `{}`, actual `{}`)", expected_error_str, error_str)
}, },
Err(msgs::HandleError{..}) => {panic!("unexpected HandleError action")}, Err(msgs::LightningError{..}) => {panic!("unexpected LightningError action")},
_ => panic!("insane OpenChannel message was somehow Ok"), _ => panic!("insane OpenChannel message was somehow Ok"),
} }
}; };
@ -952,7 +952,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) {
// transaction. // transaction.
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
if let Err(msgs::HandleError{action: Some(msgs::ErrorAction::SendErrorMessage{msg}), ..}) = if let Err(msgs::LightningError{action: msgs::ErrorAction::SendErrorMessage{msg}, ..}) =
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &node_0_2nd_reestablish) { nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &node_0_2nd_reestablish) {
nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msg); nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msg);
let msgs::ErrorMessage {ref channel_id, ..} = msg; let msgs::ErrorMessage {ref channel_id, ..} = msg;
@ -1245,8 +1245,75 @@ fn duplicate_htlc_test() {
claim_payment(&nodes[1], &vec!(&nodes[3])[..], payment_preimage); claim_payment(&nodes[1], &vec!(&nodes[3])[..], payment_preimage);
} }
#[test]
fn test_duplicate_htlc_different_direction_onchain() {
// Test that ChannelMonitor doesn't generate 2 preimage txn
// when we have 2 HTLCs with same preimage that go across a node
// in opposite directions.
let nodes = create_network(2, &[None, None]);
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new());
// balancing
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
let (payment_preimage, payment_hash) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000);
let route = nodes[1].router.get_route(&nodes[0].node.get_our_node_id(), None, &Vec::new(), 800_000, TEST_FINAL_CLTV).unwrap();
send_along_route_with_hash(&nodes[1], route, &vec!(&nodes[0])[..], 800_000, payment_hash);
// Provide preimage to node 0 by claiming payment
nodes[0].node.claim_funds(payment_preimage);
check_added_monitors!(nodes[0], 1);
// Broadcast node 1 commitment txn
let remote_txn = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
assert_eq!(remote_txn[0].output.len(), 4); // 1 local, 1 remote, 1 htlc inbound, 1 htlc outbound
let mut has_both_htlcs = 0; // check htlcs match ones committed
for outp in remote_txn[0].output.iter() {
if outp.value == 800_000 / 1000 {
has_both_htlcs += 1;
} else if outp.value == 900_000 / 1000 {
has_both_htlcs += 1;
}
}
assert_eq!(has_both_htlcs, 2);
let header = BlockHeader { version: 0x2000_0000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![remote_txn[0].clone()] }, 1);
// Check we only broadcast 1 timeout tx
let claim_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
let htlc_pair = if claim_txn[0].output[0].value == 800_000 / 1000 { (claim_txn[0].clone(), claim_txn[1].clone()) } else { (claim_txn[1].clone(), claim_txn[0].clone()) };
assert_eq!(claim_txn.len(), 6);
assert_eq!(htlc_pair.0.input.len(), 1);
assert_eq!(htlc_pair.0.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
check_spends!(htlc_pair.0, remote_txn[0].clone());
assert_eq!(htlc_pair.1.input.len(), 1);
assert_eq!(htlc_pair.1.input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
check_spends!(htlc_pair.1, remote_txn[0].clone());
let events = nodes[0].node.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 2);
for e in events {
match e {
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, .. } } => {
assert!(update_add_htlcs.is_empty());
assert!(update_fail_htlcs.is_empty());
assert_eq!(update_fulfill_htlcs.len(), 1);
assert!(update_fail_malformed_htlcs.is_empty());
assert_eq!(nodes[1].node.get_our_node_id(), *node_id);
},
_ => panic!("Unexpected event"),
}
}
}
fn do_channel_reserve_test(test_recv: bool) { fn do_channel_reserve_test(test_recv: bool) {
use ln::msgs::HandleError; use ln::msgs::LightningError;
let mut nodes = create_network(3, &[None, None, None]); let mut nodes = create_network(3, &[None, None, None]);
let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1900, 1001, LocalFeatures::new(), LocalFeatures::new()); let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1900, 1001, LocalFeatures::new(), LocalFeatures::new());
@ -1382,7 +1449,7 @@ fn do_channel_reserve_test(test_recv: bool) {
if test_recv { if test_recv {
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg).err().unwrap(); let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg).err().unwrap();
match err { match err {
HandleError{err, .. } => assert_eq!(err, "Remote HTLC add would put them over their reserve value"), LightningError{err, .. } => assert_eq!(err, "Remote HTLC add would put them over their reserve value"),
} }
// If we send a garbage message, the channel should get closed, making the rest of this test case fail. // If we send a garbage message, the channel should get closed, making the rest of this test case fail.
assert_eq!(nodes[1].node.list_channels().len(), 1); assert_eq!(nodes[1].node.list_channels().len(), 1);
@ -3455,7 +3522,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
nodes[3].node.peer_connected(&nodes[0].node.get_our_node_id()); nodes[3].node.peer_connected(&nodes[0].node.get_our_node_id());
let reestablish = get_event_msg!(nodes[3], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id()); let reestablish = get_event_msg!(nodes[3], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id());
nodes[0].node.peer_connected(&nodes[3].node.get_our_node_id()); nodes[0].node.peer_connected(&nodes[3].node.get_our_node_id());
if let Err(msgs::HandleError { action: Some(msgs::ErrorAction::SendErrorMessage { msg }), .. }) = nodes[0].node.handle_channel_reestablish(&nodes[3].node.get_our_node_id(), &reestablish) { if let Err(msgs::LightningError { action: msgs::ErrorAction::SendErrorMessage { msg }, .. }) = nodes[0].node.handle_channel_reestablish(&nodes[3].node.get_our_node_id(), &reestablish) {
assert_eq!(msg.channel_id, channel_id); assert_eq!(msg.channel_id, channel_id);
} else { panic!("Unexpected result"); } } else { panic!("Unexpected result"); }
} }
@ -5101,7 +5168,7 @@ fn test_update_add_htlc_bolt2_receiver_check_amount_received_more_than_min() {
let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
updates.update_add_htlcs[0].amount_msat = htlc_minimum_msat-1; updates.update_add_htlcs[0].amount_msat = htlc_minimum_msat-1;
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote side tried to send less than our minimum HTLC value"); assert_eq!(err, "Remote side tried to send less than our minimum HTLC value");
} else { } else {
assert!(false); assert!(false);
@ -5127,7 +5194,7 @@ fn test_update_add_htlc_bolt2_receiver_sender_can_afford_amount_sent() {
updates.update_add_htlcs[0].amount_msat = 5000000-their_channel_reserve+1; updates.update_add_htlcs[0].amount_msat = 5000000-their_channel_reserve+1;
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote HTLC add would put them over their reserve value"); assert_eq!(err, "Remote HTLC add would put them over their reserve value");
} else { } else {
assert!(false); assert!(false);
@ -5174,7 +5241,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
msg.htlc_id = (super::channel::OUR_MAX_HTLCS) as u64; msg.htlc_id = (super::channel::OUR_MAX_HTLCS) as u64;
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg); let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote tried to push more than our max accepted HTLCs"); assert_eq!(err, "Remote tried to push more than our max accepted HTLCs");
} else { } else {
assert!(false); assert!(false);
@ -5197,7 +5264,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_in_flight_msat() {
updates.update_add_htlcs[0].amount_msat = get_channel_value_stat!(nodes[1], chan.2).their_max_htlc_value_in_flight_msat + 1; updates.update_add_htlcs[0].amount_msat = get_channel_value_stat!(nodes[1], chan.2).their_max_htlc_value_in_flight_msat + 1;
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err,"Remote HTLC add would put them over our max HTLC value"); assert_eq!(err,"Remote HTLC add would put them over our max HTLC value");
} else { } else {
assert!(false); assert!(false);
@ -5220,7 +5287,7 @@ fn test_update_add_htlc_bolt2_receiver_check_cltv_expiry() {
updates.update_add_htlcs[0].cltv_expiry = 500000000; updates.update_add_htlcs[0].cltv_expiry = 500000000;
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err,"Remote provided CLTV expiry in seconds instead of block height"); assert_eq!(err,"Remote provided CLTV expiry in seconds instead of block height");
} else { } else {
assert!(false); assert!(false);
@ -5266,7 +5333,7 @@ fn test_update_add_htlc_bolt2_receiver_check_repeated_id_ignore() {
let _bs_responses = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); let _bs_responses = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id());
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote skipped HTLC ID"); assert_eq!(err, "Remote skipped HTLC ID");
} else { } else {
assert!(false); assert!(false);
@ -5298,7 +5365,7 @@ fn test_update_fulfill_htlc_bolt2_update_fulfill_htlc_before_commitment() {
let err = nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_msg); let err = nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_msg);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote tried to fulfill/fail HTLC before it had been committed"); assert_eq!(err, "Remote tried to fulfill/fail HTLC before it had been committed");
} else { } else {
assert!(false); assert!(false);
@ -5330,7 +5397,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_htlc_before_commitment() {
let err = nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_msg); let err = nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_msg);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote tried to fulfill/fail HTLC before it had been committed"); assert_eq!(err, "Remote tried to fulfill/fail HTLC before it had been committed");
} else { } else {
assert!(false); assert!(false);
@ -5363,7 +5430,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_malformed_htlc_before_commitment()
let err = nodes[0].node.handle_update_fail_malformed_htlc(&nodes[1].node.get_our_node_id(), &update_msg); let err = nodes[0].node.handle_update_fail_malformed_htlc(&nodes[1].node.get_our_node_id(), &update_msg);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote tried to fulfill/fail HTLC before it had been committed"); assert_eq!(err, "Remote tried to fulfill/fail HTLC before it had been committed");
} else { } else {
assert!(false); assert!(false);
@ -5404,7 +5471,7 @@ fn test_update_fulfill_htlc_bolt2_incorrect_htlc_id() {
update_fulfill_msg.htlc_id = 1; update_fulfill_msg.htlc_id = 1;
let err = nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_msg); let err = nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_msg);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote tried to fulfill/fail an HTLC we couldn't find"); assert_eq!(err, "Remote tried to fulfill/fail an HTLC we couldn't find");
} else { } else {
assert!(false); assert!(false);
@ -5445,7 +5512,7 @@ fn test_update_fulfill_htlc_bolt2_wrong_preimage() {
update_fulfill_msg.payment_preimage = PaymentPreimage([1; 32]); update_fulfill_msg.payment_preimage = PaymentPreimage([1; 32]);
let err = nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_msg); let err = nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_msg);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Remote tried to fulfill HTLC with an incorrect preimage"); assert_eq!(err, "Remote tried to fulfill HTLC with an incorrect preimage");
} else { } else {
assert!(false); assert!(false);
@ -5491,7 +5558,7 @@ fn test_update_fulfill_htlc_bolt2_missing_badonion_bit_for_malformed_htlc_messag
}; };
update_msg.failure_code &= !0x8000; update_msg.failure_code &= !0x8000;
let err = nodes[0].node.handle_update_fail_malformed_htlc(&nodes[1].node.get_our_node_id(), &update_msg); let err = nodes[0].node.handle_update_fail_malformed_htlc(&nodes[1].node.get_our_node_id(), &update_msg);
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err { if let Err(msgs::LightningError{err, action: msgs::ErrorAction::SendErrorMessage {..}}) = err {
assert_eq!(err, "Got update_fail_malformed_htlc with BADONION not set"); assert_eq!(err, "Got update_fail_malformed_htlc with BADONION not set");
} else { } else {
assert!(false); assert!(false);
@ -5864,14 +5931,12 @@ fn test_upfront_shutdown_script() {
node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh(); node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh();
// Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we disconnect peer // Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we disconnect peer
if let Err(error) = nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown) { if let Err(error) = nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown) {
if let Some(error) = error.action { match error.action {
match error { ErrorAction::SendErrorMessage { msg } => {
ErrorAction::SendErrorMessage { msg } => { assert_eq!(msg.data,"Got shutdown request with a scriptpubkey which did not match their previous scriptpubkey");
assert_eq!(msg.data,"Got shutdown request with a scriptpubkey which did not match their previous scriptpubkey"); },
}, _ => { assert!(false); }
_ => { assert!(false); } }
}
} else { assert!(false); }
} else { assert!(false); } } else { assert!(false); }
let events = nodes[2].node.get_and_clear_pending_msg_events(); let events = nodes[2].node.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 1); assert_eq!(events.len(), 1);
@ -5981,14 +6046,12 @@ fn test_user_configurable_csv_delay() {
let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
accept_channel.to_self_delay = 200; accept_channel.to_self_delay = 200;
if let Err(error) = nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), LocalFeatures::new(), &accept_channel) { if let Err(error) = nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), LocalFeatures::new(), &accept_channel) {
if let Some(error) = error.action { match error.action {
match error { ErrorAction::SendErrorMessage { msg } => {
ErrorAction::SendErrorMessage { msg } => { assert_eq!(msg.data,"They wanted our payments to be delayed by a needlessly long period");
assert_eq!(msg.data,"They wanted our payments to be delayed by a needlessly long period"); },
}, _ => { assert!(false); }
_ => { assert!(false); } }
}
} else { assert!(false); }
} else { assert!(false); } } else { assert!(false); }
// We test msg.to_self_delay <= config.their_to_self_delay is enforced in Channel::new_from_req() // We test msg.to_self_delay <= config.their_to_self_delay is enforced in Channel::new_from_req()
@ -6056,14 +6119,12 @@ fn test_data_loss_protect() {
// Check we update monitor following learning of per_commitment_point from B // Check we update monitor following learning of per_commitment_point from B
if let Err(err) = nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_0[0]) { if let Err(err) = nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_0[0]) {
if let Some(error) = err.action { match err.action {
match error { ErrorAction::SendErrorMessage { msg } => {
ErrorAction::SendErrorMessage { msg } => { assert_eq!(msg.data, "We have fallen behind - we have received proof that if we broadcast remote is going to claim our funds - we can't do any automated broadcasting");
assert_eq!(msg.data, "We have fallen behind - we have received proof that if we broadcast remote is going to claim our funds - we can't do any automated broadcasting"); },
}, _ => panic!("Unexpected event!"),
_ => panic!("Unexpected event!"), }
}
} else { assert!(false); }
} else { assert!(false); } } else { assert!(false); }
check_added_monitors!(nodes[0], 1); check_added_monitors!(nodes[0], 1);
@ -6085,13 +6146,11 @@ fn test_data_loss_protect() {
// Check we close channel detecting A is fallen-behind // Check we close channel detecting A is fallen-behind
if let Err(err) = nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]) { if let Err(err) = nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]) {
if let Some(error) = err.action { match err.action {
match error { ErrorAction::SendErrorMessage { msg } => {
ErrorAction::SendErrorMessage { msg } => { assert_eq!(msg.data, "Peer attempted to reestablish channel with a very old local commitment transaction"); },
assert_eq!(msg.data, "Peer attempted to reestablish channel with a very old local commitment transaction"); }, _ => panic!("Unexpected event!"),
_ => panic!("Unexpected event!"), }
}
} else { assert!(false); }
} else { assert!(false); } } else { assert!(false); }
let events = nodes[1].node.get_and_clear_pending_msg_events(); let events = nodes[1].node.get_and_clear_pending_msg_events();

View file

@ -525,7 +525,7 @@ pub struct ChannelUpdate {
pub(crate) contents: UnsignedChannelUpdate, pub(crate) contents: UnsignedChannelUpdate,
} }
/// Used to put an error message in a HandleError /// Used to put an error message in a LightningError
#[derive(Clone)] #[derive(Clone)]
pub enum ErrorAction { pub enum ErrorAction {
/// The peer took some action which made us think they were useless. Disconnect them. /// The peer took some action which made us think they were useless. Disconnect them.
@ -543,11 +543,11 @@ pub enum ErrorAction {
} }
/// An Err type for failure to process messages. /// An Err type for failure to process messages.
pub struct HandleError { //TODO: rename me pub struct LightningError {
/// A human-readable message describing the error /// A human-readable message describing the error
pub err: &'static str, pub err: &'static str,
/// The action which should be taken against the offending peer. /// The action which should be taken against the offending peer.
pub action: Option<ErrorAction>, //TODO: Make this required pub action: ErrorAction,
} }
/// Struct used to return values from revoke_and_ack messages, containing a bunch of commitment /// Struct used to return values from revoke_and_ack messages, containing a bunch of commitment
@ -616,42 +616,42 @@ pub enum OptionalField<T> {
pub trait ChannelMessageHandler : events::MessageSendEventsProvider + Send + Sync { pub trait ChannelMessageHandler : events::MessageSendEventsProvider + Send + Sync {
//Channel init: //Channel init:
/// Handle an incoming open_channel message from the given peer. /// Handle an incoming open_channel message from the given peer.
fn handle_open_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &OpenChannel) -> Result<(), HandleError>; fn handle_open_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &OpenChannel) -> Result<(), LightningError>;
/// Handle an incoming accept_channel message from the given peer. /// Handle an incoming accept_channel message from the given peer.
fn handle_accept_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &AcceptChannel) -> Result<(), HandleError>; fn handle_accept_channel(&self, their_node_id: &PublicKey, their_local_features: LocalFeatures, msg: &AcceptChannel) -> Result<(), LightningError>;
/// Handle an incoming funding_created message from the given peer. /// Handle an incoming funding_created message from the given peer.
fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated) -> Result<(), HandleError>; fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated) -> Result<(), LightningError>;
/// Handle an incoming funding_signed message from the given peer. /// Handle an incoming funding_signed message from the given peer.
fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &FundingSigned) -> Result<(), HandleError>; fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &FundingSigned) -> Result<(), LightningError>;
/// Handle an incoming funding_locked message from the given peer. /// Handle an incoming funding_locked message from the given peer.
fn handle_funding_locked(&self, their_node_id: &PublicKey, msg: &FundingLocked) -> Result<(), HandleError>; fn handle_funding_locked(&self, their_node_id: &PublicKey, msg: &FundingLocked) -> Result<(), LightningError>;
// Channl close: // Channl close:
/// Handle an incoming shutdown message from the given peer. /// Handle an incoming shutdown message from the given peer.
fn handle_shutdown(&self, their_node_id: &PublicKey, msg: &Shutdown) -> Result<(), HandleError>; fn handle_shutdown(&self, their_node_id: &PublicKey, msg: &Shutdown) -> Result<(), LightningError>;
/// Handle an incoming closing_signed message from the given peer. /// Handle an incoming closing_signed message from the given peer.
fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned) -> Result<(), HandleError>; fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned) -> Result<(), LightningError>;
// HTLC handling: // HTLC handling:
/// Handle an incoming update_add_htlc message from the given peer. /// Handle an incoming update_add_htlc message from the given peer.
fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &UpdateAddHTLC) -> Result<(), HandleError>; fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &UpdateAddHTLC) -> Result<(), LightningError>;
/// Handle an incoming update_fulfill_htlc message from the given peer. /// Handle an incoming update_fulfill_htlc message from the given peer.
fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFulfillHTLC) -> Result<(), HandleError>; fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFulfillHTLC) -> Result<(), LightningError>;
/// Handle an incoming update_fail_htlc message from the given peer. /// Handle an incoming update_fail_htlc message from the given peer.
fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFailHTLC) -> Result<(), HandleError>; fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFailHTLC) -> Result<(), LightningError>;
/// Handle an incoming update_fail_malformed_htlc message from the given peer. /// Handle an incoming update_fail_malformed_htlc message from the given peer.
fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFailMalformedHTLC) -> Result<(), HandleError>; fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFailMalformedHTLC) -> Result<(), LightningError>;
/// Handle an incoming commitment_signed message from the given peer. /// Handle an incoming commitment_signed message from the given peer.
fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &CommitmentSigned) -> Result<(), HandleError>; fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &CommitmentSigned) -> Result<(), LightningError>;
/// Handle an incoming revoke_and_ack message from the given peer. /// Handle an incoming revoke_and_ack message from the given peer.
fn handle_revoke_and_ack(&self, their_node_id: &PublicKey, msg: &RevokeAndACK) -> Result<(), HandleError>; fn handle_revoke_and_ack(&self, their_node_id: &PublicKey, msg: &RevokeAndACK) -> Result<(), LightningError>;
/// Handle an incoming update_fee message from the given peer. /// Handle an incoming update_fee message from the given peer.
fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &UpdateFee) -> Result<(), HandleError>; fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &UpdateFee) -> Result<(), LightningError>;
// Channel-to-announce: // Channel-to-announce:
/// Handle an incoming announcement_signatures message from the given peer. /// Handle an incoming announcement_signatures message from the given peer.
fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &AnnouncementSignatures) -> Result<(), HandleError>; fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &AnnouncementSignatures) -> Result<(), LightningError>;
// Connection loss/reestablish: // Connection loss/reestablish:
/// Indicates a connection to the peer failed/an existing connection was lost. If no connection /// Indicates a connection to the peer failed/an existing connection was lost. If no connection
@ -663,7 +663,7 @@ pub trait ChannelMessageHandler : events::MessageSendEventsProvider + Send + Syn
/// Handle a peer reconnecting, possibly generating channel_reestablish message(s). /// Handle a peer reconnecting, possibly generating channel_reestablish message(s).
fn peer_connected(&self, their_node_id: &PublicKey); fn peer_connected(&self, their_node_id: &PublicKey);
/// Handle an incoming channel_reestablish message from the given peer. /// Handle an incoming channel_reestablish message from the given peer.
fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &ChannelReestablish) -> Result<(), HandleError>; fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &ChannelReestablish) -> Result<(), LightningError>;
// Error: // Error:
/// Handle an incoming error message from the given peer. /// Handle an incoming error message from the given peer.
@ -674,13 +674,13 @@ pub trait ChannelMessageHandler : events::MessageSendEventsProvider + Send + Syn
pub trait RoutingMessageHandler : Send + Sync { pub trait RoutingMessageHandler : Send + Sync {
/// Handle an incoming node_announcement message, returning true if it should be forwarded on, /// Handle an incoming node_announcement message, returning true if it should be forwarded on,
/// false or returning an Err otherwise. /// false or returning an Err otherwise.
fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result<bool, HandleError>; fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result<bool, LightningError>;
/// Handle a channel_announcement message, returning true if it should be forwarded on, false /// Handle a channel_announcement message, returning true if it should be forwarded on, false
/// or returning an Err otherwise. /// or returning an Err otherwise.
fn handle_channel_announcement(&self, msg: &ChannelAnnouncement) -> Result<bool, HandleError>; fn handle_channel_announcement(&self, msg: &ChannelAnnouncement) -> Result<bool, LightningError>;
/// Handle an incoming channel_update message, returning true if it should be forwarded on, /// Handle an incoming channel_update message, returning true if it should be forwarded on,
/// false or returning an Err otherwise. /// false or returning an Err otherwise.
fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<bool, HandleError>; fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<bool, LightningError>;
/// Handle some updates to the route graph that we learned due to an outbound failed payment. /// Handle some updates to the route graph that we learned due to an outbound failed payment.
fn handle_htlc_fail_channel_update(&self, update: &HTLCFailChannelUpdate); fn handle_htlc_fail_channel_update(&self, update: &HTLCFailChannelUpdate);
/// Gets a subset of the channel announcements and updates required to dump our routing table /// Gets a subset of the channel announcements and updates required to dump our routing table
@ -770,7 +770,7 @@ impl fmt::Display for DecodeError {
} }
} }
impl fmt::Debug for HandleError { impl fmt::Debug for LightningError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.err) f.write_str(self.err)
} }

View file

@ -1,4 +1,4 @@
use ln::msgs::HandleError; use ln::msgs::LightningError;
use ln::msgs; use ln::msgs;
use bitcoin_hashes::{Hash, HashEngine, Hmac, HmacEngine}; use bitcoin_hashes::{Hash, HashEngine, Hmac, HmacEngine};
@ -133,13 +133,13 @@ impl PeerChannelEncryptor {
} }
#[inline] #[inline]
fn decrypt_with_ad(res: &mut[u8], n: u64, key: &[u8; 32], h: &[u8], cyphertext: &[u8]) -> Result<(), HandleError> { fn decrypt_with_ad(res: &mut[u8], n: u64, key: &[u8; 32], h: &[u8], cyphertext: &[u8]) -> Result<(), LightningError> {
let mut nonce = [0; 12]; let mut nonce = [0; 12];
nonce[4..].copy_from_slice(&byte_utils::le64_to_array(n)); nonce[4..].copy_from_slice(&byte_utils::le64_to_array(n));
let mut chacha = ChaCha20Poly1305RFC::new(key, &nonce, h); let mut chacha = ChaCha20Poly1305RFC::new(key, &nonce, h);
if !chacha.decrypt(&cyphertext[0..cyphertext.len() - 16], res, &cyphertext[cyphertext.len() - 16..]) { if !chacha.decrypt(&cyphertext[0..cyphertext.len() - 16], res, &cyphertext[cyphertext.len() - 16..]) {
return Err(HandleError{err: "Bad MAC", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })}); return Err(LightningError{err: "Bad MAC", action: msgs::ErrorAction::DisconnectPeer{ msg: None }});
} }
Ok(()) Ok(())
} }
@ -189,15 +189,15 @@ impl PeerChannelEncryptor {
} }
#[inline] #[inline]
fn inbound_noise_act(state: &mut BidirectionalNoiseState, act: &[u8], our_key: &SecretKey) -> Result<(PublicKey, [u8; 32]), HandleError> { fn inbound_noise_act(state: &mut BidirectionalNoiseState, act: &[u8], our_key: &SecretKey) -> Result<(PublicKey, [u8; 32]), LightningError> {
assert_eq!(act.len(), 50); assert_eq!(act.len(), 50);
if act[0] != 0 { if act[0] != 0 {
return Err(HandleError{err: "Unknown handshake version number", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })}); return Err(LightningError{err: "Unknown handshake version number", action: msgs::ErrorAction::DisconnectPeer{ msg: None }});
} }
let their_pub = match PublicKey::from_slice(&act[1..34]) { let their_pub = match PublicKey::from_slice(&act[1..34]) {
Err(_) => return Err(HandleError{err: "Invalid public key", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })}), Err(_) => return Err(LightningError{err: "Invalid public key", action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
Ok(key) => key, Ok(key) => key,
}; };
@ -239,7 +239,7 @@ impl PeerChannelEncryptor {
} }
} }
pub fn process_act_one_with_keys(&mut self, act_one: &[u8], our_node_secret: &SecretKey, our_ephemeral: SecretKey) -> Result<[u8; 50], HandleError> { pub fn process_act_one_with_keys(&mut self, act_one: &[u8], our_node_secret: &SecretKey, our_ephemeral: SecretKey) -> Result<[u8; 50], LightningError> {
assert_eq!(act_one.len(), 50); assert_eq!(act_one.len(), 50);
match self.noise_state { match self.noise_state {
@ -266,7 +266,7 @@ impl PeerChannelEncryptor {
} }
} }
pub fn process_act_two(&mut self, act_two: &[u8], our_node_secret: &SecretKey) -> Result<([u8; 66], PublicKey), HandleError> { pub fn process_act_two(&mut self, act_two: &[u8], our_node_secret: &SecretKey) -> Result<([u8; 66], PublicKey), LightningError> {
assert_eq!(act_two.len(), 50); assert_eq!(act_two.len(), 50);
let final_hkdf; let final_hkdf;
@ -317,7 +317,7 @@ impl PeerChannelEncryptor {
Ok((res, self.their_node_id.unwrap().clone())) Ok((res, self.their_node_id.unwrap().clone()))
} }
pub fn process_act_three(&mut self, act_three: &[u8]) -> Result<PublicKey, HandleError> { pub fn process_act_three(&mut self, act_three: &[u8]) -> Result<PublicKey, LightningError> {
assert_eq!(act_three.len(), 66); assert_eq!(act_three.len(), 66);
let final_hkdf; let final_hkdf;
@ -330,14 +330,14 @@ impl PeerChannelEncryptor {
panic!("Requested act at wrong step"); panic!("Requested act at wrong step");
} }
if act_three[0] != 0 { if act_three[0] != 0 {
return Err(HandleError{err: "Unknown handshake version number", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })}); return Err(LightningError{err: "Unknown handshake version number", action: msgs::ErrorAction::DisconnectPeer{ msg: None }});
} }
let mut their_node_id = [0; 33]; let mut their_node_id = [0; 33];
PeerChannelEncryptor::decrypt_with_ad(&mut their_node_id, 1, &temp_k2.unwrap(), &bidirectional_state.h, &act_three[1..50])?; PeerChannelEncryptor::decrypt_with_ad(&mut their_node_id, 1, &temp_k2.unwrap(), &bidirectional_state.h, &act_three[1..50])?;
self.their_node_id = Some(match PublicKey::from_slice(&their_node_id) { self.their_node_id = Some(match PublicKey::from_slice(&their_node_id) {
Ok(key) => key, Ok(key) => key,
Err(_) => return Err(HandleError{err: "Bad node_id from peer", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })}), Err(_) => return Err(LightningError{err: "Bad node_id from peer", action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
}); });
let mut sha = Sha256::engine(); let mut sha = Sha256::engine();
@ -403,7 +403,7 @@ impl PeerChannelEncryptor {
/// Decrypts a message length header from the remote peer. /// Decrypts a message length header from the remote peer.
/// panics if noise handshake has not yet finished or msg.len() != 18 /// panics if noise handshake has not yet finished or msg.len() != 18
pub fn decrypt_length_header(&mut self, msg: &[u8]) -> Result<u16, HandleError> { pub fn decrypt_length_header(&mut self, msg: &[u8]) -> Result<u16, LightningError> {
assert_eq!(msg.len(), 16+2); assert_eq!(msg.len(), 16+2);
match self.noise_state { match self.noise_state {
@ -426,7 +426,7 @@ impl PeerChannelEncryptor {
/// Decrypts the given message. /// Decrypts the given message.
/// panics if msg.len() > 65535 + 16 /// panics if msg.len() > 65535 + 16
pub fn decrypt_message(&mut self, msg: &[u8]) -> Result<Vec<u8>, HandleError> { pub fn decrypt_message(&mut self, msg: &[u8]) -> Result<Vec<u8>, LightningError> {
if msg.len() > 65535 + 16 { if msg.len() > 65535 + 16 {
panic!("Attempted to encrypt message longer than 65535 bytes!"); panic!("Attempted to encrypt message longer than 65535 bytes!");
} }

View file

@ -481,26 +481,21 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
match $thing { match $thing {
Ok(x) => x, Ok(x) => x,
Err(e) => { Err(e) => {
if let Some(action) = e.action { match e.action {
match action { msgs::ErrorAction::DisconnectPeer { msg: _ } => {
msgs::ErrorAction::DisconnectPeer { msg: _ } => { //TODO: Try to push msg
//TODO: Try to push msg log_trace!(self, "Got Err handling message, disconnecting peer because {}", e.err);
log_trace!(self, "Got Err handling message, disconnecting peer because {}", e.err); return Err(PeerHandleError{ no_connection_possible: false });
return Err(PeerHandleError{ no_connection_possible: false }); },
}, msgs::ErrorAction::IgnoreError => {
msgs::ErrorAction::IgnoreError => { log_trace!(self, "Got Err handling message, ignoring because {}", e.err);
log_trace!(self, "Got Err handling message, ignoring because {}", e.err); continue;
continue; },
}, msgs::ErrorAction::SendErrorMessage { msg } => {
msgs::ErrorAction::SendErrorMessage { msg } => { log_trace!(self, "Got Err handling message, sending Error message because {}", e.err);
log_trace!(self, "Got Err handling message, sending Error message because {}", e.err); encode_and_send_msg!(msg, 17);
encode_and_send_msg!(msg, 17); continue;
continue; },
},
}
} else {
log_debug!(self, "Got Err handling message, action not yet filled in: {}", e.err);
return Err(PeerHandleError{ no_connection_possible: false });
} }
} }
}; };
@ -1020,42 +1015,38 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
self.message_handler.route_handler.handle_htlc_fail_channel_update(update); self.message_handler.route_handler.handle_htlc_fail_channel_update(update);
}, },
MessageSendEvent::HandleError { ref node_id, ref action } => { MessageSendEvent::HandleError { ref node_id, ref action } => {
if let Some(ref action) = *action { match *action {
match *action { msgs::ErrorAction::DisconnectPeer { ref msg } => {
msgs::ErrorAction::DisconnectPeer { ref msg } => { if let Some(mut descriptor) = peers.node_id_to_descriptor.remove(node_id) {
if let Some(mut descriptor) = peers.node_id_to_descriptor.remove(node_id) { peers.peers_needing_send.remove(&descriptor);
peers.peers_needing_send.remove(&descriptor); if let Some(mut peer) = peers.peers.remove(&descriptor) {
if let Some(mut peer) = peers.peers.remove(&descriptor) { if let Some(ref msg) = *msg {
if let Some(ref msg) = *msg { log_trace!(self, "Handling DisconnectPeer HandleError event in peer_handler for node {} with message {}",
log_trace!(self, "Handling DisconnectPeer HandleError event in peer_handler for node {} with message {}", log_pubkey!(node_id),
log_pubkey!(node_id), msg.data);
msg.data); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 17)));
peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 17))); // This isn't guaranteed to work, but if there is enough free
// This isn't guaranteed to work, but if there is enough free // room in the send buffer, put the error message there...
// room in the send buffer, put the error message there... self.do_attempt_write_data(&mut descriptor, &mut peer);
self.do_attempt_write_data(&mut descriptor, &mut peer); } else {
} else { log_trace!(self, "Handling DisconnectPeer HandleError event in peer_handler for node {} with no message", log_pubkey!(node_id));
log_trace!(self, "Handling DisconnectPeer HandleError event in peer_handler for node {} with no message", log_pubkey!(node_id));
}
} }
descriptor.disconnect_socket();
self.message_handler.chan_handler.peer_disconnected(&node_id, false);
} }
}, descriptor.disconnect_socket();
msgs::ErrorAction::IgnoreError => {}, self.message_handler.chan_handler.peer_disconnected(&node_id, false);
msgs::ErrorAction::SendErrorMessage { ref msg } => { }
log_trace!(self, "Handling SendErrorMessage HandleError event in peer_handler for node {} with message {}", },
log_pubkey!(node_id), msgs::ErrorAction::IgnoreError => {},
msg.data); msgs::ErrorAction::SendErrorMessage { ref msg } => {
let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, { log_trace!(self, "Handling SendErrorMessage HandleError event in peer_handler for node {} with message {}",
//TODO: Do whatever we're gonna do for handling dropped messages log_pubkey!(node_id),
}); msg.data);
peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 17))); let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
self.do_attempt_write_data(&mut descriptor, peer); //TODO: Do whatever we're gonna do for handling dropped messages
}, });
} peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 17)));
} else { self.do_attempt_write_data(&mut descriptor, peer);
log_error!(self, "Got no-action HandleError Event in peer_handler for node {}, no such events should ever be generated!", log_pubkey!(node_id)); },
} }
} }
} }
@ -1172,7 +1163,7 @@ mod tests {
let chan_handler = test_utils::TestChannelMessageHandler::new(); let chan_handler = test_utils::TestChannelMessageHandler::new();
chan_handler.pending_events.lock().unwrap().push(events::MessageSendEvent::HandleError { chan_handler.pending_events.lock().unwrap().push(events::MessageSendEvent::HandleError {
node_id: their_id, node_id: their_id,
action: Some(msgs::ErrorAction::DisconnectPeer { msg: None }), action: msgs::ErrorAction::DisconnectPeer { msg: None },
}); });
assert_eq!(chan_handler.pending_events.lock().unwrap().len(), 1); assert_eq!(chan_handler.pending_events.lock().unwrap().len(), 1);
peers[0].message_handler.chan_handler = Arc::new(chan_handler); peers[0].message_handler.chan_handler = Arc::new(chan_handler);

View file

@ -14,7 +14,7 @@ use bitcoin::blockdata::opcodes;
use chain::chaininterface::{ChainError, ChainWatchInterface}; use chain::chaininterface::{ChainError, ChainWatchInterface};
use ln::channelmanager; use ln::channelmanager;
use ln::msgs::{DecodeError,ErrorAction,HandleError,RoutingMessageHandler,NetAddress,GlobalFeatures}; use ln::msgs::{DecodeError,ErrorAction,LightningError,RoutingMessageHandler,NetAddress,GlobalFeatures};
use ln::msgs; use ln::msgs;
use util::ser::{Writeable, Readable, Writer, ReadableArgs}; use util::ser::{Writeable, Readable, Writer, ReadableArgs};
use util::logger::Logger; use util::logger::Logger;
@ -404,13 +404,13 @@ macro_rules! secp_verify_sig {
( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr ) => { ( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr ) => {
match $secp_ctx.verify($msg, $sig, $pubkey) { match $secp_ctx.verify($msg, $sig, $pubkey) {
Ok(_) => {}, Ok(_) => {},
Err(_) => return Err(HandleError{err: "Invalid signature from remote node", action: None}), Err(_) => return Err(LightningError{err: "Invalid signature from remote node", action: ErrorAction::IgnoreError}),
} }
}; };
} }
impl RoutingMessageHandler for Router { impl RoutingMessageHandler for Router {
fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, HandleError> { fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> {
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]); let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id); secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id);
@ -420,10 +420,10 @@ impl RoutingMessageHandler for Router {
let mut network = self.network_map.write().unwrap(); let mut network = self.network_map.write().unwrap();
match network.nodes.get_mut(&msg.contents.node_id) { match network.nodes.get_mut(&msg.contents.node_id) {
None => Err(HandleError{err: "No existing channels for node_announcement", action: Some(ErrorAction::IgnoreError)}), None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
Some(node) => { Some(node) => {
if node.last_update >= msg.contents.timestamp { if node.last_update >= msg.contents.timestamp {
return Err(HandleError{err: "Update older than last processed update", action: Some(ErrorAction::IgnoreError)}); return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
} }
node.features = msg.contents.features.clone(); node.features = msg.contents.features.clone();
@ -439,9 +439,9 @@ impl RoutingMessageHandler for Router {
} }
} }
fn handle_channel_announcement(&self, msg: &msgs::ChannelAnnouncement) -> Result<bool, HandleError> { fn handle_channel_announcement(&self, msg: &msgs::ChannelAnnouncement) -> Result<bool, LightningError> {
if msg.contents.node_id_1 == msg.contents.node_id_2 || msg.contents.bitcoin_key_1 == msg.contents.bitcoin_key_2 { if msg.contents.node_id_1 == msg.contents.node_id_2 || msg.contents.bitcoin_key_1 == msg.contents.bitcoin_key_2 {
return Err(HandleError{err: "Channel announcement node had a channel with itself", action: Some(ErrorAction::IgnoreError)}); return Err(LightningError{err: "Channel announcement node had a channel with itself", action: ErrorAction::IgnoreError});
} }
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]); let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
@ -462,7 +462,7 @@ impl RoutingMessageHandler for Router {
.push_opcode(opcodes::all::OP_PUSHNUM_2) .push_opcode(opcodes::all::OP_PUSHNUM_2)
.push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script().to_v0_p2wsh(); .push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script().to_v0_p2wsh();
if script_pubkey != expected_script { if script_pubkey != expected_script {
return Err(HandleError{err: "Channel announcement keys didn't match on-chain script", action: Some(ErrorAction::IgnoreError)}); return Err(LightningError{err: "Channel announcement keys didn't match on-chain script", action: ErrorAction::IgnoreError});
} }
//TODO: Check if value is worth storing, use it to inform routing, and compare it //TODO: Check if value is worth storing, use it to inform routing, and compare it
//to the new HTLC max field in channel_update //to the new HTLC max field in channel_update
@ -473,10 +473,10 @@ impl RoutingMessageHandler for Router {
false false
}, },
Err(ChainError::NotWatched) => { Err(ChainError::NotWatched) => {
return Err(HandleError{err: "Channel announced on an unknown chain", action: Some(ErrorAction::IgnoreError)}); return Err(LightningError{err: "Channel announced on an unknown chain", action: ErrorAction::IgnoreError});
}, },
Err(ChainError::UnknownTx) => { Err(ChainError::UnknownTx) => {
return Err(HandleError{err: "Channel announced without corresponding UTXO entry", action: Some(ErrorAction::IgnoreError)}); return Err(LightningError{err: "Channel announced without corresponding UTXO entry", action: ErrorAction::IgnoreError});
}, },
}; };
@ -527,7 +527,7 @@ impl RoutingMessageHandler for Router {
Self::remove_channel_in_nodes(network.nodes, &entry.get(), msg.contents.short_channel_id); Self::remove_channel_in_nodes(network.nodes, &entry.get(), msg.contents.short_channel_id);
*entry.get_mut() = chan_info; *entry.get_mut() = chan_info;
} else { } else {
return Err(HandleError{err: "Already have knowledge of channel", action: Some(ErrorAction::IgnoreError)}) return Err(LightningError{err: "Already have knowledge of channel", action: ErrorAction::IgnoreError})
} }
}, },
BtreeEntry::Vacant(entry) => { BtreeEntry::Vacant(entry) => {
@ -592,19 +592,19 @@ impl RoutingMessageHandler for Router {
} }
} }
fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<bool, HandleError> { fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<bool, LightningError> {
let mut network = self.network_map.write().unwrap(); let mut network = self.network_map.write().unwrap();
let dest_node_id; let dest_node_id;
let chan_enabled = msg.contents.flags & (1 << 1) != (1 << 1); let chan_enabled = msg.contents.flags & (1 << 1) != (1 << 1);
let chan_was_enabled; let chan_was_enabled;
match network.channels.get_mut(&NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) { match network.channels.get_mut(&NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
None => return Err(HandleError{err: "Couldn't find channel for update", action: Some(ErrorAction::IgnoreError)}), None => return Err(LightningError{err: "Couldn't find channel for update", action: ErrorAction::IgnoreError}),
Some(channel) => { Some(channel) => {
macro_rules! maybe_update_channel_info { macro_rules! maybe_update_channel_info {
( $target: expr) => { ( $target: expr) => {
if $target.last_update >= msg.contents.timestamp { if $target.last_update >= msg.contents.timestamp {
return Err(HandleError{err: "Update older than last processed update", action: Some(ErrorAction::IgnoreError)}); return Err(LightningError{err: "Update older than last processed update", action: ErrorAction::IgnoreError});
} }
chan_was_enabled = $target.enabled; chan_was_enabled = $target.enabled;
$target.last_update = msg.contents.timestamp; $target.last_update = msg.contents.timestamp;
@ -824,17 +824,17 @@ impl Router {
/// The fees on channels from us to next-hops are ignored (as they are assumed to all be /// The fees on channels from us to next-hops are ignored (as they are assumed to all be
/// equal), however the enabled/disabled bit on such channels as well as the htlc_minimum_msat /// equal), however the enabled/disabled bit on such channels as well as the htlc_minimum_msat
/// *is* checked as they may change based on the receiving node. /// *is* checked as they may change based on the receiving node.
pub fn get_route(&self, target: &PublicKey, first_hops: Option<&[channelmanager::ChannelDetails]>, last_hops: &[RouteHint], final_value_msat: u64, final_cltv: u32) -> Result<Route, HandleError> { pub fn get_route(&self, target: &PublicKey, first_hops: Option<&[channelmanager::ChannelDetails]>, last_hops: &[RouteHint], final_value_msat: u64, final_cltv: u32) -> Result<Route, LightningError> {
// TODO: Obviously *only* using total fee cost sucks. We should consider weighting by // TODO: Obviously *only* using total fee cost sucks. We should consider weighting by
// uptime/success in using a node in the past. // uptime/success in using a node in the past.
let network = self.network_map.read().unwrap(); let network = self.network_map.read().unwrap();
if *target == network.our_node_id { if *target == network.our_node_id {
return Err(HandleError{err: "Cannot generate a route to ourselves", action: None}); return Err(LightningError{err: "Cannot generate a route to ourselves", action: ErrorAction::IgnoreError});
} }
if final_value_msat > 21_000_000 * 1_0000_0000 * 1000 { if final_value_msat > 21_000_000 * 1_0000_0000 * 1000 {
return Err(HandleError{err: "Cannot generate a route of more value than all existing satoshis", action: None}); return Err(LightningError{err: "Cannot generate a route of more value than all existing satoshis", action: ErrorAction::IgnoreError});
} }
// We do a dest-to-source Dijkstra's sorting by each node's distance from the destination // We do a dest-to-source Dijkstra's sorting by each node's distance from the destination
@ -871,7 +871,7 @@ impl Router {
first_hop_targets.insert(chan.remote_network_id, short_channel_id); first_hop_targets.insert(chan.remote_network_id, short_channel_id);
} }
if first_hop_targets.is_empty() { if first_hop_targets.is_empty() {
return Err(HandleError{err: "Cannot route when there are no outbound routes away from us", action: None}); return Err(LightningError{err: "Cannot route when there are no outbound routes away from us", action: ErrorAction::IgnoreError});
} }
} }
@ -985,7 +985,7 @@ impl Router {
while res.last().unwrap().pubkey != *target { while res.last().unwrap().pubkey != *target {
let new_entry = match dist.remove(&res.last().unwrap().pubkey) { let new_entry = match dist.remove(&res.last().unwrap().pubkey) {
Some(hop) => hop.3, Some(hop) => hop.3,
None => return Err(HandleError{err: "Failed to find a non-fee-overflowing path to the given destination", action: None}), None => return Err(LightningError{err: "Failed to find a non-fee-overflowing path to the given destination", action: ErrorAction::IgnoreError}),
}; };
res.last_mut().unwrap().fee_msat = new_entry.fee_msat; res.last_mut().unwrap().fee_msat = new_entry.fee_msat;
res.last_mut().unwrap().cltv_expiry_delta = new_entry.cltv_expiry_delta; res.last_mut().unwrap().cltv_expiry_delta = new_entry.cltv_expiry_delta;
@ -1006,7 +1006,7 @@ impl Router {
} }
} }
Err(HandleError{err: "Failed to find a path to the given destination", action: None}) Err(LightningError{err: "Failed to find a path to the given destination", action: ErrorAction::IgnoreError})
} }
} }

View file

@ -210,7 +210,7 @@ pub enum MessageSendEvent {
/// The node_id of the node which should receive this message /// The node_id of the node which should receive this message
node_id: PublicKey, node_id: PublicKey,
/// The action which should be taken. /// The action which should be taken.
action: Option<msgs::ErrorAction> action: msgs::ErrorAction
}, },
/// When a payment fails we may receive updates back from the hop where it failed. In such /// When a payment fails we may receive updates back from the hop where it failed. In such
/// cases this event is generated so that we can inform the router of this information. /// cases this event is generated so that we can inform the router of this information.

View file

@ -5,7 +5,7 @@ use chain::keysinterface;
use ln::channelmonitor; use ln::channelmonitor;
use ln::msgs; use ln::msgs;
use ln::msgs::LocalFeatures; use ln::msgs::LocalFeatures;
use ln::msgs::{HandleError}; use ln::msgs::{LightningError};
use ln::channelmonitor::HTLCUpdate; use ln::channelmonitor::HTLCUpdate;
use util::events; use util::events;
use util::logger::{Logger, Level, Record}; use util::logger::{Logger, Level, Record};
@ -98,53 +98,53 @@ impl TestChannelMessageHandler {
} }
impl msgs::ChannelMessageHandler for TestChannelMessageHandler { impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
fn handle_open_channel(&self, _their_node_id: &PublicKey, _their_local_features: LocalFeatures, _msg: &msgs::OpenChannel) -> Result<(), HandleError> { fn handle_open_channel(&self, _their_node_id: &PublicKey, _their_local_features: LocalFeatures, _msg: &msgs::OpenChannel) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_accept_channel(&self, _their_node_id: &PublicKey, _their_local_features: LocalFeatures, _msg: &msgs::AcceptChannel) -> Result<(), HandleError> { fn handle_accept_channel(&self, _their_node_id: &PublicKey, _their_local_features: LocalFeatures, _msg: &msgs::AcceptChannel) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_funding_created(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingCreated) -> Result<(), HandleError> { fn handle_funding_created(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingCreated) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_funding_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingSigned) -> Result<(), HandleError> { fn handle_funding_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingSigned) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_funding_locked(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingLocked) -> Result<(), HandleError> { fn handle_funding_locked(&self, _their_node_id: &PublicKey, _msg: &msgs::FundingLocked) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_shutdown(&self, _their_node_id: &PublicKey, _msg: &msgs::Shutdown) -> Result<(), HandleError> { fn handle_shutdown(&self, _their_node_id: &PublicKey, _msg: &msgs::Shutdown) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_closing_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::ClosingSigned) -> Result<(), HandleError> { fn handle_closing_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::ClosingSigned) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_update_add_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateAddHTLC) -> Result<(), HandleError> { fn handle_update_add_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateAddHTLC) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_update_fulfill_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFulfillHTLC) -> Result<(), HandleError> { fn handle_update_fulfill_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFulfillHTLC) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_update_fail_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFailHTLC) -> Result<(), HandleError> { fn handle_update_fail_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFailHTLC) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_update_fail_malformed_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), HandleError> { fn handle_update_fail_malformed_htlc(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_commitment_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::CommitmentSigned) -> Result<(), HandleError> { fn handle_commitment_signed(&self, _their_node_id: &PublicKey, _msg: &msgs::CommitmentSigned) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_revoke_and_ack(&self, _their_node_id: &PublicKey, _msg: &msgs::RevokeAndACK) -> Result<(), HandleError> { fn handle_revoke_and_ack(&self, _their_node_id: &PublicKey, _msg: &msgs::RevokeAndACK) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFee) -> Result<(), HandleError> { fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &msgs::UpdateFee) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &msgs::AnnouncementSignatures) -> Result<(), HandleError> { fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &msgs::AnnouncementSignatures) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_channel_reestablish(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelReestablish) -> Result<(), HandleError> { fn handle_channel_reestablish(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelReestablish) -> Result<(), LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {} fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {}
fn peer_connected(&self, _their_node_id: &PublicKey) {} fn peer_connected(&self, _their_node_id: &PublicKey) {}
@ -168,14 +168,14 @@ impl TestRoutingMessageHandler {
} }
} }
impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result<bool, HandleError> { fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result<bool, HandleError> { fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result<bool, LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<bool, HandleError> { fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<bool, LightningError> {
Err(HandleError { err: "", action: None }) Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
} }
fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {} fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}
fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, msgs::ChannelUpdate,msgs::ChannelUpdate)> { fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, msgs::ChannelUpdate,msgs::ChannelUpdate)> {