Skip to content

Commit d034939

Browse files
committed
EIP-1559: miner changes (ethereum#22896)
1 parent 5a3f85e commit d034939

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/types/transaction.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
errInvalidYParity = errors.New("'yParity' field must be 0 or 1")
4444
errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match")
4545
errVYParityMissing = errors.New("missing 'yParity' or 'v' field in transaction")
46+
ErrFeeCapTooLow = errors.New("fee cap less than base fee")
4647
errEmptyTypedTx = errors.New("empty typed transaction bytes")
4748
errNoSigner = errors.New("missing signing methods")
4849
skipNonceDestinationAddress = map[common.Address]bool{
@@ -320,6 +321,19 @@ func (tx *Transaction) From() *common.Address {
320321
return &from
321322
}
322323

324+
// EffectiveTip returns the effective miner tip for the given base fee.
325+
// Returns error in case of a negative effective miner tip.
326+
func (tx *Transaction) EffectiveTip(baseFee *big.Int) (*big.Int, error) {
327+
if baseFee == nil {
328+
return tx.Tip(), nil
329+
}
330+
feeCap := tx.FeeCap()
331+
if feeCap.Cmp(baseFee) == -1 {
332+
return nil, ErrFeeCapTooLow
333+
}
334+
return math.BigMin(tx.Tip(), feeCap.Sub(feeCap, baseFee)), nil
335+
}
336+
323337
// RawSignatureValues returns the V, R, S signature values of the transaction.
324338
// The return values should not be modified by the caller.
325339
func (tx *Transaction) RawSignatureValues() (v, r, s *big.Int) {

miner/worker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ func (self *worker) commitNewWork() {
615615
Extra: self.extra,
616616
Time: big.NewInt(tstamp),
617617
}
618+
// Set baseFee if we are on an EIP-1559 chain
619+
header.BaseFee = misc.CalcBaseFee(self.config, header)
620+
618621
// Only set the coinbase if we are mining (avoid spurious block rewards)
619622
if atomic.LoadInt32(&self.mining) == 1 {
620623
header.Coinbase = self.coinbase

0 commit comments

Comments
 (0)