mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
core/types: reduce allocations
This commit is contained in:
parent
f8125260de
commit
a4ad86b280
2 changed files with 20 additions and 14 deletions
|
|
@ -355,36 +355,40 @@ func (tx *Transaction) GasTipCapIntCmp(other *big.Int) int {
|
|||
// Note: if the effective gasTipCap is negative, this method returns both error
|
||||
// the actual negative value, _and_ ErrGasFeeCapTooLow
|
||||
func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) {
|
||||
out, err := tx.effectiveGasTip(baseFee)
|
||||
return new(big.Int).Set(out), err
|
||||
}
|
||||
|
||||
// effectiveGasTip returns the effective miner gasTipCap for the given base fee but does not allocate.
|
||||
// Note: if the effective gasTipCap is negative, this method returns both error
|
||||
// the actual negative value, _and_ ErrGasFeeCapTooLow
|
||||
// Note: please copy the return value before modifying.
|
||||
func (tx *Transaction) effectiveGasTip(baseFee *big.Int) (*big.Int, error) {
|
||||
if baseFee == nil {
|
||||
return tx.GasTipCap(), nil
|
||||
return tx.inner.gasTipCap(), nil
|
||||
}
|
||||
var err error
|
||||
gasFeeCap := tx.GasFeeCap()
|
||||
gasFeeCap := tx.inner.gasFeeCap()
|
||||
if gasFeeCap.Cmp(baseFee) < 0 {
|
||||
err = ErrGasFeeCapTooLow
|
||||
}
|
||||
gasFeeCap = gasFeeCap.Sub(gasFeeCap, baseFee)
|
||||
gasFeeCap = new(big.Int).Sub(gasFeeCap, baseFee)
|
||||
|
||||
gasTipCap := tx.inner.gasTipCap()
|
||||
if gasTipCap.Cmp(gasFeeCap) < 0 {
|
||||
return gasFeeCap.Set(gasTipCap), err
|
||||
return gasTipCap, err
|
||||
}
|
||||
return gasFeeCap, err
|
||||
}
|
||||
|
||||
// EffectiveGasTipValue is identical to EffectiveGasTip, but does not return an
|
||||
// error in case the effective gasTipCap is negative
|
||||
func (tx *Transaction) EffectiveGasTipValue(baseFee *big.Int) *big.Int {
|
||||
effectiveTip, _ := tx.EffectiveGasTip(baseFee)
|
||||
return effectiveTip
|
||||
}
|
||||
|
||||
// EffectiveGasTipCmp compares the effective gasTipCap of two transactions assuming the given base fee.
|
||||
func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int) int {
|
||||
if baseFee == nil {
|
||||
return tx.GasTipCapCmp(other)
|
||||
}
|
||||
return tx.EffectiveGasTipValue(baseFee).Cmp(other.EffectiveGasTipValue(baseFee))
|
||||
effectiveGasTip, _ := tx.effectiveGasTip(baseFee)
|
||||
otherEffectiveGasTip, _ := other.effectiveGasTip(baseFee)
|
||||
return effectiveGasTip.Cmp(otherEffectiveGasTip)
|
||||
}
|
||||
|
||||
// EffectiveGasTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.
|
||||
|
|
@ -392,7 +396,8 @@ func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) i
|
|||
if baseFee == nil {
|
||||
return tx.GasTipCapIntCmp(other)
|
||||
}
|
||||
return tx.EffectiveGasTipValue(baseFee).Cmp(other)
|
||||
effectiveGasTip, _ := tx.effectiveGasTip(baseFee)
|
||||
return effectiveGasTip.Cmp(other)
|
||||
}
|
||||
|
||||
// BlobGas returns the blob gas limit of the transaction for blob transactions, 0 otherwise.
|
||||
|
|
|
|||
|
|
@ -260,7 +260,8 @@ func (t *jsTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from
|
|||
t.activePrecompiles = vm.ActivePrecompiles(rules)
|
||||
t.ctx["block"] = t.vm.ToValue(t.env.BlockNumber.Uint64())
|
||||
t.ctx["gas"] = t.vm.ToValue(tx.Gas())
|
||||
gasPriceBig, err := t.toBig(t.vm, tx.EffectiveGasTipValue(env.BaseFee).String())
|
||||
gasTip, _ := tx.EffectiveGasTip(env.BaseFee)
|
||||
gasPriceBig, err := t.toBig(t.vm, gasTip.String())
|
||||
if err != nil {
|
||||
t.err = err
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue