Skip to content

feat: add gov v1 params #71

Draft
JeancarloBarrios wants to merge 7 commits intoDCFoundation:mainfrom
agoric-labs:JeancarloBarrios/adding-govv1-params
Draft

feat: add gov v1 params #71
JeancarloBarrios wants to merge 7 commits intoDCFoundation:mainfrom
agoric-labs:JeancarloBarrios/adding-govv1-params

Conversation

@JeancarloBarrios
Copy link
Copy Markdown

No description provided.

@netlify
Copy link
Copy Markdown

netlify bot commented Sep 10, 2025

Deploy Preview for cosmos-proposal-builder failed.

Name Link
🔨 Latest commit 66adc3a
🔍 Latest deploy log https://app.netlify.com/projects/cosmos-proposal-builder/deploys/68c960b49044860008497e3e

Comment on lines +100 to +101
maxDepositPeriod: durationToSeconds(params.maxDepositPeriod),
votingPeriod: durationToSeconds(params.votingPeriod),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The api returns the params in snake case

Suggested change
maxDepositPeriod: durationToSeconds(params.maxDepositPeriod),
votingPeriod: durationToSeconds(params.votingPeriod),
maxDepositPeriod: durationToSeconds(params.max_deposit_period),
votingPeriod: durationToSeconds(params.voting_period),

@michaelfig michaelfig force-pushed the JeancarloBarrios/adding-govv1-params branch from 87e02e1 to f9ec53d Compare September 11, 2025 16:27
import { CommunityPoolSpendProposal } from "cosmjs-types/cosmos/distribution/v1beta1/distribution";
import { Params as CosmjsGovV1Params } from "cosmjs-types/cosmos/gov/v1/gov";
import { MsgUpdateParams as MsgUpdateGovParamsV1, MsgSubmitProposal } from "cosmjs-types/cosmos/gov/v1/tx";
import Long from "long";
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is unidiomatic, use big int for seconds

Copy link
Copy Markdown
Collaborator

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

There is a possibility that the attached chain will know about governance parameters that are not present in the Protobuf that Cosgov is compiled against, and since this is downloading the entire parameter state, editing it, then pushing it back, there is a possibility that the new, unknown parameters will be implicitly reset to their zero values.

I am not sure what options we have in that case. If we’re downloading JSON, merging changes into that JSON, and submitting the JSON back in its entirety, there is no problem.

It is possible to write Protobuf stubs that associate parsed messages with aux metadata that includes the unparsed fields, mapping their field number to the corresponding read bytes, and then possible in turn to make the Protobuf writer incorporate the unknown fields. I do not believe that our stubs support this feature. It would be evident in the TypeScript type definition corresponding to the Protobuf message as a bag of unknown fields. So, we might be in a pickle.

It may simply be the case that we need the params parser to fail if it finds unrecognized fields so folks know not to use Cosgov until an upgrade is deployed.

Comment on lines +48 to +52
// Gov v1 Duration type (from protobuf)
export type Duration = {
seconds?: string;
nanos?: number;
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is weird. A single string in nanosecond resolution should suffice to represent a Go uint64-backed Duration and the two-field has multiple representations of the same value. Is this out of our hands?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am hoping (and believe) that these types are generated in @agoric/cosmic-proto and it’s a small matter of figuring out the import specifier that reaches them. That’ll mean looking in the "exports" of the package.json of @agoric/cosmic-proto (agoric-sdk/packages/cosmic-proto/package.json) and looking for the module specifier pattern on the left that matches the physical location of the generated types on the right. I believe that’s reaching into dist/*, but those are generated form generated code at src/codegen.

Comment on lines +62 to +63
// Remove duplicate - will use the one at the end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TODO

const data: GovV1ParamsQueryResponse = await res.json();
return data?.params;
},
enabled: !!api,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It may be desirable to be more explicit. For the type definition for api, this is equivalent to api !== undefined && api !== '', taking into account the string-to-boolean implicit coercion rules for boolean. I’m wondering whether both terms are intentional. For Protobuf, I would expect empty string to correspond to either “absent on the wire because the sender didn’t know about it, or absent because the sender explicitly set it to empty string”, which are not distinguishable. In JavaScript, I would expect, if the api is optional, that it must be undefined when not provided, and I would assert that the string is valid (not "") if it is provided.

Comment on lines +186 to +203
export const makeGovV1ProposalMsg = ({
messages,
initialDeposit,
proposer,
metadata,
title,
summary,
}: MsgSubmitProposal) => ({
typeUrl: "/cosmos.gov.v1.MsgSubmitProposal",
value: MsgSubmitProposal.fromPartial({
messages,
initialDeposit,
proposer,
metadata,
title,
summary,
}),
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I’m suspicious of the value that these builders are providing. They seem to be the sort of thing that ought to be present in the generated code, or have more precise types than the generated code, or perform some translation, but they do not seem to do any of these things and might as well be inlined.

Comment on lines +12 to +14
import { Params as CosmjsGovV1Params } from "cosmjs-types/cosmos/gov/v1/gov";
import { MsgUpdateParams as MsgUpdateGovParamsV1, MsgSubmitProposal } from "cosmjs-types/cosmos/gov/v1/tx";
import { Long } from "cosmjs-types/helpers";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see there’s precedent for using cosmjs-types here, but I suspect (and am uncertain) we could be using the stubs generated for @agoric/cosmic-proto and have a more uniform treatment of Protobuf. The use of Long in particular suggests that these stubs predate the availability of bigint for representing 64 bit integers and beyond on the JavaScript side.

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.

4 participants