Self {
err: LightningError {
err,
- action: Some(msgs::ErrorAction::SendErrorMessage {
+ action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage {
channel_id,
data: err.to_string()
},
- }),
+ },
},
shutdown_finish: None,
}
Self {
err: LightningError {
err,
- action: Some(msgs::ErrorAction::IgnoreError),
+ action: msgs::ErrorAction::IgnoreError,
},
shutdown_finish: None,
}
Self {
err: LightningError {
err,
- action: Some(msgs::ErrorAction::SendErrorMessage {
+ action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage {
channel_id,
data: err.to_string()
},
- }),
+ },
},
shutdown_finish: Some((shutdown_res, channel_update)),
}
err: match err {
ChannelError::Ignore(msg) => LightningError {
err: msg,
- action: Some(msgs::ErrorAction::IgnoreError),
+ action: msgs::ErrorAction::IgnoreError,
},
ChannelError::Close(msg) => LightningError {
err: msg,
- action: Some(msgs::ErrorAction::SendErrorMessage {
+ action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage {
channel_id,
data: msg.to_string()
},
- }),
+ },
},
ChannelError::CloseDelayBroadcast { msg, .. } => LightningError {
err: msg,
- action: Some(msgs::ErrorAction::SendErrorMessage {
+ action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage {
channel_id,
data: msg.to_string()
},
- }),
+ },
},
},
shutdown_finish: None,
/// Non-proportional fees are fixed according to our risk using the provided fee estimator.
///
/// 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 res = Arc::new(ChannelManager {
chain_monitor,
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()),
secp_ctx,
/// May be called with channel_state already locked!
fn get_channel_update(&self, chan: &Channel) -> Result<msgs::ChannelUpdate, LightningError> {
let short_channel_id = match chan.get_short_channel_id() {
- None => return Err(LightningError{err: "Channel not yet established", action: None}),
+ None => return Err(LightningError{err: "Channel not yet established", action: msgs::ErrorAction::IgnoreError}),
Some(id) => id,
};
match handle_error!(self, err) {
Ok(_) => unreachable!(),
Err(e) => {
- if let Some(msgs::ErrorAction::IgnoreError) = e.action {
+ if let msgs::ErrorAction::IgnoreError = e.action {
} else {
log_error!(self, "Got bad keys: {}!", e.err);
let mut channel_state = self.channel_state.lock().unwrap();
let (commitment_msg, monitor) = match chan.get_mut().send_commitment() {
Ok(res) => res,
Err(e) => {
- if let ChannelError::Ignore(_) = e {
- panic!("Stated return value requirements in send_commitment() were not met");
+ // We surely failed send_commitment due to bad keys, in that case
+ // 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) => {
+ if let Some(msgs::ErrorAction::IgnoreError) = e.action {
+ } else {
+ 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) {
handle_errors.push((chan.get().get_their_node_id(), handle_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true)));
match handle_error!(self, err) {
Ok(_) => {},
Err(e) => {
- if let Some(msgs::ErrorAction::IgnoreError) = e.action {
+ if let msgs::ErrorAction::IgnoreError = e.action {
} else {
let mut channel_state = self.channel_state.lock().unwrap();
channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
match handle_error!(self, err) {
Ok(_) => {},
Err(e) => {
- if let Some(msgs::ErrorAction::IgnoreError) = e.action {
+ if let msgs::ErrorAction::IgnoreError = e.action {
} else {
let mut channel_state = self.channel_state.lock().unwrap();
channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
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() {
- return Err(MsgHandleErrInternal::from_no_close(LightningError{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();
match handle_error!(self, err) {
Ok(_) => unreachable!(),
Err(e) => {
- if let Some(msgs::ErrorAction::IgnoreError) = e.action {
+ if let msgs::ErrorAction::IgnoreError = e.action {
} else {
log_error!(self, "Got bad keys: {}!", e.err);
let mut channel_state = self.channel_state.lock().unwrap();
} else if let Err(e) = chan_res {
pending_msg_events.push(events::MessageSendEvent::HandleError {
node_id: channel.get_their_node_id(),
- action: Some(msgs::ErrorAction::SendErrorMessage { msg: e }),
+ action: msgs::ErrorAction::SendErrorMessage { msg: e },
});
return false;
}