Skip to content

Breaking change 0.34 -> 0.37: get tx by hash encoding #443

Closed

Description

@webmaster128

At some point between version 0.34.x and 0.37.x, the expected encoding of the hash for the tx RPC method changed. For years this has always been hex encoded. Now base64 is expected.

Using 0.37, the following requests

{
  jsonrpc: '2.0',
  id: 822644577673,
  method: 'tx',
  params: {
    hash: '71bde7375ee47feaf0348f8b292c81b57b32da6766c523a774ab10423fdfecca',
    prove: true
  }
}

fails with

Error: {"code":-32603,"message":"Internal error","data":"tx (EF56DD7BBDFBE5E7B8EDF79A7F4DF8F1FF1BDBDD9CF356F9EDBDF675AEBBEBA739DB76BBEF869BD74E36DDF75F79C71A) not found"}

Here you can see the hash parameter is interpretes as a base64 string:

$ echo 71bde7375ee47feaf0348f8b292c81b57b32da6766c523a774ab10423fdfecca | base64 -D | xxd -p -u -c 100
EF56DD7BBDFBE5E7B8EDF79A7F4DF8F1FF1BDBDD9CF356F9EDBDF675AEBBEBA739DB76BBEF869BD74E36DDF75F79C71A

When I change the request encoding from hex to base64 it works

--- a/packages/tendermint-rpc/src/tendermint37/adaptor/requests.ts
+++ b/packages/tendermint-rpc/src/tendermint37/adaptor/requests.ts
@@ -80,7 +80,7 @@ interface RpcTxParams {
 }
 function encodeTxParams(params: requests.TxParams): RpcTxParams {
   return {
-    hash: toHex(assertNotEmpty(params.hash)),
+    hash: toBase64(assertNotEmpty(params.hash)),
     prove: params.prove,
   };
 }
{
  jsonrpc: '2.0',
  id: 886676211497,
  method: 'tx',
  params: { hash: 'iqiqKpltx8bZlHDbOXdgEv0kSMLz4XrYuCY7SiT3JmA=', prove: true }
}

Affected versions

The hex encoding worked for many years and the change must have been introduced recently

Version Expected encoding
0.34 hex base64
0.35 hex
tendermint/tendermint:v0.37.0-rc2 base64
cometbft/cometbft:v0.37.0-rc3 base64

To hex or not to hex

Now the question is: is this change expected and intended? Should I build a client that uses base64?

The tx_search query with tx.hash='AABBAABB' expects hex consistently.

