Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 4ca2566

Browse files
committed
Merge remote-tracking branch 'origin/main' into bundle-tx-discard
2 parents 40ec427 + 9acf640 commit 4ca2566

File tree

8 files changed

+63
-19
lines changed

8 files changed

+63
-19
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ $ geth --help
139139
--miner.extradata value
140140
Block extra data set by the miner (default = client version)
141141
142+
--miner.price_cutoff_percent value (default: 50)
143+
flashbots - The minimum effective gas price threshold used for bucketing
144+
transactions by price. For example if the top transaction in a list has an
145+
effective gas price of 1000 wei and price_cutoff_percent is 10 (i.e. 10%), then
146+
the minimum effective gas price included in the same bucket as the top
147+
transaction is (1000 * 10%) = 100 wei.
148+
NOTE: This flag is only used when
149+
miner.algotype=greedy-buckets
150+
142151
METRICS
143152
144153
--metrics.builder value (default: false)

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ var (
133133
utils.MinerMaxMergedBundlesFlag,
134134
utils.MinerBlocklistFileFlag,
135135
utils.MinerNewPayloadTimeout,
136+
utils.MinerPriceCutoffPercentFlag,
136137
utils.NATFlag,
137138
utils.NoDiscoverFlag,
138139
utils.DiscoveryV5Flag,

cmd/utils/flags.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ var (
548548
}
549549
MinerAlgoTypeFlag = &cli.StringFlag{
550550
Name: "miner.algotype",
551-
Usage: "Block building algorithm to use [=mev-geth] (mev-geth, greedy)",
551+
Usage: "Block building algorithm to use [=mev-geth] (mev-geth, greedy, greedy-buckets)",
552552
Value: "mev-geth",
553553
Category: flags.MinerCategory,
554554
}
@@ -591,6 +591,17 @@ var (
591591
Value: ethconfig.Defaults.Miner.NewPayloadTimeout,
592592
Category: flags.MinerCategory,
593593
}
594+
MinerPriceCutoffPercentFlag = &cli.IntFlag{
595+
Name: "miner.price_cutoff_percent",
596+
Usage: "flashbots - The minimum effective gas price threshold used for bucketing transactions by price. " +
597+
"For example if the top transaction in a list has an effective gas price of 1000 wei and price_cutoff_percent " +
598+
"is 10 (i.e. 10%), then the minimum effective gas price included in the same bucket as the top transaction " +
599+
"is (1000 * 10%) = 100 wei.\n" +
600+
"NOTE: This flag is only used when miner.algotype=greedy-buckets",
601+
Value: ethconfig.Defaults.Miner.PriceCutoffPercent,
602+
Category: flags.MinerCategory,
603+
EnvVars: []string{"FLASHBOTS_MINER_PRICE_CUTOFF_PERCENT"},
604+
}
594605

595606
// Account settings
596607
UnlockedAccountFlag = &cli.StringFlag{
@@ -1903,6 +1914,8 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
19031914
Fatalf("Failed to parse blocklist: %s", err)
19041915
}
19051916
}
1917+
1918+
cfg.PriceCutoffPercent = ctx.Int(MinerPriceCutoffPercentFlag.Name)
19061919
}
19071920

