Skip to content

Commit

Permalink
[genesis] raise block gas limit to 50M starting Tsunami height (#4181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie authored Mar 14, 2024
1 parent 0ef24a2 commit ba264c2
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 24 deletions.
2 changes: 1 addition & 1 deletion action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand Down
4 changes: 2 additions & 2 deletions action/protocol/poll/consortium.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions action/protocol/poll/staking_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand Down
22 changes: 18 additions & 4 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand All @@ -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),
})
}

Expand Down
2 changes: 1 addition & 1 deletion blockchain/blockdao/blockindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions blockchain/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -45,6 +45,7 @@ func defaultConfig() Genesis {
Blockchain: Blockchain{
Timestamp: 1546329600,
BlockGasLimit: 20000000,
TsunamiBlockGasLimit: 50000000,
ActionGasLimit: 5000000,
BlockInterval: 10 * time.Second,
NumSubEpochs: 2,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions blockchain/genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions gasstation/gasstattion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-- {
Expand Down
4 changes: 2 additions & 2 deletions state/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
)
Expand Down
4 changes: 2 additions & 2 deletions state/factory/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
)
Expand Down

0 comments on commit ba264c2

Please sign in to comment.