-
Notifications
You must be signed in to change notification settings - Fork 634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: ica tx atomicity docs and code snippet updates #719
Changes from all commits
11d2729
9ec49f8
7652585
8aaf1c4
52e8c68
7fe8570
c15e66c
e330389
7c1ae19
dd537db
15fd539
0700e80
54eb032
94ba9bd
032a04c
6ea3b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<!-- | ||
order: 3 | ||
order: 2 | ||
--> | ||
|
||
# Building an ICA authentication module | ||
# Building an authentication module | ||
|
||
The controller module is used for account registration and packet sending. | ||
Authentication modules play the role of the `Base Application` as described in [ICS30 IBC Middleware](https://github.com/cosmos/ibc/tree/master/spec/app/ics-030-middleware), and enable application developers to perform custom logic when working with the Interchain Accounts controller API. {synopsis} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking that maybe we should give a concrete example of what an authentication module would do. Probably governance is the easiest to understand. wdyt? I feel like our explanations of I can try and think of something to write. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, something with governance would be great. I think that could be added in a separate PR |
||
|
||
The controller submodule is used for account registration and packet sending. | ||
It executes only logic required of all controllers of interchain accounts. | ||
The type of authentication used to manage the interchain accounts remains unspecified. | ||
There may exist many different types of authentication which are desirable for different use cases. | ||
|
@@ -108,9 +110,8 @@ func (im IBCModule) OnChanOpenTry( | |
channelID string, | ||
chanCap *capabilitytypes.Capability, | ||
counterparty channeltypes.Counterparty, | ||
version, | ||
counterpartyVersion string, | ||
) error { | ||
) (string, error) { | ||
panic("UNIMPLEMENTED") | ||
} | ||
|
||
|
@@ -142,26 +143,14 @@ func (im IBCModule) OnRecvPacket( | |
) ibcexported.Acknowledgement { | ||
panic("UNIMPLEMENTED") | ||
} | ||
|
||
// NegotiateAppVersion implements the IBCModule interface | ||
func (im IBCModule) NegotiateAppVersion( | ||
ctx sdk.Context, | ||
order channeltypes.Order, | ||
connectionID string, | ||
portID string, | ||
counterparty channeltypes.Counterparty, | ||
proposedVersion string, | ||
) (string, error) { | ||
panic("UNIMPLEMENTED") | ||
} | ||
``` | ||
|
||
## `InitInterchainAccount` | ||
|
||
The authentication module can begin registering interchain accounts by calling `InitInterchainAccount`: | ||
|
||
```go | ||
if err := keeper.icaControllerKeeper.InitInterchainAccount(ctx, connectionID, counterpartyConnectionID, owner.String()); err != nil { | ||
if err := keeper.icaControllerKeeper.InitInterchainAccount(ctx, connectionID, owner.String()); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -176,19 +165,18 @@ The authentication module can attempt to send a packet by calling `TrySendTx`: | |
// Authenticate owner | ||
// perform custom logic | ||
|
||
// Lookup portID based on interchain account owner address | ||
portID, err := icatypes.GeneratePortID(owner.String(), connectionID, counterpartyConnectionID) | ||
// Construct controller portID based on interchain account owner address | ||
portID, err := icatypes.NewControllerPortID(owner.String()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
channelID, found := keeper.icaControllerKeeper.GetActiveChannelID(ctx, portID) | ||
if !found { | ||
return sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portId) | ||
return sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) | ||
} | ||
|
||
// Obtain the channel capability. | ||
// The channel capability should have been claimed by the authentication module in OnChanOpenInit | ||
// Obtain the channel capability, claimed in OnChanOpenInit | ||
chanCap, found := keeper.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) | ||
if !found { | ||
return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") | ||
|
@@ -215,7 +203,8 @@ packetData := icatypes.InterchainAccountPacketData{ | |
// If the packet times out, the channel will be closed requiring a new channel to be created | ||
timeoutTimestamp := obtainTimeoutTimestamp() | ||
|
||
_, err = keeper.icaControllerKeeper.TrySendTx(ctx, chanCap, p, packetData, timeoutTimestamp) | ||
// Send the interchain accounts packet, returning the packet sequence | ||
seq, err = keeper.icaControllerKeeper.TrySendTx(ctx, chanCap, portID, packetData, timeoutTimestamp) | ||
``` | ||
|
||
The data within an `InterchainAccountPacketData` must be serialized using a format supported by the host chain. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!-- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added separate page for parameters. More easy to navigate and more explicit! |
||
order: 4 | ||
--> | ||
|
||
# Parameters | ||
|
||
The Interchain Accounts module contains the following on-chain parameters, logically separated for each distinct submodule: | ||
|
||
### Controller Submodule Parameters | ||
|
||
| Key | Type | Default Value | | ||
|------------------------|------|---------------| | ||
| `ControllerEnabled` | bool | `true` | | ||
|
||
#### ControllerEnabled | ||
|
||
The `ControllerEnabled` parameter controls a chains ability to service ICS-27 controller specific logic. This includes the sending of Interchain Accounts packet data as well as the following ICS-26 callback handlers: | ||
- `OnChanOpenInit` | ||
- `OnChanOpenAck` | ||
- `OnChanCloseConfirm` | ||
- `OnAcknowledgementPacket` | ||
- `OnTimeoutPacket` | ||
|
||
### Host Submodule Parameters | ||
|
||
| Key | Type | Default Value | | ||
|------------------------|----------|---------------| | ||
| `HostEnabled` | bool | `true` | | ||
| `AllowMessages` | []string | `[]` | | ||
|
||
#### HostEnabled | ||
|
||
The `HostEnabled` parameter controls a chains ability to service ICS27 host specific logic. This includes the following ICS-26 callback handlers: | ||
- `OnChanOpenTry` | ||
- `OnChanOpenConfirm` | ||
- `OnChanCloseConfirm` | ||
- `OnRecvPacket` | ||
|
||
#### AllowMessages | ||
|
||
The `AllowMessages` parameter provides the ability for a chain to limit the types of messages or transactions that hosted interchain accounts are authorized to execute by defining an allowlist using the Protobuf message TypeURL format. | ||
|
||
For example, a Cosmos SDK based chain that elects to provide hosted Interchain Accounts with the ability of governance voting and staking delegations will define its parameters as follows: | ||
|
||
``` | ||
"params": { | ||
"host_enabled": true, | ||
"allow_messages": ["/cosmos.staking.v1beta1.MsgDelegate", "/cosmos.gov.v1beta1.MsgVote"] | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- | ||
order: 5 | ||
--> | ||
|
||
# Transactions | ||
|
||
Learn about Interchain Accounts transaction execution {synopsis} | ||
|
||
## Executing a transaction | ||
|
||
As described in [Authentication Modules](./auth-modules.md#trysendtx) transactions are executed using the interchain accounts controller API and require a `Base Application` as outlined in [ICS30 IBC Middleware](https://github.com/cosmos/ibc/tree/master/spec/app/ics-030-middleware) to facilitate authentication. The method of authentication remains unspecified to provide flexibility for the authentication module developer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worked when I was running a local server with docs. Link checker is happy too |
||
|
||
Transactions are executed via the ICS27 [`TrySendTx` API](./auth-modules.md#trysendtx). This must be invoked through an Interchain Accounts authentication module and follows the outlined path of execution below. Packet relaying semantics provided by the IBC core transport, authentication, and ordering (IBC/TAO) layer are omitted for brevity. | ||
|
||
![send-tx-flow](../../assets/send-interchain-tx.png "Transaction Execution") | ||
|
||
## Atomicity | ||
|
||
As the Interchain Accounts module supports the execution of multiple transactions using the Cosmos SDK `Msg` interface, it provides the same atomicity guarantees as Cosmos SDK-based applications, leveraging the [`CacheMultiStore`](https://docs.cosmos.network/master/core/store.html#cachemultistore) architecture provided by the [`Context`](https://docs.cosmos.network/master/core/context.html) type. | ||
|
||
This provides atomic execution of transactions when using Interchain Accounts, where state changes are only committed if all `Msg`s succeed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to dashed casing to align with other directories and files. E.g. ADRs or
upgrades/developer-guide.md
..etc