Skip to content

Commit

Permalink
don't store bech32 in state
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 19, 2023
1 parent 228789f commit 14292ae
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 204 deletions.
156 changes: 78 additions & 78 deletions api/cosmos/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/build/building-modules/05-protobuf-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Example of Int scalar:
https://github.com/cosmos/cosmos-sdk/blob/e8f28bf5db18b8d6b7e0d94b542ce4cf48fed9d6/proto/cosmos/gov/v1/gov.proto#L137
```

There are a few options for what can be provided as a scalar: cosmos.AddressString, cosmos.ValidatorAddressString, cosmos.ConsensusAddressString, cosmos.Int, cosmos.Dec.
There are a few options for what can be provided as a scalar: `cosmos.AddressString`, `cosmos.ValidatorAddressString`, `cosmos.ConsensusAddressString`, and their bytes counterparts `cosmos.AddressBytes`, `cosmos.ValidatorAddressBytes`, `cosmos.ConsensusAddressBytes`. There are also scalars for `cosmos.Dec` and `cosmos.Int`.

## Implements_Interface

Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ message Params {
// submit optimistic proposals
//
// Since: x/gov v1.0.0
repeated string optimistic_authorized_addresses = 17 [(cosmos_proto.scalar) = "cosmos.AddressString"];
repeated bytes optimistic_authorized_addresses = 17 [(cosmos_proto.scalar) = "cosmos.AddressBytes"];

// optimistic rejected threshold defines at which percentage of NO votes, the optimistic proposal should fail and be
// converted to a standard proposal. The threshold is expressed as a percentage of the total bonded tokens.
Expand Down
17 changes: 11 additions & 6 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"fmt"
"slices"
"strings"
"time"

Expand All @@ -18,21 +17,27 @@ import (
)

// SubmitProposal creates a new proposal given an array of messages
func (keeper Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress, proposalType v1.ProposalType) (v1.Proposal, error) {
func (keeper Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer []byte, proposalType v1.ProposalType) (v1.Proposal, error) {
params, err := keeper.Params.Get(ctx)
if err != nil {
return v1.Proposal{}, err
}

// additional checks per proposal types
if proposalType == v1.ProposalType_PROPOSAL_TYPE_OPTIMISTIC {
proposerStr, _ := keeper.authKeeper.AddressCodec().BytesToString(proposer)
proposerBytes := proposer
found := false

if len(params.OptimisticAuthorizedAddresses) > 0 {
if !slices.Contains(params.OptimisticAuthorizedAddresses, proposerStr) {
return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidProposer, "proposer is not authorized to submit optimistic proposal")
for _, addr := range params.OptimisticAuthorizedAddresses {
if bytes.Equal(addr, proposerBytes) {
found = true
break
}
}

if !found {
return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidProposer, "proposer is not authorized to submit optimistic proposal")
}
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
Expand Down
2 changes: 1 addition & 1 deletion x/gov/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func RandomizedGenState(simState *module.SimulationState) {

govGenesis := v1.NewGenesisState(
startingProposalID,
v1.NewParams(minDeposit, expeditedMinDeposit, depositPeriod, votingPeriod, expeditedVotingPeriod, quorum.String(), threshold.String(), expitedVotingThreshold.String(), veto.String(), minInitialDepositRatio.String(), proposalCancelRate.String(), "", simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, minDepositRatio.String(), optimisticRejectedThreshold.String(), []string{}),
v1.NewParams(minDeposit, expeditedMinDeposit, depositPeriod, votingPeriod, expeditedVotingPeriod, quorum.String(), threshold.String(), expitedVotingThreshold.String(), veto.String(), minInitialDepositRatio.String(), proposalCancelRate.String(), "", simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, minDepositRatio.String(), optimisticRejectedThreshold.String(), [][]byte{}),
)

bz, err := json.MarshalIndent(&govGenesis, "", " ")
Expand Down
1 change: 1 addition & 0 deletions x/gov/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestRandomizedGenState(t *testing.T) {
assert.Equal(t, tallyThreshold, govGenesis.Params.Threshold)
assert.Equal(t, tallyExpeditedThreshold, govGenesis.Params.ExpeditedThreshold)
assert.Equal(t, tallyVetoThreshold, govGenesis.Params.VetoThreshold)
assert.DeepEqual(t, [][]byte{}, govGenesis.Params.OptimisticAuthorizedAddresses)
assert.Equal(t, uint64(0x28), govGenesis.StartingProposalId)
assert.DeepEqual(t, []*v1.Deposit{}, govGenesis.Deposits)
assert.DeepEqual(t, []*v1.Vote{}, govGenesis.Votes)
Expand Down
9 changes: 9 additions & 0 deletions x/gov/types/v1/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func TestValidateGenesis(t *testing.T) {
},
expErrMsg: "deposit proposal_id:1 depositor:\"depositor\"",
},
{
name: "optimistic authorized address",
genesisState: func() *v1.GenesisState {
params1 := params
params1.OptimisticAuthorizedAddresses = [][]byte{{0x1}}

return v1.NewGenesisState(v1.DefaultStartingProposalID, params1)
},
},
}

for _, tc := range testCases {
Expand Down
Loading

0 comments on commit 14292ae

Please sign in to comment.