19081921
func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) {

core/types/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ func (t *TxWithMinerFee) Profit(baseFee *big.Int, gasUsed uint64) *big.Int {
535535
}
536536
return profit
537537
} else if bundle := t.Bundle(); bundle != nil {
538-
return bundle.TotalEth
538+
return bundle.EthSentToCoinbase
539539
} else if sbundle := t.SBundle(); sbundle != nil {
540540
return sbundle.Profit
541541
} else {

miner/algo_common.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ const (
2222
popTx = 2
2323
)
2424

25-
// defaultProfitPercentMinimum is to ensure committed transactions, bundles, sbundles don't fall below this threshold
26-
// when profit is enforced
27-
const defaultProfitPercentMinimum = 70
25+
const (
26+
// defaultProfitThresholdPercent is to ensure committed transactions, bundles, sbundles don't fall below this threshold
27+
// when profit is enforced
28+
defaultProfitThresholdPercent = 70
29+
30+
// defaultPriceCutoffPercent is for bucketing transactions by price, used for greedy buckets algorithm
31+
defaultPriceCutoffPercent = 50
32+
)
2833

2934
var (
3035
defaultAlgorithmConfig = algorithmConfig{
3136
DropRevertibleTxOnErr: false,
3237
EnforceProfit: false,
33-
ProfitThresholdPercent: defaultProfitPercentMinimum,
38+
ProfitThresholdPercent: defaultProfitThresholdPercent,
39+
PriceCutoffPercent: defaultPriceCutoffPercent,
3440
}
3541
)
3642

@@ -63,8 +69,15 @@ type algorithmConfig struct {
6369
// EnforceProfit is true if we want to enforce a minimum profit threshold
6470
// for committing a transaction based on ProfitThresholdPercent
6571
EnforceProfit bool
72+
6673
// ProfitThresholdPercent is the minimum profit threshold for committing a transaction
6774
ProfitThresholdPercent int // 0-100, e.g. 70 means 70%
75+
76+
// PriceCutoffPercent is the minimum effective gas price threshold used for bucketing transactions by price.
77+
// For example if the top transaction in a list has an effective gas price of 1000 wei and PriceCutoffPercent
78+
// is 10 (i.e. 10%), then the minimum effective gas price included in the same bucket as the top transaction
79+
// is (1000 * 10%) = 100 wei.
80+
PriceCutoffPercent int
6881
}
6982

7083
type chainData struct {

miner/algo_greedy_buckets.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func newGreedyBucketsBuilder(
3434
if algoConf == nil {
3535
algoConf = &algorithmConfig{
3636
EnforceProfit: true,
37-
ProfitThresholdPercent: defaultProfitPercentMinimum,
37+
ProfitThresholdPercent: defaultProfitThresholdPercent,
3838
}
3939
}
4040
return &greedyBucketsBuilder{
@@ -48,7 +48,7 @@ func newGreedyBucketsBuilder(
4848
}
4949

5050
// CutoffPriceFromOrder returns the cutoff price for a given order based on the cutoff percent.
51-
// For example, if the cutoff percent is 0.9, the cutoff price will be 90% of the order price, rounded down to the nearest integer.
51+
// For example, if the cutoff percent is 90, the cutoff price will be 90% of the order price, rounded down to the nearest integer.
5252
func CutoffPriceFromOrder(order *types.TxWithMinerFee, cutoffPercent int) *big.Int {
5353
return common.PercentOf(order.Price(), cutoffPercent)
5454
}
@@ -190,12 +190,12 @@ func (b *greedyBucketsBuilder) mergeOrdersIntoEnvDiff(
190190
const retryLimit = 1
191191

192192
var (
193-
baseFee = envDiff.baseEnvironment.header.BaseFee
194-
retryMap = make(map[*types.TxWithMinerFee]int)
195-
usedBundles []types.SimulatedBundle
196-
usedSbundles []types.UsedSBundle
197-
transactions []*types.TxWithMinerFee
198-
percent = b.algoConf.ProfitThresholdPercent
193+
baseFee = envDiff.baseEnvironment.header.BaseFee
194+
retryMap = make(map[*types.TxWithMinerFee]int)
195+
usedBundles []types.SimulatedBundle
196+
usedSbundles []types.UsedSBundle
197+
transactions []*types.TxWithMinerFee
198+
priceCutoffPercent = b.algoConf.PriceCutoffPercent
199199

200200
SortInPlaceByProfit = func(baseFee *big.Int, transactions []*types.TxWithMinerFee, gasUsedMap map[*types.TxWithMinerFee]uint64) {
201201
sort.SliceStable(transactions, func(i, j int) bool {
@@ -204,7 +204,7 @@ func (b *greedyBucketsBuilder) mergeOrdersIntoEnvDiff(
204204
}
205205
)
206206

207-
minPrice := CutoffPriceFromOrder(orders.Peek(), percent)
207+
minPrice := CutoffPriceFromOrder(orders.Peek(), priceCutoffPercent)
208208
for {
209209
order := orders.Peek()
210210
if order == nil {
@@ -232,7 +232,7 @@ func (b *greedyBucketsBuilder) mergeOrdersIntoEnvDiff(
232232
usedSbundles = append(usedSbundles, sbundles...)
233233
transactions = nil
234234
}
235-
minPrice = CutoffPriceFromOrder(order, percent)
235+
minPrice = CutoffPriceFromOrder(order, priceCutoffPercent)
236236
}
237237
}
238238

miner/miner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type Config struct {
9898
MaxMergedBundles int
9999
Blocklist []common.Address `toml:",omitempty"`
100100
NewPayloadTimeout time.Duration // The maximum time allowance for creating a new payload
101+
PriceCutoffPercent int // Effective gas price cutoff % used for bucketing transactions by price (only useful in greedy-buckets AlgoType)
101102
}
102103

103104
// DefaultConfig contains default settings for miner.
@@ -109,8 +110,9 @@ var DefaultConfig = Config{
109110
// consensus-layer usually will wait a half slot of time(6s)
110111
// for payload generation. It should be enough for Geth to
111112
// run 3 rounds.
112-
Recommit: 2 * time.Second,
113-
NewPayloadTimeout: 2 * time.Second,
113+
Recommit: 2 * time.Second,
114+
NewPayloadTimeout: 2 * time.Second,
115+
PriceCutoffPercent: defaultPriceCutoffPercent,
114116
}
115117

116118
// Miner creates blocks and searches for proof-of-work values.

miner/worker.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,16 @@ func (w *worker) fillTransactionsAlgoWorker(interrupt *int32, env *environment)
14031403
)
14041404
switch w.flashbots.algoType {
14051405
case ALGO_GREEDY_BUCKETS:
1406+
priceCutoffPercent := w.config.PriceCutoffPercent
1407+
if !(priceCutoffPercent >= 0 && priceCutoffPercent <= 100) {
1408+
return nil, nil, nil, errors.New("invalid price cutoff percent - must be between 0 and 100")
1409+
}
1410+
14061411
algoConf := &algorithmConfig{
14071412
DropRevertibleTxOnErr: w.flashbots.discardRevertedHashes,
14081413
EnforceProfit: true,
1409-
ProfitThresholdPercent: defaultProfitPercentMinimum,
1414+
ProfitThresholdPercent: defaultProfitThresholdPercent,
1415+
PriceCutoffPercent: priceCutoffPercent,
14101416
}
14111417
builder := newGreedyBucketsBuilder(
14121418
w.chain, w.chainConfig, algoConf, w.blockList, env,

0 commit comments

Comments
 (0)