From c4cf5a9b7cbf14226783e7b95c9adefa6c6d1ba2 Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Tue, 6 Jul 2021 21:29:47 -0700 Subject: [PATCH] flashbots: Add baseFee to callBundle --- internal/ethapi/api.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index dc47347fd924..a72545c9e473 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -2133,6 +2133,7 @@ type CallBundleArgs struct { Timeout *int64 `json:"timeout"` GasLimit *uint64 `json:"gasLimit"` Difficulty *big.Int `json:"difficulty"` + BaseFee *big.Int `json:"baseFee"` } // CallBundle will simulate a bundle of transactions at the top of a given block @@ -2187,6 +2188,12 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st if args.GasLimit != nil { gasLimit = *args.GasLimit } + var baseFee *big.Int + if args.BaseFee != nil { + baseFee = args.BaseFee + } else if s.b.ChainConfig().IsLondon(big.NewInt(args.BlockNumber.Int64())) { + baseFee = misc.CalcBaseFee(s.b.ChainConfig(), parent) + } header := &types.Header{ ParentHash: parent.Hash(), Number: blockNumber, @@ -2194,6 +2201,7 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st Time: timestamp, Difficulty: difficulty, Coinbase: coinbase, + BaseFee: baseFee, } // Setup context so it may be cancelled the call has completed @@ -2246,7 +2254,11 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st "toAddress": to, } totalGasUsed += receipt.GasUsed - gasFeesTx := new(big.Int).Mul(big.NewInt(int64(receipt.GasUsed)), tx.GasPrice()) + gasPrice, err := tx.EffectiveGasTip(header.BaseFee) + if err != nil { + return nil, fmt.Errorf("err: %w; txhash %s", err, tx.Hash()) + } + gasFeesTx := new(big.Int).Mul(big.NewInt(int64(receipt.GasUsed)), gasPrice) gasFees.Add(gasFees, gasFeesTx) bundleHash.Write(tx.Hash().Bytes()) if result.Err != nil {