ignite / cli

Ignite is a CLI tool and hub designed for constructing Proof of Stake Blockchains rooted in Cosmos-SDK
https://ignite.com
Other
1.26k stars 547 forks source link

Dashes in chain id are in the defaults, but not in the actual chain id #1666

Closed wilwade closed 2 years ago

wilwade commented 3 years ago

Describe the bug I scaffold a chain where the package name has dashes, then use the generated chain to create a transaction without the --chain-id parameter. The default hash dashes, but the actually generated chain id does not. The resulting error is just a signing failure due to account of chain id.

To Reproduce Steps to reproduce the behavior: Setup

  1. `starport scaffold chain github.com/wilwade/with-dash
  2. starport scaffold module thisisamodule
  3. starport scaffold list saveastring str --module thisisamodule
  4. starport chain serve

Error Case 1: No Chain Id set

with-dashd tx thisisamodule create-saveastring "hello world" --from alice

Expected: Success

Result:

$ with-dashd tx thisisamodule create-saveastring "hello world" --from alice
{"body":{"messages":[{"@type":"/wilwade.withdash.thisisamodule.MsgCreateSaveastring","creator":"cosmos150gqaf549em7er4xrhujafmlwsw5tutp872u05","str":"hello world"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}

confirm transaction before signing and broadcasting [y/N]: y
code: 4
codespace: sdk
data: ""
gas_used: "29920"
gas_wanted: "200000"
height: "0"
info: ""
logs: []
raw_log: 'signature verification failed; please verify account number (0) and chain-id
  (withdash): unauthorized'
timestamp: ""
tx: null
txhash: EB4440C1532AA68B9093CAE24AFD757C4797C38A161590CF09B0BE93E1A14401

Works:

$ with-dashd tx thisisamodule create-saveastring "hello world" --from alice --chain-id withdash
{"body":{"messages":[{"@type":"/wilwade.withdash.thisisamodule.MsgCreateSaveastring","creator":"cosmos150gqaf549em7er4xrhujafmlwsw5tutp872u05","str":"hello world"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}

confirm transaction before signing and broadcasting [y/N]: y
code: 0
codespace: ""
data: 0A360A342F77696C776164652E77697468646173682E746869736973616D6F64756C652E4D73674372656174655361766561737472696E67
gas_used: "45165"
gas_wanted: "200000"
height: "145"
info: ""
logs:
- events:
  - attributes:
    - key: action
      value: CreateSaveastring
    type: message
  log: ""
  msg_index: 0
raw_log: '[{"events":[{"type":"message","attributes":[{"key":"action","value":"CreateSaveastring"}]}]}]'
timestamp: ""
tx: null
txhash: D37B7828C99BEC1625EABAD76E641093ADFE105CD321B07FA9E0AC6CEB180B5A

Error Case 2: Bad Default

See the default is set to with-dash instead of what apparently was scaffolded was withdash.

$ with-dashd tx thisisamodule
thisisamodule transactions subcommands

Usage:
  with-dashd tx thisisamodule [flags]
  with-dashd tx thisisamodule [command]

Available Commands:
  create-saveastring Create a new saveastring
  delete-saveastring Delete a saveastring by id
  update-saveastring Update a saveastring

Flags:
  -h, --help   help for thisisamodule

Global Flags:
      --chain-id string     The network chain ID (default "with-dash") // <-- SEE BAD DEFAULT HERE
      --home string         directory for config and data (default "/Users/wil/.with-dash")
      --log_format string   The logging format (json|plain) (default "plain")
      --log_level string    The logging level (trace|debug|info|warn|error|fatal|panic) (default "info")
      --trace               print out full stack trace on errors

Use "with-dashd tx thisisamodule [command] --help" for more information about a command.

Expected: Either with-dash is the chain id, or the default is set to withdash.

Please provide the version output

Thanks everyone. Starport really is great and just wanted to add something that tripped me up getting started with it.

Search terms for those who want a different name for a - char: chain id with hyphen, hyphenation, bar

gjermundgaraba commented 2 years ago

I just wanted to chime in on this since I just encountered this myself. This seems like an unnecessary speed bump for new people when trying to send their first transaction.

I might be inclined to help out with this issue as it seems fairly straightforward, but I think there is need for some clarity on the correct behavior before I dive into this.

As @wilwade mentioned in the issue there is a mismatch between what is being scaffolded and the default value.

I would imagine the "obivous" easy fix is to change the default value so it matches what is being scaffolded. But I wonder if it is intended (or wanted) that the chain-id should strip dashes? If yes: would be great to the context/why (and then I suppose the fix is to change the default value, and perhaps some kind of notice to the user upon scaffolding that the chain-id was stripped) If no: Is the fix then to update what starport scaffolds as the chain-id (to include the dashes)

mehdisbys commented 2 years ago

Thanks for this it saved me a lot of head scratching .

Maybe an easy solution would be to add more details in the error

from : signature verification failed; please verify account number (0) and chain-id

to : signature verification failed; please verify account number (0) and chain-id (with-dash) current value is (withdash)

@ilgooz (tagging you since I see you often in the Discord 😁 )

abrindam commented 2 years ago

Adding my voice here too - this just ate several hours of my life. As a newcomer, I had basically no idea how to solve this and assumed I must be doing something wrong. It was only after three hours or so that I got the "crazy" idea that it might be due to the dashes in my project name - which ultimately turned out to be correct.

Putting dashes in your project name is not unusual at all - in fact I would argue it is quite common, especially for GitHub projects (e.g. cosmos-sdk).

While trying to figure this out, I also found an additional workaround - you can explicitly set the chain-id in config.yml like so:

...
genesis:
  chain_id: "with-dashd"

Given that this works, it seems like chain-ids can have dashes in them so in response to @bjaanes 's excellent question, it seems like dashes don't need to be stripped.

My theory is that the stripping was originally intended for Go package names, which do not allow dashes, but it wound up affecting more than necessary.

I think the problem might here: https://github.com/ignite/cli/blob/develop/ignite/services/chain/chain.go#L248 (.N() strips out dashes)

ilgooz commented 2 years ago

cc @tbruyelle @jeronimoalbi