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

R4R: Parameter Change Proposal #3880

Closed
wants to merge 89 commits into from
Closed
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
8fbe541
in progress
mossid Mar 1, 2019
19b04db
in progres
mossid Mar 1, 2019
4fdabb1
fix test in progress
mossid Mar 1, 2019
ec133ef
fix test
mossid Mar 1, 2019
aac536d
fix lint
mossid Mar 1, 2019
cd0eb03
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
d6b1e53
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
6b13eb7
address comments
mossid Mar 2, 2019
502bfc9
fix integration test
mossid Mar 2, 2019
afa4038
Merge branch 'joon/3570-split-proposal-interface' of github.com:cosmo…
mossid Mar 2, 2019
dcea8ef
add SoftwareUpgradeProposal
mossid Mar 3, 2019
31bda27
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
0e58adb
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
e2ec4fe
Merge branch 'joon/3570-split-proposal-interface' of github.com:cosmo…
mossid Mar 4, 2019
90c1d7c
add to codec
mossid Mar 4, 2019
a03bcc8
add pending
mossid Mar 4, 2019
ea820cf
Merge branch 'develop' into joon/3570-split-proposal-interface
mossid Mar 8, 2019
c0a556a
expose SubmitProposal(), fix ProposalEqual()
mossid Mar 8, 2019
43dcee0
fix test, add docs
mossid Mar 11, 2019
0f998cb
Merge branch 'develop' into joon/3570-split-proposal-interface
mossid Mar 14, 2019
d9ea2d1
in progress
mossid Mar 3, 2019
a9011be
fix tests
mossid Mar 4, 2019
3442ec5
implement params.NewProposalHandler in progress
mossid Mar 4, 2019
322c95c
in progress
mossid Mar 11, 2019
a3e89b2
fix SubmitParameterChangeProposal
mossid Mar 11, 2019
f4a7c47
move to gov/proposal, writing test in progress
mossid Mar 11, 2019
e6f8d97
writing test in progress
mossid Mar 12, 2019
9beca06
fix test
mossid Mar 12, 2019
8ba2eda
in progress
mossid Mar 14, 2019
b9cead1
write test in progress
mossid Mar 14, 2019
ba6b52a
fix lint
mossid Mar 14, 2019
f1b2192
rm SubmitForm, fix lint
mossid Mar 14, 2019
7cb7d4f
Update x/gov/test_common.go
cwgoes Mar 15, 2019
3fc1cb3
Merge branch 'joon/3570-split-proposal-interface' of github.com:cosmo…
mossid Mar 18, 2019
e80c27b
Update x/gov/client/rest/rest.go
fedekunze Mar 18, 2019
47aae50
Update x/gov/errors/errors.go
fedekunze Mar 18, 2019
ea1a9aa
Update x/params/contents.go
fedekunze Mar 18, 2019
79080c1
Update x/params/msgs.go
fedekunze Mar 18, 2019
3f8b67d
Update x/gov/keeper.go
fedekunze Mar 18, 2019
06b1325
Update x/gov/keeper.go
fedekunze Mar 18, 2019
18265bf
add legacy
mossid Mar 18, 2019
373c81b
add legacy test
mossid Mar 18, 2019
8173a73
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 18, 2019
cbd38b4
Update x/gov/keeper.go
fedekunze Mar 18, 2019
e9d7fcc
address comments in progress
mossid Mar 18, 2019
542f83d
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
mossid Mar 18, 2019
fbd5ac8
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
mossid Mar 18, 2019
2aaf227
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 18, 2019
b20bfb1
rm legacy
mossid Mar 19, 2019
f5ecc4e
Update x/gov/msgs.go
fedekunze Mar 19, 2019
77a8bc6
address comments in progress
mossid Mar 19, 2019
f29f1a5
address comments in progress
mossid Mar 19, 2019
031da7c
fix lint
mossid Mar 19, 2019
d68f935
addressing comments in progress
mossid Mar 22, 2019
ae7bcb3
address commtnes
mossid Mar 22, 2019
330a7ae
Update x/gov/handler.go
alexanderbez Mar 22, 2019
7735a05
in progress
mossid Mar 25, 2019
bb90b15
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
mossid Mar 25, 2019
55626e6
fix sim
mossid Mar 25, 2019
869e90c
Update x/gov/handler.go
alexanderbez Mar 25, 2019
7521116
address comments
mossid Mar 25, 2019
5f78daa
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 25, 2019
bd4a849
add genesis migration
mossid Mar 25, 2019
d1d67b5
fix test
mossid Mar 25, 2019
a63d24f
Apply suggestions from code review
rigelrozanski Mar 26, 2019
81458a9
apply requests
mossid Mar 26, 2019
9eaaf3d
apply comments
mossid Mar 26, 2019
dd0e476
rm startingProposalID
mossid Mar 26, 2019
8fbbd5e
Update x/gov/keeper.go
alexanderbez Mar 26, 2019
dc21c9c
apply comments
mossid Mar 27, 2019
dd5adad
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 27, 2019
765ec24
rm abstract rename legacy
mossid Mar 27, 2019
0893103
revert json encoding change for encoding compat
mossid Apr 3, 2019
f13b696
Apply suggestions from code review
fedekunze Apr 8, 2019
7a8f90b
add test
mossid Apr 10, 2019
d806275
rename MsgSubmitParameterChangeProposal -> MsgSubmitProposal
mossid Apr 10, 2019
b05ebdb
Apply suggestions from code review
alexanderbez Apr 10, 2019
244ad53
Merge branch 'develop' of github.com:cosmos/cosmos-sdk into joon/3565…
mossid Apr 10, 2019
ded0fcf
unifying msg form, add validatebasic to content
mossid Apr 10, 2019
a7edcbe
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Apr 10, 2019
0820bea
unify msg into gov
mossid Apr 10, 2019
008b6f2
Merge branch 'develop' of github.com:cosmos/cosmos-sdk into joon/3565…
mossid Apr 10, 2019
b098315
add rest/cli, address comments
mossid Apr 12, 2019
d7056b7
mistake
mossid Apr 12, 2019
ebdd392
gobot
mossid Apr 12, 2019
901cf44
Apply suggestions from code review
fedekunze Apr 12, 2019
a784ee9
address comments
mossid Apr 12, 2019
6b4cbda
rename to ParameterChangeProposal, fix test
mossid Apr 12, 2019
93b9dda
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
alexanderbez Apr 16, 2019
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
9 changes: 7 additions & 2 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams, params.DefaultCodespace)

