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: param changes for block and cost per byte #8598

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions app/upgrades/v26/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ const (

// MaximumUnauthenticatedGas for smart account transactions to verify the fee payer
MaximumUnauthenticatedGas = uint64(250_000)

// BlockMaxBytes is the max bytes for a block, 2mb
PaddyMc marked this conversation as resolved.
Show resolved Hide resolved
BlockMaxBytes = int64(5000000)

// BlockMaxGas is the max gas allowed in a block
BlockMaxGas = int64(300000000)

// CostPerByte is the gas cost per byte
CostPerByte = uint64(30)
)

var Upgrade = upgrades.Upgrade{
Expand Down
18 changes: 18 additions & 0 deletions app/upgrades/v26/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"

cmttypes "github.com/cometbft/cometbft/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v25/app/keepers"
Expand Down Expand Up @@ -60,6 +61,23 @@ func CreateUpgradeHandler(
authenticatorParams.MaximumUnauthenticatedGas = MaximumUnauthenticatedGas
keepers.SmartAccountKeeper.SetParams(ctx, authenticatorParams)

// Set the next block limits
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
defaultConsensusParams.Block.MaxBytes = BlockMaxBytes // previously 5000000
defaultConsensusParams.Block.MaxGas = BlockMaxGas // unchanged
err = keepers.ConsensusParamsKeeper.ParamsStore.Set(ctx, defaultConsensusParams)
if err != nil {
return nil, err
}

// Increase the tx size cost per byte to 30 to reduce the exploitability of bandwidth amplification problems.
accountParams := keepers.AccountKeeper.GetParams(ctx)
accountParams.TxSizeCostPerByte = CostPerByte // increase from 20 to 30
err = keepers.AccountKeeper.Params.Set(ctx, accountParams)
if err != nil {
return nil, err
}

return migrations, nil
}
}
30 changes: 30 additions & 0 deletions app/upgrades/v26/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

cmttypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/suite"

"cosmossdk.io/core/appmodule"
Expand Down Expand Up @@ -49,6 +50,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {

s.PrepareTradingPairTakerFeeTest()
s.PrepareIncreaseUnauthenticatedGasTest()
s.PrepareChangeBlockParamsTest()
s.PrepareCostPerByteTest()

// Run the upgrade
dummyUpgrade(s)
Expand All @@ -59,6 +62,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {

s.ExecuteTradingPairTakerFeeTest()
s.ExecuteIncreaseUnauthenticatedGasTest()
s.ExecuteChangeBlockParamsTest()
s.ExecuteCostPerByteTest()
}

func dummyUpgrade(s *UpgradeTestSuite) {
Expand Down Expand Up @@ -115,3 +120,28 @@ func (s *UpgradeTestSuite) ExecuteIncreaseUnauthenticatedGasTest() {
authenticatorParams := s.App.SmartAccountKeeper.GetParams(s.Ctx)
s.Require().Equal(authenticatorParams.MaximumUnauthenticatedGas, v26.MaximumUnauthenticatedGas)
}

func (s *UpgradeTestSuite) PrepareChangeBlockParamsTest() {
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
defaultConsensusParams.Block.MaxBytes = 1
defaultConsensusParams.Block.MaxGas = 1
s.App.ConsensusParamsKeeper.ParamsStore.Set(s.Ctx, defaultConsensusParams)
}

func (s *UpgradeTestSuite) ExecuteChangeBlockParamsTest() {
consParams, err := s.App.ConsensusParamsKeeper.ParamsStore.Get(s.Ctx)
s.Require().NoError(err)
s.Require().Equal(consParams.Block.MaxBytes, v26.BlockMaxBytes)
s.Require().Equal(consParams.Block.MaxGas, v26.BlockMaxGas)
}

func (s *UpgradeTestSuite) PrepareCostPerByteTest() {
accountParams := s.App.AccountKeeper.GetParams(s.Ctx)
accountParams.TxSizeCostPerByte = 0
s.App.AccountKeeper.Params.Set(s.Ctx, accountParams)
}

func (s *UpgradeTestSuite) ExecuteCostPerByteTest() {
accountParams := s.App.AccountKeeper.GetParams(s.Ctx)
s.Require().Equal(accountParams.TxSizeCostPerByte, v26.CostPerByte)
}