IBC queries #605
Replies: 11 comments 18 replies
-
There are going to be applications on other chains that are going to depend on reads from other chains |
Beta Was this translation helpful? Give feedback.
-
I agree it would be useful. I wonder if it is better to have some interchain account like protocol, where we expose different queries for each module, or to just expose raw state queries (which are also exposed on the tendermint rpc layer). The advantage of the raw queries is no code is needed on the chain to be read. Raw queries can generate Merkle proofs already. One could develop a protocol to verify any state key using the same clients. This reader could be deployed to one chain, a relayer updated, and it will be able to read account balances from other chains in a trust less manner |
Beta Was this translation helpful? Give feedback.
-
So if we aren't going to use the full IBC stack for queries across chains, then the query system still needs to share access to the IBC client infrastructure and thus we need to define an architecture where interchain queries can use the IBC client. |
Beta Was this translation helpful? Give feedback.
-
I would trust the interface of the state machine over the internals. There's no guarantee internals will keep the spec they have currently, which will eventually make for dependency hell (esp with smart contract enabled chains where permissionless and chaotic upgrades happen all the time). We did historical state proofs for Ethereum, it was a horrible experience. Strongly support having interchain queries - without them interchain applications won't be useful. |
Beta Was this translation helpful? Give feedback.
-
Then this is not a simple "get account" but perform any application-specific query (which is also not guaranteed to remain stable over time). But more akin to Interchain Accounts, and them using the protobuf-encoded messages as the unit of communication. Just protobuf-encoding gRPC-like queries? |
Beta Was this translation helpful? Give feedback.
-
IBC queries are better to be key-value access, instead of turing complete application specific, but with additional layer of converting virtual key position into machine key position. ICS 24 is actually a kind of this conversion scheme; there is a string form of interface key format, which each host translates into machine specific key format. The conversion scheme could be simply described in a single schema language and embedded inside the ConnectionState(so we don't have to upgrade the chain each time the schema changes). The querier uses the conversion scheme to find the machine key from the application provided key, verify the key-value pair using the ClientState, which is done synchronously and without depending on the queried chain's response. Usual application specific query could be done using the existing IBC packets and Querier interface. Query packet contains the querier path data which the receiving chain calls the module querier to retrieve and send receipt of the result. This is done async and depends on the queried chain correctly respond. |
Beta Was this translation helpful? Give feedback.
-
So one way to do this would be for the SDK to support Msg based reads more generally so apps can define queries that can be done via a Msg type in consensus (the need for consensus based reads is common in traditional dbs, eg. see this issue in etcd). Then it will come for free over IBC via Interchain Accounts. Conceivably all grpc Queries could be auto exposed as Msg-based queries as well (could be a general MsgQuery that takes a module name and method string, or a per module MsgQuery that takes a method string, etc.), but maybe apps will want to be selective about what they expose, and we need to be careful about iteration and large responses (paging over IBC is probably going to be a pain lol). Raw kv-store queries over IBC are probably too low level, especially if an app changes its data model. But msg-based reads provide a more normalized/consistent API to the state and might be useful generally rather than making this a custom IBC feature. On a related note, Msg-based reads combined with a stateless VM module could allow us to do conditional txs pretty nicely:
|
Beta Was this translation helpful? Give feedback.
-
Love the discussion that is happening here. Reading the messages and talking with people on telegram it seems this feature is in high demand. I would propose organising a working group to flush out a design. Since the Hub is looking at using this along with a few other projects I have talked with, I'm happy to take the lead on organising the calls and taking notes. |
Beta Was this translation helpful? Give feedback.
-
I propose doing the raw KV store read method Bucky alluded to. This is basically the Solana light client approach. We make a StateReadMsg, that takes in one of: The StateReadMsg emits the values at the relevant entries of states into a Thus the flow for a cross-chain query will be: Chain A wants to query state 'S' from Chain B. Then afterwards, we work on sugar coating for common queries. Likely using Aaron's great work on the ORM module as an end state, and in the initial days judiciously applying the 80/20 principle for common use cases. The interface for an application will look like: Re: comparing to bucky's point about brittleness of raw KV store reads: The state key here may break every consensus version for an application but so will messages. I think we can get nearly everywhere we need to be pre-ORM module by just using aliases, and I worry that an approach based on running more general messages and tracing/merkelizing outputs will take a lot longer to ship, and not have much incremental utility vs lots of helpers and then great ORM module integration. We should be imagining GRPC queries as moving to separate queries away from the chain datastore back-end for the most part -- I'm not at all in favor of exposing these directly over IBC. |
Beta Was this translation helpful? Give feedback.
-
Ok so my proposal is even simpler than @ValarDragon's chatted about it briefly in the IBC Queries Working Group telegram yesterday but for visibility I'll write it up here. Basic idea is that we use ABCI queries and use the IBC Clients to prove the data from the queries is accurate. This should be sufficient for the same security guarantees as IBC w/o the overhead of requiring any upgrades from counterparty chains. The following is an ABCI query request: type RequestQuery struct {
Data []byte
Path string
Height int64
Prove bool
} I propose we create a module that allows modules or smart contracts to create type CrossChainABCIQueryRequest struct {
Data []byte
Path string
ClientID string
Bounty sdk.Coin
} These requests would be seen by relayers who would then take the Timeouts would be height based in the same way IBC packet timeouts are. Relayers could easily perform this operation and be paid by the calling module/smart contract. |
Beta Was this translation helpful? Give feedback.
-
Ok, so this is a quick spec (work in progress) for the interchain-query module utilizing @jackzampolin suggested method. https://github.com/schnetzlerjoe/interchain-query-spec. All suggestions are welcome. |
Beta Was this translation helpful? Give feedback.
-
IBC has enabled many chains to talk to many chains, but to query state of an account on another chain the user must either query an exposed rpc endpoint or run a node themselves. This present a UX issue for third party integrators that would like to integrate one chain but use tokens of many.
Allowing a client to submit a cross-chain query for data of a specific account or state could provide better UX for the end user.
Opening this to get thoughts on a new message type for this. It would be useful in our use case of interchain custody.
Beta Was this translation helpful? Give feedback.
All reactions