// define the accountKeeper
app.accountKeeper = auth.NewAccountKeeper(
Expand Down Expand Up @@ -138,7 +138,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
&stakingKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace),
slashing.DefaultCodespace,
)
app.govKeeper = gov.NewKeeper(
var grouter gov.Router
mossid marked this conversation as resolved.
Show resolved Hide resolved
app.govKeeper, grouter = gov.NewKeeper(
mossid marked this conversation as resolved.
Show resolved Hide resolved
app.cdc,
app.keyGov,
app.paramsKeeper, app.paramsKeeper.Subspace(gov.DefaultParamspace), app.bankKeeper, &stakingKeeper,
Expand Down Expand Up @@ -180,6 +181,10 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
AddRoute(staking.QuerierRoute, staking.NewQuerier(app.stakingKeeper, app.cdc)).
AddRoute(mint.QuerierRoute, mint.NewQuerier(app.mintKeeper))

grouter.
mossid marked this conversation as resolved.
Show resolved Hide resolved
AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewProposalHandler(app.paramsKeeper))

// initialize BaseApp
app.MountStores(app.keyMain, app.keyAccount, app.keyStaking, app.keyMint, app.keyDistr,
app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams,
Expand Down
Binary file added cmd/gaia/cmd/gaiadebug/gaiadebug
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams, params.DefaultCodespace)

// define the accountKeeper
app.accountKeeper = auth.NewAccountKeeper(
Expand Down
2 changes: 1 addition & 1 deletion types/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func MakeTag(k string, v string) Tag {
//__________________________________________________

// common tags
var (
const (
TagAction = "action"
TagCategory = "category"
TagSender = "sender"
Expand Down
6 changes: 3 additions & 3 deletions x/auth/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

codec "github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/params/subspace"
)

const (
Expand Down Expand Up @@ -40,14 +40,14 @@ type AccountKeeper struct {
// The codec codec for binary encoding/decoding of accounts.
cdc *codec.Codec

paramSubspace params.Subspace
paramSubspace subspace.Subspace
}

// NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to
// (binary) encode and decode concrete sdk.Accounts.
// nolint
func NewAccountKeeper(
cdc *codec.Codec, key sdk.StoreKey, paramstore params.Subspace, proto func() Account,
cdc *codec.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() Account,
) AccountKeeper {

return AccountKeeper{
Expand Down
12 changes: 6 additions & 6 deletions x/auth/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/params/subspace"
)

// DefaultParamspace defines the default auth module parameter subspace
Expand All @@ -29,7 +29,7 @@ var (
KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
)

var _ params.ParamSet = &Params{}
var _ subspace.ParamSet = &Params{}

// Params defines the parameters for the auth module.
type Params struct {
Expand All @@ -41,15 +41,15 @@ type Params struct {
}

// ParamKeyTable for auth module
func ParamKeyTable() params.KeyTable {
return params.NewKeyTable().RegisterParamSet(&Params{})
func ParamKeyTable() subspace.KeyTable {
return subspace.NewKeyTable().RegisterParamSet(&Params{})
}

// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
// pairs of auth module's parameters.
// nolint
func (p *Params) ParamSetPairs() params.ParamSetPairs {
return params.ParamSetPairs{
func (p *Params) ParamSetPairs() subspace.ParamSetPairs {
return subspace.ParamSetPairs{
{KeyMaxMemoCharacters, &p.MaxMemoCharacters},
{KeyTxSigLimit, &p.TxSigLimit},
{KeyTxSizeCostPerByte, &p.TxSizeCostPerByte},
Expand Down
10 changes: 5 additions & 5 deletions x/auth/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/params"
subspace "github.com/cosmos/cosmos-sdk/x/params/subspace"
)

type testInput struct {
Expand All @@ -29,8 +29,8 @@ func setupTestInput() testInput {

authCapKey := sdk.NewKVStoreKey("authCapKey")
fckCapKey := sdk.NewKVStoreKey("fckCapKey")
keyParams := sdk.NewKVStoreKey("params")
tkeyParams := sdk.NewTransientStoreKey("transient_params")
keyParams := sdk.NewKVStoreKey("subspace")
tkeyParams := sdk.NewTransientStoreKey("transient_subspace")

ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(authCapKey, sdk.StoreTypeIAVL, db)
Expand All @@ -39,8 +39,8 @@ func setupTestInput() testInput {
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
ms.LoadLatestVersion()

pk := params.NewKeeper(cdc, keyParams, tkeyParams)
ak := NewAccountKeeper(cdc, authCapKey, pk.Subspace(DefaultParamspace), ProtoBaseAccount)
ps := subspace.NewSubspace(cdc, keyParams, tkeyParams, DefaultParamspace)
ak := NewAccountKeeper(cdc, authCapKey, ps, ProtoBaseAccount)
fck := NewFeeCollectionKeeper(cdc, fckCapKey)
ctx := sdk.NewContext(ms, abci.Header{ChainID: "test-chain-id"}, false, log.NewNopLogger())

Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func setupTestInput() testInput {
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
ms.LoadLatestVersion()

pk := params.NewKeeper(cdc, keyParams, tkeyParams)
pk := params.NewKeeper(cdc, keyParams, tkeyParams, params.DefaultCodespace)
ak := auth.NewAccountKeeper(
cdc, authCapKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount,
)
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func CreateTestInputAdvanced(t *testing.T, isCheckTx bool, initPower int64,
require.Nil(t, err)

cdc := MakeTestCodec()
pk := params.NewKeeper(cdc, keyParams, tkeyParams)
pk := params.NewKeeper(cdc, keyParams, tkeyParams, params.DefaultCodespace)

ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger())
accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)
Expand Down
4 changes: 4 additions & 0 deletions x/gov/client/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func parseSubmitProposalFlags() (*proposal, error) {
proposal.Description = viper.GetString(flagDescription)
proposal.Type = govClientUtils.NormalizeProposalType(viper.GetString(flagProposalType))
proposal.Deposit = viper.GetString(flagDeposit)

if proposal.Type == "" {
return nil, fmt.Errorf("Invalid ProposalType %s was given", flagProposalType)
}
return proposal, nil
}

Expand Down
9 changes: 5 additions & 4 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome
return err
}

proposalType, err := gov.ProposalTypeFromString(proposal.Type)
if err != nil {
return err
content := gov.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)
if content == nil {
mossid marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("Invalid proposal type %s", proposal.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto. From the line above I'd have expected something like "proposal content is empty"

}

msg := gov.NewMsgSubmitProposal(proposal.Title, proposal.Description, proposalType, from, amount)
msg := gov.NewMsgSubmitProposal(content, from, amount)

err = msg.ValidateBasic()
if err != nil {
return err
Expand Down
14 changes: 10 additions & 4 deletions x/gov/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,20 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
return
}

proposalType, err := gov.ProposalTypeFromString(govClientUtils.NormalizeProposalType(req.ProposalType))
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
proposalType := govClientUtils.NormalizeProposalType(req.ProposalType)
if proposalType == "" {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("Invalid ProposalType %s", req.ProposalType))
mossid marked this conversation as resolved.
Show resolved Hide resolved
return
}

// create the message
msg := gov.NewMsgSubmitProposal(req.Title, req.Description, proposalType, req.Proposer, req.InitialDeposit)

content := gov.ContentFromProposalType(req.Title, req.Description, proposalType)
if content == nil {
mossid marked this conversation as resolved.
Show resolved Hide resolved
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("Invalid proposalType %s", proposalType))
mossid marked this conversation as resolved.
Show resolved Hide resolved
return
}
msg := gov.NewMsgSubmitProposal(content, req.Proposer, req.InitialDeposit)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down
8 changes: 4 additions & 4 deletions x/gov/client/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package utils

import "github.com/cosmos/cosmos-sdk/x/gov"

// NormalizeVoteOption - normalize user specified vote option
func NormalizeVoteOption(option string) string {
switch option {
Expand All @@ -19,11 +21,9 @@ func NormalizeVoteOption(option string) string {
func NormalizeProposalType(proposalType string) string {
switch proposalType {
case "Text", "text":
return "Text"
case "ParameterChange", "parameter_change":
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each proposal content type is managed by the module where it is defined, but still sending the tx to the governance handler.

return "ParameterChange"
return gov.ProposalTypeText
case "SoftwareUpgrade", "software_upgrade":
return "SoftwareUpgrade"
return gov.ProposalTypeSoftwareUpgrade
}
return ""
}
Expand Down
3 changes: 2 additions & 1 deletion x/gov/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gov

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/gov/proposal"
)

var msgCdc = codec.New()
Expand All @@ -12,7 +13,7 @@ func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
cdc.RegisterConcrete(MsgVote{}, "cosmos-sdk/MsgVote", nil)

cdc.RegisterInterface((*ProposalContent)(nil), nil)
proposal.RegisterCodec(cdc)
cdc.RegisterConcrete(TextProposal{}, "gov/TextProposal", nil)
cdc.RegisterConcrete(SoftwareUpgradeProposal{}, "gov/SoftwareUpgradeProposal", nil)
}
Expand Down
76 changes: 76 additions & 0 deletions x/gov/contents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package gov

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/proposal"
)

//nolint
const (
ProposalTypeText string = "Text"
ProposalTypeSoftwareUpgrade string = "SoftwareUpgrade"
Copy link
Collaborator

Choose a reason for hiding this comment

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

where's ProposalTypeParameterChange ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I omitted because 1. there is no parameter change proposal now and 2. it is hard to migrate the existing format of parameter change proposal(which is basically just a textproposal) to the current format(which actually describes which parameter will be modified). Do you think we should migrate it to a textproposal?

)

// Text Proposals
type TextProposal struct {
Title string `json:"title"`
Description string `json:"description"`
}

func NewTextProposal(title, description string) proposal.Content {
return TextProposal{title, description}
}

// Implements Proposal Interface
var _ proposal.Content = TextProposal{}

// nolint
func (tp TextProposal) GetTitle() string { return tp.Title }
func (tp TextProposal) GetDescription() string { return tp.Description }
func (tp TextProposal) ProposalRoute() string { return RouterKey }
func (tp TextProposal) ProposalType() string { return ProposalTypeText }
func (tp TextProposal) ValidateBasic() sdk.Error {
return proposal.ValidateAbstract(DefaultCodespace, tp)
}
func (tp TextProposal) String() string {
return fmt.Sprintf("TextProposal{%s, %s}", tp.Title, tp.Description)
}

// Software Upgrade Proposals
// TODO: we have to add fields for SUP specific arguments e.g. commit hash, upgrade date, etc.
type SoftwareUpgradeProposal struct {
Title string `json:"title"`
Description string `json:"description"`
}

func NewSoftwareUpgradeProposal(title, description string) proposal.Content {
return SoftwareUpgradeProposal{title, description}
}

// Implements Proposal Interface
var _ proposal.Content = SoftwareUpgradeProposal{}

// nolint
func (sup SoftwareUpgradeProposal) GetTitle() string { return sup.Title }
func (sup SoftwareUpgradeProposal) GetDescription() string { return sup.Description }
func (sup SoftwareUpgradeProposal) ProposalRoute() string { return RouterKey }
func (sup SoftwareUpgradeProposal) ProposalType() string { return ProposalTypeSoftwareUpgrade }
func (sup SoftwareUpgradeProposal) ValidateBasic() sdk.Error {
return proposal.ValidateAbstract(DefaultCodespace, sup)
}
func (sup SoftwareUpgradeProposal) String() string {
return fmt.Sprintf("SoftwareUpgradeProposal{%s, %s}", sup.Title, sup.Description)
}

func ContentFromProposalType(title, desc, ty string) proposal.Content {
switch ty {
case ProposalTypeText:
return NewTextProposal(title, desc)
case ProposalTypeSoftwareUpgrade:
return NewSoftwareUpgradeProposal(title, desc)
default:
return nil
}
}
26 changes: 23 additions & 3 deletions x/gov/endblocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,33 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags {
passes, tallyResults := tally(ctx, keeper, activeProposal)

var tagValue string
var logMsg string
if passes {
keeper.RefundDeposits(ctx, activeProposal.ProposalID)
activeProposal.Status = StatusPassed
tagValue = tags.ActionProposalPassed

handler := keeper.router.GetRoute(activeProposal.ProposalRoute())

cctx, writeCache := ctx.CacheContext()
mossid marked this conversation as resolved.
Show resolved Hide resolved

// The handler is state mutating logic depending on the proposal content.
// The handler may mutate the state or not
// if handler fails no state mutation happened and the err msg is logged.
contentErr := handler(cctx, activeProposal.Content)
mossid marked this conversation as resolved.
Show resolved Hide resolved
if contentErr == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use err == nil ?

tagValue = tags.ActionProposalPassed
logMsg = "passed"

// writes state mutation to the underlying multistore
writeCache()
} else {
logMsg = fmt.Sprintf("passed, but failed on execution: %s", contentErr.ABCILog())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
logMsg = fmt.Sprintf("passed, but failed on execution: %s", contentErr.ABCILog())
logMsg = fmt.Sprintf("proposal %d passed, but failed on execution: %s", activeProposal.ProposalID, contentErr.ABCILog())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tagValue = tags.ActionProposalFailed
}
} else {
keeper.DeleteDeposits(ctx, activeProposal.ProposalID)
activeProposal.Status = StatusRejected
logMsg = "rejected"
tagValue = tags.ActionProposalRejected
}

Expand All @@ -69,8 +89,8 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags {

logger.Info(
fmt.Sprintf(
"proposal %d (%s) tallied; passed: %v",
activeProposal.ProposalID, activeProposal.GetTitle(), passes,
"proposal %d (%s) %s",
activeProposal.ProposalID, activeProposal.GetTitle(), logMsg,
),
)

Expand Down
Loading