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

add annotations for client tooling and codegen #3782

Closed

Conversation

pyramation
Copy link

@pyramation pyramation commented Dec 18, 2022

What is the purpose of the change

This adds new annotations used by codegen tools to create encoders/decoders that can manage the google.protobuf.Any types. This change has many (positive) implications:

RPC calls get properly decoded

Currently, when you do an RPC call, for example,

const request: QueryPoolsRequest;
const result = await osmosis.gamm.v1beta1.pools(request);

In the current system, you get back results that just have a bunch of encoded bytes (not very useful for FE devs):

{
  "pools": [
    {
        "typeUrl": "/osmosis.gamm.v1beta1.Pool",
        "value": <a bunch of bytes>
    },
    {
        "typeUrl": "/osmosis.gamm.v1beta1.Pool",
        "value": <a bunch of bytes>
    },
    ...
    {
        "typeUrl": "/osmosis.gamm.poolmodels.stableswap.v1beta1.Pool",
        "value": <a bunch of bytes>
    }
  ]
}

Leveraging the implements_interface and accepts_interface, we can now derive and generate decoders, in this case, the pools:

export const PoolI_InterfaceDecoder = (input: _m0.Reader | Uint8Array): Pool1 | Pool2 | Any => {
  const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
  const data = Any.decode(reader, reader.uint32());

  switch (data.typeUrl) {
    case "/osmosis.gamm.v1beta1.Pool":
      return Pool1.decode(data.value);

    case "/osmosis.gamm.poolmodels.stableswap.v1beta1.Pool":
      return Pool2.decode(data.value);

    default:
      return data;
  }
};

This will now give us the expected API result when fetching pools (and will also close issues like this one and make people like Larry0x happy)

Messages with nested messages/protos and their amino encoders for ledger support

Additionally, we can create encoders for toAmino/fromAmino that leverage interfaces with proper annotations. Here is an example for proposals that multiplex on content using the Content interface:

This can enable a new class of dApps built on osmosis. Currently developers have to manually construct all of these encodings.

Changes required

importing amino/amino.proto

  • we need to be able to import amino/amino.proto which currently exists in the cosmos/cosmos-sdk
  • issue in osmosis-labs/cosmos-sdk is here

Notes (and nice to haves)

Missing codec registrations

These are missing amino registrations (via RegisterConcrete):

  • MsgExtendLockup
  • MsgForceUnlock
  • MsgRedelegateValidatorSet

These are missing amino registration (via RegisterConcrete), but registered via RegisterProposalTypeCodec:

  • ReplacePoolIncentivesProposal (osmosis/ReplacePoolIncentivesProposal)
  • SetProtoRevAdminAccountProposal
  • SetProtoRevEnabledProposal

Conventions

convention for Register* names (amino/proposal/etc)

should we have a convention for Register* names? I noticed some discrepancies:

  • osmosis/SetSuperfluidAssetsProposal for RegisterProposalTypeCodec vs osmosis/set-superfluid-assets-proposal for RegisterConcrete
  • osmosis/UpdatePoolIncentivesProposal is used for BOTH RegisterProposalTypeCodec and RegisterConcrete

interface conventions

Once we resolve that conversation, we can determine if we need to do this

-  option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";
+ option (cosmos_proto.implements_interface) = "Content";

Brief Changelog

  • imports amino/amino.proto (which means this PR needs to be rebased BEFORE merge, issue here)
  • adds interface annotations
  • adds amino annotations

Testing and Verifying

This change added tests and can be verified as follows:

  • should NOT affect Go compilation (to my knowledge)
  • was tested locally for tranpilation/codegen with Telescope

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? NO — not for Go or Cosmos SDK side of things.

@faddat
Copy link
Member

faddat commented Dec 18, 2022

I'm of the opinion that it is important to make Larry happy!

You mentioned that this would be aided by adding annotations to the osmosis-sdk, right?

@pyramation
Copy link
Author

pyramation commented Dec 18, 2022

I'm of the opinion that it is important to make Larry happy!

You mentioned that this would be aided by adding annotations to the osmosis-sdk, right?

yep! this depends on importing amino/amino.proto, which is a new proto that exists in the cosmos/cosmos-sdk. I've raised an issue in osmosis-labs/cosmos-sdk here

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Looks great to me! I'll do the proto builds

@ValarDragon
Copy link
Member

ah wait no, we need to update our SDK to have amino.proto first.

@pyramation
Copy link
Author

ah wait no, we need to update our SDK to have amino.proto first.

yep, issue documented here, will comment over there now osmosis-labs/cosmos-sdk#400

Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

Do we have any test that has been done to ensure that this way of amino encoding / decoding ensures compatibility with the old way of handling amino?

Otherwise LGTM, but lets hold merging until osmosis-labs/cosmos-sdk#400 has been pushed forward

@pyramation
Copy link
Author

pyramation commented Jan 3, 2023

Do we have any test that has been done to ensure that this way of amino encoding / decoding ensures compatibility with the old way of handling amino?

There is not a test, but as far as I understand it, this is only annotations for fields, option (amino.name). No Go code should be affected. Maybe @AmauryM or @tac0turtle can comment more about the impact these annotations have as they're aware of the new proto annotations.

Otherwise LGTM, but lets hold merging until osmosis-labs/cosmos-sdk#400 has been pushed forward

Cool!

@tac0turtle
Copy link
Contributor

this will not effect go code since the generator doesn't account for it. It will be part of the proto descriptor that clients can use though

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Jan 18, 2023
@pyramation
Copy link
Author

let's not mark this as stale or old, thanks!

@github-actions github-actions bot removed the Stale label Jan 19, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2023

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Feb 2, 2023
@mattverse mattverse removed the Stale label Feb 2, 2023
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Feb 17, 2023
@pyramation
Copy link
Author

let me know if we can make this PR happen, or if I need to rebase and make a new one, thanks!

@github-actions github-actions bot removed the Stale label Feb 23, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Mar 9, 2023
@p0mvn p0mvn removed the Stale label Mar 13, 2023
@pyramation
Copy link
Author

hey @mattverse — the last PR adds the amino file, right? Which means we likely can add this PR soon.

@mattverse
Copy link
Member

hey @pyramation yeah! working on porting your changes over right now

@mattverse
Copy link
Member

mattverse commented Mar 15, 2023

@pyramation Would you mind if I close this PR and open a new PR that includes these changes? Need some additional updates in go.mod and compile protobuf files as well

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Mar 30, 2023
@pyramation
Copy link
Author

@pyramation Would you mind if I close this PR and open a new PR that includes these changes? Need some additional updates in go.mod and compile protobuf files as well

whatever works! sounds good!

@github-actions github-actions bot removed the Stale label Mar 31, 2023
@mattverse
Copy link
Member

@pyramation sweet! Closing this in favor of #4629

@mattverse mattverse closed this Apr 6, 2023
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.

6 participants