diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index cf6c0168249..2866e868105 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -43,7 +43,7 @@ write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. -- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/build/building-modules/11-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). +- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/build/building-modules/11-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x//spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). diff --git a/docs/apps/transfer/metrics.md b/docs/apps/transfer/metrics.md index 3d2bb4bd82f..9dc866deee8 100644 --- a/docs/apps/transfer/metrics.md +++ b/docs/apps/transfer/metrics.md @@ -4,7 +4,7 @@ order: 6 # Metrics -The IBC transfer application module exposes the following set of [metrics](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/develop/advanced/09-telemetry.md). +The IBC transfer application module exposes the following set of [metrics](https://github.com/cosmos/cosmos-sdk/blob/main/docs/develop/advanced/09-telemetry.md). | Metric | Description | Unit | Type | |:--------------------------------|:------------------------------------------------------------------------------------------|:----------------|:--------| diff --git a/docs/architecture/README.md b/docs/architecture/README.md index d83b7a00857..60e09a3de34 100644 --- a/docs/architecture/README.md +++ b/docs/architecture/README.md @@ -34,7 +34,7 @@ To suggest an ADR, please make use of the [ADR template](./adr-template.md) prov | [005](./adr-005-consensus-height-events.md) | `UpdateClient` events - `ClientState` consensus heights | Accepted | | [006](./adr-006-02-client-refactor.md) | ICS02 client refactor | Accepted | | [007](./adr-007-solomachine-signbytes.md) | ICS06 Solo machine sign bytes | -| [008](./adr-008-app-caller-cbs/adr-008-app-caller-cbs.md) | Callback to IBC ACtors | Accepted | +| [008](./adr-008-app-caller-cbs.md) | Callback to IBC ACtors | Accepted | | [009](./adr-009-v6-ics27-msgserver.md) | ICS27 message server addition | Accepted | | [010](./adr-010-light-clients-as-sdk-modules.md) | IBC light clients as SDK modules | Accepted | | [011](./adr-011-transfer-total-escrow-state-entry.md) | ICS20 state entry for total amount of tokens in escrow | Accepted | diff --git a/docs/architecture/adr-008-app-caller-cbs.md b/docs/architecture/adr-008-app-caller-cbs.md new file mode 100644 index 00000000000..2d6db9a3cd2 --- /dev/null +++ b/docs/architecture/adr-008-app-caller-cbs.md @@ -0,0 +1,543 @@ +# ADR 008: Callback to IBC Actors + +## Changelog + +* 2022-08-10: Initial Draft +* 2023-03-22: Merged +* 2023-09-13: Updated with decisions made in implementation + +## Status + +Accepted, middleware implemented + +## Context + +IBC was designed with callbacks between core IBC and IBC applications. IBC apps would send a packet to core IBC. When the result of the packet lifecycle eventually resolved into either an acknowledgement or a timeout, core IBC called a callback on the IBC application so that the IBC application could take action on the basis of the result (e.g. unescrow tokens for ICS-20). + +This setup worked well for off-chain users interacting with IBC applications. + +We are now seeing the desire for secondary applications (e.g. smart contracts, modules) to call into IBC apps as part of their state machine logic and then do some actions on the basis of the packet result. Or to receive a packet from IBC and do some logic upon receipt. + +Example Usecases: +- Send an ICS-20 packet, and if it is successful, then send an ICA-packet to swap tokens on LP and return funds to sender +- Execute some logic upon receipt of token transfer to a smart contract address + +This requires a second layer of callbacks. The IBC application already gets the result of the packet from core IBC, but currently there is no standardized way to pass this information on to an actor module/smart contract. + +## Definitions + +- Actor: an actor is an on-chain module (this may be a hardcoded module in the chain binary or a smart contract) that wishes to execute custom logic whenever IBC receives a packet flow that it has either sent or received. It **must** be addressable by a string value. + +## Decision + +Create a middleware that can interface between IBC applications and smart contract VMs. The IBC applications and smart contract VMs will implement respective interfaces that will then be composed together by the callback middleware to allow a smart contract of any compatible VM to interact programmatically with an IBC application. + +## Data structures + +The `CallbackPacketData` struct will get constructed from custom callback data in the application packet. The `CallbackAddress` is the IBC Actor address on which the callback should be called on. The `SenderAddress` is also provided to optionally allow a VM to ensure that the sender is the same as the callback address. + +The struct also defines a `CommitGasLimit` which is the maximum gas a callback is allowed to use. If the callback exceeds this limit, the callback will panic and the tx will commit without the callback's state changes. + +The `ExecutionGasLimit` is the practical limit of the tx execution that is set in the context gas meter. It is the minimum of the `CommitGasLimit` and the gas left in the context gas meter which is determined by the relayer's choice of tx gas limit. If `ExecutionGasLimit < CommitGasLimit`, then an out-of-gas error will revert the entire transaction without committing anything, allowing for a different relayer to retry with a larger tx gas limit. + +Any middleware targeting this interface for callback handling should define a global limit that caps the gas that a callback is allowed to take (especially on AcknowledgePacket and TimeoutPacket) so that a custom callback does not prevent the packet lifecycle from completing. However, since this is a global cap it is likely to be very large. Thus, users may specify a smaller limit to cap the amount of fees a relayer must pay in order to complete the packet lifecycle on the user's behalf. + +```go +// Implemented by any packet data type that wants to support PacketActor callbacks +// PacketActor's will be unable to act on any packet data type that does not implement +// this interface. +type CallbackPacketData struct { + CallbackAddress: string + ExecutionGasLimit: uint64 + SenderAddress: string + CommitGasLimit: uint64 +} +``` + +IBC Apps or middleware can then call the IBCActor callbacks like so in their own callbacks: + +### Callback Middleware + +The CallbackMiddleware wraps an underlying IBC application along with a contractKeeper that delegates the callback to a virtual machine. This allows the Callback middleware to interface any compatible IBC application with any compatible VM (e.g. EVM, WASM) so long as the application implements the `CallbacksCompatibleModule` interface and the VM implements the `ContractKeeper` interface. + +```go +// IBCMiddleware implements the ICS26 callbacks for the ibc-callbacks middleware given +// the underlying application. +type IBCMiddleware struct { + app types.CallbacksCompatibleModule + ics4Wrapper porttypes.ICS4Wrapper + + contractKeeper types.ContractKeeper + + // maxCallbackGas defines the maximum amount of gas that a callback actor can ask the + // relayer to pay for. If a callback fails due to insufficient gas, the entire tx + // is reverted if the relayer hadn't provided the minimum(userDefinedGas, maxCallbackGas). + // If the actor hasn't defined a gas limit, then it is assumed to be the maxCallbackGas. + maxCallbackGas uint64 +} +``` + +### Callback-Compatible IBC Application + +The `CallbacksCompatibleModule` extends `porttypes.IBCModule` to include an `UnmarshalPacketData` function that allows the middleware to request that the underlying app unmarshal the packet data. This will then allow the middleware to retrieve the callback specific data from an arbitrary set of IBC application packets. + +```go +// CallbacksCompatibleModule is an interface that combines the IBCModule and PacketDataUnmarshaler +// interfaces to assert that the underlying application supports both. +type CallbacksCompatibleModule interface { + porttypes.IBCModule + porttypes.PacketDataUnmarshaler +} + +// PacketDataUnmarshaler defines an optional interface which allows a middleware to +// request the packet data to be unmarshaled by the base application. +type PacketDataUnmarshaler interface { + // UnmarshalPacketData unmarshals the packet data into a concrete type + UnmarshalPacketData([]byte) (interface{}, error) +} +``` + +The application's packet data must additionally implement the following interfaces: + +```go +// PacketData defines an optional interface which an application's packet data structure may implement. +type PacketData interface { + // GetPacketSender returns the sender address of the packet data. + // If the packet sender is unknown or undefined, an empty string should be returned. + GetPacketSender(sourcePortID string) string +} + +// PacketDataProvider defines an optional interfaces for retrieving custom packet data stored on behalf of another application. +// An existing problem in the IBC middleware design is the inability for a middleware to define its own packet data type and insert packet sender provided information. +// A short term solution was introduced into several application's packet data to utilize a memo field to carry this information on behalf of another application. +// This interfaces standardizes that behaviour. Upon realization of the ability for middleware's to define their own packet data types, this interface will be deprecated and removed with time. +type PacketDataProvider interface { + // GetCustomPacketData returns the packet data held on behalf of another application. + // The name the information is stored under should be provided as the key. + // If no custom packet data exists for the key, nil should be returned. + GetCustomPacketData(key string) interface{} +} +``` + +The callback data can be embedded in an application packet by providing custom packet data for source and destination callback in the custom packet data under the appropriate key. + +```jsonc +// Custom Packet data embedded as a JSON object in the packet data + +// src callback custom data +{ + "src_callback": { + "address": "callbackAddressString", + // optional + "gas_limit": "userDefinedGasLimitString", + } +} + +// dest callback custom data +{ + "dest_callback": { + "address": "callbackAddressString", + // optional + "gas_limit": "userDefinedGasLimitString", + } +} + +// src and dest callback custom data embedded together +{ + "src_callback": { + "address": "callbackAddressString", + // optional + "gas_limit": "userDefinedGasLimitString", + }, + "dest_callback": { + "address": "callbackAddressString", + // optional + "gas_limit": "userDefinedGasLimitString", + } +} +``` + +## ContractKeeper + +The `ContractKeeper` interface must be implemented by any VM that wants to support IBC callbacks. This allows for separation of concerns +between the middleware which is handling logic intended for all VMs (e.g. setting gas meter, extracting callback data, emitting events), +while the ContractKeeper can handle the specific details of calling into the VM in question. + +The `ContractKeeper` **may** impose additional checks such as ensuring that the contract address is the same as the packet sender in source callbacks. +It may also disable certain callback methods by simply performing a no-op. + +```go +// ContractKeeper defines the entry points exposed to the VM module which invokes a smart contract +type ContractKeeper interface { + // IBCSendPacketCallback is called in the source chain when a PacketSend is executed. The + // packetSenderAddress is determined by the underlying module, and may be empty if the sender is + // unknown or undefined. The contract is expected to handle the callback within the user defined + // gas limit, and handle any errors, or panics gracefully. + // This entry point is called with a cached context. If an error is returned, then the changes in + // this context will not be persisted, and the error will be propagated to the underlying IBC + // application, resulting in a packet send failure. + // + // Implementations are provided with the packetSenderAddress and MAY choose to use this to perform + // validation on the origin of a given packet. It is recommended to perform the same validation + // on all source chain callbacks (SendPacket, AcknowledgementPacket, TimeoutPacket). This + // defensively guards against exploits due to incorrectly wired SendPacket ordering in IBC stacks. + IBCSendPacketCallback( + cachedCtx sdk.Context, + sourcePort string, + sourceChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + packetData []byte, + contractAddress, + packetSenderAddress string, + ) error + // IBCOnAcknowledgementPacketCallback is called in the source chain when a packet acknowledgement + // is received. The packetSenderAddress is determined by the underlying module, and may be empty if + // the sender is unknown or undefined. The contract is expected to handle the callback within the + // user defined gas limit, and handle any errors, or panics gracefully. + // This entry point is called with a cached context. If an error is returned, then the changes in + // this context will not be persisted, but the packet lifecycle will not be blocked. + // + // Implementations are provided with the packetSenderAddress and MAY choose to use this to perform + // validation on the origin of a given packet. It is recommended to perform the same validation + // on all source chain callbacks (SendPacket, AcknowledgementPacket, TimeoutPacket). This + // defensively guards against exploits due to incorrectly wired SendPacket ordering in IBC stacks. + IBCOnAcknowledgementPacketCallback( + cachedCtx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, + contractAddress, + packetSenderAddress string, + ) error + // IBCOnTimeoutPacketCallback is called in the source chain when a packet is not received before + // the timeout height. The packetSenderAddress is determined by the underlying module, and may be + // empty if the sender is unknown or undefined. The contract is expected to handle the callback + // within the user defined gas limit, and handle any error, out of gas, or panics gracefully. + // This entry point is called with a cached context. If an error is returned, then the changes in + // this context will not be persisted, but the packet lifecycle will not be blocked. + // + // Implementations are provided with the packetSenderAddress and MAY choose to use this to perform + // validation on the origin of a given packet. It is recommended to perform the same validation + // on all source chain callbacks (SendPacket, AcknowledgementPacket, TimeoutPacket). This + // defensively guards against exploits due to incorrectly wired SendPacket ordering in IBC stacks. + IBCOnTimeoutPacketCallback( + cachedCtx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, + contractAddress, + packetSenderAddress string, + ) error + // IBCReceivePacketCallback is called in the destination chain when a packet acknowledgement is written. + // The contract is expected to handle the callback within the user defined gas limit, and handle any errors, + // out of gas, or panics gracefully. + // This entry point is called with a cached context. If an error is returned, then the changes in + // this context will not be persisted, but the packet lifecycle will not be blocked. + IBCReceivePacketCallback( + cachedCtx sdk.Context, + packet ibcexported.PacketI, + ack ibcexported.Acknowledgement, + contractAddress string, + ) error +} +``` + +### PacketCallbacks + +The packet callbacks implemented in the middleware will first call the underlying application and then route to the IBC actor callback in the post-processing step. +It will extract the callback data from the application packet and set the callback gas meter depending on the global limit, the user limit, and the gas left in the transaction gas meter. +The callback will then be routed through the callback keeper which will either panic or return a result (success or failure). In the event of a (non-oog) panic or an error, the callback state changes +are discarded and the transaction is committed. + +If the relayer-defined gas limit is exceeded before the user-defined gas limit or global callback gas limit is exceeded, then the entire transaction is reverted to allow for resubmission. If the chain-defined or user-defined gas limit is reached, +the callback state changes are reverted and the transaction is committed. + +For the `SendPacket` callback, we will revert the entire transaction on any kind of error or panic. This is because the packet lifecycle has not yet started, so we can revert completely to avoid starting the packet lifecycle if the callback is not successful. + +```go +// SendPacket implements source callbacks for sending packets. +// It defers to the underlying application and then calls the contract callback. +// If the contract callback returns an error, panics, or runs out of gas, then +// the packet send is rejected. +func (im IBCMiddleware) SendPacket( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + sourcePort string, + sourceChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, +) (uint64, error) { + // run underlying app logic first + // IBCActor logic will postprocess + seq, err := im.ics4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) + if err != nil { + return 0, err + } + + // use underlying app to get source callback information from packet data + callbackData, err := types.GetSourceCallbackData(im.app, data, sourcePort, ctx.GasMeter().GasRemaining(), im.maxCallbackGas) + // SendPacket is not blocked if the packet does not opt-in to callbacks + if err != nil { + return seq, nil + } + + callbackExecutor := func(cachedCtx sdk.Context) error { + return im.contractKeeper.IBCSendPacketCallback( + cachedCtx, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data, callbackData.CallbackAddress, callbackData.SenderAddress, + ) + } + + err = im.processCallback(ctx, types.CallbackTypeSendPacket, callbackData, callbackExecutor) + // contract keeper is allowed to reject the packet send. + if err != nil { + return 0, err + } + + types.EmitCallbackEvent(ctx, sourcePort, sourceChannel, seq, types.CallbackTypeSendPacket, callbackData, nil) + return seq, nil +} + +// WriteAcknowledgement implements the ReceivePacket destination callbacks for the ibc-callbacks middleware +// during asynchronous packet acknowledgement. +// It defers to the underlying application and then calls the contract callback. +// If the contract callback runs out of gas and may be retried with a higher gas limit then the state changes are +// reverted via a panic. +func (im IBCMiddleware) WriteAcknowledgement( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + packet ibcexported.PacketI, + ack ibcexported.Acknowledgement, +) error { + // run underlying app logic first + // IBCActor logic will postprocess + err := im.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, ack) + if err != nil { + return err + } + + // use underlying app to get destination callback information from packet data + callbackData, err := types.GetDestCallbackData( + im.app, packet.GetData(), packet.GetSourcePort(), ctx.GasMeter().GasRemaining(), im.maxCallbackGas, + ) + // WriteAcknowledgement is not blocked if the packet does not opt-in to callbacks + if err != nil { + return nil + } + + callbackExecutor := func(cachedCtx sdk.Context) error { + return im.contractKeeper.IBCReceivePacketCallback(cachedCtx, packet, ack, callbackData.CallbackAddress) + } + + // callback execution errors are not allowed to block the packet lifecycle, they are only used in event emissions + err = im.processCallback(ctx, types.CallbackTypeReceivePacket, callbackData, callbackExecutor) + // emit events + types.EmitCallbackEvent( + ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), + types.CallbackTypeAcknowledgementPacket, callbackData, err, + ) + + return nil +} + +// Call the IBCActor recvPacket callback after processing the packet +// if the recvPacket callback exists. If the callback returns an error +// then return an error ack to revert all packet data processing. +func (im IBCMiddleware) OnRecvPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) (ack exported.Acknowledgement) { + // run underlying app logic first + // IBCActor logic will postprocess + ack := im.app.OnRecvPacket(ctx, packet, relayer) + // if ack is nil (asynchronous acknowledgements), then the callback will be handled in WriteAcknowledgement + // if ack is not successful, all state changes are reverted. If a packet cannot be received, then there is + // no need to execute a callback on the receiving chain. + if ack == nil || !ack.Success() { + return ack + } + + // use underlying app to get destination callback information from packet data + callbackData, err := types.GetDestCallbackData( + im.app, packet.GetData(), packet.GetSourcePort(), ctx.GasMeter().GasRemaining(), im.maxCallbackGas, + ) + // OnRecvPacket is not blocked if the packet does not opt-in to callbacks + if err != nil { + return ack + } + + callbackExecutor := func(cachedCtx sdk.Context) error { + return im.contractKeeper.IBCReceivePacketCallback(cachedCtx, packet, ack, callbackData.CallbackAddress) + } + + // callback execution errors are not allowed to block the packet lifecycle, they are only used in event emissions + err = im.processCallback(ctx, types.CallbackTypeReceivePacket, callbackData, callbackExecutor) + types.EmitCallbackEvent( + ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), + types.CallbackTypeReceivePacket, callbackData, err, + ) + + return ack +} + +// Call the IBCActor acknowledgementPacket callback after processing the packet +// if the ackPacket callback exists and returns an error +// DO NOT return the error upstream. The acknowledgement must complete for the packet +// lifecycle to end, so the custom callback cannot block completion. +// Instead we emit error events and set the error in state +// so that users and on-chain logic can handle this appropriately +func (im IBCModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + // we first call the underlying app to handle the acknowledgement + // IBCActor logic will postprocess + err := im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) + if err != nil { + return err + } + + // use underlying app to get source callback information from packet data + callbackData, err := types.GetSourceCallbackData( + im.app, packet.GetData(), packet.GetSourcePort(), ctx.GasMeter().GasRemaining(), im.maxCallbackGas, + ) + // OnAcknowledgementPacket is not blocked if the packet does not opt-in to callbacks + if err != nil { + return nil + } + + callbackExecutor := func(cachedCtx sdk.Context) error { + return im.contractKeeper.IBCOnAcknowledgementPacketCallback( + cachedCtx, packet, acknowledgement, relayer, callbackData.CallbackAddress, callbackData.SenderAddress, + ) + } + + // callback execution errors are not allowed to block the packet lifecycle, they are only used in event emissions + err = im.processCallback(ctx, types.CallbackTypeAcknowledgementPacket, callbackData, callbackExecutor) + types.EmitCallbackEvent( + ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), + types.CallbackTypeAcknowledgementPacket, callbackData, err, + ) + + return nil +} + +// Call the IBCActor timeoutPacket callback after processing the packet +// if the timeoutPacket callback exists and returns an error +// DO NOT return the error upstream. The timeout must complete for the packet +// lifecycle to end, so the custom callback cannot block completion. +// Instead we emit error events and set the error in state +// so that users and on-chain logic can handle this appropriately +func (im IBCModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) error { + // application-specific onTimeoutPacket logic + err := im.app.OnTimeoutPacket(ctx, packet, relayer) + if err != nil { + return err + } + + // use underlying app to get source callback information from packet data + callbackData, err := types.GetSourceCallbackData( + im.app, packet.GetData(), packet.GetSourcePort(), ctx.GasMeter().GasRemaining(), im.maxCallbackGas, + ) + // OnTimeoutPacket is not blocked if the packet does not opt-in to callbacks + if err != nil { + return nil + } + + callbackExecutor := func(cachedCtx sdk.Context) error { + return im.contractKeeper.IBCOnTimeoutPacketCallback(cachedCtx, packet, relayer, callbackData.CallbackAddress, callbackData.SenderAddress) + } + + // callback execution errors are not allowed to block the packet lifecycle, they are only used in event emissions + err = im.processCallback(ctx, types.CallbackTypeTimeoutPacket, callbackData, callbackExecutor) + types.EmitCallbackEvent( + ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), + types.CallbackTypeTimeoutPacket, callbackData, err, + ) + + return nil +} + +// processCallback executes the callbackExecutor and reverts contract changes if the callbackExecutor fails. +// +// Error Precedence and Returns: +// - oogErr: Takes the highest precedence. If the callback runs out of gas, an error wrapped with types.ErrCallbackOutOfGas is returned. +// - panicErr: Takes the second-highest precedence. If a panic occurs and it is not propagated, an error wrapped with types.ErrCallbackPanic is returned. +// - callbackErr: If the callbackExecutor returns an error, it is returned as-is. +// +// panics if +// - the contractExecutor panics for any reason, and the callbackType is SendPacket, or +// - the contractExecutor runs out of gas and the relayer has not reserved gas grater than or equal to +// CommitGasLimit. +func (IBCMiddleware) processCallback( + ctx sdk.Context, callbackType types.CallbackType, + callbackData types.CallbackData, callbackExecutor func(sdk.Context) error, +) (err error) { + cachedCtx, writeFn := ctx.CacheContext() + cachedCtx = cachedCtx.WithGasMeter(storetypes.NewGasMeter(callbackData.ExecutionGasLimit)) + + defer func() { + // consume the minimum of g.consumed and g.limit + ctx.GasMeter().ConsumeGas(cachedCtx.GasMeter().GasConsumedToLimit(), fmt.Sprintf("ibc %s callback", callbackType)) + + // recover from all panics except during SendPacket callbacks + if r := recover(); r != nil { + if callbackType == types.CallbackTypeSendPacket { + panic(r) + } + err = errorsmod.Wrapf(types.ErrCallbackPanic, "ibc %s callback panicked with: %v", callbackType, r) + } + + // if the callback ran out of gas and the relayer has not reserved enough gas, then revert the state + if cachedCtx.GasMeter().IsPastLimit() { + if callbackData.AllowRetry() { + panic(storetypes.ErrorOutOfGas{Descriptor: fmt.Sprintf("ibc %s callback out of gas; commitGasLimit: %d", callbackType, callbackData.CommitGasLimit)}) + } + err = errorsmod.Wrapf(types.ErrCallbackOutOfGas, "ibc %s callback out of gas", callbackType) + } + + // allow the transaction to be committed, continuing the packet lifecycle + }() + + err = callbackExecutor(cachedCtx) + if err == nil { + writeFn() + } + + return err +} +``` + +Chains are expected to specify a `maxCallbackGas` to ensure that callbacks do not consume an arbitrary amount of gas. Thus, it should always be possible for a relayer to complete the packet lifecycle even if the actor callbacks cannot run successfully. + +## Consequences + +### Positive + +- IBC Actors can now programmatically execute logic that involves sending a packet and then performing some additional logic once the packet lifecycle is complete +- Middleware implementing ADR-8 can be generally used for any application +- Leverages a similar callback architecture to the one used between core IBC and IBC applications + +### Negative + +- Callbacks may now have unbounded gas consumption since the actor may execute arbitrary logic. Chains implementing this feature should take care to place limitations on how much gas an actor callback can consume. +- The relayer pays for the callback gas instead of the IBCActor + +### Neutral + +- Application packets that want to support ADR-8 must additionally have their packet data implement `PacketDataProvider` and `PacketData` interfaces. +- Applications must implement `PacketDataUnmarshaler` interface +- Callback receiving module must implement the `ContractKeeper` interface + +## References + +- [Original issue](https://github.com/cosmos/ibc-go/issues/1660) +- [CallbackPacketData interface implementation](https://github.com/cosmos/ibc-go/pull/3287) +- [ICS 20, ICS 27 implementations of the CallbackPacketData interface](https://github.com/cosmos/ibc-go/pull/3287) diff --git a/docs/architecture/adr-008-app-caller-cbs/adr-008-app-caller-cbs.md b/docs/architecture/adr-008-app-caller-cbs/adr-008-app-caller-cbs.md deleted file mode 100644 index b67275ccf49..00000000000 --- a/docs/architecture/adr-008-app-caller-cbs/adr-008-app-caller-cbs.md +++ /dev/null @@ -1,421 +0,0 @@ -# ADR 008: Callback to IBC Actors - -## Changelog - -* 2022-08-10: Initial Draft -* 2023-03-22: Merged - -## Status - -Accepted, packet callback interface implemented - -## Context - -IBC was designed with callbacks between core IBC and IBC applications. IBC apps would send a packet to core IBC. When the result of the packet lifecycle eventually resolved into either an acknowledgement or a timeout, core IBC called a callback on the IBC application so that the IBC application could take action on the basis of the result (e.g. unescrow tokens for ICS-20). - -This setup worked well for off-chain users interacting with IBC applications. - -We are now seeing the desire for secondary applications (e.g. smart contracts, modules) to call into IBC apps as part of their state machine logic and then do some actions on the basis of the packet result. Or to receive a packet from IBC and do some logic upon receipt. - -Example Usecases: -- Send an ICS-20 packet, and if it is successful, then send an ICA-packet to swap tokens on LP and return funds to sender -- Execute some logic upon receipt of token transfer to a smart contract address - -This requires a second layer of callbacks. The IBC application already gets the result of the packet from core IBC, but currently there is no standardized way to pass this information on to an actor module/smart contract. - -## Definitions - -- Actor: an actor is an on-chain module (this may be a hardcoded module in the chain binary or a smart contract) that wishes to execute custom logic whenever IBC receives a packet flow that it has either sent or received. It **must** be addressable by a string value. - -## Decision - -Create a standardized callback interface that actors can implement. IBC applications (or middleware that wraps IBC applications) can now call this callback to route the result of the packet/channel handshake from core IBC to the IBC application to the original actor on the sending chain. IBC applications can route the packet receipt to the destination actor on the receiving chain. - -IBC actors may implement the following interface: - -```go -type IBCActor interface { - // OnChannelOpen will be called on the IBCActor when the channel opens - // this will happen either on ChanOpenAck or ChanOpenConfirm - OnChannelOpen(ctx sdk.Context, portID, channelID, version string) - - // OnChannelClose will be called on the IBCActor if the channel closes - // this will be called on either ChanCloseInit or ChanCloseConfirm and if the channel handshake fails on our end - // NOTE: currently the channel does not automatically close if the counterparty fails the handhshake so actors must be prepared for an OpenInit to never return a callback for the time being - OnChannelClose(ctx sdk.Context, portID, channelID string) - - // IBCActor must also implement PacketActor interface - PacketActor -} - -// PacketActor is split out into its own separate interface since implementors may choose -// to only support callbacks for packet methods rather than supporting the full IBCActor interface -type PacketActor interface { - // OnRecvPacket will be called on the IBCActor after the IBC Application - // handles the RecvPacket callback if the packet has an IBC Actor as a receiver. - OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error - - // OnAcknowledgementPacket will be called on the IBC Actor - // after the IBC Application handles its own OnAcknowledgementPacket callback - OnAcknowledgmentPacket( - ctx sdk.Context, - packet channeltypes.Packet, - ack exported.Acknowledgement, - relayer sdk.AccAddress, - ) error - - // OnTimeoutPacket will be called on the IBC Actor - // after the IBC Application handles its own OnTimeoutPacket callback - OnTimeoutPacket( - ctx sdk.Context, - packet channeltypes.Packet, - relayer sdk.AccAddress, - ) error -} -``` - -The `CallbackPacketData` interface will get created to add `GetSourceCallbackAddress` and `GetDestCallbackAddress` methods. These may return an address -or they may return the empty string. The address may reference an PacketActor or it may be a regular user address. If the address is not a PacketActor, the actor callback must continue processing (no-op). Any IBC application or middleware that uses these methods must handle these cases. In most cases, the `GetSourceCallbackAddress` will be the sender address and the `GetDestCallbackAddress` will be the receiver address. However, these are named generically so that implementors may choose a different contract address for the callback if they choose. - -The interface also defines a `UserDefinedGasLimit` method. Any middleware targeting this interface for callback handling should cap the gas that a callback is allowed to take (especially on AcknowledgePacket and TimeoutPacket) so that a custom callback does not prevent the packet lifecycle from completing. However, since this is a global cap it is likely to be very large. Thus, users may specify a smaller limit to cap the amount of fees a relayer must pay in order to complete the packet lifecycle on the user's behalf. - -IBC applications which provide the base packet data type must implement the `CallbackPacketData` interface to allow `PacketActor` callbacks. - -```go -// Implemented by any packet data type that wants to support PacketActor callbacks -// PacketActor's will be unable to act on any packet data type that does not implement -// this interface. -type CallbackPacketData interface { - // GetSourceCallbackAddress should return the callback address of a packet data on the source chain. - // This may or may not be the sender of the packet. If no source callback address exists for the packet, - // an empty string may be returned. - GetSourceCallbackAddress() string - - // GetDestCallbackAddress should return the callback address of a packet data on the destination chain. - // This may or may not be the receiver of the packet. If no dest callback address exists for the packet, - // an empty string may be returned. - GetDestCallbackAddress() string - - // UserDefinedGasLimit allows the sender of the packet to define inside the packet data - // a gas limit for how much the ADR-8 callbacks can consume. If defined, this will be passed - // in as the gas limit so that the callback is guaranteed to complete within a specific limit. - // On recvPacket, a gas-overflow will just fail the transaction allowing it to timeout on the sender side. - // On ackPacket and timeoutPacket, a gas-overflow will reject state changes made during callback but still - // commit the transaction. This ensures the packet lifecycle can always complete. - // If the packet data returns 0, the remaining gas limit will be passed in (modulo any chain-defined limit) - // Otherwise, we will set the gas limit passed into the callback to the `min(ctx.GasLimit, UserDefinedGasLimit())` - UserDefinedGasLimit() uint64 -} -``` - -IBC Apps or middleware can then call the IBCActor callbacks like so in their own callbacks: - -### Handshake Callbacks - -The `OnChanOpenInit` handshake callback will need to include an additional field so that the initiating actor can be tracked and called upon during handshake completion. -The actor provided in the `OnChanOpenInit` callback will be the signer of the `MsgChanOpenInit` message. - -```go -func OnChanOpenInit( - ctx sdk.Context, - order channeltypes.Order, - connectionHops []string, - portID string, - channelID string, - channelCap *capabilitytypes.Capability, - counterparty channeltypes.Counterparty, - version string, - actor string, -) (string, error) { - acc := k.getAccount(ctx, actor) - ibcActor, ok := acc.(IBCActor) - if ok { - k.setActor(ctx, portID, channelID, actor) - } - - // continued logic -} - -func OnChanOpenAck( - ctx sdk.Context, - portID, - channelID string, - counterpartyChannelID string, - counterpartyVersion string, -) error { - // run any necessary logic first - // negotiate final version - - actor := k.getActor(ctx, portID, channelID) - if actor != "" { - ibcActor, _ := acc.(IBCActor) - ibcActor.OnChanOpen(ctx, portID, channelID, version) - } - - // the same actor will be used for channel closure -} - -func OnChanCloseInit( - ctx sdk.Context, - portID, - channelID, -) error { - // run any necesssary logic first - - actor := k.getActor(ctx, portID, channelID) - if actor != "" { - ibcActor, _ := acc.(IBCActor) - ibcActor.OnChanClose(ctx, portID, channelID) - } - // cleanup state - k.deleteActor(ctx, portID, channelID) -} - -func OnChanCloseConfirm( - ctx sdk.Context, - portID, - channelID string, -) error { - // run any necesssary logic first - - actor := k.getActor(ctx, portID, channelID) - if actor != "" { - ibcActor, _ := acc.(IBCActor) - ibcActor.OnChanClose(ctx, portID, channelID) - } - // cleanup state - k.deleteActor(ctx, portID, channelID) -} -``` - -NOTE: The handshake calls `OnChanOpenTry` and `OnChanOpenConfirm` are explicitly left out as it is still to be determined how the actor of the `OnChanOpenTry` step should be provided. Initially only the initiating side of the channel handshake may support setting a channel actor, future improvements should allow both sides of the channel handshake to set channel actors. - -### PacketCallbacks - -No packet callback API will need to change. - -```go -// Call the IBCActor recvPacket callback after processing the packet -// if the recvPacket callback exists. If the callback returns an error -// then return an error ack to revert all packet data processing. -func OnRecvPacket( - ctx sdk.Context, - packet channeltypes.Packet, - relayer sdk.AccAddress, -) (ack exported.Acknowledgement) { - // run any necesssary logic first - // IBCActor logic will postprocess - - // postprocessing should only if the underlying application - // returns a successful ack - - // unmarshal packet data into expected interface - var cbPacketData callbackPacketData - unmarshalInterface(packet.GetData(), cbPacketData) - - if cbPacketData == nil { - // the packet data does not implement the CallbackPacketData interface - // continue processing (no-op) - return - } - - acc := k.getAccount(ctx, cbPacketData.GetDstCallbackAddress()) - ibcActor, ok := acc.(IBCActor) - if ok { - // set gas limit for callback - gasLimit := getGasLimit(ctx, cbPacketData) - cbCtx = ctx.WithGasLimit(gasLimit) - - err := ibcActor.OnRecvPacket(cbCtx, packet, relayer) - - // deduct consumed gas from original context - ctx = ctx.WithGasLimit(ctx.GasMeter().RemainingGas() - cbCtx.GasMeter().GasConsumed()) - if err != nil { - // NOTE: by returning an error acknowledgement, it is assumed that the - // base IBC application on the counterparty callback stack will be able - // to properly unmarshal the error acknowledgement. It should not expect - // some custom error acknowledgement. If it does, failed acknowledgements - // will be unsuccessfully processed which can be catastrophic in processing - // refund logic. - // - // If this issue is a serious concern, an ADR 8 implementation can construct its own - // acknowledgement type which wraps the underlying application acknowledgement. This - // would require deployment on both sides of the packet flow, in addition to version - // negotiation to enable the custom acknowledgement type usage. - // - // Future improvmenets should allow for each IBC application in a stack of - // callbacks to provide their own acknowledgement without disrupting the unmarshaling - // of an application above or below it in the stack. - return AcknowledgementError(err) - } - } - return -} - -// Call the IBCActor acknowledgementPacket callback after processing the packet -// if the ackPacket callback exists and returns an error -// DO NOT return the error upstream. The acknowledgement must complete for the packet -// lifecycle to end, so the custom callback cannot block completion. -// Instead we emit error events and set the error in state -// so that users and on-chain logic can handle this appropriately -func (im IBCModule) OnAcknowledgementPacket( - ctx sdk.Context, - packet channeltypes.Packet, - acknowledgement []byte, - relayer sdk.AccAddress, -) error { - // application-specific onAcknowledgmentPacket logic - - // unmarshal packet data into expected interface - var cbPacketData callbackPacketData - unmarshalInterface(packet.GetData(), cbPacketData) - - if cbPacketData == nil { - // the packet data does not implement the CallbackPacketData interface - // continue processing (no-op) - return - } - - // unmarshal ack bytes into the acknowledgment interface - var ack exported.Acknowledgement - unmarshal(acknowledgement, ack) - - // send acknowledgement to original actor - acc := k.getAccount(ctx, cbPacketData.GetSourceCallbackAddress()) - ibcActor, ok := acc.(IBCActor) - if ok { - gasLimit := getGasLimit(ctx, cbPacketData) - - - handleCallback := func() error { - // create cached context with gas limit - cacheCtx, writeFn := ctx.CacheContext() - cacheCtx = cacheCtx.WithGasLimit(gasLimit) - - defer func() { - if e := recover(); e != nil { - log("ran out of gas in callback. reverting callback state") - } else if err == nil { - // only write callback state if we did not panic during execution - // and the error returned is nil - writeFn() - } - } - - err := ibcActor.OnAcknowledgementPacket(cacheCtx, packet, ack, relayer) - - // deduct consumed gas from original context - ctx = ctx.WithGasLimit(ctx.GasMeter().RemainingGas() - cbCtx.GasMeter().GasConsumed()) - - return err - } - - if err := handleCallback(); err != nil { - setAckCallbackError(ctx, packet, err) // optional - emitAckCallbackErrorEvents(err) - } - } - - return nil -} - -// Call the IBCActor timeoutPacket callback after processing the packet -// if the timeoutPacket callback exists and returns an error -// DO NOT return the error upstream. The timeout must complete for the packet -// lifecycle to end, so the custom callback cannot block completion. -// Instead we emit error events and set the error in state -// so that users and on-chain logic can handle this appropriately -func (im IBCModule) OnTimeoutPacket( - ctx sdk.Context, - packet channeltypes.Packet, - relayer sdk.AccAddress, -) error { - // application-specific onTimeoutPacket logic - - // unmarshal packet data into expected interface - var cbPacketData callbackPacketData - unmarshalInterface(packet.GetData(), cbPacketData) - - if cbPacketData == nil { - // the packet data does not implement the CallbackPacketData interface - // continue processing (no-op) - return - } - - // call timeout callback on original actor - acc := k.getAccount(ctx, cbPacketData.GetSourceCallbackAddress()) - ibcActor, ok := acc.(IBCActor) - if ok { - gasLimit := getGasLimit(ctx, cbPacketData) - - handleCallback := func() error { - // create cached context with gas limit - cacheCtx, writeFn := ctx.CacheContext() - cacheCtx = cacheCtx.WithGasLimit(gasLimit) - - defer func() { - if e := recover(); e != nil { - log("ran out of gas in callback. reverting callback state") - } else if err == nil { - // only write callback state if we did not panic during execution - // and the error returned is nil - writeFn() - } - } - - err := ibcActor.OnTimeoutPacket(ctx, packet, relayer) - - // deduct consumed gas from original context - ctx = ctx.WithGasLimit(ctx.GasMeter().RemainingGas() - cbCtx.GasMeter().GasConsumed()) - - return err - } - - if err := handleCallback(); err != nil { - setTimeoutCallbackError(ctx, packet, err) // optional - emitTimeoutCallbackErrorEvents(err) - } - } - - return nil -} - -func getGasLimit(ctx sdk.Context, cbPacketData CallbackPacketData) uint64 { - // getGasLimit returns the gas limit to pass into the actor callback - // this will be the minimum of the remaining gas limit in the tx - // and the config defined gas limit. The config limit is itself - // the minimum of a user defined gas limit and the chain-defined gas limit - // for actor callbacks - var configLimit uint64 - if cbPacketData == 0 { - configLimit = chainDefinedActorCallbackLimit - } else { - configLimit = min(chainDefinedActorCallbackLimit, cbPacketData.UserDefinedGasLimit()) - } - return min(ctx.GasMeter().GasRemaining(), configLimit) -} -``` - -Chains are expected to specify a `chainDefinedActorCallbackLimit` to ensure that callbacks do not consume an arbitrary amount of gas. Thus, it should always be possible for a relayer to complete the packet lifecycle even if the actor callbacks cannot run successfully. - -## Consequences - -### Positive - -- IBC Actors can now programatically execute logic that involves sending a packet and then performing some additional logic once the packet lifecycle is complete -- Middleware implementing ADR-8 can be generally used for any application -- Leverages the same callback architecture used between core IBC and IBC applications - -### Negative - -- Callbacks may now have unbounded gas consumption since the actor may execute arbitrary logic. Chains implementing this feature should take care to place limitations on how much gas an actor callback can consume. - -### Neutral - -- Application packets that want to support ADR-8 must additionally have their packet data implement the `CallbackPacketData` interface and register their implementation on the chain codec - -## References - -- [Original issue](https://github.com/cosmos/ibc-go/issues/1660) -- [CallbackPacketData interface implementation](https://github.com/cosmos/ibc-go/pull/3287) -- [ICS 20, ICS 27 implementations of the CallbackPacketData interface](https://github.com/cosmos/ibc-go/pull/3287) diff --git a/docs/architecture/adr-008-app-caller-cbs/transfer-callback-scaffold.md b/docs/architecture/adr-008-app-caller-cbs/transfer-callback-scaffold.md deleted file mode 100644 index 904a6c52423..00000000000 --- a/docs/architecture/adr-008-app-caller-cbs/transfer-callback-scaffold.md +++ /dev/null @@ -1,223 +0,0 @@ -# Scaffold for ICS20 Callback Middleware - -The following is a very simple scaffold for middleware that implements actor callbacks for transfer channels. Since a channel does not need to be owned by a single actor, the handshake callbacks are no-ops. The packet callbacks will call into the relevant actor. For `OnRecvPacket`, this will be `data.Receiver`, and for `OnAcknowledgePacket` and `OnTimeoutPacket` this will be `data.Sender`. - -The exact nature of the callbacks to the smart contract will depend on the environment in question (e.g. cosmwasm, evm). Thus the place where the callbacks to the smart contract are stubbed out and commented so that it can be completed by implementers for the specific environment they are targetting. - -Implementers may wish to support callbacks to more IBC applications by adding a switch statement to unmarshal the specific packet data types they wish to support and passing them into the smart contract callback functions. - -### Scaffold Middleware - -```go -package callbacks - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - - transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" - porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" - "github.com/cosmos/ibc-go/v6/modules/core/exported" -) - -var _ porttypes.Middleware = &IBCMiddleware{} - -// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the -// fee keeper and the underlying application. -type IBCMiddleware struct { - app porttypes.IBCModule - chanWrapper porttypes.ICS4Wrapper -} - -// NewIBCMiddleware creates a new IBCMiddlware given the keeper and underlying application -func NewIBCMiddleware(app porttypes.IBCModule, chanWrapper porttypes.ICS4Wrapper) IBCMiddleware { - return IBCMiddleware{ - app: app, - chanWrapper: chanWrapper, - } -} - -// OnChanOpenInit implements the IBCMiddleware interface -func (im IBCMiddleware) OnChanOpenInit( - ctx sdk.Context, - order channeltypes.Order, - connectionHops []string, - portID string, - channelID string, - chanCap *capabilitytypes.Capability, - counterparty channeltypes.Counterparty, - version string, -) (string, error) { - // call underlying app's OnChanOpenInit callback - return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, - chanCap, counterparty, version) -} - -// OnChanOpenTry implements the IBCMiddleware interface -// If the channel is not fee enabled the underlying application version will be returned -// If the channel is fee enabled we merge the underlying application version with the ics29 version -func (im IBCMiddleware) OnChanOpenTry( - ctx sdk.Context, - order channeltypes.Order, - connectionHops []string, - portID, - channelID string, - chanCap *capabilitytypes.Capability, - counterparty channeltypes.Counterparty, - counterpartyVersion string, -) (string, error) { - // call underlying app's OnChanOpenTry callback - return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion) -} - -// OnChanOpenAck implements the IBCMiddleware interface -func (im IBCMiddleware) OnChanOpenAck( - ctx sdk.Context, - portID, - channelID string, - counterpartyChannelID string, - counterpartyVersion string, -) error { - // call underlying app's OnChanOpenAck callback - return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) -} - -// OnChanOpenConfirm implements the IBCMiddleware interface -func (im IBCMiddleware) OnChanOpenConfirm( - ctx sdk.Context, - portID, - channelID string, -) error { - // call underlying app's OnChanOpenConfirm callback. - return im.app.OnChanOpenConfirm(ctx, portID, channelID) -} - -// OnChanCloseInit implements the IBCMiddleware interface -func (im IBCMiddleware) OnChanCloseInit( - ctx sdk.Context, - portID, - channelID string, -) error { - // call underlying app's OnChanCloseInit callback. - return im.app.OnChanCloseInit(ctx, portID, channelID) -} - -// OnChanCloseConfirm implements the IBCMiddleware interface -func (im IBCMiddleware) OnChanCloseConfirm( - ctx sdk.Context, - portID, - channelID string, -) error { - // call underlying app's OnChanCloseConfirm callback. - return im.app.OnChanCloseConfirm(ctx, portID, channelID) -} - -// OnRecvPacket implements the IBCMiddleware interface. -// If fees are not enabled, this callback will default to the ibc-core packet callback -func (im IBCMiddleware) OnRecvPacket( - ctx sdk.Context, - packet channeltypes.Packet, - relayer sdk.AccAddress, -) exported.Acknowledgement { - // first do the underlying ibc app callback - ack := im.app.OnRecvPacket(ctx, packet, relayer) - - // postprocess the ibc application by executing a callback to the receiver smart contract - // if the receiver of the transfer packet is a smart contract - var data transfertypes.FungibleTokenPacketData - if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err == nil { - // check if data.Receiver is a smart contract address - // if it is a smart contract address - // then call the smart-contract defined callback for RecvPacket and pass in the transfer packet data - // if the callback returns an error, then return an error acknowledgement - if isSmartContract(data.Receiver) { - err := data.Receiver.recvPacketCallback(data) - if err != nil { - return channeltypes.NewErrorAcknowledgement(err) - } - } - } - return ack -} - -// OnAcknowledgementPacket implements the IBCMiddleware interface -// If fees are not enabled, this callback will default to the ibc-core packet callback -func (im IBCMiddleware) OnAcknowledgementPacket( - ctx sdk.Context, - packet channeltypes.Packet, - acknowledgement []byte, - relayer sdk.AccAddress, -) error { - // call underlying callback - err := im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) - - // postprocess the ibc application by executing a callback to the sender smart contract - // if the sender of the transfer packet is a smart contract - var data transfertypes.FungibleTokenPacketData - if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err == nil { - // check if data.Sender is a smart contract address - // if it is a smart contract address - // then call the smart-contract defined callback for RecvPacket and pass in the transfer packet data - // if the callback returns an error, then return an error - if isSmartContract(data.Sender) { - data.Sender.ackPacketCallback(data) - } - } - return err -} - -// OnTimeoutPacket implements the IBCMiddleware interface -// If fees are not enabled, this callback will default to the ibc-core packet callback -func (im IBCMiddleware) OnTimeoutPacket( - ctx sdk.Context, - packet channeltypes.Packet, - relayer sdk.AccAddress, -) error { - // call underlying callback - err := im.app.OnTimeoutPacket(ctx, packet, relayer) - - // postprocess the ibc application by executing a callback to the sender smart contract - // if the sender of the transfer packet is a smart contract - var data transfertypes.FungibleTokenPacketData - if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err == nil { - // check if data.Sender is a smart contract address - // if it is a smart contract address - // then call the smart-contract defined callback for RecvPacket and pass in the transfer packet data - // if the callback returns an error, then return an error - if isSmartContract(data.Sender) { - data.Sender.timeoutPacketCallback(data) - } - } - return err -} - -// SendPacket implements the ICS4 Wrapper interface -func (im IBCMiddleware) SendPacket( - ctx sdk.Context, - chanCap *capabilitytypes.Capability, - sourcePort string, - sourceChannel string, - timeoutHeight clienttypes.Height, - timeoutTimestamp uint64, - data []byte, -) (uint64, error) { - return im.chanWrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) -} - -// WriteAcknowledgement implements the ICS4 Wrapper interface -func (im IBCMiddleware) WriteAcknowledgement( - ctx sdk.Context, - chanCap *capabilitytypes.Capability, - packet exported.PacketI, - ack exported.Acknowledgement, -) error { - return im.chanWrapper.WriteAcknowledgement(ctx, chanCap, packet, ack) -} - -// GetAppVersion returns the application version of the underlying application -func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { - return im.chanWrapper.GetAppVersion(ctx, portID, channelID) -} -``` \ No newline at end of file diff --git a/docs/dev/project-structure.md b/docs/dev/project-structure.md index bb8e697d904..5056b325625 100644 --- a/docs/dev/project-structure.md +++ b/docs/dev/project-structure.md @@ -1,6 +1,6 @@ # Project structure -If you're not familiar with the overall module structure from the SDK modules, please check this [document](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/build/building-modules/11-structure.md) as prerequisite reading. +If you're not familiar with the overall module structure from the SDK modules, please check this [document](https://github.com/cosmos/cosmos-sdk/blob/main/docs/build/building-modules/11-structure.md) as prerequisite reading. Every Interchain Standard (ICS) has been developed in its own package. The development team separated the IBC TAO (Transport, Authentication, Ordering) ICS specifications from the IBC application level specification. The following sections describe the architecture of the most relevant directories that comprise this repository. diff --git a/docs/ibc/apps.md b/docs/ibc/apps.md index 7e5293bfd0a..acb05a9c8c7 100644 --- a/docs/ibc/apps.md +++ b/docs/ibc/apps.md @@ -488,4 +488,4 @@ callbacks](https://github.com/cosmos/ibc-go/blob/main/modules/apps/transfer/ibc_ ## Next {hide} -Learn about [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/build/building-modules/00-intro.md) {hide} +Learn about [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/build/building-modules/00-intro.md) {hide} diff --git a/docs/ibc/apps/apps.md b/docs/ibc/apps/apps.md index 93f86d464b0..7798c903b6c 100644 --- a/docs/ibc/apps/apps.md +++ b/docs/ibc/apps/apps.md @@ -48,4 +48,4 @@ callbacks](https://github.com/cosmos/ibc-go/blob/main/modules/apps/transfer/ibc_ ## Next {hide} -Learn about [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/build/building-modules/00-intro.md) {hide} +Learn about [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/build/building-modules/00-intro.md) {hide} diff --git a/docs/ibc/integration.md b/docs/ibc/integration.md index ec8a78765f9..97482bd450c 100644 --- a/docs/ibc/integration.md +++ b/docs/ibc/integration.md @@ -157,7 +157,7 @@ func NewApp(...args) *App { ### Module Managers -In order to use IBC, we need to add the new modules to the module `Manager` and to the `SimulationManager` in case your application supports [simulations](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/build/building-modules/14-simulator.md). +In order to use IBC, we need to add the new modules to the module `Manager` and to the `SimulationManager` in case your application supports [simulations](https://github.com/cosmos/cosmos-sdk/blob/main/docs/build/building-modules/14-simulator.md). ```go // app.go diff --git a/docs/ibc/overview.md b/docs/ibc/overview.md index 68c6d31ed8e..ca7c406a6cf 100644 --- a/docs/ibc/overview.md +++ b/docs/ibc/overview.md @@ -136,7 +136,7 @@ Proofs are passed from core IBC to light-clients as bytes. It is up to light cli [ICS-24 Host State Machine Requirements](https://github.com/cosmos/ics/tree/master/spec/core/ics-024-host-requirements). - The proof format that all implementations must be able to produce and verify is defined in [ICS-23 Proofs](https://github.com/cosmos/ics23) implementation. -### [Capabilities](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/develop/advanced/10-ocap.md) +### [Capabilities](https://github.com/cosmos/cosmos-sdk/blob/main/docs/develop/advanced/10-ocap.md) IBC is intended to work in execution environments where modules do not necessarily trust each other. Thus, IBC must authenticate module actions on ports and channels so that only modules with the diff --git a/docs/ibc/relayer.md b/docs/ibc/relayer.md index 7da4e73bf92..7348a854b09 100644 --- a/docs/ibc/relayer.md +++ b/docs/ibc/relayer.md @@ -7,7 +7,7 @@ order: 6 ## Pre-requisites Readings - [IBC Overview](./overview.md) {prereq} -- [Events](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/develop/advanced/08-events.md) {prereq} +- [Events](https://github.com/cosmos/cosmos-sdk/blob/main/docs/develop/advanced/08-events.md) {prereq} ## Events diff --git a/docs/middleware/callbacks/overview.md b/docs/middleware/callbacks/overview.md index 9a10b53388a..c7e64c28d4c 100644 --- a/docs/middleware/callbacks/overview.md +++ b/docs/middleware/callbacks/overview.md @@ -14,7 +14,7 @@ This setup worked well for off-chain users interacting with IBC applications. Ho The Callbacks Middleware allows for this functionality by allowing the packets of the underlying IBC applications to register callbacks to secondary applications for lifecycle events. These callbacks are then executed by the Callbacks Middleware when the corresponding packet lifecycle event occurs. -After much discussion, the design was expanded to [an ADR](../../architecture/adr-008-app-caller-cbs/adr-008-app-caller-cbs.md), and the Callbacks Middleware is an implementation of that ADR. +After much discussion, the design was expanded to [an ADR](../../architecture/adr-008-app-caller-cbs.md), and the Callbacks Middleware is an implementation of that ADR. ## Concepts diff --git a/docs/middleware/ics29-fee/fee-distribution.md b/docs/middleware/ics29-fee/fee-distribution.md index d1be7e2ff8a..6efb9972fd5 100644 --- a/docs/middleware/ics29-fee/fee-distribution.md +++ b/docs/middleware/ics29-fee/fee-distribution.md @@ -50,7 +50,7 @@ type MsgRegisterCounterpartyPayee struct { > > - `PortId` is invalid (see [24-host naming requirements](https://github.com/cosmos/ibc/blob/master/spec/core/ics-024-host-requirements/README.md#paths-identifiers-separators). > - `ChannelId` is invalid (see [24-host naming requirements](https://github.com/cosmos/ibc/blob/master/spec/core/ics-024-host-requirements/README.md#paths-identifiers-separators)). -> - `Relayer` is an invalid address (see [Cosmos SDK Addresses](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/develop/beginner/03-accounts.md#addresses)). +> - `Relayer` is an invalid address (see [Cosmos SDK Addresses](https://github.com/cosmos/cosmos-sdk/blob/main/docs/develop/beginner/03-accounts.md#addresses)). > - `CounterpartyPayee` is empty. See below for an example CLI command: @@ -95,8 +95,8 @@ type MsgRegisterPayee struct { > > - `PortId` is invalid (see [24-host naming requirements](https://github.com/cosmos/ibc/blob/master/spec/core/ics-024-host-requirements/README.md#paths-identifiers-separators). > - `ChannelId` is invalid (see [24-host naming requirements](https://github.com/cosmos/ibc/blob/master/spec/core/ics-024-host-requirements/README.md#paths-identifiers-separators)). -> - `Relayer` is an invalid address (see [Cosmos SDK Addresses](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/develop/beginner/03-accounts.md#addresses)). -> - `Payee` is an invalid address (see [Cosmos SDK Addresses](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/develop/beginner/03-accounts.md#addresses)). +> - `Relayer` is an invalid address (see [Cosmos SDK Addresses](https://github.com/cosmos/cosmos-sdk/blob/main/docs/develop/beginner/03-accounts.md#addresses)). +> - `Payee` is an invalid address (see [Cosmos SDK Addresses](https://github.com/cosmos/cosmos-sdk/blob/main/docs/develop/beginner/03-accounts.md#addresses)). See below for an example CLI command: diff --git a/e2e/go.mod b/e2e/go.mod index b8d87d09dfa..994f00ace1e 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -13,7 +13,7 @@ require ( github.com/docker/docker v24.0.6+incompatible github.com/strangelove-ventures/interchaintest/v8 v8.0.0-20230913202406-3e11bf474a3b github.com/stretchr/testify v1.8.4 - go.uber.org/zap v1.25.0 + go.uber.org/zap v1.26.0 golang.org/x/mod v0.12.0 google.golang.org/grpc v1.58.1 gopkg.in/yaml.v2 v2.4.0 @@ -44,7 +44,6 @@ require ( github.com/Microsoft/go-winio v0.6.0 // indirect github.com/avast/retry-go/v4 v4.5.0 // indirect github.com/aws/aws-sdk-go v1.44.224 // indirect - github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect diff --git a/e2e/go.sum b/e2e/go.sum index 5be620ef1ae..966d0bde030 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -267,8 +267,6 @@ github.com/aws/aws-sdk-go v1.44.224 h1:09CiaaF35nRmxrzWZ2uRq5v6Ghg/d2RiPjZnSgtt+ github.com/aws/aws-sdk-go v1.44.224/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= -github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= -github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -1079,8 +1077,8 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= -go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c= -go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= diff --git a/e2e/sample.config.yaml b/e2e/sample.config.yaml index 5392ad5664d..e7e185737ac 100644 --- a/e2e/sample.config.yaml +++ b/e2e/sample.config.yaml @@ -5,7 +5,7 @@ --- chains: # the entry at index 0 corresponds to CHAIN_A -- chainId: chain-a +- chainId: chainA-1 numValidators: 1 numFullNodes: 0 image: ghcr.io/cosmos/ibc-go-simd # override with CHAIN_IMAGE @@ -13,7 +13,7 @@ chains: binary: simd # override with CHAIN_BINARY # the entry at index 1 corresponds to CHAIN_B -- chainId: chain-b +- chainId: chainB-1 numValidators: 1 numFullNodes: 0 image: ghcr.io/cosmos/ibc-go-simd # override with CHAIN_IMAGE diff --git a/e2e/tests/core/02-client/client_test.go b/e2e/tests/core/02-client/client_test.go index 319159a6d8b..a3dfedcc6f8 100644 --- a/e2e/tests/core/02-client/client_test.go +++ b/e2e/tests/core/02-client/client_test.go @@ -94,9 +94,9 @@ func (s *ClientTestSuite) TestScheduleIBCUpgrade_Succeeds() { s.Require().NoError(err) originalChainID := clientState.(*ibctm.ClientState).ChainId - revisionNumber := clienttypes.ParseChainID(fmt.Sprintf("%s-%d", originalChainID, 1)) + revisionNumber := clienttypes.ParseChainID(originalChainID) // increment revision number even with new chain ID to prevent loss of misbehaviour detection support - newChainID, err = clienttypes.SetRevisionNumber(fmt.Sprintf("%s-%d", originalChainID, 1), revisionNumber+1) + newChainID, err = clienttypes.SetRevisionNumber(originalChainID, revisionNumber+1) s.Require().NoError(err) s.Require().NotEqual(originalChainID, newChainID) diff --git a/e2e/testsuite/testconfig.go b/e2e/testsuite/testconfig.go index 541770be982..18c64bb2b67 100644 --- a/e2e/testsuite/testconfig.go +++ b/e2e/testsuite/testconfig.go @@ -114,7 +114,7 @@ func (tc TestConfig) GetChainAID() string { if tc.ChainConfigs[0].ChainID != "" { return tc.ChainConfigs[0].ChainID } - return "chain-a" + return "chainA-1" } // GetChainBID returns the chain-id for chain B. @@ -122,7 +122,7 @@ func (tc TestConfig) GetChainBID() string { if tc.ChainConfigs[1].ChainID != "" { return tc.ChainConfigs[1].ChainID } - return "chain-b" + return "chainB-1" } // UpgradeConfig holds values relevant to upgrade tests. diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 3dd1d3342a6..78980421d65 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -52,6 +52,10 @@ func NewKeeper( legacySubspace = legacySubspace.WithKeyTable(types.ParamKeyTable()) } + if strings.TrimSpace(authority) == "" { + panic(fmt.Errorf("authority must be non-empty")) + } + return Keeper{ storeKey: key, cdc: cdc, diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go index 22e01d1a697..68abb999c2e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" @@ -107,6 +108,58 @@ func TestKeeperTestSuite(t *testing.T) { testifysuite.Run(t, new(KeeperTestSuite)) } +func (suite *KeeperTestSuite) TestNewKeeper() { + testCases := []struct { + name string + instantiateFn func() + expPass bool + }{ + {"success", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + suite.chainA.GetSimApp().ScopedICAControllerKeeper, + suite.chainA.GetSimApp().MsgServiceRouter(), + suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(), + ) + }, true}, + {"failure: empty authority", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + suite.chainA.GetSimApp().ScopedICAControllerKeeper, + suite.chainA.GetSimApp().MsgServiceRouter(), + "", // authority + ) + }, false}, + } + + for _, tc := range testCases { + tc := tc + suite.SetupTest() + + suite.Run(tc.name, func() { + if tc.expPass { + suite.Require().NotPanics( + tc.instantiateFn, + ) + } else { + suite.Require().Panics( + tc.instantiateFn, + ) + } + }) + } +} + func (suite *KeeperTestSuite) TestGetAllPorts() { suite.SetupTest() diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index c9e442854e6..b60ac4d652c 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -59,6 +59,10 @@ func NewKeeper( legacySubspace = legacySubspace.WithKeyTable(types.ParamKeyTable()) } + if strings.TrimSpace(authority) == "" { + panic(fmt.Errorf("authority must be non-empty")) + } + return Keeper{ storeKey: key, cdc: cdc, diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 0c44b0f10d4..a0acc4b21d6 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -6,7 +6,10 @@ import ( testifysuite "github.com/stretchr/testify/suite" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper" @@ -127,6 +130,74 @@ func TestKeeperTestSuite(t *testing.T) { testifysuite.Run(t, new(KeeperTestSuite)) } +func (suite *KeeperTestSuite) TestNewKeeper() { + testCases := []struct { + name string + instantiateFn func() + expPass bool + }{ + {"success", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + suite.chainA.GetSimApp().AccountKeeper, + suite.chainA.GetSimApp().ScopedICAHostKeeper, + suite.chainA.GetSimApp().MsgServiceRouter(), + suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), + ) + }, true}, + {"failure: interchain accounts module account does not exist", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + authkeeper.AccountKeeper{}, // empty account keeper + suite.chainA.GetSimApp().ScopedICAHostKeeper, + suite.chainA.GetSimApp().MsgServiceRouter(), + suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), + ) + }, false}, + {"failure: empty mock staking keeper", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + suite.chainA.GetSimApp().AccountKeeper, + suite.chainA.GetSimApp().ScopedICAHostKeeper, + suite.chainA.GetSimApp().MsgServiceRouter(), + "", // authority + ) + }, false}, + } + + for _, tc := range testCases { + tc := tc + suite.SetupTest() + + suite.Run(tc.name, func() { + if tc.expPass { + suite.Require().NotPanics( + tc.instantiateFn, + ) + } else { + suite.Require().Panics( + tc.instantiateFn, + ) + } + }) + } +} + func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { suite.SetupTest() diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index e08857d7bf8..0236b295852 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -227,5 +227,6 @@ func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes. // RegisterStoreDecoder registers a decoder for interchain accounts module's types func (AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { - sdr[types.StoreKey] = simulation.NewDecodeStore() + sdr[controllertypes.StoreKey] = simulation.NewDecodeStore() + sdr[hosttypes.StoreKey] = simulation.NewDecodeStore() } diff --git a/modules/apps/27-interchain-accounts/types/keys.go b/modules/apps/27-interchain-accounts/types/keys.go index 2a062130ce2..ddd21716c61 100644 --- a/modules/apps/27-interchain-accounts/types/keys.go +++ b/modules/apps/27-interchain-accounts/types/keys.go @@ -17,9 +17,6 @@ const ( // Version defines the current version for interchain accounts Version = "ics27-1" - // StoreKey is the store key string for interchain accounts - StoreKey = ModuleName - // RouterKey is the message route for interchain accounts RouterKey = ModuleName diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 5a033980d87..e3e0da974fc 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -63,6 +63,10 @@ func NewKeeper( legacySubspace = legacySubspace.WithKeyTable(types.ParamKeyTable()) } + if strings.TrimSpace(authority) == "" { + panic(fmt.Errorf("authority must be non-empty")) + } + return Keeper{ cdc: cdc, storeKey: key, diff --git a/modules/apps/transfer/keeper/keeper_test.go b/modules/apps/transfer/keeper/keeper_test.go index 56afd3fcbd5..281bebd9aff 100644 --- a/modules/apps/transfer/keeper/keeper_test.go +++ b/modules/apps/transfer/keeper/keeper_test.go @@ -12,7 +12,9 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" ibctesting "github.com/cosmos/ibc-go/v8/testing" @@ -43,6 +45,74 @@ func TestKeeperTestSuite(t *testing.T) { testifysuite.Run(t, new(KeeperTestSuite)) } +func (suite *KeeperTestSuite) TestNewKeeper() { + testCases := []struct { + name string + instantiateFn func() + expPass bool + }{ + {"success", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.ModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + suite.chainA.GetSimApp().AccountKeeper, + suite.chainA.GetSimApp().BankKeeper, + suite.chainA.GetSimApp().ScopedTransferKeeper, + suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(), + ) + }, true}, + {"failure: transfer module account does not exist", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.ModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + authkeeper.AccountKeeper{}, // empty account keeper + suite.chainA.GetSimApp().BankKeeper, + suite.chainA.GetSimApp().ScopedTransferKeeper, + suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(), + ) + }, false}, + {"failure: empty authority", func() { + keeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(types.StoreKey), + suite.chainA.GetSimApp().GetSubspace(types.ModuleName), + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, + &suite.chainA.GetSimApp().IBCKeeper.PortKeeper, + suite.chainA.GetSimApp().AccountKeeper, + suite.chainA.GetSimApp().BankKeeper, + suite.chainA.GetSimApp().ScopedTransferKeeper, + "", // authority + ) + }, false}, + } + + for _, tc := range testCases { + tc := tc + suite.SetupTest() + + suite.Run(tc.name, func() { + if tc.expPass { + suite.Require().NotPanics( + tc.instantiateFn, + ) + } else { + suite.Require().Panics( + tc.instantiateFn, + ) + } + }) + } +} + func (suite *KeeperTestSuite) TestSetGetTotalEscrowForDenom() { const denom = "atom" var expAmount sdkmath.Int diff --git a/modules/apps/transfer/types/query.pb.go b/modules/apps/transfer/types/query.pb.go index e7e3343b0b4..2f7b696daa7 100644 --- a/modules/apps/transfer/types/query.pb.go +++ b/modules/apps/transfer/types/query.pb.go @@ -622,7 +622,7 @@ var fileDescriptor_a638e2800a01538c = []byte{ 0xc1, 0xd3, 0x40, 0x20, 0x1c, 0xa0, 0x52, 0xa1, 0xa5, 0xa5, 0xea, 0x01, 0x02, 0xa7, 0x72, 0x88, 0x26, 0xf6, 0xd4, 0xb1, 0x94, 0x78, 0x8c, 0xc7, 0x49, 0x85, 0x22, 0x2e, 0xfd, 0x04, 0x95, 0xf8, 0x12, 0x55, 0xa5, 0x6a, 0xbf, 0xc2, 0x1e, 0x39, 0xa2, 0x5d, 0x69, 0xc5, 0x69, 0x77, 0x05, 0xfb, - 0x41, 0x56, 0x1e, 0x8f, 0x13, 0x7b, 0x09, 0x21, 0xd9, 0x53, 0x3c, 0xf3, 0xfe, 0xfd, 0x7e, 0xef, + 0x41, 0x56, 0x1e, 0x8f, 0x13, 0x7b, 0x09, 0x21, 0xd9, 0x53, 0x3c, 0xf3, 0xfe, 0xfd, 0x7e, 0xbf, 0x37, 0xef, 0x29, 0xb0, 0xe2, 0xd4, 0x4c, 0x4c, 0x3c, 0xaf, 0xe1, 0x98, 0x24, 0x70, 0x98, 0xcb, 0x71, 0xe0, 0x13, 0x97, 0xff, 0x49, 0x7d, 0xdc, 0x2e, 0xe2, 0xf3, 0x16, 0xf5, 0x2f, 0x0c, 0xcf, 0x67, 0x01, 0x43, 0x0b, 0x4e, 0xcd, 0x34, 0x92, 0x9e, 0x46, 0xec, 0x69, 0xb4, 0x8b, 0xea, 0x8c, @@ -633,42 +633,42 @@ var fileDescriptor_a638e2800a01538c = []byte{ 0xea, 0xab, 0xf0, 0xe5, 0x71, 0x58, 0xec, 0x27, 0xea, 0xb2, 0xe6, 0xa9, 0x4f, 0x4c, 0x5a, 0xa1, 0xe7, 0x2d, 0xca, 0x03, 0x84, 0x60, 0xbc, 0x4e, 0x78, 0x7d, 0x4e, 0x59, 0x52, 0x56, 0x72, 0x15, 0xf1, 0xad, 0x5b, 0x30, 0xfb, 0xc0, 0x9b, 0x7b, 0xcc, 0xe5, 0x14, 0x1d, 0x42, 0xde, 0x0a, 0x6f, - 0xab, 0x41, 0x78, 0x2d, 0xa2, 0xf2, 0xeb, 0x2b, 0xc6, 0xa0, 0x4e, 0x19, 0x89, 0x34, 0x60, 0x75, - 0xbf, 0x75, 0xf2, 0xa0, 0x0a, 0x8f, 0x41, 0x1d, 0x00, 0xf4, 0xba, 0x21, 0x8b, 0x7c, 0x63, 0x44, - 0xad, 0x33, 0xc2, 0xd6, 0x19, 0x91, 0x4e, 0xb2, 0x75, 0xc6, 0x11, 0xb1, 0x63, 0x42, 0x95, 0x44, - 0xa4, 0xfe, 0x5c, 0x81, 0xb9, 0x87, 0x35, 0x24, 0x95, 0x33, 0xf8, 0x3c, 0x41, 0x85, 0xcf, 0x29, - 0x4b, 0x9f, 0x8c, 0xc2, 0x65, 0x6f, 0xea, 0xfa, 0xf5, 0x62, 0xe6, 0xbf, 0x37, 0x8b, 0x59, 0x99, - 0x37, 0xdf, 0xe3, 0xc6, 0xd1, 0x2f, 0x29, 0x06, 0x63, 0x82, 0xc1, 0xb7, 0x4f, 0x32, 0x88, 0x90, - 0xa5, 0x28, 0xcc, 0x00, 0x12, 0x0c, 0x8e, 0x88, 0x4f, 0x9a, 0x71, 0x83, 0xf4, 0x13, 0x98, 0x4e, - 0xdd, 0x4a, 0x4a, 0x3b, 0x90, 0xf5, 0xc4, 0x8d, 0xec, 0xd9, 0xf2, 0x60, 0x32, 0x32, 0x5a, 0xc6, - 0xe8, 0x6b, 0xf0, 0x45, 0xaf, 0x59, 0xbf, 0x12, 0x5e, 0x8f, 0xe5, 0x98, 0x81, 0x89, 0x9e, 0xdc, - 0xb9, 0x4a, 0x74, 0x48, 0xbf, 0xa9, 0xc8, 0x5d, 0xc2, 0xe8, 0xf7, 0xa6, 0x4e, 0x60, 0x5e, 0x78, - 0xff, 0xcc, 0x4d, 0x9f, 0xfd, 0xf5, 0xa3, 0x65, 0xf9, 0x94, 0x77, 0xf5, 0x9e, 0x85, 0x4f, 0x3d, - 0xe6, 0x07, 0x55, 0xc7, 0x92, 0x31, 0xd9, 0xf0, 0x78, 0x68, 0xa1, 0xaf, 0x00, 0xcc, 0x3a, 0x71, - 0x5d, 0xda, 0x08, 0x6d, 0x63, 0xc2, 0x96, 0x93, 0x37, 0x87, 0x96, 0xbe, 0x0f, 0x6a, 0xbf, 0xa4, - 0x12, 0xc6, 0xd7, 0x30, 0x45, 0x85, 0xa1, 0x4a, 0x22, 0x8b, 0x4c, 0x3e, 0x49, 0x93, 0xee, 0x7a, - 0x19, 0x16, 0x45, 0x92, 0x53, 0x16, 0x90, 0x46, 0x94, 0xe9, 0x80, 0xf9, 0x82, 0x55, 0xa2, 0x01, - 0x42, 0xdc, 0xb8, 0x01, 0xe2, 0xa0, 0x9f, 0xc1, 0xd2, 0xe3, 0x81, 0x12, 0x43, 0x19, 0xb2, 0xa4, - 0xc9, 0x5a, 0x6e, 0x20, 0x15, 0x99, 0x4f, 0xbd, 0x81, 0x58, 0xfd, 0x7d, 0xe6, 0xb8, 0x7b, 0xe3, - 0xe1, 0x7b, 0xaa, 0x48, 0xf7, 0xf5, 0xdb, 0xcf, 0x60, 0x42, 0x64, 0x47, 0xcf, 0x14, 0x80, 0xde, - 0xb3, 0x43, 0xa5, 0xc1, 0x9a, 0xf6, 0x1f, 0x73, 0x75, 0x73, 0xc4, 0xa8, 0x08, 0xbe, 0x5e, 0xfa, - 0xfb, 0xe5, 0xbb, 0xab, 0x31, 0x03, 0xad, 0x62, 0xb9, 0x8b, 0xd2, 0x3b, 0x28, 0x39, 0x3f, 0xb8, - 0x13, 0xea, 0xbc, 0x5b, 0x28, 0x5c, 0xa2, 0x7f, 0x15, 0xc8, 0x27, 0x26, 0x0e, 0x8d, 0x56, 0x3c, - 0x7e, 0x15, 0xea, 0xd6, 0xa8, 0x61, 0x12, 0x74, 0x41, 0x80, 0x5e, 0x46, 0xfa, 0xd3, 0xa0, 0xd1, - 0x95, 0x02, 0xd9, 0x68, 0x0c, 0xd0, 0xf7, 0x43, 0x94, 0x4b, 0x4d, 0xa1, 0x5a, 0x1c, 0x21, 0x42, - 0x62, 0x5b, 0x16, 0xd8, 0x34, 0xb4, 0xd0, 0x1f, 0x5b, 0x34, 0x89, 0xe8, 0x7f, 0x05, 0x72, 0xdd, - 0xb1, 0x42, 0x1b, 0xc3, 0xf6, 0x21, 0x31, 0xb3, 0x6a, 0x69, 0xb4, 0x20, 0x09, 0x6f, 0x53, 0xc0, - 0xc3, 0x68, 0x6d, 0x50, 0xeb, 0x42, 0x9d, 0x43, 0xbd, 0x45, 0x0b, 0x85, 0xe0, 0xaf, 0x14, 0x98, - 0x4c, 0xcd, 0x20, 0x2a, 0x0f, 0x51, 0xbe, 0xdf, 0x2a, 0x50, 0xb7, 0x47, 0x0f, 0x94, 0xd8, 0x2b, - 0x02, 0xfb, 0xef, 0xe8, 0xb7, 0xfe, 0xd8, 0xe5, 0xd6, 0xe0, 0xb8, 0xd3, 0xdb, 0x28, 0x97, 0x38, - 0xdc, 0x33, 0x1c, 0x77, 0xe4, 0xf6, 0xb9, 0xc4, 0xe9, 0x85, 0x81, 0x5e, 0x28, 0x30, 0xdd, 0x67, - 0xbc, 0xd1, 0xee, 0x10, 0x28, 0x1f, 0xdf, 0x27, 0xea, 0x0f, 0x1f, 0x1b, 0x2e, 0xa9, 0xee, 0x08, - 0xaa, 0x5b, 0xa8, 0x34, 0x40, 0x26, 0x8e, 0x3b, 0xe2, 0x37, 0x14, 0x08, 0x07, 0x61, 0xb2, 0x6a, - 0x44, 0x6e, 0xef, 0xf8, 0xfa, 0x4e, 0x53, 0x6e, 0xee, 0x34, 0xe5, 0xed, 0x9d, 0xa6, 0xfc, 0x73, - 0xaf, 0x65, 0x6e, 0xee, 0xb5, 0xcc, 0xed, 0xbd, 0x96, 0xf9, 0xa3, 0x6c, 0x3b, 0x41, 0xbd, 0x55, - 0x33, 0x4c, 0xd6, 0xc4, 0xf2, 0x8f, 0x8a, 0x53, 0x33, 0xd7, 0x6c, 0x86, 0xdb, 0xdb, 0xb8, 0xc9, - 0xac, 0x56, 0x83, 0xf2, 0x0f, 0xca, 0x05, 0x17, 0x1e, 0xe5, 0xb5, 0xac, 0xf8, 0x9b, 0xb1, 0xf1, - 0x3e, 0x00, 0x00, 0xff, 0xff, 0x78, 0xf1, 0x3d, 0x9d, 0x5d, 0x09, 0x00, 0x00, + 0xab, 0x41, 0x78, 0x2d, 0xa2, 0xf2, 0xeb, 0x2b, 0xc6, 0x20, 0xa5, 0x8c, 0x44, 0x1a, 0xb0, 0xba, + 0xdf, 0x3a, 0x79, 0x50, 0x85, 0xc7, 0xa0, 0x0e, 0x00, 0x7a, 0x6a, 0xc8, 0x22, 0xdf, 0x18, 0x91, + 0x74, 0x46, 0x28, 0x9d, 0x11, 0xf5, 0x49, 0x4a, 0x67, 0x1c, 0x11, 0x3b, 0x26, 0x54, 0x49, 0x44, + 0xea, 0xcf, 0x15, 0x98, 0x7b, 0x58, 0x43, 0x52, 0x39, 0x83, 0xcf, 0x13, 0x54, 0xf8, 0x9c, 0xb2, + 0xf4, 0xc9, 0x28, 0x5c, 0xf6, 0xa6, 0xae, 0x5f, 0x2f, 0x66, 0xfe, 0x7b, 0xb3, 0x98, 0x95, 0x79, + 0xf3, 0x3d, 0x6e, 0x1c, 0xfd, 0x92, 0x62, 0x30, 0x26, 0x18, 0x7c, 0xfb, 0x24, 0x83, 0x08, 0x59, + 0x8a, 0xc2, 0x0c, 0x20, 0xc1, 0xe0, 0x88, 0xf8, 0xa4, 0x19, 0x0b, 0xa4, 0x9f, 0xc0, 0x74, 0xea, + 0x56, 0x52, 0xda, 0x81, 0xac, 0x27, 0x6e, 0xa4, 0x66, 0xcb, 0x83, 0xc9, 0xc8, 0x68, 0x19, 0xa3, + 0xaf, 0xc1, 0x17, 0x3d, 0xb1, 0x7e, 0x25, 0xbc, 0x1e, 0xb7, 0x63, 0x06, 0x26, 0x7a, 0xed, 0xce, + 0x55, 0xa2, 0x43, 0xfa, 0x4d, 0x45, 0xee, 0x12, 0x46, 0xbf, 0x37, 0x75, 0x02, 0xf3, 0xc2, 0xfb, + 0x67, 0x6e, 0xfa, 0xec, 0xaf, 0x1f, 0x2d, 0xcb, 0xa7, 0xbc, 0xdb, 0xef, 0x59, 0xf8, 0xd4, 0x63, + 0x7e, 0x50, 0x75, 0x2c, 0x19, 0x93, 0x0d, 0x8f, 0x87, 0x16, 0xfa, 0x0a, 0xc0, 0xac, 0x13, 0xd7, + 0xa5, 0x8d, 0xd0, 0x36, 0x26, 0x6c, 0x39, 0x79, 0x73, 0x68, 0xe9, 0xfb, 0xa0, 0xf6, 0x4b, 0x2a, + 0x61, 0x7c, 0x0d, 0x53, 0x54, 0x18, 0xaa, 0x24, 0xb2, 0xc8, 0xe4, 0x93, 0x34, 0xe9, 0xae, 0x97, + 0x61, 0x51, 0x24, 0x39, 0x65, 0x01, 0x69, 0x44, 0x99, 0x0e, 0x98, 0x2f, 0x58, 0x25, 0x04, 0x10, + 0xcd, 0x8d, 0x05, 0x10, 0x07, 0xfd, 0x0c, 0x96, 0x1e, 0x0f, 0x94, 0x18, 0xca, 0x90, 0x25, 0x4d, + 0xd6, 0x72, 0x03, 0xd9, 0x91, 0xf9, 0xd4, 0x1b, 0x88, 0xbb, 0xbf, 0xcf, 0x1c, 0x77, 0x6f, 0x3c, + 0x7c, 0x4f, 0x15, 0xe9, 0xbe, 0x7e, 0xfb, 0x19, 0x4c, 0x88, 0xec, 0xe8, 0x5f, 0x05, 0xf2, 0x89, + 0xf7, 0x8b, 0x36, 0x07, 0x37, 0xf5, 0x91, 0x99, 0x52, 0xb7, 0x46, 0x0d, 0x8b, 0x18, 0xe8, 0x85, + 0xbf, 0x5f, 0xbe, 0xbb, 0x1a, 0x5b, 0x46, 0x3a, 0x96, 0xeb, 0x28, 0xbd, 0x86, 0x92, 0x23, 0x84, + 0x9e, 0x29, 0x00, 0xbd, 0x1c, 0xa8, 0x34, 0x52, 0xc9, 0x18, 0xe8, 0xe6, 0x88, 0x51, 0x12, 0x67, + 0x49, 0xe0, 0x34, 0xd0, 0xea, 0xd3, 0x38, 0x71, 0x27, 0x7c, 0x92, 0xbb, 0x85, 0xc2, 0x25, 0xba, + 0x52, 0x20, 0x1b, 0x8d, 0x01, 0xfa, 0x7e, 0x88, 0xba, 0xa9, 0x29, 0x54, 0x8b, 0x23, 0x44, 0x48, + 0x94, 0xcb, 0x02, 0xa5, 0x86, 0x16, 0xfa, 0xa3, 0x8c, 0x26, 0x11, 0xfd, 0xaf, 0x40, 0xae, 0x3b, + 0x56, 0x68, 0x63, 0x58, 0x41, 0x12, 0x33, 0xab, 0x96, 0x46, 0x0b, 0x92, 0xf0, 0x36, 0x05, 0x3c, + 0x8c, 0xd6, 0x06, 0x89, 0x18, 0x8a, 0x17, 0x8a, 0x28, 0xc4, 0x14, 0x2a, 0xbe, 0x52, 0x60, 0x32, + 0x35, 0x83, 0xa8, 0x3c, 0x44, 0xf9, 0x7e, 0xab, 0x40, 0xdd, 0x1e, 0x3d, 0x50, 0x62, 0xaf, 0x08, + 0xec, 0xbf, 0xa3, 0xdf, 0xfa, 0x63, 0x97, 0x5b, 0x83, 0xe3, 0x4e, 0x6f, 0xa3, 0x5c, 0xe2, 0x70, + 0xcf, 0x70, 0xdc, 0x91, 0xdb, 0xe7, 0x12, 0xa7, 0x17, 0x06, 0x7a, 0xa1, 0xc0, 0x74, 0x9f, 0xf1, + 0x46, 0xbb, 0x43, 0xa0, 0x7c, 0x7c, 0x9f, 0xa8, 0x3f, 0x7c, 0x6c, 0xb8, 0xa4, 0xba, 0x23, 0xa8, + 0x6e, 0xa1, 0xd2, 0x80, 0x36, 0x71, 0xdc, 0x11, 0xbf, 0x61, 0x83, 0x70, 0x10, 0x26, 0xab, 0x46, + 0xe4, 0xf6, 0x8e, 0xaf, 0xef, 0x34, 0xe5, 0xe6, 0x4e, 0x53, 0xde, 0xde, 0x69, 0xca, 0x3f, 0xf7, + 0x5a, 0xe6, 0xe6, 0x5e, 0xcb, 0xdc, 0xde, 0x6b, 0x99, 0x3f, 0xca, 0xb6, 0x13, 0xd4, 0x5b, 0x35, + 0xc3, 0x64, 0x4d, 0x2c, 0xff, 0xa8, 0x38, 0x35, 0x73, 0xcd, 0x66, 0xb8, 0xbd, 0x8d, 0x9b, 0xcc, + 0x6a, 0x35, 0x28, 0xff, 0xa0, 0x5c, 0x70, 0xe1, 0x51, 0x5e, 0xcb, 0x8a, 0xbf, 0x19, 0x1b, 0xef, + 0x03, 0x00, 0x00, 0xff, 0xff, 0xb4, 0x97, 0xb6, 0x42, 0x5d, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -683,10 +683,10 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // DenomTrace queries a denomination trace information. - DenomTrace(ctx context.Context, in *QueryDenomTraceRequest, opts ...grpc.CallOption) (*QueryDenomTraceResponse, error) // DenomTraces queries all denomination traces. DenomTraces(ctx context.Context, in *QueryDenomTracesRequest, opts ...grpc.CallOption) (*QueryDenomTracesResponse, error) + // DenomTrace queries a denomination trace information. + DenomTrace(ctx context.Context, in *QueryDenomTraceRequest, opts ...grpc.CallOption) (*QueryDenomTraceResponse, error) // Params queries all parameters of the ibc-transfer module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) // DenomHash queries a denomination hash information. @@ -705,18 +705,18 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) DenomTrace(ctx context.Context, in *QueryDenomTraceRequest, opts ...grpc.CallOption) (*QueryDenomTraceResponse, error) { - out := new(QueryDenomTraceResponse) - err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v1.Query/DenomTrace", in, out, opts...) +func (c *queryClient) DenomTraces(ctx context.Context, in *QueryDenomTracesRequest, opts ...grpc.CallOption) (*QueryDenomTracesResponse, error) { + out := new(QueryDenomTracesResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v1.Query/DenomTraces", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *queryClient) DenomTraces(ctx context.Context, in *QueryDenomTracesRequest, opts ...grpc.CallOption) (*QueryDenomTracesResponse, error) { - out := new(QueryDenomTracesResponse) - err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v1.Query/DenomTraces", in, out, opts...) +func (c *queryClient) DenomTrace(ctx context.Context, in *QueryDenomTraceRequest, opts ...grpc.CallOption) (*QueryDenomTraceResponse, error) { + out := new(QueryDenomTraceResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v1.Query/DenomTrace", in, out, opts...) if err != nil { return nil, err } @@ -761,10 +761,10 @@ func (c *queryClient) TotalEscrowForDenom(ctx context.Context, in *QueryTotalEsc // QueryServer is the server API for Query service. type QueryServer interface { - // DenomTrace queries a denomination trace information. - DenomTrace(context.Context, *QueryDenomTraceRequest) (*QueryDenomTraceResponse, error) // DenomTraces queries all denomination traces. DenomTraces(context.Context, *QueryDenomTracesRequest) (*QueryDenomTracesResponse, error) + // DenomTrace queries a denomination trace information. + DenomTrace(context.Context, *QueryDenomTraceRequest) (*QueryDenomTraceResponse, error) // Params queries all parameters of the ibc-transfer module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) // DenomHash queries a denomination hash information. @@ -779,12 +779,12 @@ type QueryServer interface { type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) DenomTrace(ctx context.Context, req *QueryDenomTraceRequest) (*QueryDenomTraceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method DenomTrace not implemented") -} func (*UnimplementedQueryServer) DenomTraces(ctx context.Context, req *QueryDenomTracesRequest) (*QueryDenomTracesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DenomTraces not implemented") } +func (*UnimplementedQueryServer) DenomTrace(ctx context.Context, req *QueryDenomTraceRequest) (*QueryDenomTraceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DenomTrace not implemented") +} func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } @@ -802,38 +802,38 @@ func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_DenomTrace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryDenomTraceRequest) +func _Query_DenomTraces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDenomTracesRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).DenomTrace(ctx, in) + return srv.(QueryServer).DenomTraces(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/ibc.applications.transfer.v1.Query/DenomTrace", + FullMethod: "/ibc.applications.transfer.v1.Query/DenomTraces", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).DenomTrace(ctx, req.(*QueryDenomTraceRequest)) + return srv.(QueryServer).DenomTraces(ctx, req.(*QueryDenomTracesRequest)) } return interceptor(ctx, in, info, handler) } -func _Query_DenomTraces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryDenomTracesRequest) +func _Query_DenomTrace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDenomTraceRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).DenomTraces(ctx, in) + return srv.(QueryServer).DenomTrace(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/ibc.applications.transfer.v1.Query/DenomTraces", + FullMethod: "/ibc.applications.transfer.v1.Query/DenomTrace", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).DenomTraces(ctx, req.(*QueryDenomTracesRequest)) + return srv.(QueryServer).DenomTrace(ctx, req.(*QueryDenomTraceRequest)) } return interceptor(ctx, in, info, handler) } @@ -914,14 +914,14 @@ var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "ibc.applications.transfer.v1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ - { - MethodName: "DenomTrace", - Handler: _Query_DenomTrace_Handler, - }, { MethodName: "DenomTraces", Handler: _Query_DenomTraces_Handler, }, + { + MethodName: "DenomTrace", + Handler: _Query_DenomTrace_Handler, + }, { MethodName: "Params", Handler: _Query_Params_Handler, diff --git a/modules/apps/transfer/types/query.pb.gw.go b/modules/apps/transfer/types/query.pb.gw.go index e7b727dbd50..0bb5025494e 100644 --- a/modules/apps/transfer/types/query.pb.gw.go +++ b/modules/apps/transfer/types/query.pb.gw.go @@ -33,6 +33,42 @@ var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage var _ = metadata.Join +var ( + filter_Query_DenomTraces_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDenomTracesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.DenomTraces(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDenomTracesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.DenomTraces(ctx, &protoReq) + return msg, metadata, err + +} + func request_Query_DenomTrace_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryDenomTraceRequest var metadata runtime.ServerMetadata @@ -87,42 +123,6 @@ func local_request_Query_DenomTrace_0(ctx context.Context, marshaler runtime.Mar } -var ( - filter_Query_DenomTraces_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryDenomTracesRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.DenomTraces(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryDenomTracesRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.DenomTraces(ctx, &protoReq) - return msg, metadata, err - -} - func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest var metadata runtime.ServerMetadata @@ -331,7 +331,7 @@ func local_request_Query_TotalEscrowForDenom_0(ctx context.Context, marshaler ru // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_DenomTrace_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_DenomTraces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -342,7 +342,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_DenomTrace_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_DenomTraces_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -350,11 +350,11 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_DenomTraces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_DenomTrace_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -365,7 +365,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_DenomTraces_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_DenomTrace_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -373,7 +373,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -510,7 +510,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_DenomTrace_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_DenomTraces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -519,18 +519,18 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_DenomTrace_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_DenomTraces_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_DenomTraces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_DenomTrace_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -539,14 +539,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_DenomTraces_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_DenomTrace_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -634,10 +634,10 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_DenomTrace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 3, 0, 4, 1, 5, 5}, []string{"ibc", "apps", "transfer", "v1", "denom_traces", "hash"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_DenomTraces_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"ibc", "apps", "transfer", "v1", "denom_traces"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_DenomTrace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 3, 0, 4, 1, 5, 5}, []string{"ibc", "apps", "transfer", "v1", "denom_traces", "hash"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"ibc", "apps", "transfer", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_DenomHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 3, 0, 4, 1, 5, 5}, []string{"ibc", "apps", "transfer", "v1", "denom_hashes", "trace"}, "", runtime.AssumeColonVerbOpt(false))) @@ -648,10 +648,10 @@ var ( ) var ( - forward_Query_DenomTrace_0 = runtime.ForwardResponseMessage - forward_Query_DenomTraces_0 = runtime.ForwardResponseMessage + forward_Query_DenomTrace_0 = runtime.ForwardResponseMessage + forward_Query_Params_0 = runtime.ForwardResponseMessage forward_Query_DenomHash_0 = runtime.ForwardResponseMessage diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index 040d0a3ffed..5c42acbf6fb 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" "reflect" + "strings" storetypes "cosmossdk.io/store/types" @@ -64,6 +65,10 @@ func NewKeeper( panic(fmt.Errorf("cannot initialize IBC keeper: empty scoped keeper")) } + if strings.TrimSpace(authority) == "" { + panic(fmt.Errorf("authority must be non-empty")) + } + clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper) connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper(scopedKeeper) diff --git a/modules/core/keeper/keeper_test.go b/modules/core/keeper/keeper_test.go index 58e8167fb1c..0cd6b2a5857 100644 --- a/modules/core/keeper/keeper_test.go +++ b/modules/core/keeper/keeper_test.go @@ -64,17 +64,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { stakingKeeper clienttypes.StakingKeeper upgradeKeeper clienttypes.UpgradeKeeper scopedKeeper capabilitykeeper.ScopedKeeper - newIBCKeeperFn = func() { - ibckeeper.NewKeeper( - suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), - suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName), - stakingKeeper, - upgradeKeeper, - scopedKeeper, - suite.chainA.App.GetIBCKeeper().GetAuthority(), - ) - } + newIBCKeeperFn func() ) testCases := []struct { @@ -113,6 +103,19 @@ func (suite *KeeperTestSuite) TestNewKeeper() { scopedKeeper = emptyScopedKeeper }, false}, + {"failure: empty authority", func() { + newIBCKeeperFn = func() { + ibckeeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), + suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName), + stakingKeeper, + upgradeKeeper, + scopedKeeper, + "", // authority + ) + } + }, false}, {"success: replace stakingKeeper with non-empty MockStakingKeeper", func() { // use a different implementation of clienttypes.StakingKeeper mockStakingKeeper := MockStakingKeeper{"not empty"} @@ -126,6 +129,19 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.SetupTest() suite.Run(tc.name, func() { + // set default behaviour + newIBCKeeperFn = func() { + ibckeeper.NewKeeper( + suite.chainA.GetSimApp().AppCodec(), + suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), + suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName), + stakingKeeper, + upgradeKeeper, + scopedKeeper, + suite.chainA.App.GetIBCKeeper().GetAuthority(), + ) + } + stakingKeeper = suite.chainA.GetSimApp().StakingKeeper upgradeKeeper = suite.chainA.GetSimApp().UpgradeKeeper scopedKeeper = suite.chainA.GetSimApp().ScopedIBCKeeper diff --git a/proto/ibc/applications/transfer/v1/query.proto b/proto/ibc/applications/transfer/v1/query.proto index 2323ea171c1..788296718fe 100644 --- a/proto/ibc/applications/transfer/v1/query.proto +++ b/proto/ibc/applications/transfer/v1/query.proto @@ -12,16 +12,16 @@ option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"; // Query provides defines the gRPC querier service. service Query { - // DenomTrace queries a denomination trace information. - rpc DenomTrace(QueryDenomTraceRequest) returns (QueryDenomTraceResponse) { - option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{hash=**}"; - } - // DenomTraces queries all denomination traces. rpc DenomTraces(QueryDenomTracesRequest) returns (QueryDenomTracesResponse) { option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces"; } + // DenomTrace queries a denomination trace information. + rpc DenomTrace(QueryDenomTraceRequest) returns (QueryDenomTraceResponse) { + option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{hash=**}"; + } + // Params queries all parameters of the ibc-transfer module. rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { option (google.api.http).get = "/ibc/apps/transfer/v1/params";