Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmjs failes to parse blocks with double sign evidence #980

Closed
JoeKash opened this issue Jan 14, 2022 · 9 comments · Fixed by #1012
Closed

Cosmjs failes to parse blocks with double sign evidence #980

JoeKash opened this issue Jan 14, 2022 · 9 comments · Fixed by #1012
Milestone

Comments

@JoeKash
Copy link

JoeKash commented Jan 14, 2022

On vega-testnet when we call stargateClient.getBlock(height) for block '7900625'

We get a parsing error from tendermint34 package -

Error: Value must not be undefined 
at assertSet (node_modules/@cosmjs/tendermint-rpc/build/tendermint34/encodings.js:13:15) 
at Object.assertNotEmpty (node_modules/@cosmjs/tendermint-rpc/build/tendermint34/encodings.js:107:5) 
at decodeEvidence (node_modules/@cosmjs/tendermint-rpc/build/tendermint34/adaptor/responses.js:329:55)

We are running v0.27

@webmaster128
Copy link
Member

Thanks for the report. Can you provide a Tendermint RPC endpoint that we can use to reproduce?

@JoeKash
Copy link
Author

JoeKash commented Jan 14, 2022

Thanks @webmaster128 I think cosmos has a public testnet rpc -
https://rpc.testnet.cosmos.network

@webmaster128
Copy link
Member

https://rpc.testnet.cosmos.network/block?height=7900625 tells me height 7900625 must be less than or equal to the current blockchain height 1250979. So those seem to be different networks.

@webmaster128
Copy link
Member

There is https://vega-rpc.interchain.io from https://github.com/cosmos/vega-test/tree/master/public-testnet but it tells me "height 7900625 is not available, lowest height is 8197001".

@webmaster128
Copy link
Member

webmaster128 commented Jan 20, 2022

I found a different node that has the block in the docs.

curl -sS "http://198.50.215.1:36657/block?height=7900625" | jq

gives us

