From 6e18ed633a7590b67dbec3949120a74881af06dd Mon Sep 17 00:00:00 2001 From: YI Date: Tue, 9 Jul 2024 00:16:09 +0800 Subject: [PATCH] Don't return error on repeated channel shutdown --- src/ckb/channel.rs | 11 ++++++++--- .../22-node2-send-shutdown-channel-1.bru | 8 ++------ .../24-node3-send-shutdown-channel-2.bru | 15 +++------------ .../udt/12-node2-send-shutdown-channel-error.bru | 15 +++------------ 4 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/ckb/channel.rs b/src/ckb/channel.rs index 1615a037a..47cdbb891 100644 --- a/src/ckb/channel.rs +++ b/src/ckb/channel.rs @@ -645,6 +645,10 @@ impl ChannelActor { ) -> ProcessingChannelResult { debug!("Handling shutdown command: {:?}", &command); let flags = match state.state { + ChannelState::Closed => { + debug!("Channel already closed, ignoring shutdown command"); + return Ok(()); + } ChannelState::ChannelReady() => { debug!("Handling shutdown command in ChannelReady state"); ShuttingDownFlags::empty() @@ -652,9 +656,10 @@ impl ChannelActor { ChannelState::ShuttingDown(flags) => flags, _ => { debug!("Handling shutdown command in state {:?}", &state.state); - return Err(ProcessingChannelError::InvalidState( - "Trying to send shutdown message while in invalid state".to_string(), - )); + return Err(ProcessingChannelError::InvalidState(format!( + "Trying to send shutdown message while in invalid state {:?}", + &state.state + ))); } }; diff --git a/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru b/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru index 022658c31..976927e75 100644 --- a/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru +++ b/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru @@ -35,15 +35,11 @@ body:json { } assert { - res.body.error: isDefined - res.body.result: isUndefined + res.body.error: isUndefined + res.body.result: isNull } script:post-response { // Sleep for sometime to make sure current operation finishes before next request starts. - // will get error message since channel is closed in previous step await new Promise(r => setTimeout(r, 100)); - if (!(res.body.error.message === "Messaging failed because channel is closed")) { - throw new Error("Assertion failed: error message is not right"); - } } diff --git a/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru b/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru index f0d3d0bd7..4431e746d 100644 --- a/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru +++ b/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru @@ -35,15 +35,6 @@ body:json { } assert { - res.body.error: isDefined - res.body.result: isUndefined -} - -script:post-response { - // Sleep for sometime to make sure current operation finishes before next request starts. - // will get error message since channel is closed in previous step - await new Promise(r => setTimeout(r, 100)); - if (!(res.body.error.message === "Messaging failed because channel is closed")) { - throw new Error("Assertion failed: error message is not right"); - } -} + res.body.error: isUndefined + res.body.result: isNull +} \ No newline at end of file diff --git a/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru b/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru index 9470f5b20..729b7c5f6 100644 --- a/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru +++ b/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru @@ -35,15 +35,6 @@ body:json { } assert { - res.body.error: isDefined - res.body.result: isUndefined -} - -script:post-response { - // Sleep for sometime to make sure current operation finishes before next request starts. - // will get error message since channel is closed in previous step - await new Promise(r => setTimeout(r, 100)); - if (!(res.body.error.message === "Messaging failed because channel is closed")) { - throw new Error("Assertion failed: error message is not right"); - } -} + res.body.error: isUndefined + res.body.result: isNull +} \ No newline at end of file