ADR-019/020 cleanups: HybridCodec, Pubkey (#8683)
* wip adr019 * Remove hybrid codec * Change date * Update docs/architecture/adr-019-protobuf-state-encoding.md Co-authored-by: Robert Zaremba <robert@zaremba.ch> * Update pubkey interface Co-authored-by: Robert Zaremba <robert@zaremba.ch> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
5d3f29b089
commit
19e79e00d6
|
@ -7,6 +7,7 @@
|
||||||
- 2020 Apr 27: Convert usages of `oneof` for interfaces to `Any`
|
- 2020 Apr 27: Convert usages of `oneof` for interfaces to `Any`
|
||||||
- 2020 May 15: Describe `cosmos_proto` extensions and amino compatibility
|
- 2020 May 15: Describe `cosmos_proto` extensions and amino compatibility
|
||||||
- 2020 Dec 4: Move and rename `MarshalAny` and `UnmarshalAny` into the `codec.Marshaler` interface.
|
- 2020 Dec 4: Move and rename `MarshalAny` and `UnmarshalAny` into the `codec.Marshaler` interface.
|
||||||
|
- 2021 Feb 24: Remove mentions of `HybridCodec`, which has been abandoned in [#6843](https://github.com/cosmos/cosmos-sdk/pull/6843).
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
|
@ -59,24 +60,26 @@ We will adopt [Protocol Buffers](https://developers.google.com/protocol-buffers)
|
||||||
persisted structured data in the Cosmos SDK while providing a clean mechanism and developer UX for
|
persisted structured data in the Cosmos SDK while providing a clean mechanism and developer UX for
|
||||||
applications wishing to continue to use Amino. We will provide this mechanism by updating modules to
|
applications wishing to continue to use Amino. We will provide this mechanism by updating modules to
|
||||||
accept a codec interface, `Marshaler`, instead of a concrete Amino codec. Furthermore, the Cosmos SDK
|
accept a codec interface, `Marshaler`, instead of a concrete Amino codec. Furthermore, the Cosmos SDK
|
||||||
will provide three concrete implementations of the `Marshaler` interface: `AminoCodec`, `ProtoCodec`,
|
will provide two concrete implementations of the `Marshaler` interface: `AminoCodec` and `ProtoCodec`.
|
||||||
and `HybridCodec`.
|
|
||||||
|
|
||||||
- `AminoCodec`: Uses Amino for both binary and JSON encoding.
|
- `AminoCodec`: Uses Amino for both binary and JSON encoding.
|
||||||
- `ProtoCodec`: Uses Protobuf for or both binary and JSON encoding.
|
- `ProtoCodec`: Uses Protobuf for both binary and JSON encoding.
|
||||||
- `HybridCodec`: Uses Amino for JSON encoding and Protobuf for binary encoding.
|
|
||||||
|
|
||||||
Until the client migration landscape is fully understood and designed, modules will use a `HybridCodec`
|
Modules will use whichever codec that is instantiated in the app. By default, the SDK's `simapp`
|
||||||
as the concrete codec it accepts and/or extends. This means that all client JSON encoding, including
|
instantiates a `ProtoCodec` as the concrete implementation of `Marshaler`, inside the `MakeTestEncodingConfig`
|
||||||
genesis state, will still use Amino. The ultimate goal will be to replace Amino JSON encoding with
|
function. This can be easily overwritten by app developers if they so desire.
|
||||||
Protbuf encoding and thus have modules accept and/or extend `ProtoCodec`.
|
|
||||||
|
The ultimate goal will be to replace Amino JSON encoding with Protobuf encoding and thus have
|
||||||
|
modules accept and/or extend `ProtoCodec`. Until then, Amino JSON is still provided for legacy use-cases.
|
||||||
|
A handful of places in the SDK still have Amino JSON hardcoded, such as the Legacy API REST endpoints
|
||||||
|
and the `x/params` store. They are planned to be converted to Protobuf in a gradual manner.
|
||||||
|
|
||||||
### Module Codecs
|
### Module Codecs
|
||||||
|
|
||||||
Modules that do not require the ability to work with and serialize interfaces, the path to Protobuf
|
Modules that do not require the ability to work with and serialize interfaces, the path to Protobuf
|
||||||
migration is pretty straightforward. These modules are to simply migrate any existing types that
|
migration is pretty straightforward. These modules are to simply migrate any existing types that
|
||||||
are encoded and persisted via their concrete Amino codec to Protobuf and have their keeper accept a
|
are encoded and persisted via their concrete Amino codec to Protobuf and have their keeper accept a
|
||||||
`Marshaler` that will be a `HybridCodec`. This migration is simple as things will just work as-is.
|
`Marshaler` that will be a `ProtoCodec`. This migration is simple as things will just work as-is.
|
||||||
|
|
||||||
Note, any business logic that needs to encode primitive types like `bool` or `int64` should use
|
Note, any business logic that needs to encode primitive types like `bool` or `int64` should use
|
||||||
[gogoprotobuf](https://github.com/gogo/protobuf) Value types.
|
[gogoprotobuf](https://github.com/gogo/protobuf) Value types.
|
||||||
|
@ -207,7 +210,7 @@ Note that `InterfaceRegistry` usage does not deviate from standard protobuf
|
||||||
usage of `Any`, it just introduces a security and introspection layer for
|
usage of `Any`, it just introduces a security and introspection layer for
|
||||||
golang usage.
|
golang usage.
|
||||||
|
|
||||||
`InterfaceRegistry` will be a member of `ProtoCodec` and `HybridCodec` as
|
`InterfaceRegistry` will be a member of `ProtoCodec`
|
||||||
described above. In order for modules to register interface types, app modules
|
described above. In order for modules to register interface types, app modules
|
||||||
can optionally implement the following interface:
|
can optionally implement the following interface:
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
- 2020 August 19: Move sequence field from `SignDoc` to `SignerInfo`, as discussed in [#6966](https://github.com/cosmos/cosmos-sdk/issues/6966).
|
- 2020 August 19: Move sequence field from `SignDoc` to `SignerInfo`, as discussed in [#6966](https://github.com/cosmos/cosmos-sdk/issues/6966).
|
||||||
- 2020 September 25: Remove `PublicKey` type in favor of `secp256k1.PubKey`, `ed25519.PubKey` and `multisig.LegacyAminoPubKey`.
|
- 2020 September 25: Remove `PublicKey` type in favor of `secp256k1.PubKey`, `ed25519.PubKey` and `multisig.LegacyAminoPubKey`.
|
||||||
- 2020 October 15: Add `GetAccount` and `GetAccountWithHeight` methods to the `AccountRetriever` interface.
|
- 2020 October 15: Add `GetAccount` and `GetAccountWithHeight` methods to the `AccountRetriever` interface.
|
||||||
|
- 2021 Feb 24: The SDK does not use Tendermint's `PubKey` interface anymore, but its own `cryptotypes.PubKey`. Updates to reflect this.
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
|
@ -286,7 +287,7 @@ and `FileDescriptor`s and returns a boolean result.
|
||||||
|
|
||||||
### Public Key Encoding
|
### Public Key Encoding
|
||||||
|
|
||||||
Public keys in the Cosmos SDK implement Tendermint's `crypto.PubKey` interface.
|
Public keys in the Cosmos SDK implement the `cryptotypes.PubKey` interface.
|
||||||
We propose to use `Any` for protobuf encoding as we are doing with other interfaces (e.g. in `BaseAccount` `PubKey` or `SignerInfo` `PublicKey`).
|
We propose to use `Any` for protobuf encoding as we are doing with other interfaces (e.g. in `BaseAccount` `PubKey` or `SignerInfo` `PublicKey`).
|
||||||
Following public keys are implemented: secp256k1, ed25519 and multisignature.
|
Following public keys are implemented: secp256k1, ed25519 and multisignature.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue