From a24c02e4ee6b64c043a57afdc35355893b73a99d Mon Sep 17 00:00:00 2001 From: 0xcary <0xcary.web3@gmail.com> Date: Tue, 16 Jan 2024 15:06:53 +0800 Subject: [PATCH] Optimize gas price oracle and increase default gas ceil (#136) * update default gas ceiling for mined blocks * version * increase tx mas size --- core/tx_pool.go | 2 +- eth/ethconfig/config.go | 2 +- eth/gasprice/gasprice.go | 39 ++++++++++++++++++++++++--------------- params/version.go | 8 ++++---- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index 1c25442dd9c5..dc3a6c269c82 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -50,7 +50,7 @@ const ( // non-trivial consequences: larger transactions are significantly harder and // more expensive to propagate; larger transactions also take more resources // to validate whether they fit into the pool or not. - txMaxSize = 4 * txSlotSize // 128KB + txMaxSize = 5 * txSlotSize // 160KB ) var ( diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 676b2ba4b3b9..f917b45a66a4 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -88,7 +88,7 @@ var Defaults = Config{ SnapshotCache: 102, FilterLogCacheSize: 32, Miner: miner.Config{ - GasCeil: 14000000, + GasCeil: 20000000, GasPrice: big.NewInt(params.GWei), Recommit: 3 * time.Second, }, diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index 893b59149831..b9df4db93cda 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -38,6 +38,8 @@ var ( DefaultMaxPrice = big.NewInt(500 * params.GWei) DefaultMinPrice = big.NewInt(3 * params.GWei) DefaultIgnorePrice = big.NewInt(2 * params.Wei) + + DefaultGasUsedRatio = 0.9 ) type Config struct { @@ -279,26 +281,33 @@ func (oracle *Oracle) getBlockValues(ctx context.Context, signer types.Signer, b } return } - // Sort the transaction by effective tip in ascending sort. - txs := make([]*types.Transaction, len(block.Transactions())) - copy(txs, block.Transactions()) - sorter := newSorter(txs, block.BaseFee()) - sort.Sort(sorter) var prices []*big.Int - for _, tx := range sorter.txs { - tip, _ := tx.EffectiveGasTip(block.BaseFee()) - if ignoreUnder != nil && tip.Cmp(ignoreUnder) == -1 { - continue - } - sender, err := types.Sender(signer, tx) - if err == nil && sender != block.Coinbase() { - prices = append(prices, tip) - if len(prices) >= limit { - break + gasUsedRatio := float64(block.Header().GasUsed) / float64(block.Header().GasLimit) + if gasUsedRatio < DefaultGasUsedRatio { + prices = append(prices, []*big.Int{DefaultMinPrice, DefaultMinPrice, DefaultMinPrice}...) + } else { + // Sort the transaction by effective tip in ascending sort. + txs := make([]*types.Transaction, len(block.Transactions())) + copy(txs, block.Transactions()) + sorter := newSorter(txs, block.BaseFee()) + sort.Sort(sorter) + + for _, tx := range sorter.txs { + tip, _ := tx.EffectiveGasTip(block.BaseFee()) + if ignoreUnder != nil && tip.Cmp(ignoreUnder) == -1 { + continue + } + sender, err := types.Sender(signer, tx) + if err == nil && sender != block.Coinbase() { + prices = append(prices, tip) + if len(prices) >= limit { + break + } } } } + select { case result <- results{prices, nil}: case <-quit: diff --git a/params/version.go b/params/version.go index 54ffcda7be0c..bca52f229602 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 4 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release - VersionMeta = "stable" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 4 // Minor version component of the current release + VersionPatch = 3 // Patch version component of the current release + VersionMeta = "unstable" // Version metadata to append to the version string ) // Version holds the textual version string.