You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a new table in 'peer_state' to maintain unaccepted inbound
channels; i.e., a channel for which we've received an 'open_channel'
message but that user code has not yet confirmed for acceptance. When
user code accepts the channel (e.g. via 'accept_inbound_channel'),
create the channel object and as before.
Currently, the 'open_channel' message eagerly creates an
InboundV1Channel object before determining if the channel should be
accepted. Because this happens /before/ the channel has been assigned
a user identity (which happens in the handler for OpenChannelRequest),
the channel is assigned a random user identity. As part of the
creation process, the channel's cryptographic material is initialized,
which then uses this randomly generated value for the user's channel
identity e.g. in SignerProvider::generate_channel_keys_id.
By delaying the creation of the InboundV1Channel until /after/ the
channel has been accepted, we ensure that we defer cryptographic
initialization until we have given the user the opportunity to assign
an identity to the channel.
return Err(APIError::ChannelUnavailable{ err: format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!(*channel_id), peer_node_id) });
2564
2581
}
@@ -5187,49 +5204,54 @@ where
5187
5204
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
5188
5205
let peer_state = &mut *peer_state_lock;
5189
5206
let is_only_peer_channel = peer_state.total_channel_count() == 1;
5190
-
match peer_state.inbound_v1_channel_by_id.entry(temporary_channel_id.clone()){
5191
-
hash_map::Entry::Occupied(mut channel) => {
5192
-
if !channel.get().is_awaiting_accept(){
5193
-
returnErr(APIError::APIMisuseError{err:"The channel isn't currently awaiting to be accepted.".to_owned()});
5207
+
5208
+
// Find (and remove) the channel in the unaccepted table. If it's
5209
+
// not there, something weird is happening and return an error.
5210
+
let mut channel = match peer_state.inbound_channel_request_by_id.remove(temporary_channel_id) {
5211
+
Some(unaccepted_channel) => {
5212
+
let best_block_height = self.best_block.read().unwrap().height();
returnErr(APIError::APIMisuseError{err:"Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned()});
5207
-
}else{
5208
-
// If this peer already has some channels, a new channel won't increase our number of peers
5209
-
// with unfunded channels, so as long as we aren't over the maximum number of unfunded
5210
-
// channels per-peer we can accept channels from a peer with existing ones.
5211
-
if is_only_peer_channel && peers_without_funded_channels >= MAX_UNFUNDED_CHANNEL_PEERS{
5212
-
let send_msg_err_event = events::MessageSendEvent::HandleError{
msg: msgs::ErrorMessage{channel_id: temporary_channel_id.clone(),data:"Have too many peers with unfunded channels, not accepting new ones".to_owned(),}
return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
5232
+
} else {
5233
+
// If this peer already has some channels, a new channel won't increase our number of peers
5234
+
// with unfunded channels, so as long as we aren't over the maximum number of unfunded
5235
+
// channels per-peer we can accept channels from a peer with existing ones.
5236
+
if is_only_peer_channel && peers_without_funded_channels >= MAX_UNFUNDED_CHANNEL_PEERS {
5237
+
let send_msg_err_event = events::MessageSendEvent::HandleError {
msg: msgs::ErrorMessage { channel_id: temporary_channel_id.clone(), data: "Have too many peers with unfunded channels, not accepting new ones".to_owned(), }
returnErr(APIError::ChannelUnavailable{err:format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!(*temporary_channel_id), counterparty_node_id)});
return Err(MsgHandleErrInternal::send_err_msg_no_close("temporary_channel_id collision for the same peer!".to_owned(), msg.temporary_channel_id.clone()));
5355
+
}
5356
+
5357
+
// If we're doing manual acceptance checks on the channel, then defer creation until we're sure we want to accept.
5358
+
if self.default_configuration.manually_accept_inbound_channels {
5359
+
let mut pending_events = self.pending_events.lock().unwrap();
returnErr(MsgHandleErrInternal::send_err_msg_no_close("temporary_channel_id collision for the same peer!".to_owned(), msg.temporary_channel_id.clone()))
5343
-
}else{
5344
-
if !self.default_configuration.manually_accept_inbound_channels{
5345
-
let channel_type = channel.context.get_channel_type();
5346
-
if channel_type.requires_zero_conf(){
5347
-
returnErr(MsgHandleErrInternal::send_err_msg_no_close("No zero confirmation channels accepted".to_owned(), msg.temporary_channel_id.clone()));
5348
-
}
5349
-
if channel_type.requires_anchors_zero_fee_htlc_tx(){
5350
-
returnErr(MsgHandleErrInternal::send_err_msg_no_close("No channels with anchor outputs accepted".to_owned(), msg.temporary_channel_id.clone()));
let api_res = nodes[0].node.accept_inbound_channel(&unknown_channel_id, &nodes[1].node.get_our_node_id(), 0);
7994
7997
match api_res {
7995
-
Err(APIError::ChannelUnavailable { err }) => {
7996
-
assert_eq!(err, format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!(unknown_channel_id), nodes[1].node.get_our_node_id()));
7998
+
Err(APIError::APIMisuseError { err }) => {
7999
+
assert_eq!(err, "No such channel awaiting to be accepted.");
7997
8000
},
7998
8001
Ok(_) => panic!("It shouldn't be possible to accept an unkown channel"),
0 commit comments