{
  "jsonrpc": "2.0",
  "id": -1,
  "result": {
    "block_id": {
      "hash": "01C9137F31324A1D73C7314E451944CEF2ED3BEDC2E52EDC73B1DE850B2D42E4",
      "parts": {
        "total": 1,
        "hash": "6A3AF50547BA2F9EEED5A085475F8A74834D3C8FA8082F9E412A6D00F5310DF2"
      }
    },
    "block": {
      "header": {
        "version": {
          "block": "11"
        },
        "chain_id": "vega-testnet",
        "height": "7900625",
        "time": "2021-12-17T15:27:12.046033739Z",
        "last_block_id": {
          "hash": "33421BD13E15158F0546ABACDAFE73B2F12F2A17FC2A57EF217772C0D7469982",
          "parts": {
            "total": 1,
            "hash": "2715C33243C4EF37072D09CDE3243A26136835F691FF4E2753C5010D645E5F51"
          }
        },
        "last_commit_hash": "69A4839FF7A5D6C1FD1C0C1C29E3C1476FDDC4052BB56C2B606C4BB5F955E0A1",
        "data_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
        "validators_hash": "1D7D959034A55FEE27E002420618ADC0FD4BF72DD3FD747FAEDDF594B0DEF7B5",
        "next_validators_hash": "1D7D959034A55FEE27E002420618ADC0FD4BF72DD3FD747FAEDDF594B0DEF7B5",
        "consensus_hash": "80364965B7C2CC9DE961C0998B47A7F93F1970077EB882E0ED1C3822408888C7",
        "app_hash": "9063D8AB2A1A09211AE86BF457D620D17E19FD7469990AD21F28B39A72549710",
        "last_results_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
        "evidence_hash": "E46B9B015A3F49987F74F60F90C14CB5F7436319C70507D6E9C053AB991528CD",
        "proposer_address": "27ABF8D4C5493645B312D1456F8599DD0FA9A3F3"
      },
      "data": {
        "txs": []
      },
      "evidence": {
        "evidence": [
          {
            "type": "tendermint/DuplicateVoteEvidence",
            "value": {
              "vote_a": {
                "type": 1,
                "height": "7900624",
                "round": 0,
                "block_id": {
                  "hash": "33421BD13E15158F0546ABACDAFE73B2F12F2A17FC2A57EF217772C0D7469982",
                  "parts": {
                    "total": 1,
                    "hash": "2715C33243C4EF37072D09CDE3243A26136835F691FF4E2753C5010D645E5F51"
                  }
                },
                "timestamp": "2021-12-17T15:27:11.32814003Z",
                "validator_address": "7C9F0FADF306FED9663F811619141F99147E6722",
                "validator_index": 0,
                "signature": "9ECSHcTemL1lVUzZ4FIGVkvSy9z6Tw0/CYhTQXep/IQsPd1DqG9cMGo7JAnADM5m7USlvlWA4vX7uTG1iwU5Dw=="
              },
              "vote_b": {
                "type": 1,
                "height": "7900624",
                "round": 0,
                "block_id": {
                  "hash": "404C802DA70B54AD7E9F436EE127044A278636D1019F724B93361A12513A6757",
                  "parts": {
                    "total": 1,
                    "hash": "5E933348AE59EC41CCF69CE47260F6068A0744738F79236FE47BB03DB1242A11"
                  }
                },
                "timestamp": "2021-12-17T15:27:11.341922144Z",
                "validator_address": "7C9F0FADF306FED9663F811619141F99147E6722",
                "validator_index": 0,
                "signature": "P2oRVmLmy/53cZ+Vd0Pd0xNSv8KB0l/sGanpQJFypXsLR0llIQNVavT8O2VX0TOtsbsl3r+IvvzQKlzKyJk2CA=="
              },
              "TotalVotingPower": "6036072429",
              "ValidatorPower": "1513944317",
              "Timestamp": "2021-12-17T15:27:03.208785493Z"
            }
          }
        ]
      },
      "last_commit": {
        "height": "7900624",
        "round": 0,
        "block_id": {
          "hash": "33421BD13E15158F0546ABACDAFE73B2F12F2A17FC2A57EF217772C0D7469982",
          "parts": {
            "total": 1,
            "hash": "2715C33243C4EF37072D09CDE3243A26136835F691FF4E2753C5010D645E5F51"
          }
        },
        "signatures": [
          {
            "block_id_flag": 2,
            "validator_address": "7C9F0FADF306FED9663F811619141F99147E6722",
            "timestamp": "2021-12-17T15:27:12.062078712Z",
            "signature": "Uc9h3q2rKT8wV/ZYbMc3cy/Qj8qbmYkcopvssJN67jUEnAFi47EJSTyCm2jEyYNHNAfWOBDeaNhYgEsCZcMaDA=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "132BAA3FAD92DDB2A23BB1FC8144F2D04F16DCC8",
            "timestamp": "2021-12-17T15:27:12.0450877Z",
            "signature": "JnFMBGBdUdyI4wLc/eTipMlF2lg2oe35kZuxEieCR0bn7hKzRG8ikxIu8eQobtLzkKndLr1urc+q48OdOiY4Cg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "17472F7923685922F8165C33F4E02176189AF253",
            "timestamp": "2021-12-17T15:27:11.737653153Z",
            "signature": "QJKdSMMDL4rk2akwmFYyRUdKIvg9T+8+TWtZw+BNbYrfoG+rB7KH2Ffg5+8Mo9U9+OZ3ORmOTAk2k2TzyRvEAg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "27ABF8D4C5493645B312D1456F8599DD0FA9A3F3",
            "timestamp": "2021-12-17T15:27:12.046033739Z",
            "signature": "H+THXd8Eylhv5fyizn5gVU01VxGKHPHymVhU7dqb0A0Mse7Ky56Gp4pD70p1RbRacjSYyymEHsUxCMMRWzVACg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "51205659A717DFFB96E054F8BD1108730E17AEA7",
            "timestamp": "2021-12-17T15:27:12.095423635Z",
            "signature": "ov11uelFNCoYfNdA6eaiJx9AHfJ+pt3g+H78VaEIG81Mq9bbu2n8Bl1ane9ji9ktvy9wObZ2XgsFNFd5OvG7AQ=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "1CED30733D1625C89AB698677606D0E37B3676A9",
            "timestamp": "2021-12-17T15:27:12.41455257Z",
            "signature": "UP61lPxZ5pieOR5mgojVfdbqYPHbcYIq7EABCVjWrTRf3J62w8SBrPs0XlygnKVJPszEvQ9lyaLis7MtvO5EAw=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "E6FF323EF8F7BC36DD01006AFAE13546B172B335",
            "timestamp": "2021-12-17T15:27:12.414631207Z",
            "signature": "coVsd8XXIAHSX2VSL9Z4CMBHBnHKFqGYYrWXXtzyxk3EVwCIjWSisZL2AUkCjk8Aq0EvW6KfLgMOiPen+oZaDQ=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "663660C7CF53625C6EF179DB4434F83CF1597F9F",
            "timestamp": "2021-12-17T15:27:12.476589755Z",
            "signature": "QY9PT4TW26htTGpebVqtypRgehChAUVkb2YgIvWDEflsAV2IE33XHoQE3eZslfSsp33wcOZ0XVNpTOZuS/0xCA=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "3F357ABFE229B10A087A67A099FE29E959600FF9",
            "timestamp": "2021-12-17T15:27:12.431114597Z",
            "signature": "cHGqAWeOCKIMULMKp5gnYMrbwtElZoSYDMoum28USqQ+pmYP0qE/9soAQxWj29NyZxOzcDxSyDm3XXYrAw1fCw=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "087DF7F4F906DB11077BDC3050EFA3C49E3F0730",
            "timestamp": "2021-12-17T15:27:12.146366549Z",
            "signature": "rKi9SBp/AdbulLb6XRR7I/eCRkUCgsD8SI4G8cmEFOV+/NY8U0MA6gPE9mUoUrCdK+bTXeY87iQCeS7A7+QxDg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "159BBC35BAE17D8583BAEDEE3B9941B36CFC8F52",
            "timestamp": "2021-12-17T15:27:12.439414681Z",
            "signature": "H7z1uZs800JiOFMcO9QBtKQ3VZvc2UvqeGzRKo/K+cfrPR6YmRSIoVLpTw31em1MvO+RocZ3uzAO1oz4dEV6Cg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "EEF62A365F7F4139629B5512814DAFB92ADC8A58",
            "timestamp": "2021-12-17T15:27:12.195331631Z",
            "signature": "5ya3ePTUIry9/V8HYle92nv8SfDO3tZGNjsqggmBdY3fmswYdAfvt5VjDlxQtWKO4UVM9wnn45Isc0GGfEMbDg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "200C351A6FF28FFEA0115C2D3199C1CECCE19453",
            "timestamp": "2021-12-17T15:27:12.060101616Z",
            "signature": "kk6WnWdId2xKaQHuVawXHiLTacz4pt8NvkqyrZttX01ZKILKBfoY7/0MjELKI94fQ0rs/bYi3t2nvzz47zsIBg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "2AE1D078C024F45F2227EBD927B44E0D7568B34A",
            "timestamp": "2021-12-17T15:27:12.476965799Z",
            "signature": "W/2eB5i+jq+A0lwErvzGWBZ+UDA+fvp8bzOGV6dcrn5QF7sBFmrBuc7AqZwISCAUHawEpJlDkF+Ej7fIGJIwCw=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "EB991318C25714A7A7F7539E7D44C39370B6562E",
            "timestamp": "2021-12-17T15:27:12.149035188Z",
            "signature": "UNCdhnUlf8RV7nee7blhGLwFU7JcZocZ6nVsF2al7S77xYeR4vUEAE4bEYORQHwjOvJ19H1MufkHISbovPqxCg=="
          },
          {
            "block_id_flag": 1,
            "validator_address": "",
            "timestamp": "0001-01-01T00:00:00Z",
            "signature": null
          },
          {
            "block_id_flag": 2,
            "validator_address": "AB4A058110F1C083ADDAA6FAF69896EF7F823574",
            "timestamp": "2021-12-17T15:27:12.149417072Z",
            "signature": "IP4Jc93WMGNBLC4tcr2ViXvdFuZKI97sqzwbiT3QhdmlFr6VgX5KX0hnNDD1Rx2QMy4OrIvSN3Jfpb4wKSC0Dg=="
          },
          {
            "block_id_flag": 2,
            "validator_address": "18D424796DF437AB63C663B7A5F3C52B453CCE9B",
            "timestamp": "2021-12-17T15:27:12.184479903Z",
            "signature": "/LppU2dD0WlGnYzDEB87czuJeBMTVtbW6YCqCYj2lt+QFymQ6YnxqDfBFAOlnF4viGZypjeG/WZ7oJ/G8vS4Aw=="
          },
          {
            "block_id_flag": 1,
            "validator_address": "",
            "timestamp": "0001-01-01T00:00:00Z",
            "signature": null
          },
          {
            "block_id_flag": 2,
            "validator_address": "88EE27E22F974DB5ED2E015249C6AE185F4C0CA1",
            "timestamp": "2021-12-17T15:27:12.07415231Z",
            "signature": "e5A4PEgtUWHC/0Xb9VWlbL0v5+kO6MGPP8Ze3gOA/SHLnmt/BYLGYJmfKZYCHirXsyBmmLz62JCr77VN5TvjAw=="
          }
        ]
      }
    }
  }
}

