-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Properly handle gRPC and CLI's bech32 serialization of account addresses #7195
Comments
If we go with option 1, we need some protobuf annotations to indicate which type of address (account, validator, etc) is stored in the Option 2 is definitely simpler to implement and has the added benefit of obviating the need for client apps to properly handle bech32 <-> binary conversions and get the prefixes right for each chain. That would prevent a scenario where an app would mistakenly allow a user to use Not all state would need to be encoded as strings, but likely it is simpler to use strings for addresses almost everywhere in protobuf if we go with option 2. IBC by the way always encodes addresses as strings as far as I know. Possibly compression can mitigate the storage overhead. |
Without knowing in too much detail how difficult of a refactor it would be, i'm in favor of Option 2, as it seems like given the known disadvantage of Option 1, Option 2 is the better long term strategy. |
The more I dig-in, the more I am in favour of option-2. We might find some easy/hacky methods to gRPC gateway issues but option-2 looks clean comparatively. |
Wondering if we can move forward with a decision here.. Noting that:
I'd like to propose we move forward with Option 2: Change the |
The need to inject the address public async getAccount(searchAddress: string): Promise<Account | null> {
const { prefix } = Bech32.decode(searchAddress);
const account = await this.queryClient.auth.account(searchAddress);
return account ? accountFromProto(account, prefix /* use the prefix from the request in the result */) : null;
} If storage matters, I propose option 3A binary representation of a address's I'm not promoting this option but want to put it on the table. |
Currently in the SDK we store base account addresses (as well as any account address as raw bytes. This was chosen mainly for efficient storage reasons.
However, this decision has now resulted in complications when these fields are serialized using standard JSON / string marshalling over gPRC Gateway (for REST endpoints), or with jsonpb (used for encoding/decoding of CLI queries & txs).
In short, both jsonpb and gRPC gateway serialize raw bytes as base64 encoded strings by defualt, and we need all
account.address
fields to be serialized using our bech32 prefixed address strings.There are 2 main strategies we can pursue then:
option 1
Override the string serialization in jsonpb and gRPC gateway for these specific account fields.
Jsonpb is supposed to have some support for custom serialization of bytes, but @aaronc pointed out that this actually does not seem to work in both directions (encoding as well as decoding), and we would need it for both directions.
gRPC gateway may require a fork, or us writing some custom plugin logic around gRPC gateway to handle this.
Advantages:
Disadvantages:
option 2
Refactor all
address
fields in protobuf to be stored as strings instead of bytes.Advantages:
Disadvantages:
The text was updated successfully, but these errors were encountered: