Open freshfab opened 2 years ago
Was just talking about this today with some folks and happened to see this issue.
This behavior is a known issue with the Cosmos SDK. When you call SetSDKContext, that setting is global within the SDK. I recommend that you avoid the AccAddress's .String() function and call EncodeBech32AccAddr
in Lens client/address.go
instead.
As a second option, you could call a function that holds the lock on the SDK context until its finished generating the address. For example, your function could be something like this:
sdkConfigMutex.Lock()
defer sdkConfigMutex.Unlock()
sdkConf := sdk.GetConfig()
sdkConf.SetBech32PrefixForAccount(cc.Config.AccountPrefix, cc.Config.AccountPrefix+"pub")
sdkConf.SetBech32PrefixForValidator(cc.Config.AccountPrefix+"valoper", cc.Config.AccountPrefix+"valoperpub")
sdkConf.SetBech32PrefixForConsensusNode(cc.Config.AccountPrefix+"valcons", cc.Config.AccountPrefix+"valconspub")
osmoAddr.String()
Thanks @KyleMoser , the first solution seems to work 🙏🏼
I have a program that needs to interact with multiple chains. I've given each chain-specific sub-module its own
ChainClient
&ChainClientConfig
to work with, but any time I want to interact with two chains or more (either via query or tx), the second one to get executed uses the Bech32 prefix of the module that was executed first.The calls to the SDK config did not panic, so it can't be sealed. AFAICS the calls are made each time
AccAddress.String()
orValAddress.String()
are called, so I tried the following:But that didn't work either. I'm not sure how much further down this rabbit hole goes, so maybe someone can enlighten me here.
How To Reproduce
Create two accounts in your local keyring, e.g. one for Cosmos and one for Osmosis.
Then, run this program.
This code example is intentionally racy as to show that the results are different each time you run the thing.