Skip to content

Commit

Permalink
Problem: Missing CloseChannel command (fixes #71) (#74)
Browse files Browse the repository at this point in the history
Solution: 

add close-channel command, the ibc-go does not allowed the user to close the channel by default because of this, we need to add a path for it and recompile the chain-maind if we want to use this feature.

@@ -304,8 +304,9 @@ func (am AppModule) OnChanCloseInit(
        portID,
        channelID string,
 ) error {
-       // Disallow user-initiated channel closing for transfer channels
-       return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel")
+       // Allow user-initiated channel closing for transfer channels
+       // return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel")
+        return nil
 }
  • Loading branch information
linfeng-crypto authored Oct 29, 2021
1 parent 49d9d87 commit f1274d0
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 122 deletions.
7 changes: 7 additions & 0 deletions solo-machine-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ pub enum Event {
/// Channel ID of solo machine client on IBC enabled chain
channel_id: ChannelId,
},
/// Close channel on IBC enabled chain
CloseChannelInitOnSoloMachine {
/// Chain ID of IBC enabled chain
chain_id: String,
/// Channel ID of IBC enabled chain on solo machine
channel_id: ChannelId,
},
/// Initialized channel on solo machine
InitializedChannelOnSoloMachine {
/// Channel ID of IBC enabled chain on solo machine
Expand Down
1 change: 1 addition & 0 deletions solo-machine-core/src/ibc/core/ics04_channel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod msg_acknowledgement;
pub mod msg_channel_close_init;
pub mod msg_channel_open_ack;
pub mod msg_channel_open_init;
pub mod msg_recv_packet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use cosmos_sdk_proto::ibc::core::channel::v1::MsgChannelCloseInit;

const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseInit";

impl_any_conversion!(MsgChannelCloseInit, TYPE_URL);
25 changes: 16 additions & 9 deletions solo-machine-core/src/model/chain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,27 @@ pub struct Chain {
impl Chain {
/// Returns the IBC denom of given denomination based on connection details. Returns `None` if connection details
/// are not present.
pub fn get_ibc_denom(&self, denom: &Identifier) -> Option<String> {
let connection_details = self.connection_details.as_ref()?;
pub fn get_ibc_denom(&self, denom: &Identifier) -> Result<String> {
let connection_details = self.connection_details.as_ref();
ensure!(
connection_details.is_some(),
"connection is not established with given chain"
);
let connection_details = connection_details.unwrap();
ensure!(
connection_details.solo_machine_channel_id.is_some(),
"can't find solo machine channel, channel is already closed"
);

let denom_trace = DenomTrace::new(
&self.config.port_id,
&connection_details.solo_machine_channel_id,
connection_details.solo_machine_channel_id.as_ref().unwrap(),
denom,
);

let hash = Sha256::digest(denom_trace.to_string().as_bytes());

Some(format!("ibc/{}", hex::encode_upper(hash)))
Ok(format!("ibc/{}", hex::encode_upper(hash)))
}

/// Fetches on-chain balance of given denom
Expand All @@ -76,9 +85,7 @@ impl Chain {
self.config.grpc_addr
))?;

let denom = self
.get_ibc_denom(denom)
.ok_or_else(|| anyhow!("connection details not found when fetching balance"))?;
let denom = self.get_ibc_denom(denom)?;

let request = QueryBalanceRequest {
address: signer.to_account_address()?,
Expand Down Expand Up @@ -170,9 +177,9 @@ pub struct ConnectionDetails {
/// Connection ID of IBC enabled chain on solo machine
pub tendermint_connection_id: ConnectionId,
/// Channel ID of solo machine client on IBC enabled chain
pub solo_machine_channel_id: ChannelId,
pub solo_machine_channel_id: Option<ChannelId>,
/// Channel ID of IBC enabled chain on solo machine
pub tendermint_channel_id: ChannelId,
pub tendermint_channel_id: Option<ChannelId>,
}

impl From<Chain> for RawChain {
Expand Down
4 changes: 1 addition & 3 deletions solo-machine-core/src/service/chain_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ impl ChainService {
.get(chain_id)
.await?
.ok_or_else(|| anyhow!("chain details not found when computing ibc denom"))?;
chain
.get_ibc_denom(denom)
.ok_or_else(|| anyhow!("connection details not found when computing ibc denom"))
chain.get_ibc_denom(denom)
}

/// Fetches details of a chain
Expand Down
Loading

0 comments on commit f1274d0

Please sign in to comment.