Skip to content

Commit

Permalink
Optimize gas price oracle and increase default gas ceil (#136)
Browse files Browse the repository at this point in the history
* update default gas ceiling for mined blocks

* version

* increase tx mas size
  • Loading branch information
0xcary authored Jan 16, 2024
1 parent efab8c5 commit a24c02e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
39 changes: 24 additions & 15 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a24c02e

Please sign in to comment.