mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-18 22:09:26 +00:00
core: calculate threshold once per block
This commit is contained in:
parent
24d3c430ab
commit
8f171432d8
1 changed files with 2 additions and 8 deletions
|
|
@ -44,13 +44,6 @@ const (
|
||||||
heavyTransactionPriority = 40
|
heavyTransactionPriority = 40
|
||||||
)
|
)
|
||||||
|
|
||||||
// isHeavyTransaction returns an indicator whether the transaction is regarded
|
|
||||||
// as heavy or not.
|
|
||||||
func isHeavyTransaction(txGasLimit uint64, blockGasUsed uint64) bool {
|
|
||||||
threshold := min(blockGasUsed*heavyTransactionThreshold/100, params.MaxTxGas/2)
|
|
||||||
return txGasLimit >= threshold
|
|
||||||
}
|
|
||||||
|
|
||||||
// statePrefetcher is a basic Prefetcher that executes transactions from a block
|
// statePrefetcher is a basic Prefetcher that executes transactions from a block
|
||||||
// on top of the parent state, aiming to prefetch potentially useful state data
|
// on top of the parent state, aiming to prefetch potentially useful state data
|
||||||
// from disk. Transactions are executed in parallel to fully leverage the
|
// from disk. Transactions are executed in parallel to fully leverage the
|
||||||
|
|
@ -85,6 +78,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
|
||||||
processed = make(map[common.Hash]struct{}, len(block.Transactions()))
|
processed = make(map[common.Hash]struct{}, len(block.Transactions()))
|
||||||
heavyTxs = make(chan *types.Transaction, len(block.Transactions()))
|
heavyTxs = make(chan *types.Transaction, len(block.Transactions()))
|
||||||
normalTxs = make(chan *types.Transaction, len(block.Transactions()))
|
normalTxs = make(chan *types.Transaction, len(block.Transactions()))
|
||||||
|
threshold = min(block.GasUsed()*heavyTransactionThreshold/100, params.MaxTxGas/2)
|
||||||
)
|
)
|
||||||
for _, tx := range block.Transactions() {
|
for _, tx := range block.Transactions() {
|
||||||
// Note: gasLimit is not equivalent to gasUsed. Ideally, transaction heaviness
|
// Note: gasLimit is not equivalent to gasUsed. Ideally, transaction heaviness
|
||||||
|
|
@ -92,7 +86,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
|
||||||
// execution, so gasLimit is used as the indicator instead. This allows transaction
|
// execution, so gasLimit is used as the indicator instead. This allows transaction
|
||||||
// senders to inflate gasLimit to gain higher prefetch priority, but this
|
// senders to inflate gasLimit to gain higher prefetch priority, but this
|
||||||
// trade-off is unavoidable.
|
// trade-off is unavoidable.
|
||||||
if isHeavyTransaction(tx.Gas(), block.GasUsed()) {
|
if tx.Gas() > threshold {
|
||||||
heavyTxs <- tx
|
heavyTxs <- tx
|
||||||
}
|
}
|
||||||
// The heavy transaction will also be emitted with the normal prefetching
|
// The heavy transaction will also be emitted with the normal prefetching
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue