From ba264c25f16307c9df67336927ed38e2e972426e Mon Sep 17 00:00:00 2001 From: dustinxie Date: Wed, 13 Mar 2024 17:46:45 -0700 Subject: [PATCH] [genesis] raise block gas limit to 50M starting Tsunami height (#4181) --- action/protocol/execution/evm/evm.go | 2 +- action/protocol/poll/consortium.go | 4 ++-- action/protocol/poll/staking_committee.go | 4 ++-- api/coreservice.go | 22 ++++++++++++++++++---- blockchain/blockchain.go | 4 ++-- blockchain/blockdao/blockindexer.go | 2 +- blockchain/genesis/genesis.go | 17 ++++++++++++++--- blockchain/genesis/genesis_test.go | 16 ++++++++++++++++ gasstation/gasstattion.go | 12 +++++++----- state/factory/factory.go | 4 ++-- state/factory/statedb.go | 4 ++-- 11 files changed, 67 insertions(+), 24 deletions(-) diff --git a/action/protocol/execution/evm/evm.go b/action/protocol/execution/evm/evm.go index 5bf8ca7f5f..b66fe20004 100644 --- a/action/protocol/execution/evm/evm.go +++ b/action/protocol/execution/evm/evm.go @@ -660,7 +660,7 @@ func SimulateExecution( protocol.BlockCtx{ BlockHeight: bcCtx.Tip.Height + 1, BlockTimeStamp: bcCtx.Tip.Timestamp.Add(g.BlockInterval), - GasLimit: g.BlockGasLimit, + GasLimit: g.BlockGasLimitByHeight(bcCtx.Tip.Height + 1), Producer: zeroAddr, }, ) diff --git a/action/protocol/poll/consortium.go b/action/protocol/poll/consortium.go index ae99171f4a..7fe54d61b6 100644 --- a/action/protocol/poll/consortium.go +++ b/action/protocol/poll/consortium.go @@ -96,7 +96,7 @@ func (cc *consortiumCommittee) CreateGenesisStates(ctx context.Context, sm proto g := genesis.MustExtractGenesisContext(ctx) blkCtx := protocol.MustGetBlockCtx(ctx) blkCtx.Producer, _ = address.FromString(_consortiumCommitteeContractCreator) - blkCtx.GasLimit = g.BlockGasLimit + blkCtx.GasLimit = g.BlockGasLimitByHeight(0) bytes, err := hexutil.Decode(g.ConsortiumCommitteeContractCode) if err != nil { return err @@ -105,7 +105,7 @@ func (cc *consortiumCommittee) CreateGenesisStates(ctx context.Context, sm proto "", _consortiumCommitteeContractNonce, big.NewInt(0), - g.BlockGasLimit, + g.BlockGasLimitByHeight(0), big.NewInt(0), bytes, ) diff --git a/action/protocol/poll/staking_committee.go b/action/protocol/poll/staking_committee.go index 2598981ad3..fb97d01c84 100644 --- a/action/protocol/poll/staking_committee.go +++ b/action/protocol/poll/staking_committee.go @@ -105,7 +105,7 @@ func (sc *stakingCommittee) CreateGenesisStates(ctx context.Context, sm protocol return nil } blkCtx.Producer, _ = address.FromString(address.ZeroAddress) - blkCtx.GasLimit = g.BlockGasLimit + blkCtx.GasLimit = g.BlockGasLimitByHeight(0) bytes, err := hexutil.Decode(g.NativeStakingContractCode) if err != nil { return err @@ -114,7 +114,7 @@ func (sc *stakingCommittee) CreateGenesisStates(ctx context.Context, sm protocol "", _nativeStakingContractNonce, big.NewInt(0), - g.BlockGasLimit, + g.BlockGasLimitByHeight(0), big.NewInt(0), bytes, ) diff --git a/api/coreservice.go b/api/coreservice.go index 5292688ecb..3fbfd3ad85 100644 --- a/api/coreservice.go +++ b/api/coreservice.go @@ -553,7 +553,10 @@ func (core *coreService) ReadContract(ctx context.Context, callerAddr address.Ad pendingNonce = state.PendingNonce() } sc.SetNonce(pendingNonce) - blockGasLimit := core.bc.Genesis().BlockGasLimit + var ( + g = core.bc.Genesis() + blockGasLimit = g.BlockGasLimitByHeight(core.bc.TipHeight()) + ) if sc.GasLimit() == 0 || blockGasLimit < sc.GasLimit() { sc.SetGasLimit(blockGasLimit) } @@ -1507,7 +1510,10 @@ func (core *coreService) EstimateExecutionGasConsumption(ctx context.Context, sc sc.SetNonce(pendingNonce) //gasprice should be 0, otherwise it may cause the API to return an error, such as insufficient balance. sc.SetGasPrice(big.NewInt(0)) - blockGasLimit := core.bc.Genesis().BlockGasLimit + var ( + g = core.bc.Genesis() + blockGasLimit = g.BlockGasLimitByHeight(core.bc.TipHeight()) + ) sc.SetGasLimit(blockGasLimit) enough, receipt, err := core.isGasLimitEnough(ctx, callerAddr, sc) if err != nil { @@ -1718,7 +1724,11 @@ func (core *coreService) SimulateExecution(ctx context.Context, addr address.Add pendingNonce = state.PendingNonce() } exec.SetNonce(pendingNonce) - exec.SetGasLimit(core.bc.Genesis().BlockGasLimit) + var ( + g = core.bc.Genesis() + blockGasLimit = g.BlockGasLimitByHeight(core.bc.TipHeight()) + ) + exec.SetGasLimit(blockGasLimit) return core.simulateExecution(ctx, addr, exec, core.dao.GetBlockHash, core.getBlockTime) } @@ -1760,8 +1770,12 @@ func (core *coreService) TraceCall(ctx context.Context, gasLimit uint64, data []byte, config *tracers.TraceConfig) ([]byte, *action.Receipt, any, error) { + var ( + g = core.bc.Genesis() + blockGasLimit = g.BlockGasLimitByHeight(core.bc.TipHeight()) + ) if gasLimit == 0 { - gasLimit = core.bc.Genesis().BlockGasLimit + gasLimit = blockGasLimit } ctx, err := core.bc.Context(ctx) if err != nil { diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 5d45ff42ca..0dc1c539d8 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -309,7 +309,7 @@ func (bc *blockchain) ValidateBlock(blk *block.Block) error { protocol.BlockCtx{ BlockHeight: blk.Height(), BlockTimeStamp: blk.Timestamp(), - GasLimit: bc.genesis.BlockGasLimit, + GasLimit: bc.genesis.BlockGasLimitByHeight(blk.Height()), Producer: producerAddr, }, ) @@ -335,7 +335,7 @@ func (bc *blockchain) contextWithBlock(ctx context.Context, producer address.Add BlockHeight: height, BlockTimeStamp: timestamp, Producer: producer, - GasLimit: bc.genesis.BlockGasLimit, + GasLimit: bc.genesis.BlockGasLimitByHeight(height), }) } diff --git a/blockchain/blockdao/blockindexer.go b/blockchain/blockdao/blockindexer.go index dfd70241ae..f8cefba58e 100644 --- a/blockchain/blockdao/blockindexer.go +++ b/blockchain/blockdao/blockindexer.go @@ -111,7 +111,7 @@ func (bic *BlockIndexerChecker) CheckIndexer(ctx context.Context, indexer BlockI BlockHeight: i, BlockTimeStamp: blk.Timestamp(), Producer: producer, - GasLimit: g.BlockGasLimit, + GasLimit: g.BlockGasLimitByHeight(i), }, ), blk); err == nil { break diff --git a/blockchain/genesis/genesis.go b/blockchain/genesis/genesis.go index d4abb55547..a74f9c65da 100644 --- a/blockchain/genesis/genesis.go +++ b/blockchain/genesis/genesis.go @@ -28,10 +28,10 @@ import ( "github.com/iotexproject/iotex-core/test/identityset" ) -// Default contains the default genesis config -var Default = defaultConfig() - var ( + // Default contains the default genesis config + Default = defaultConfig() + _genesisTs int64 _loadGenesisTs sync.Once ) @@ -45,6 +45,7 @@ func defaultConfig() Genesis { Blockchain: Blockchain{ Timestamp: 1546329600, BlockGasLimit: 20000000, + TsunamiBlockGasLimit: 50000000, ActionGasLimit: 5000000, BlockInterval: 10 * time.Second, NumSubEpochs: 2, @@ -162,6 +163,8 @@ type ( Timestamp int64 // BlockGasLimit is the total gas limit could be consumed in a block BlockGasLimit uint64 `yaml:"blockGasLimit"` + // TsunamiBlockGasLimit is the block gas limit starting Tsunami height (raised to 50M by default) + TsunamiBlockGasLimit uint64 `yaml:"tsunamiBlockGasLimit"` // ActionGasLimit is the per action gas limit cap ActionGasLimit uint64 `yaml:"actionGasLimit"` // BlockInterval is the interval between two blocks @@ -611,6 +614,14 @@ func (g *Blockchain) IsToBeEnabled(height uint64) bool { return g.isPost(g.ToBeEnabledBlockHeight, height) } +func (g *Blockchain) BlockGasLimitByHeight(height uint64) uint64 { + if g.isPost(g.TsunamiBlockHeight, height) { + // block gas limit raised to 50M after Tsunami block height + return g.TsunamiBlockGasLimit + } + return g.BlockGasLimit +} + // IsDeployerWhitelisted returns if the replay deployer is whitelisted func (a *Account) IsDeployerWhitelisted(deployer address.Address) bool { for _, v := range a.ReplayDeployerWhitelist { diff --git a/blockchain/genesis/genesis_test.go b/blockchain/genesis/genesis_test.go index 7a85f93575..207e8a6c5c 100644 --- a/blockchain/genesis/genesis_test.go +++ b/blockchain/genesis/genesis_test.go @@ -49,6 +49,22 @@ func TestAccount_InitBalances(t *testing.T) { require.Equal(InitBalanceMap["io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms"], balances[1].Text(10)) } +func TestTsunamiBlockGasLimit(t *testing.T) { + r := require.New(t) + + cfg := Default + for _, v := range []struct { + height, gasLimit uint64 + }{ + {1, 20000000}, + {cfg.TsunamiBlockHeight - 1, 20000000}, + {cfg.TsunamiBlockHeight, 50000000}, + {cfg.ToBeEnabledBlockHeight, 50000000}, + } { + r.Equal(v.gasLimit, cfg.BlockGasLimitByHeight(v.height)) + } +} + func TestDeployerWhitelist(t *testing.T) { r := require.New(t) diff --git a/gasstation/gasstattion.go b/gasstation/gasstattion.go index ffc510e33f..ccd82f6669 100644 --- a/gasstation/gasstattion.go +++ b/gasstation/gasstattion.go @@ -46,14 +46,16 @@ func NewGasStation(bc blockchain.Blockchain, dao BlockDAO, cfg Config) *GasStati // SuggestGasPrice suggest gas price func (gs *GasStation) SuggestGasPrice() (uint64, error) { - var smallestPrices []*big.Int - tip := gs.bc.TipHeight() - - endBlockHeight := uint64(0) + var ( + smallestPrices []*big.Int + endBlockHeight uint64 + tip = gs.bc.TipHeight() + g = gs.bc.Genesis() + ) if tip > uint64(gs.cfg.SuggestBlockWindow) { endBlockHeight = tip - uint64(gs.cfg.SuggestBlockWindow) } - maxGas := gs.bc.Genesis().BlockGasLimit * (tip - endBlockHeight) + maxGas := g.BlockGasLimitByHeight(tip) * (tip - endBlockHeight) defaultGasPrice := gs.cfg.DefaultGas gasConsumed := uint64(0) for height := tip; height > endBlockHeight; height-- { diff --git a/state/factory/factory.go b/state/factory/factory.go index 7c7ee61356..645aed3260 100644 --- a/state/factory/factory.go +++ b/state/factory/factory.go @@ -220,7 +220,7 @@ func (sf *factory) Start(ctx context.Context) error { BlockHeight: 0, BlockTimeStamp: time.Unix(sf.cfg.Genesis.Timestamp, 0), Producer: sf.cfg.Chain.ProducerAddress(), - GasLimit: sf.cfg.Genesis.BlockGasLimit, + GasLimit: sf.cfg.Genesis.BlockGasLimitByHeight(0), }) ctx = protocol.WithFeatureCtx(ctx) // init the state factory @@ -428,7 +428,7 @@ func (sf *factory) PutBlock(ctx context.Context, blk *block.Block) error { protocol.BlockCtx{ BlockHeight: blk.Height(), BlockTimeStamp: blk.Timestamp(), - GasLimit: g.BlockGasLimit, + GasLimit: g.BlockGasLimitByHeight(blk.Height()), Producer: producer, }, ) diff --git a/state/factory/statedb.go b/state/factory/statedb.go index 00092d6493..780a50eb2e 100644 --- a/state/factory/statedb.go +++ b/state/factory/statedb.go @@ -142,7 +142,7 @@ func (sdb *stateDB) Start(ctx context.Context) error { BlockHeight: 0, BlockTimeStamp: time.Unix(sdb.cfg.Genesis.Timestamp, 0), Producer: sdb.cfg.Chain.ProducerAddress(), - GasLimit: sdb.cfg.Genesis.BlockGasLimit, + GasLimit: sdb.cfg.Genesis.BlockGasLimitByHeight(0), }) ctx = protocol.WithFeatureCtx(ctx) // init the state factory @@ -310,7 +310,7 @@ func (sdb *stateDB) PutBlock(ctx context.Context, blk *block.Block) error { protocol.BlockCtx{ BlockHeight: blk.Height(), BlockTimeStamp: blk.Timestamp(), - GasLimit: g.BlockGasLimit, + GasLimit: g.BlockGasLimitByHeight(blk.Height()), Producer: producer, }, )