with the evidence part curl -sS "http://198.50.215.1:36657/block?height=7900625" | jq .result.block.evidence being

{
  "evidence": [
    {
      "type": "tendermint/DuplicateVoteEvidence",
      "value": {
        "vote_a": {
          "type": 1,
          "height": "7900624",
          "round": 0,
          "block_id": {
            "hash": "33421BD13E15158F0546ABACDAFE73B2F12F2A17FC2A57EF217772C0D7469982",
            "parts": {
              "total": 1,
              "hash": "2715C33243C4EF37072D09CDE3243A26136835F691FF4E2753C5010D645E5F51"
            }
          },
          "timestamp": "2021-12-17T15:27:11.32814003Z",
          "validator_address": "7C9F0FADF306FED9663F811619141F99147E6722",
          "validator_index": 0,
          "signature": "9ECSHcTemL1lVUzZ4FIGVkvSy9z6Tw0/CYhTQXep/IQsPd1DqG9cMGo7JAnADM5m7USlvlWA4vX7uTG1iwU5Dw=="
        },
        "vote_b": {
          "type": 1,
          "height": "7900624",
          "round": 0,
          "block_id": {
            "hash": "404C802DA70B54AD7E9F436EE127044A278636D1019F724B93361A12513A6757",
            "parts": {
              "total": 1,
              "hash": "5E933348AE59EC41CCF69CE47260F6068A0744738F79236FE47BB03DB1242A11"
            }
          },
          "timestamp": "2021-12-17T15:27:11.341922144Z",
          "validator_address": "7C9F0FADF306FED9663F811619141F99147E6722",
          "validator_index": 0,
          "signature": "P2oRVmLmy/53cZ+Vd0Pd0xNSv8KB0l/sGanpQJFypXsLR0llIQNVavT8O2VX0TOtsbsl3r+IvvzQKlzKyJk2CA=="
        },
        "TotalVotingPower": "6036072429",
        "ValidatorPower": "1513944317",
        "Timestamp": "2021-12-17T15:27:03.208785493Z"
      }
    }
  ]
}

