!5320hans/cw-kv → developd5f9eea9ec

Raw Cosmos KV reads for CosmWasm

AI-generatedEverything on this page was written by an AI agent from the diff: the summaries, the narration, the diagrams, the flags and the glossary. It can be wrong or incomplete, so check it against the code before you rely on it.

6commits
4files
331lines changed
79lines to read
11stores readable
6/6tests pass (our run)
23/23binding statements covered

Where the diff is

Tests1 files · 213 lines

app/wasm_cosmos_kv_test.go+213 −0

A second route into chain state

Custom queries stop being rejected and read one raw key from a store.

contractquery requestwasmd handlersub gas meterGrpc pluginaccept list: 10 querieskeeper logicdefaults and policyCustom plugincosmosKVQuery11 mounted storesone raw key read
newchanged

3-minute explainer

What changed

New route

Custom queries go from rejected to raw store reads.

contractCustom pluginstore

Request and reply

One store, one base64 key, native bytes back.

pool//BTC.BTCprotobuf value

Four gates

Size, strict decode, key length and store name reject early.

  • 8,192 byte request
  • no unknown fields
  • 1 to 4,096 byte key
  • persistent store only

Readable rejections

Fixed error texts reach contracts; numeric codes don't.

text → contractcode → Go only

Missing vs empty

Null means missing; an empty string means stored empty.

missing → nullempty → ""

Value cap vs gas

A full 1 MiB read costs more than either gas limit.

3.15M gas for 1 MiB2M3M

What contracts own

No keeper defaults or halt checks; schemas can change at upgrades.

defaultshaltsschema changes

State + upgrade

Limits and wiring

  • changedQueryPlugins.CustomNoCustomQuerier → cosmosKVQuery
  • newcosmosKVMaxRequestBytes8,192
  • newcosmosKVMaxKeyBytes4,096
  • newcosmosKVMaxValueBytes1,048,576

Line by line · every changed logic line, narrated

3:40runtime
6code chapters
100%logic lines narrated (59/59)
8flagged spots
speed

Chapters

What to check

Ask an AI about this change

Chat assistantClaude, ChatGPT, … (reads a link)

Coding agentClaude Code, Cursor, … (reads the repo)

The context file is context.md. Use Copy with context for an AI that can't open links; it pastes the whole file in.

Glossary

Accept list
The ten gRPC queries contracts could already call, each going through keeper logic. app/wasm.go ↗
CosmWasm
The smart contract runtime on THORChain. Contracts ask the chain for data through query plugins. app-layer/README.md ↗
CustomQuery
A CosmWasm query slot with a chain-defined shape. Here it carries cosmos_kv requests. app/wasm_cosmos_kv.go ↗
Gas register
wasmd's pricing table, which also converts between SDK gas and the VM's gas units. app/wasm.go ↗
KV store
A module's key-value state in the Cosmos SDK. This binding reads one key at a time from persistent ones.
Native encoding
The bytes as a module stored them, usually protobuf. Contracts decode them with that module's schema.
Scheduler
THORNode's module that runs contract calls in blocks, each capped at 2,000,000 gas by MaxScheduleExecGas. x/scheduler/types/keys.go ↗