diff --git a/src/rpc/README.md b/src/rpc/README.md index d62baebe9..b664cc837 100644 --- a/src/rpc/README.md +++ b/src/rpc/README.md @@ -44,6 +44,7 @@ You may refer to the e2e test cases in the `tests/bruno/e2e` directory for examp * [Type `Channel`](#type-channel) * [Type `ChannelInfo`](#type-channelinfo) + * [Type `ChannelState`](#type-channelstate) * [Type `NodeInfo`](#type-nodeinfo) * [Type `RemoveTlcReason`](#type-removetlcreason) * [Type `UdtArgInfo`](#type-udtarginfo) @@ -519,6 +520,27 @@ Disconnect from a peer. ## RPC Types + +### Type `ChannelState` + +The state of a channel + + +#### Enum with values of + +* `NegotiatingFunding` - NegotiatingFundingFlags, We are negotiating the parameters required for the channel prior to funding it. +* `CollaboratingFundingTx` - CollaboratingFundingTxFlags, We're collaborating with the other party on the funding transaction. +* `SigningCommitment` - SigningCommitmentFlags, We have collaborated over the funding and are now waiting for CommitmentSigned messages. +* `AwaitingTxSignatures` - AwaitingTxSignaturesFlags, We've received and sent `commitment_signed` and are now waiting for both + party to collaborate on creating a valid funding transaction. +* `AwaitingChannelReady` - AwaitingChannelReadyFlags, We've received/sent `funding_created` and `funding_signed` and are thus now waiting on the + funding transaction to confirm. +* `ChannelReady` - , Both we and our counterparty consider the funding transaction confirmed and the channel is + now operational. +* `ShuttingDown` - ShuttingDownFlags, We've successfully negotiated a `closing_signed` dance. At this point, the `ChannelManager` + is about to drop us, but we store this anyway. +* `Closed` - CloseFlags, This channel is closed. + ### Type `Channel` diff --git a/src/rpc/channel.rs b/src/rpc/channel.rs index dec68fa51..229fa288e 100644 --- a/src/rpc/channel.rs +++ b/src/rpc/channel.rs @@ -1,7 +1,10 @@ use crate::fiber::{ channel::{ - AddTlcCommand, ChannelActorStateStore, ChannelCommand, ChannelCommandWithId, ChannelState, - RemoveTlcCommand, ShutdownCommand, UpdateCommand, + AddTlcCommand, AwaitingChannelReadyFlags, AwaitingTxSignaturesFlags, + ChannelActorStateStore, ChannelCommand, ChannelCommandWithId, + ChannelState as RawChannelState, CloseFlags, CollaboratingFundingTxFlags, + NegotiatingFundingFlags, RemoveTlcCommand, ShutdownCommand, ShuttingDownFlags, + SigningCommitmentFlags, UpdateCommand, }, graph::PaymentSessionStatus, hash_algorithm::HashAlgorithm, @@ -129,6 +132,59 @@ pub(crate) struct ListChannelsResult { channels: Vec, } +/// The state of a channel +// `ChannelState` is a copy of `ChannelState` with `#[serde(...)]` attributes for compatibility +// `bincode` does not support deserialize_identifier +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde( + rename_all = "SCREAMING_SNAKE_CASE", + tag = "state_name", + content = "state_flags" +)] +pub enum ChannelState { + /// We are negotiating the parameters required for the channel prior to funding it. + NegotiatingFunding(NegotiatingFundingFlags), + /// We're collaborating with the other party on the funding transaction. + CollaboratingFundingTx(CollaboratingFundingTxFlags), + /// We have collaborated over the funding and are now waiting for CommitmentSigned messages. + SigningCommitment(SigningCommitmentFlags), + /// We've received and sent `commitment_signed` and are now waiting for both + /// party to collaborate on creating a valid funding transaction. + AwaitingTxSignatures(AwaitingTxSignaturesFlags), + /// We've received/sent `funding_created` and `funding_signed` and are thus now waiting on the + /// funding transaction to confirm. + AwaitingChannelReady(AwaitingChannelReadyFlags), + /// Both we and our counterparty consider the funding transaction confirmed and the channel is + /// now operational. + ChannelReady(), + /// We've successfully negotiated a `closing_signed` dance. At this point, the `ChannelManager` + /// is about to drop us, but we store this anyway. + ShuttingDown(ShuttingDownFlags), + /// This channel is closed. + Closed(CloseFlags), +} + +impl From for ChannelState { + fn from(state: RawChannelState) -> Self { + match state { + RawChannelState::NegotiatingFunding(flags) => ChannelState::NegotiatingFunding(flags), + RawChannelState::CollaboratingFundingTx(flags) => { + ChannelState::CollaboratingFundingTx(flags) + } + RawChannelState::SigningCommitment(flags) => ChannelState::SigningCommitment(flags), + RawChannelState::AwaitingTxSignatures(flags) => { + ChannelState::AwaitingTxSignatures(flags) + } + RawChannelState::AwaitingChannelReady(flags) => { + ChannelState::AwaitingChannelReady(flags) + } + RawChannelState::ChannelReady() => ChannelState::ChannelReady(), + RawChannelState::ShuttingDown(flags) => ChannelState::ShuttingDown(flags), + RawChannelState::Closed(flags) => ChannelState::Closed(flags), + } + } +} + /// The channel data structure #[serde_as] #[derive(Clone, Serialize)] @@ -480,7 +536,7 @@ where .funding_udt_type_script .clone() .map(Into::into), - state: state.state, + state: state.state.into(), local_balance: state.get_local_balance(), remote_balance: state.get_remote_balance(), offered_tlc_balance: state.get_offered_tlc_balance(), diff --git a/tests/bruno/e2e/3-nodes-transfer/20-node3-list-channels.bru b/tests/bruno/e2e/3-nodes-transfer/20-node3-list-channels.bru index 7b62ce0be..7896b0729 100644 --- a/tests/bruno/e2e/3-nodes-transfer/20-node3-list-channels.bru +++ b/tests/bruno/e2e/3-nodes-transfer/20-node3-list-channels.bru @@ -46,4 +46,7 @@ script:post-response { if (res.body.result.channels[0].local_balance != "0xe7b68ae00" || res.body.result.channels[0].remote_balance != "0x376abe5fa400") { throw new Error("Assertion failed: channel amount is not right"); } + if (res.body.result.channels[0].state.state_name != "CHANNEL_READY") { + throw new Error("Assertion failed: channel status is not right"); + } }