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

[genesis] raise block gas limit to 50M #4181

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@
protocol.BlockCtx{
BlockHeight: bcCtx.Tip.Height + 1,
BlockTimeStamp: bcCtx.Tip.Timestamp.Add(g.BlockInterval),
GasLimit: g.BlockGasLimit,
GasLimit: g.BlockGasLimitByHeight(bcCtx.Tip.Height + 1),

Check warning on line 663 in action/protocol/execution/evm/evm.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/execution/evm/evm.go#L663

Added line #L663 was not covered by tests
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 @@
g := genesis.MustExtractGenesisContext(ctx)
blkCtx := protocol.MustGetBlockCtx(ctx)
blkCtx.Producer, _ = address.FromString(_consortiumCommitteeContractCreator)
blkCtx.GasLimit = g.BlockGasLimit
blkCtx.GasLimit = g.BlockGasLimitByHeight(0)

Check warning on line 99 in action/protocol/poll/consortium.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/poll/consortium.go#L99

Added line #L99 was not covered by tests
bytes, err := hexutil.Decode(g.ConsortiumCommitteeContractCode)
if err != nil {
return err
Expand All @@ -105,7 +105,7 @@
"",
_consortiumCommitteeContractNonce,
big.NewInt(0),
g.BlockGasLimit,
g.BlockGasLimitByHeight(0),

Check warning on line 108 in action/protocol/poll/consortium.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/poll/consortium.go#L108

Added line #L108 was not covered by tests
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 @@
return nil
}
blkCtx.Producer, _ = address.FromString(address.ZeroAddress)
blkCtx.GasLimit = g.BlockGasLimit
blkCtx.GasLimit = g.BlockGasLimitByHeight(0)

Check warning on line 108 in action/protocol/poll/staking_committee.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/poll/staking_committee.go#L108

Added line #L108 was not covered by tests
bytes, err := hexutil.Decode(g.NativeStakingContractCode)
if err != nil {
return err
Expand All @@ -114,7 +114,7 @@
"",
_nativeStakingContractNonce,
big.NewInt(0),
g.BlockGasLimit,
g.BlockGasLimitByHeight(0),

Check warning on line 117 in action/protocol/poll/staking_committee.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/poll/staking_committee.go#L117

Added line #L117 was not covered by tests
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 @@
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 @@
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 @@
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)

Check warning on line 1731 in api/coreservice.go

View check run for this annotation

Codecov / codecov/patch

api/coreservice.go#L1727-L1731

Added lines #L1727 - L1731 were not covered by tests
return core.simulateExecution(ctx, addr, exec, core.dao.GetBlockHash, core.getBlockTime)
}

Expand Down Expand Up @@ -1760,8 +1770,12 @@
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

Check warning on line 1778 in api/coreservice.go

View check run for this annotation

Codecov / codecov/patch

api/coreservice.go#L1778

Added line #L1778 was not covered by tests
}
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 @@
protocol.BlockCtx{
BlockHeight: blk.Height(),
BlockTimeStamp: blk.Timestamp(),
GasLimit: bc.genesis.BlockGasLimit,
GasLimit: bc.genesis.BlockGasLimitByHeight(blk.Height()),

Check warning on line 312 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L312

Added line #L312 was not covered by tests
Producer: producerAddr,
},
)
Expand All @@ -335,7 +335,7 @@
BlockHeight: height,
BlockTimeStamp: timestamp,
Producer: producer,
GasLimit: bc.genesis.BlockGasLimit,
GasLimit: bc.genesis.BlockGasLimitByHeight(height),

Check warning on line 338 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L338

Added line #L338 was not covered by tests
})
}

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
Loading