So the structure is completely different from what the client expects. Especially this part looks worrying:

      "evidence": {
        "evidence": [

@JoeKash do this data in a typesafe way or just don't want the exception? I suggest changing the field to any as a short-term solution until someone really starts working with those fields in TypeScript.

@ethanfrey
Copy link
Contributor

I second the use of any and linking to this issue.
I bet this will change in tendermint 0.35 and again in 0.36 and let's just leave it any til someone has trouble with that

@JoeKash
Copy link
Author

JoeKash commented Jan 21, 2022

Thanks for digging this up @webmaster128

We mostly care about the client not throwing an exception we can work around not having type safety so type any should work great.

@webmaster128
Copy link
Member

This is addressed in #1012. Would love if someone could have a look at that PR.

@webmaster128
Copy link
Member

This @cosmjs/cli script can be used to reproduce the bug an confirm the fix:

import { StargateClient } from "@cosmjs/stargate";
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";

const rpcEndpoint = "http://198.50.215.1:36657"

// High level client
const client = await StargateClient.connect(rpcEndpoint);
for (const height of [7900624, 7900625]) {
  console.log(`Getting block ${height} …`)
  const block = await client.getBlock(7900626);
  console.log(block)
}
client.disconnect();

// Tendermint client for more details
const tmClient = await Tendermint34Client.connect(rpcEndpoint);
for (const height of [7900624, 7900625]) {
  console.log(`Getting block ${height} …`)
  const block = await tmClient.block(height);
  console.log(block);
}
tmClient.disconnect();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants