Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# direnv related temp files/directories
.direnv
/result*
.DS_Store

/tests/nodes/*/fiber/store
/tests/nodes/*/config.yml
Expand Down
10 changes: 10 additions & 0 deletions crates/fiber-lib/src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ impl Display for ChannelCommand {
}
}

impl ChannelCommand {
pub fn rpc_reply_port(self) -> Option<RpcReplyPort<Result<(), String>>> {
match self {
ChannelCommand::Shutdown(_, port) => Some(port),
ChannelCommand::Update(_, port) => Some(port),
_ => None,
}
}
}

#[cfg(any(test, feature = "bench"))]
#[derive(Debug)]
pub struct ReloadParams {
Expand Down
8 changes: 7 additions & 1 deletion crates/fiber-lib/src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3801,7 +3801,13 @@ where
actor.send_message(ChannelActorMessage::Command(command))?;
Ok(())
}
None => Err(Error::ChannelNotFound(channel_id)),
None => {
let error = Error::ChannelNotFound(channel_id);
if let Some(rpc_reply) = command.rpc_reply_port() {
let _ = rpc_reply.send(Err(error.to_string()));
}
Err(error)
}
},
}
}
Expand Down
49 changes: 49 additions & 0 deletions crates/fiber-lib/src/fiber/tests/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::needless_range_loop)]
use crate::fiber::channel::CloseFlags;
use crate::fiber::{NetworkActorCommand, NetworkActorMessage};
use crate::gen_rand_sha256_hash;
use crate::invoice::CkbInvoice;
use crate::rpc::channel::{ChannelState, ShutdownChannelParams};
Expand Down Expand Up @@ -719,3 +720,51 @@ async fn test_rpc_auth_with_fixed_token() {
let rpc_res: ListPeersResult = node_0.send_rpc_request("list_peers", ()).await.unwrap();
assert_eq!(rpc_res.peers.len(), 0);
}

#[tokio::test]
async fn test_rpc_shutdown_following_disconnect() {
init_tracing();
let _span = tracing::info_span!("node", node = "test").entered();
let (nodes, channels) = create_n_nodes_network_with_params(
&[(
(0, 1),
ChannelParameters {
public: true,
node_a_funding_amount: HUGE_CKB_AMOUNT,
node_b_funding_amount: HUGE_CKB_AMOUNT,
..Default::default()
},
)],
2,
Some(gen_rpc_config()),
)
.await;
let [node_0, node_1] = nodes.try_into().expect("2 nodes");

node_0
.network_actor
.send_message(NetworkActorMessage::new_command(
NetworkActorCommand::DisconnectPeer(node_1.peer_id),
))
.expect("node_a alive");

loop {
let res: Result<(), String> = node_0
.send_rpc_request(
"shutdown_channel",
ShutdownChannelParams {
close_script: Some(Script::default().into()),
channel_id: channels[0],
fee_rate: Some(1000),
force: Some(false),
},
)
.await;

tokio::time::sleep(tokio::time::Duration::from_millis(300)).await;
if let Err(err) = &res {
assert!(err.contains("Channel not found error"));
break;
}
}
}
Loading