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

sdk v50 proposal compatibility #840

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,20 @@ func (tn *ChainNode) QueryProposal(ctx context.Context, proposalID string) (*Pro
return &proposal, nil
}

// QueryProposal returns the state and details of an IBC-Go v8 / SDK v50 governance proposal.
func (tn *ChainNode) QueryProposalV8(ctx context.Context, proposalID string) (*ProposalResponseV8, error) {
stdout, _, err := tn.ExecQuery(ctx, "gov", "proposal", proposalID)
if err != nil {
return nil, err
}
var proposal ProposalResponseV8
err = json.Unmarshal(stdout, &proposal)
if err != nil {
return nil, err
}
return &proposal, nil
}

// SubmitProposal submits a gov v1 proposal to the chain.
func (tn *ChainNode) SubmitProposal(ctx context.Context, keyName string, prop TxProposalv1) (string, error) {
// Write msg to container
Expand Down
15 changes: 14 additions & 1 deletion chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ func (c *CosmosChain) QueryProposal(ctx context.Context, proposalID string) (*Pr
return c.getFullNode().QueryProposal(ctx, proposalID)
}

// QueryProposal returns the state and details of an IBC-Go v8 / SDK v50 governance proposal.
func (c *CosmosChain) QueryProposalV8(ctx context.Context, proposalID string) (*ProposalResponseV8, error) {
return c.getFullNode().QueryProposalV8(ctx, proposalID)
}

// PushNewWasmClientProposal submits a new wasm client governance proposal to the chain
func (c *CosmosChain) PushNewWasmClientProposal(ctx context.Context, keyName string, fileName string, prop TxProposalv1) (TxProposal, string, error) {
tx := TxProposal{}
Expand Down Expand Up @@ -439,7 +444,9 @@ func (c *CosmosChain) SubmitProposal(ctx context.Context, keyName string, prop T
}

// Build a gov v1 proposal type.
func (c *CosmosChain) BuildProposal(messages []cosmosproto.Message, title, summary, metadata, depositStr string) (TxProposalv1, error) {
//
// The proposer field should only be set for IBC-Go v8 / SDK v50 chains.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also add some sort of note that the expedited field is also not ingested for non-sdk50 chains.

Copy link
Member Author

@Reecepbcups Reecepbcups Nov 7, 2023

Choose a reason for hiding this comment

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

this will not matter so long as proposer is blank. Will error out if they try anything for legacy chains

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait how does depositStr come into play here?

Copy link
Member Author

Choose a reason for hiding this comment

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

oops! sorry I mis-copied proposer

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy that. It was more of a guidance thing for users. But yea, it's self explanatory, should be fine.

func (c *CosmosChain) BuildProposal(messages []cosmosproto.Message, title, summary, metadata, depositStr, proposer string, expedited bool) (TxProposalv1, error) {
var propType TxProposalv1
rawMsgs := make([]json.RawMessage, len(messages))

Expand All @@ -459,6 +466,12 @@ func (c *CosmosChain) BuildProposal(messages []cosmosproto.Message, title, summa
Summary: summary,
}

// SDK v50 only
if proposer != "" {
propType.Proposer = proposer
propType.Expedited = expedited
}

return propType, nil
}

Expand Down
25 changes: 25 additions & 0 deletions chain/cosmos/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,35 @@ import (
"fmt"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)

// ConvertProposalStatus converts a proposal status int to a string from IBC-Go v8 / SDK v50 chains.
func ConvertStatus(status int) string {
return govtypes.ProposalStatus_name[int32(status)]
}

// PollForProposalStatus attempts to find a proposal with matching ID and status using IBC-Go v8 / SDK v50.
func PollForProposalStatusV8(ctx context.Context, chain *CosmosChain, startHeight, maxHeight uint64, proposalID string, status int) (ProposalResponseV8, error) {
var pr ProposalResponseV8
doPoll := func(ctx context.Context, height uint64) (ProposalResponseV8, error) {
p, err := chain.QueryProposalV8(ctx, proposalID)
if err != nil {
return pr, err
}

if p.Proposal.Status != status {
return pr, fmt.Errorf("proposal status (%d / %s) does not match expected: (%d / %s)", p.Proposal.Status, ConvertStatus(p.Proposal.Status), status, ConvertStatus(status))
}
return *p, nil
}
bp := testutil.BlockPoller[ProposalResponseV8]{CurrentHeight: chain.Height, PollFunc: doPoll}
return bp.DoPoll(ctx, startHeight, maxHeight)
}

// PollForProposalStatus attempts to find a proposal with matching ID and status.
func PollForProposalStatus(ctx context.Context, chain *CosmosChain, startHeight, maxHeight uint64, proposalID string, status string) (ProposalResponse, error) {
var zero ProposalResponse
Expand Down
68 changes: 64 additions & 4 deletions chain/cosmos/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cosmos

import (
"encoding/json"
"time"
)

const (
Expand All @@ -10,12 +11,21 @@ const (
ProposalVoteNoWithVeto = "noWithVeto"
ProposalVoteAbstain = "abstain"

// IBC-Go <= v7 / SDK <= v0.47
ProposalStatusUnspecified = "PROPOSAL_STATUS_UNSPECIFIED"
ProposalStatusPassed = "PROPOSAL_STATUS_PASSED"
ProposalStatusFailed = "PROPOSAL_STATUS_FAILED"
ProposalStatusRejected = "PROPOSAL_STATUS_REJECTED"
ProposalStatusVotingPeriod = "PROPOSAL_STATUS_VOTING_PERIOD"
ProposalStatusDepositPeriod = "PROPOSAL_STATUS_DEPOSIT_PERIOD"

// IBC-Go v8 / SDK v50
ProposalStatusUnspecifiedV8 = 0
ProposalStatusDepositPeriodV8 = 1
ProposalStatusVotingPeriodV8 = 2
ProposalStatusPassedV8 = 3
ProposalStatusRejectedV8 = 4
ProposalStatusFailedV8 = 5
)

// TxProposalv1 contains chain proposal transaction detail for gov module v1 (sdk v0.46.0+)
Expand All @@ -25,6 +35,10 @@ type TxProposalv1 struct {
Deposit string `json:"deposit"`
Title string `json:"title"`
Summary string `json:"summary"`

// SDK v50 only
Proposer string `json:"proposer,omitempty"`
Expedited bool `json:"expedited,omitempty"`
}

// TxProposal contains chain proposal transaction details.
Expand Down Expand Up @@ -75,17 +89,63 @@ type ProposalResponse struct {
VotingEndTime string `json:"voting_end_time"`
}

// ProposalResponse is the proposal query response for IBC-Go v8 / SDK v50.
type ProposalResponseV8 struct {
Proposal struct {
ID string `json:"id"`
Messages []ProposalMessageV8 `json:"messages"`
Status int `json:"status"`
FinalTallyResult ProposalFinalTallyResultV8 `json:"final_tally_result"`
SubmitTime time.Time `json:"submit_time"`
DepositEndTime time.Time `json:"deposit_end_time"`
TotalDeposit []ProposalDeposit `json:"total_deposit"`
VotingStartTime time.Time `json:"voting_start_time"`
VotingEndTime time.Time `json:"voting_end_time"`
Metadata string `json:"metadata"`
Title string `json:"title"`
Summary string `json:"summary"`
Proposer string `json:"proposer"`
} `json:"proposal"`
}

type ProposalMessage struct {
Type string `json:"type"`
Value struct {
Sender string `json:"sender"`
ValidatorAddress string `json:"validator_address"`
Power string `json:"power"`
Unsafe bool `json:"unsafe"`
} `json:"value"`
}

type ProposalContent struct {
Type string `json:"@type"`
Title string `json:"title"`
Description string `json:"description"`
}

type ProposalFinalTallyResult struct {
Yes string `json:"yes"`
Abstain string `json:"abstain"`
No string `json:"no"`
NoWithVeto string `json:"no_with_veto"`
Yes string `json:"yes_count"`
Abstain string `json:"abstain_count"`
No string `json:"no_count"`
NoWithVeto string `json:"no_with_veto_count"`
}

type ProposalFinalTallyResultV8 struct {
Yes string `json:"yes_count"`
Abstain string `json:"abstain_count"`
No string `json:"no_count"`
NoWithVeto string `json:"no_with_veto_count"`
}

type ProposalMessageV8 struct {
Type string `json:"type"`
Value struct {
Sender string `json:"sender"`
ValidatorAddress string `json:"validator_address"`
Power string `json:"power"`
Unsafe bool `json:"unsafe"`
} `json:"value"`
}

type ProposalDeposit struct {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ require (
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.4 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand Down Expand Up @@ -233,7 +233,7 @@ require (
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.128.0 // indirect
google.golang.org/api v0.139.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect
Expand Down
11 changes: 3 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,7 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b h1:h9U78+dx9a4BKdQkBBos92HalKpaGKHrp+3Uo6yTodo=
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/s2a-go v0.1.4 h1:1kZ/sQM3srePvKs3tXAvQzo66XfcReoqFpIpIccE7Oc=
github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A=
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -659,8 +658,7 @@ github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg=
github.com/googleapis/enterprise-certificate-proxy v0.2.4 h1:uGy6JWR/uMIILU8wbf+OkstIrNiMjGpEIyhx8f6W7s4=
github.com/googleapis/enterprise-certificate-proxy v0.2.4/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k=
github.com/googleapis/enterprise-certificate-proxy v0.2.5 h1:UR4rDjcgpgEnqpIEvkiqTYKBCKLNmlge2eVjoZfySzM=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0=
Expand Down Expand Up @@ -1206,7 +1204,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
Expand Down Expand Up @@ -1478,7 +1475,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
Expand Down Expand Up @@ -1611,8 +1607,7 @@ google.golang.org/api v0.96.0/go.mod h1:w7wJQLTM+wvQpNf5JyEcBoxK0RH7EDrh/L4qfsuJ
google.golang.org/api v0.97.0/go.mod h1:w7wJQLTM+wvQpNf5JyEcBoxK0RH7EDrh/L4qfsuJ13s=
google.golang.org/api v0.98.0/go.mod h1:w7wJQLTM+wvQpNf5JyEcBoxK0RH7EDrh/L4qfsuJ13s=
google.golang.org/api v0.100.0/go.mod h1:ZE3Z2+ZOr87Rx7dqFsdRQkRBk36kDtp/h+QpHbB7a70=
google.golang.org/api v0.128.0 h1:RjPESny5CnQRn9V6siglged+DZCgfu9l6mO9dkX9VOg=
google.golang.org/api v0.128.0/go.mod h1:Y611qgqaE92On/7g65MQgxYul3c0rEB894kniWLY750=
google.golang.org/api v0.139.0 h1:A1TrCPgMmOiYu0AiNkvQIpIx+D8blHTDcJ5EogkP7LI=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down
Loading
Loading