Skip to content

Commit

Permalink
txpool, miner/worker: adjust reserved gas for system transactions in …
Browse files Browse the repository at this point in the history
…non-checkpoint block (#414)
  • Loading branch information
andicrypt authored Mar 12, 2024
1 parent cd68900 commit 88a7a3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// Ensure the transaction doesn't exceed the current block limit gas.
var reservedGas uint64 = 0
if pool.chainconfig.Consortium != nil {
reservedGas = params.ReservedGasForSystemTransactions
if pool.chain.CurrentBlock().NumberU64()%pool.chainconfig.Consortium.EpochV2 == pool.chainconfig.Consortium.EpochV2-1 {
reservedGas = params.ReservedGasForCheckpointSystemTransactions
} else {
reservedGas = params.ReservedGasForNormalSystemTransactions
}
}
if pool.currentMaxGas-reservedGas < tx.Gas() {
return ErrGasLimit
Expand Down
12 changes: 10 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,17 +872,25 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
return true
}

var reservedGas uint64 = 0
if w.chainConfig.Consortium != nil {
if w.current.header.Number.Uint64()%w.chainConfig.Consortium.EpochV2 == w.chainConfig.Consortium.EpochV2-1 {
reservedGas = params.ReservedGasForCheckpointSystemTransactions
} else {
reservedGas = params.ReservedGasForNormalSystemTransactions
}
}
gasLimit := w.current.header.GasLimit
if w.current.gasPool == nil {
w.current.gasPool = new(core.GasPool).AddGas(gasLimit)

// If the gas pool is newly created, reserve some gas for system transactions
if w.chainConfig.Consortium != nil {
if err := w.current.gasPool.SubGas(params.ReservedGasForSystemTransactions); err != nil {
if err := w.current.gasPool.SubGas(reservedGas); err != nil {
log.Error(
"Failed to reserve gas for system transactions",
"pool", w.current.gasPool,
"reserve", params.ReservedGasForSystemTransactions,
"reserve", reservedGas,
"error", err,
)
return true
Expand Down
3 changes: 2 additions & 1 deletion params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package params
import "math/big"

const (
ReservedGasForSystemTransactions uint64 = 10_000_000 // The reserved gas for system transactions in each block.
ReservedGasForCheckpointSystemTransactions uint64 = 10_000_000 // The reserved gas for system transactions in checkpoint blocks.
ReservedGasForNormalSystemTransactions uint64 = 2_000_000 // The reserved gas for system transactions in normal blocks.

GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
ConsortiumGasLimitBoundDivisor uint64 = 256
Expand Down

0 comments on commit 88a7a3c

Please sign in to comment.