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

feat: increase gas cost for submit proposal #9995

Merged
merged 19 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [\#9879](https://github.com/cosmos/cosmos-sdk/pull/9879) Modify ABCI Queries to use `abci.QueryRequest` Height field if it is non-zero, otherwise continue using context height.
* [\#9594](https://github.com/cosmos/cosmos-sdk/pull/9594) Remove legacy REST API. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/master/migrations/rest.html) to migrate to the new REST endpoints.
* [\#9995](https://github.com/cosmos/cosmos-sdk/pull/9995) Increased gas cost for creating proposals.

### CLI Breaking Changes

Expand Down
8 changes: 6 additions & 2 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
func TestTickExpiredDepositPeriod(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockGasMeter(sdk.NewGasMeter(20000))
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)

header := tmproto.Header{Height: app.LastBlockHeight() + 1}
Expand All @@ -39,8 +40,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
)
require.NoError(t, err)

wrapCtx := sdk.WrapSDKContext(ctx)
res, err := govMsgSvr.SubmitProposal(wrapCtx, newProposalMsg)
res, err := govMsgSvr.SubmitProposal(sdk.WrapSDKContext(ctx), newProposalMsg)
require.NoError(t, err)
require.NotNil(t, res)

Expand Down Expand Up @@ -74,6 +74,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockGasMeter(sdk.NewGasMeter(200000))
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)

header := tmproto.Header{Height: app.LastBlockHeight() + 1}
Expand Down Expand Up @@ -151,6 +152,8 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
func TestTickPassedDepositPeriod(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockGasMeter(sdk.NewGasMeter(20000))

addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)

header := tmproto.Header{Height: app.LastBlockHeight() + 1}
Expand Down Expand Up @@ -204,6 +207,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {
func TestTickPassedVotingPeriod(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockGasMeter(sdk.NewGasMeter(20000))
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)

SortAddresses(addrs)
Expand Down
12 changes: 12 additions & 0 deletions x/gov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/armon/go-metrics"

store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
Expand All @@ -31,6 +32,17 @@ func (k msgServer) SubmitProposal(goCtx context.Context, msg *types.MsgSubmitPro
return nil, err
}

bytes, err := proposal.Marshal()
if err != nil {
return nil, err
}

// ref: https://github.com/cosmos/cosmos-sdk/issues/9683
ctx.GasMeter().ConsumeGas(
3*store.KVGasConfig().WriteCostPerByte*uint64(len(bytes)),
"submit proposal",
)

defer telemetry.IncrCounter(1, types.ModuleName, "proposal")

votingStarted, err := k.Keeper.AddDeposit(ctx, proposal.ProposalId, msg.GetProposer(), msg.GetInitialDeposit())
Expand Down