-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
eth/gasprice: set default percentile to 60%, count blocks instead of transactions #15828
Merged
+34
−19
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
83fe302
eth: Set default GPO percentile to 35%, and count blocks instead of t…
Arachnid 3d1d61e
eth/gasprice: Don't include transactions made by the miner themselves
Arachnid 8c2e33f
eth: Use 60% for GPO, not 35%
Arachnid 85cc916
eth: Reduce the GPO lookback to 20 blocks from 100, for speed
Arachnid ef4d9fb
eth/gasprice: Add mistakenly deleted 'continue'
Arachnid 67d1681
eth/gasprice: gofmt
Arachnid 38e8ac0
eth/gasprice: Sort transactions by price first, to minimise use of ec…
Arachnid cd85458
eth/gasprice: gofmt
Arachnid 26f303f
eth/gasprice: Make a copy of transaction pointers before sorting
Arachnid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"sync" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/internal/ethapi" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
|
@@ -101,9 +102,9 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) { | |
ch := make(chan getBlockPricesResult, gpo.checkBlocks) | ||
sent := 0 | ||
exp := 0 | ||
var txPrices []*big.Int | ||
var blockPrices []*big.Int | ||
for sent < gpo.checkBlocks && blockNum > 0 { | ||
go gpo.getBlockPrices(ctx, blockNum, ch) | ||
go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(blockNum))), blockNum, ch) | ||
sent++ | ||
exp++ | ||
blockNum-- | ||
|
@@ -115,25 +116,25 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) { | |
return lastPrice, res.err | ||
} | ||
exp-- | ||
if len(res.prices) > 0 { | ||
txPrices = append(txPrices, res.prices...) | ||
if res.price != nil { | ||
blockPrices = append(blockPrices, res.price) | ||
continue | ||
} | ||
if maxEmpty > 0 { | ||
maxEmpty-- | ||
continue | ||
} | ||
if blockNum > 0 && sent < gpo.maxBlocks { | ||
go gpo.getBlockPrices(ctx, blockNum, ch) | ||
go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(blockNum))), blockNum, ch) | ||
sent++ | ||
exp++ | ||
blockNum-- | ||
} | ||
} | ||
price := lastPrice | ||
if len(txPrices) > 0 { | ||
sort.Sort(bigIntArray(txPrices)) | ||
price = txPrices[(len(txPrices)-1)*gpo.percentile/100] | ||
if len(blockPrices) > 0 { | ||
sort.Sort(bigIntArray(blockPrices)) | ||
price = blockPrices[(len(blockPrices)-1)*gpo.percentile/100] | ||
} | ||
if price.Cmp(maxPrice) > 0 { | ||
price = new(big.Int).Set(maxPrice) | ||
|
@@ -147,24 +148,30 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) { | |
} | ||
|
||
type getBlockPricesResult struct { | ||
prices []*big.Int | ||
err error | ||
price *big.Int | ||
err error | ||
} | ||
|
||
// getLowestPrice calculates the lowest transaction gas price in a given block | ||
// and sends it to the result channel. If the block is empty, price is nil. | ||
func (gpo *Oracle) getBlockPrices(ctx context.Context, blockNum uint64, ch chan getBlockPricesResult) { | ||
func (gpo *Oracle) getBlockPrices(ctx context.Context, signer types.Signer, blockNum uint64, ch chan getBlockPricesResult) { | ||
block, err := gpo.backend.BlockByNumber(ctx, rpc.BlockNumber(blockNum)) | ||
if block == nil { | ||
ch <- getBlockPricesResult{nil, err} | ||
return | ||
} | ||
txs := block.Transactions() | ||
prices := make([]*big.Int, len(txs)) | ||
for i, tx := range txs { | ||
prices[i] = tx.GasPrice() | ||
var minPrice *big.Int | ||
for _, tx := range txs { | ||
sender, err := types.Sender(signer, tx) | ||
if err != nil || sender == block.Coinbase() { | ||
continue | ||
} | ||
if minPrice == nil || tx.GasPrice().Cmp(minPrice) < 0 { | ||
minPrice = tx.GasPrice() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if curPrice := tx.GasPrice(); minPrice == nil || curPrice.Cmp(minPrice) < 0 {
minPrice = curPrice
} |
||
} | ||
} | ||
ch <- getBlockPricesResult{prices, nil} | ||
ch <- getBlockPricesResult{minPrice, nil} | ||
} | ||
|
||
type bigIntArray []*big.Int | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit reluctant about this change here as is. This essentially does an ecrecover. So for a single gas estimation, on mainnet we would iterate over 20 blocks x 200-300 tx, that's 4-6K ecrecovers. That would imho be a very expensive operation to do, borderline unusable on a mobile phone (maybe fully).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we could cache the senders of transactions so we don't need to ecrecover all the time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In here, or in general? We could modify this to not reprocess existing blocks, if they've been seen already by a previous call to the oracle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm very mistaken, tx sender caching helps here. The GPO loads recent blocks, so they'll be in the BlockChain LRU. The txs in those blocks have cached sender information.