# README
Interchain Query
Abstract
Stride uses interchain queries and interchain accounts to perform multichain liquid staking. The interchainquery
module creates a framework that allows other modules to query other appchains using IBC. The interchainquery
module is used to make bank balance ICQ queries to withdrawal account every N. The callback triggers ICA bank sends for 90% of the rewards to the delegation account and 10% to the stride hostzone revenue account. The ICA bank send logic is in x/stakeibc/keeper/callbacks.go.
Contents
Concepts
Nearly all of Stride's functionality is built using interchain accounts (ICAs), which are a new functionality in Cosmos, and a critical component of IBC. ICAs allow accounts on Zone A to be controlled by Zone B. ICAs communicate with one another using Interchain Queries (ICQs), which involve Zone A querying Zone B for relevant information.
Two Zones communicate via a connection and channel. All communications between the Controller Zone (the chain that is querying) and the Host Zone (the chain that is being queried) is done through a dedicated IBC channel between the two chains, which is opened the first time the two chains interact.
For context, ICS standards define that each channel is associated with a particular connection, and a connection may have any number of associated channels.
State
The interchainquery
module keeps Query
objects and modifies the information from query to query, as defined in proto/interchainquery/v1/genesis.proto
InterchainQuery information type
Query
has information types that pertain to the query itself. Query
keeps the following:
id
keeps the query identification string.connection_id
keeps the id of the channel or connection between the controller and host chain.chain_id
keeps the id of the queried chain.query_type
keeps the type of interchain queryrequest
keeps an bytecode encoded version of the interchain queryperiod
TODOlast_height
keeps the blockheight of the last block before the query was madecallback_id
keeps the function that will be called by the interchain queryttl
TODOheight
keeps the height at which the ICQ query should execute on the host zone. This is often0
, meaning the query should execute at the latest height on the host zone.
DataPoint
has information types that pertain to the data that is queried. DataPoint
keeps the following:
id
keeps the identification string of the datapointremote_height
keeps the block height of the queried chainlocal_height
keeps the block height of the querying chainvalue
keeps the bytecode value of the data retrieved by the Query
Events
The interchainquery
module emits an event at the end of every 3 base_epoch
s (e.g. 15 minutes on local testnet).
The purpose of this event is to send interchainqueries that query data about staking rewards, which Stride uses to reinvest (aka autocompound) staking rewards.
event := sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeValueQuery),
sdk.NewAttribute(types.AttributeKeyQueryId, queryInfo.Id),
sdk.NewAttribute(types.AttributeKeyChainId, queryInfo.ChainId),
sdk.NewAttribute(types.AttributeKeyConnectionId, queryInfo.ConnectionId),
sdk.NewAttribute(types.AttributeKeyType, queryInfo.QueryType),
// TODO: add height to request type
sdk.NewAttribute(types.AttributeKeyHeight, "0"),
sdk.NewAttribute(types.AttributeKeyRequest, hex.EncodeToString(queryInfo.Request)),
)
Keeper
Keeper Functions
interchainquery/keeper/
module provides utility functions to manage ICQs
// GetQuery returns query
GetQuery(ctx sdk.Context, id string) (types.Query, bool)
// SetQuery set query info
SetQuery(ctx sdk.Context, query types.Query)
// DeleteQuery delete query info
DeleteQuery(ctx sdk.Context, id string)
// IterateQueries iterate through queries
IterateQueries(ctx sdk.Context, fn func(index int64, queryInfo types.Query) (stop bool))
// AllQueries returns every queryInfo in the store
AllQueries(ctx sdk.Context) []types.Query
Msgs
interchainquery
has a Msg
service that passes messages between chains.
service Msg {
// SubmitQueryResponse defines a method for submiting query responses.
rpc SubmitQueryResponse(MsgSubmitQueryResponse) returns (MsgSubmitQueryResponseResponse)
}