Skip to content

Replace bach32 with AccAddress in dex module#483

Merged
LCyson merged 5 commits intomasterfrom
bech32
Jan 13, 2023
Merged

Replace bach32 with AccAddress in dex module#483
LCyson merged 5 commits intomasterfrom
bech32

Conversation

@LCyson
Copy link
Contributor

@LCyson LCyson commented Jan 12, 2023

Describe your changes and provide context

Current x/dex module uses plain bech32 string instead of sdk.AccAddress bytes as the KVStore key, which is inconsistent with other cosmos native modules. This issue causes the parallelization access operators unable to identify dex module KVStore resource correctly and blocks users from defining the correct dex resource dependency.

This PR adds the following changes:

  • Changed all KVStore key in dex/types/keys.go from bech32 string to sdk.AccAddress bytes
  • Updated all affected unit tests
  • Updated the local Sei deployment script to work with the latest tendermint version
  • Refactor dex/msgservers to use the ValidateBasic in the message_ files to gate bech32 incompatible addresses
  • Fix an ordering non-agnostic bug found in the contract registration (see details in the code)

Testing performed to validate your change

Unit test, e2e test

Next Steps

Discussed with @philipsu522 and @codchen, we would like to change all bech32 string used in any sei-chain custom module to sdk.AccAddress to be consistent:

dependency.ImmediateYoungerSibling = ""
found := false
for _, contractInfo := range allContractInfo {
if contractInfo.ContractAddr == newContract.ContractAddr {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was not order agnostic previously @codchen and it updated the newContract to its dependency in a wrong order

func ContractKeyPrefix(p string, contractAddr string) []byte {
return append([]byte(p), []byte(contractAddr)...)
address, _ := sdk.AccAddressFromBech32(contractAddr)
return append([]byte(p), address.Bytes()...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmos SDK uses address.MustLengthPrefix to pad the bytes so we probably want to do the same too https://github.com/sei-protocol/sei-cosmos/blob/main/x/bank/types/key.go#L58

Copy link
Contributor Author

@LCyson LCyson Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think only bank module uses that, other modules use plain accAddress bytes: https://github.com/sei-protocol/sei-cosmos/blob/main/x/auth/types/keys.go#L30-L37

actually err: other modules use MustLengthPrefix, only the auth module uses the plain accAddress as the prefix, I'll change this to MustLengthPrefix in this case

@github-actions
Copy link

Code Coverage

Package Line Rate Complexity Health
github.com/sei-protocol/sei-chain/aclmapping/bank 83% 0
github.com/sei-protocol/sei-chain/aclmapping/dex 100% 0
github.com/sei-protocol/sei-chain/aclmapping/oracle 100% 0
github.com/sei-protocol/sei-chain/aclmapping/staking 82% 0
github.com/sei-protocol/sei-chain/aclmapping/tokenfactory 96% 0
github.com/sei-protocol/sei-chain/aclmapping/utils 0% 0
github.com/sei-protocol/sei-chain/aclmapping/wasm 83% 0
github.com/sei-protocol/sei-chain/app 59% 0
github.com/sei-protocol/sei-chain/app/antedecorators 74% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/config 85% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/oracle 73% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/oracle/provider 49% 0
github.com/sei-protocol/sei-chain/oracle/price-feeder/router/v1 45% 0
github.com/sei-protocol/sei-chain/store/whitelist/cachemulti 100% 0
github.com/sei-protocol/sei-chain/store/whitelist/kv 100% 0
github.com/sei-protocol/sei-chain/store/whitelist/multi 100% 0
github.com/sei-protocol/sei-chain/utils 46% 0
github.com/sei-protocol/sei-chain/utils/datastructures 90% 0
github.com/sei-protocol/sei-chain/x/dex 58% 0
github.com/sei-protocol/sei-chain/x/dex/cache 86% 0
github.com/sei-protocol/sei-chain/x/dex/client/cli/query 23% 0
github.com/sei-protocol/sei-chain/x/dex/contract 51% 0
github.com/sei-protocol/sei-chain/x/dex/exchange 89% 0
github.com/sei-protocol/sei-chain/x/dex/keeper 67% 0
github.com/sei-protocol/sei-chain/x/dex/keeper/abci 29% 0
github.com/sei-protocol/sei-chain/x/dex/keeper/msgserver 77% 0
github.com/sei-protocol/sei-chain/x/dex/keeper/query 82% 0
github.com/sei-protocol/sei-chain/x/dex/migrations 87% 0
github.com/sei-protocol/sei-chain/x/dex/types 1% 0
github.com/sei-protocol/sei-chain/x/dex/types/utils 100% 0
github.com/sei-protocol/sei-chain/x/dex/types/wasm 83% 0
github.com/sei-protocol/sei-chain/x/epoch 11% 0
github.com/sei-protocol/sei-chain/x/epoch/keeper 66% 0
github.com/sei-protocol/sei-chain/x/epoch/types 2% 0
github.com/sei-protocol/sei-chain/x/mint 0% 0
github.com/sei-protocol/sei-chain/x/mint/keeper 75% 0
github.com/sei-protocol/sei-chain/x/mint/simulation 95% 0
github.com/sei-protocol/sei-chain/x/mint/types 2% 0
github.com/sei-protocol/sei-chain/x/nitro/client/cli 45% 0
github.com/sei-protocol/sei-chain/x/nitro/keeper 80% 0
github.com/sei-protocol/sei-chain/x/nitro/replay 63% 0
github.com/sei-protocol/sei-chain/x/oracle 64% 0
github.com/sei-protocol/sei-chain/x/oracle/keeper 82% 0
github.com/sei-protocol/sei-chain/x/oracle/simulation 18% 0
github.com/sei-protocol/sei-chain/x/oracle/types 3% 0
github.com/sei-protocol/sei-chain/x/tokenfactory/keeper 85% 0
github.com/sei-protocol/sei-chain/x/tokenfactory/types 2% 0
Summary 15% (5023 / 33925) 0

Copy link
Contributor

@philipsu522 philipsu522 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for this! Do you mind updating the title (i think there are typos)

if err != nil {
return nil, err
}
creatorAddr, _ := sdk.AccAddressFromBech32(contract.Creator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still handle err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no we can assume the creatorAddr must be a valid bech32 address (as all msgserver has validated any request's address). This is also aligned with how other cosmos native modules convert bech32 address

@LCyson LCyson changed the title Replace bach32 with AddAddress in dex module Replace bach32 with AccAddress in dex module Jan 13, 2023
@LCyson LCyson merged commit a0757cf into master Jan 13, 2023
masih pushed a commit that referenced this pull request Sep 29, 2025
## Describe your changes and provide context
This PR add latency and retries to occ scheduler log
## Testing performed to validate your change
masih pushed a commit that referenced this pull request Sep 30, 2025
## Describe your changes and provide context
This PR add latency and retries to occ scheduler log
## Testing performed to validate your change
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.

3 participants