Activity

  1. added
    bug
    needs-triage
    on Mar 2, 2023
  2. thanethomson commented on Mar 2, 2023

    @thanethomson
    Contributor

    Hasn't base64 encoding of the tx method's hash parameter (in JSON-RPC requests) always been the case? See tendermint/tendermint#6802.

    Testing this out locally with CometBFT v0.34.27, in one terminal I ran rm -rf ~/.cometbft && cometbft init && cometbft start --proxy_app kvstore and in another:

    > curl http://localhost:26657/status
    {"jsonrpc":"2.0","id":-1,"result":{"node_info":{"protocol_version":{"p2p":"8","block":"11","app":"1"},"id":"13dff5d318d30df61cdd2c93142facf1261657bd","listen_addr":"tcp://0.0.0.0:26656","network":"test-chain-H9xde8","version":"0.34.27","channels":"40202122233038606100","moniker":"thinkpad","other":{"tx_index":"on","rpc_address":"tcp://127.0.0.1:26657"}},"sync_info":{"latest_block_hash":"D60A1325F9AB39D0809D2D1559C4E68020E42D57DFD0A0FE83BB96CD008687F0","latest_app_hash":"0000000000000000","latest_block_height":"5","latest_block_time":"2023-03-02T12:16:10.062789398Z","earliest_block_hash":"77F9CDFDF72BD75BC7B644F7CA156DA46DC8A1C243322067D55047DEF7F5DBE1","earliest_app_hash":"","earliest_block_height":"1","earliest_block_time":"2023-03-02T12:16:05.961939995Z","catching_up":false},"validator_info":{"address":"C1BAE6651DB767A7FD656BC27DFF3523AB83B823","pub_key":{"type":"tendermint/PubKeyEd25519","value":"nuS+lD2sMaXITG5y8JSi/cxd9ubCanNCerwE9Tup7VU="},"voting_power":"10"}}}
    
    > curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id": 1, "method": "broadcast_tx_commit", "params": {"tx": "c29tZS1rZXk9c29tZS12YWx1ZQo="}}' http://localhost:26657
    {"jsonrpc":"2.0","id":1,"result":{"check_tx":{"code":0,"data":null,"log":"","info":"","gas_wanted":"1","gas_used":"0","events":[],"codespace":"","sender":"","priority":"0","mempoolError":""},"deliver_tx":{"code":0,"data":null,"log":"","info":"","gas_wanted":"0","gas_used":"0","events":[{"type":"app","attributes":[{"key":"Y3JlYXRvcg==","value":"Q29zbW9zaGkgTmV0b3dva28=","index":true},{"key":"a2V5","value":"c29tZS1rZXk=","index":true},{"key":"aW5kZXhfa2V5","value":"aW5kZXggaXMgd29ya2luZw==","index":true},{"key":"bm9pbmRleF9rZXk=","value":"aW5kZXggaXMgd29ya2luZw==","index":false}]},{"type":"app","attributes":[{"key":"Y3JlYXRvcg==","value":"Q29zbW9zaGk=","index":true},{"key":"a2V5","value":"c29tZS12YWx1ZQo=","index":true},{"key":"aW5kZXhfa2V5","value":"aW5kZXggaXMgd29ya2luZw==","index":true},{"key":"bm9pbmRleF9rZXk=","value":"aW5kZXggaXMgd29ya2luZw==","index":false}]}],"codespace":""},"hash":"B5C07F8F0A8FFD6D2C1808DD97A1DDE0A26E565BE99668A745ABBA5522F2900F","height":"215"}}
    
    > echo B5C07F8F0A8FFD6D2C1808DD97A1DDE0A26E565BE99668A745ABBA5522F2900F | xxd -r -p | base64
    tcB/jwqP/W0sGAjdl6Hd4KJuVlvplminRau6VSLykA8=
    
    > curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id": 2, "method": "tx", "params": {"hash": "tcB/jwqP/W0sGAjdl6Hd4KJuVlvplminRau6VSLykA8="}}' http://localhost:26657
    {"jsonrpc":"2.0","id":2,"result":{"hash":"B5C07F8F0A8FFD6D2C1808DD97A1DDE0A26E565BE99668A745ABBA5522F2900F","height":"215","index":0,"tx_result":{"code":0,"data":null,"log":"","info":"","gas_wanted":"0","gas_used":"0","events":[{"type":"app","attributes":[{"key":"Y3JlYXRvcg==","value":"Q29zbW9zaGkgTmV0b3dva28=","index":true},{"key":"a2V5","value":"c29tZS1rZXk=","index":true},{"key":"aW5kZXhfa2V5","value":"aW5kZXggaXMgd29ya2luZw==","index":true},{"key":"bm9pbmRleF9rZXk=","value":"aW5kZXggaXMgd29ya2luZw==","index":false}]},{"type":"app","attributes":[{"key":"Y3JlYXRvcg==","value":"Q29zbW9zaGk=","index":true},{"key":"a2V5","value":"c29tZS12YWx1ZQo=","index":true},{"key":"aW5kZXhfa2V5","value":"aW5kZXggaXMgd29ya2luZw==","index":true},{"key":"bm9pbmRleF9rZXk=","value":"aW5kZXggaXMgd29ya2luZw==","index":false}]}],"codespace":""},"tx":"c29tZS1rZXk9c29tZS12YWx1ZQo="}}

    The only version of Tendermint Core in which the tx method's hash parameter used hex encoding was v0.35 IIRC, because of tendermint/tendermint#6813.

  3. removed
    needs-triage
    on Mar 2, 2023
  4. webmaster128 commented on Mar 2, 2023

    @webmaster128
    Author

    Spot on, you are right! This is the 0.34 client code:

    function encodeTxParams(params: requests.TxParams): RpcTxParams {
      return {
        hash: toBase64(assertNotEmpty(params.hash)),
        prove: params.prove,
      };
    }
    

    Great, that solves it. The issue came because I built a Tendermint 0.35 client last summer, forgot about the differences between 0.34 and 0.35 and now used this client as the basis for 0.37.

    Thanks a lot 💐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions