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

fix(cosmosclient): fix account prefix config #2743

Merged
merged 2 commits into from
Aug 12, 2022

Conversation

lumtis
Copy link
Contributor

@lumtis lumtis commented Aug 12, 2022

account prefix config not correct when broadcasting a tx from a newly created default account

Fixes #2738

There is a weird bug from 0.46

When broadcasting a tx without mentioning an account with the --from flag, an account default is used. If default doesn't exist, the account will be created on the fly and will request tokens with the faucet.

In the case, default is created on the fly, the address prefix update in the SDK global config:

config.SetBech32PrefixForAccount(c.addressPrefix, c.addressPrefix+"pub")

will not update the prefix, from cosmos to spn for example. This will make the method fails because cosmos prefix will be used and the error in the related issue will occur using network commands for example.
If the command is rerun, default will exist at this point and the command will then succeed with updated prefix.

This may be caused by a race condition since SDK config is global?

This fix is more a workaround rather than a long term fix. We also update the config when create cosmosclient in New, when doing this update in this method, the prefix will be effectively updated in BroadcastTx solving the attached issue.

We keep the call in BroadcastTx in case several instance of cosmosclient exists in the program.

In the long, term we should find another way to manage prefixes, which may require refactoring in the SDK as well, I will create an issue for this

@lumtis
Copy link
Contributor Author

lumtis commented Aug 12, 2022

Might solves #2128

@lumtis lumtis self-assigned this Aug 12, 2022
@ilgooz ilgooz changed the title fix(cosmosclient): account prefix config not correct when broadcasting a tx from a newly created default account fix(cosmosclient): account prefix config Aug 12, 2022
@ilgooz ilgooz changed the title fix(cosmosclient): account prefix config fix(cosmosclient): fix account prefix config Aug 12, 2022
@tbruyelle
Copy link
Contributor

@lubtd In the node command PR, @bjaanes has also refactored this part with a similar method.
The main difference is the mutex is not unlocked at the end of the method but at the end of the caller of that method, maybe it's worth a try?

@lumtis
Copy link
Contributor Author

lumtis commented Aug 12, 2022

@lubtd In the node command PR, @bjaanes has also refactored this part with a similar method. The main difference is the mutex is not unlocked at the end of the method but at the end of the caller of that method, maybe it's worth a try?

I tested this and it didn't work. I really needed to set the config in New

Also, I don't think lockBech32Prefix name is adapted as the config is not locked but can be modified at anytime

@lumtis
Copy link
Contributor Author

lumtis commented Aug 12, 2022

@lubtd In the node command PR, @bjaanes has also refactored this part with a similar method.
The main difference is the mutex is not unlocked at the end of the method but at the end of the caller of that method, maybe it's worth a try?

@tbruyelle do you have a link to the related PR?

@tbruyelle
Copy link
Contributor

@tbruyelle do you have a link to the related PR?

Sure, #2669

@lumtis
Copy link
Contributor Author

lumtis commented Aug 12, 2022

Thanks!
I think we can move forward with both PR and see when the conflict will arise, it's a small conflict so it's fine. As said I would tend to use the naming I set here for the method

@lumtis lumtis merged commit b098f3a into feat/sdk-ibc-upgrade Aug 12, 2022
@lumtis lumtis deleted the fix/client-invalid-prefix branch August 12, 2022 13:41
@tbruyelle
Copy link
Contributor

Thanks! I think we can move forward with both PR and see when the conflict will arise, it's a small conflict so it's fine. As said I would tend to use the naming I set here for the method

I investigated and found out that the error comes from the AccountRetriever :

func prepareFactory(clientCtx client.Context, txf tx.Factory) (tx.Factory, error) {
	from := clientCtx.GetFromAddress()
	fmt.Println("prefix", sdktypes.GetConfig().GetBech32AccountAddrPrefix())
	fmt.Println("from", from.String())

	if err := txf.AccountRetriever().EnsureExists(clientCtx, from); err != nil {
		return txf, err              // <---- HERE
	}

When I reproduce the error, the debug output gives

prefix spn
from cosmos1kzwujdkez5y5ahfywhfl3txzxrmkrvwgc2gxmz

from is a sdktypes.Address, where the String() method should be impacted by the configured prefix, but it also uses a cache mechanism, and since there's a hit (I suppose String() has been called before we change the prefix in the config), the cached hit is returned :/

That's a shame the cache doesn't use the prefix as part of the key!

That's why when you set the prefix in the config at the very beginning (in cosmosclient.New()), you don't have the problem.

aljo242 pushed a commit that referenced this pull request Aug 17, 2022
* docs(changelog): add unreleased section

* feat!: Cosmos SDK v0.46.0 (#2675)

* update go mod

* update ibc path

* fix merge errors

* add temp client mock

* fix: deps (#2676)

* revert packages to old ibc-go

* fix remaining ibc paths

* fix template go.sum

* panic keyring errors

* add mockery generate instructions

* regenerate mocks

Co-authored-by: İlker G. Öztürk <[email protected]>

* fix merge

* update spn

* upgrade spn

* remove ibc-go fork

* template updates

* fix ibc and oracle templates

* update templates

* remaining tempalte updates

* fix template

* fix faucet test

* use beta ibc release

* update deps in template

* use ibcmodule idiom (#2692)

* Update ignite/templates/module/create/ibc/x/{{moduleName}}/module_ibc.go.plush

Co-authored-by: Lucas Btd <[email protected]>

* fix(`pkg/cosmosaccount`): register cryptocodec interfaces (#2702)

* register crypto codec interfaces

* improve error messages

* fix(template): removed unused methods and fix comments (#2708)

* fix(`cosmosclient`): use protobuf Any for TxMsgData  (#2714)

* fix comment

* use proto Any

* Update ignite/pkg/cosmosclient/cosmosclient.go

Co-authored-by: Lucas Btd <[email protected]>

Co-authored-by: Lucas Btd <[email protected]>

* chore(0.46): upgrade spn version (#2730)

* feat(`app`): add interchain accounts for `v0.46.0` (#2703)

* update template for ica

* Update ignite/templates/app/stargate/app/app.go.plush

Co-authored-by: Lucas Btd <[email protected]>

Co-authored-by: Lucas Btd <[email protected]>

* fix: change relayer call to use secp256k1 private keys in call (#2729)

This chage uses secp256k1 private keys instead of ASCII armored ones as
gRPC arguments when calling the TS relayer.

* docs: update tutorials (#2737)

- Change `ibc-go` import to use "v5"
- Add package missing definition to code examples that can be copy/pasted
- Change file references to paths, for consistency with other tutorials
- Fix interchange tutorial to use ports that don't overlap
- Remove unused imports
- Fix documentation issues

* feat: upgrade `ts-relayer` dependencies (#2722)

* chore: upgrade `@confio/relayer` to the latest version 0.5.1
* chore: update `@cosmjs` to version 0.28.9
* chore: remove `@cosmjs/launchpad` from dependencies
* chore: add new dependency `@cosmjs/encoding` for relayer
* chore: add `sinon` dependency required to build the relayer
* fix: remove "gasLimit" option from relayer
* fix: update `@cosmjs` to version 0.28.11

* fix(cosmosclient): fix account prefix config (#2743)

* fix(cosmosclient): account prefix config not correct when broadcasting a tx from a newly created default account

* add issue

Co-authored-by: Alex Johnson <[email protected]>
Co-authored-by: Lucas Btd <[email protected]>
Co-authored-by: Denis Fadeev <[email protected]>
Co-authored-by: Jerónimo Albi <[email protected]>
Jchicode pushed a commit to Jchicode/cli that referenced this pull request Aug 9, 2023
* docs(changelog): add unreleased section

* feat!: Cosmos SDK v0.46.0 (ignite#2675)

* update go mod

* update ibc path

* fix merge errors

* add temp client mock

* fix: deps (ignite#2676)

* revert packages to old ibc-go

* fix remaining ibc paths

* fix template go.sum

* panic keyring errors

* add mockery generate instructions

* regenerate mocks

Co-authored-by: İlker G. Öztürk <[email protected]>

* fix merge

* update spn

* upgrade spn

* remove ibc-go fork

* template updates

* fix ibc and oracle templates

* update templates

* remaining tempalte updates

* fix template

* fix faucet test

* use beta ibc release

* update deps in template

* use ibcmodule idiom (ignite#2692)

* Update ignite/templates/module/create/ibc/x/{{moduleName}}/module_ibc.go.plush

Co-authored-by: Lucas Btd <[email protected]>

* fix(`pkg/cosmosaccount`): register cryptocodec interfaces (ignite#2702)

* register crypto codec interfaces

* improve error messages

* fix(template): removed unused methods and fix comments (ignite#2708)

* fix(`cosmosclient`): use protobuf Any for TxMsgData  (ignite#2714)

* fix comment

* use proto Any

* Update ignite/pkg/cosmosclient/cosmosclient.go

Co-authored-by: Lucas Btd <[email protected]>

Co-authored-by: Lucas Btd <[email protected]>

* chore(0.46): upgrade spn version (ignite#2730)

* feat(`app`): add interchain accounts for `v0.46.0` (ignite#2703)

* update template for ica

* Update ignite/templates/app/stargate/app/app.go.plush

Co-authored-by: Lucas Btd <[email protected]>

Co-authored-by: Lucas Btd <[email protected]>

* fix: change relayer call to use secp256k1 private keys in call (ignite#2729)

This chage uses secp256k1 private keys instead of ASCII armored ones as
gRPC arguments when calling the TS relayer.

* docs: update tutorials (ignite#2737)

- Change `ibc-go` import to use "v5"
- Add package missing definition to code examples that can be copy/pasted
- Change file references to paths, for consistency with other tutorials
- Fix interchange tutorial to use ports that don't overlap
- Remove unused imports
- Fix documentation issues

* feat: upgrade `ts-relayer` dependencies (ignite#2722)

* chore: upgrade `@confio/relayer` to the latest version 0.5.1
* chore: update `@cosmjs` to version 0.28.9
* chore: remove `@cosmjs/launchpad` from dependencies
* chore: add new dependency `@cosmjs/encoding` for relayer
* chore: add `sinon` dependency required to build the relayer
* fix: remove "gasLimit" option from relayer
* fix: update `@cosmjs` to version 0.28.11

* fix(cosmosclient): fix account prefix config (ignite#2743)

* fix(cosmosclient): account prefix config not correct when broadcasting a tx from a newly created default account

* add issue

Co-authored-by: Alex Johnson <[email protected]>
Co-authored-by: Lucas Btd <[email protected]>
Co-authored-by: Denis Fadeev <[email protected]>
Co-authored-by: Jerónimo Albi <[email protected]>
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 this pull request may close these issues.

network publish: always fails when publishing a chain for the first time
3 participants