Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 7395f3f

Browse files
jparyaniRuteri
authored andcommitted
Flashbots change up to v0.3
1 parent 23bee16 commit 7395f3f

25 files changed

+4544
-405
lines changed

.github/workflows/go.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [ master ]
7+
8+
jobs:
9+
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
15+
- name: Set up Go 1.x
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: ^1.13
19+
id: go
20+
21+
- name: Check out code into the Go module directory
22+
uses: actions/checkout@v2
23+
24+
- name: Test
25+
run: go test ./core ./miner/... ./internal/ethapi/... ./les/...
26+
27+
- name: Build
28+
run: make geth
29+
30+
e2e:
31+
name: End to End
32+
runs-on: ubuntu-latest
33+
steps:
34+
35+
- name: Set up Go 1.x
36+
uses: actions/setup-go@v2
37+
with:
38+
go-version: ^1.13
39+
id: go
40+
41+
- name: Use Node.js 12.x
42+
uses: actions/setup-node@v1
43+
with:
44+
node-version: 12.x
45+
46+
- name: Check out code into the Go module directory
47+
uses: actions/checkout@v2
48+
49+
- name: Build
50+
run: make geth
51+
52+
- name: Check out the e2e code repo
53+
uses: actions/checkout@v2
54+
with:
55+
repository: flashbots/mev-geth-demo
56+
path: e2e
57+
58+
- run: cd e2e && yarn install
59+
- run: |
60+
cd e2e
61+
GETH=`pwd`/../build/bin/geth ./run.sh &
62+
sleep 15
63+
yarn run demo-simple
64+
yarn run demo-contract

README.md

Lines changed: 20 additions & 367 deletions
Large diffs are not rendered by default.

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var (
131131
utils.MinerExtraDataFlag,
132132
utils.MinerRecommitIntervalFlag,
133133
utils.MinerNoVerifyFlag,
134+
utils.MinerMaxMergedBundles,
134135
utils.NATFlag,
135136
utils.NoDiscoverFlag,
136137
utils.DiscoveryV5Flag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
187187
utils.MinerExtraDataFlag,
188188
utils.MinerRecommitIntervalFlag,
189189
utils.MinerNoVerifyFlag,
190+
utils.MinerMaxMergedBundles,
190191
},
191192
},
192193
{

cmd/utils/flags.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ var (
490490
Usage: "Time interval to recreate the block being mined",
491491
Value: ethconfig.Defaults.Miner.Recommit,
492492
}
493+
MinerMaxMergedBundles = cli.IntFlag{
494+
Name: "miner.maxmergedbundles",
495+
Usage: "flashbots - The maximum amount of bundles to merge. The miner will run this many workers in parallel to calculate if the full block is more profitable with these additional bundles.",
496+
Value: 3,
497+
}
493498
MinerNoVerifyFlag = cli.BoolFlag{
494499
Name: "miner.noverify",
495500
Usage: "Disable remote sealing verification",
@@ -1508,6 +1513,8 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
15081513
if ctx.GlobalIsSet(LegacyMinerGasTargetFlag.Name) {
15091514
log.Warn("The generic --miner.gastarget flag is deprecated and will be removed in the future!")
15101515
}
1516+
1517+
cfg.MaxMergedBundles = ctx.GlobalInt(MinerMaxMergedBundles.Name)
15111518
}
15121519

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

core/tx_pool.go

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,12 @@ type TxPool struct {
251251
locals *accountSet // Set of local transaction to exempt from eviction rules
252252
journal *txJournal // Journal of local transaction to back up to disk
253253

254-
pending map[common.Address]*txList // All currently processable transactions
255-
queue map[common.Address]*txList // Queued but non-processable transactions
256-
beats map[common.Address]time.Time // Last heartbeat from each known account
257-
all *txLookup // All transactions to allow lookups
258-
priced *txPricedList // All transactions sorted by price
254+
pending map[common.Address]*txList // All currently processable transactions
255+
queue map[common.Address]*txList // Queued but non-processable transactions
256+
beats map[common.Address]time.Time // Last heartbeat from each known account
257+
mevBundles []types.MevBundle
258+
all *txLookup // All transactions to allow lookups
259+
priced *txPricedList // All transactions sorted by price
259260

260261
chainHeadCh chan ChainHeadEvent
261262
chainHeadSub event.Subscription
@@ -557,6 +558,59 @@ func (pool *TxPool) Pending(enforceTips bool) map[common.Address]types.Transacti
557558
return pending
558559
}
559560

561+
/// AllMevBundles returns all the MEV Bundles currently in the pool
562+
func (pool *TxPool) AllMevBundles() []types.MevBundle {
563+
return pool.mevBundles
564+
}
565+
566+
// MevBundles returns a list of bundles valid for the given blockNumber/blockTimestamp
567+
// also prunes bundles that are outdated
568+
func (pool *TxPool) MevBundles(blockNumber *big.Int, blockTimestamp uint64) ([]types.MevBundle, error) {
569+
pool.mu.Lock()
570+
defer pool.mu.Unlock()
571+
572+
// returned values
573+
var ret []types.MevBundle
574+
// rolled over values
575+
var bundles []types.MevBundle
576+
577+
for _, bundle := range pool.mevBundles {
578+
// Prune outdated bundles
579+
if (bundle.MaxTimestamp != 0 && blockTimestamp > bundle.MaxTimestamp) || blockNumber.Cmp(bundle.BlockNumber) > 0 {
580+
continue
581+
}
582+
583+
// Roll over future bundles
584+
if (bundle.MinTimestamp != 0 && blockTimestamp < bundle.MinTimestamp) || blockNumber.Cmp(bundle.BlockNumber) < 0 {
585+
bundles = append(bundles, bundle)
586+
continue
587+
}
588+
589+
// return the ones which are in time
590+
ret = append(ret, bundle)
591+
// keep the bundles around internally until they need to be pruned
592+
bundles = append(bundles, bundle)
593+
}
594+
595+
pool.mevBundles = bundles
596+
return ret, nil
597+
}
598+
599+
// AddMevBundle adds a mev bundle to the pool
600+
func (pool *TxPool) AddMevBundle(txs types.Transactions, blockNumber *big.Int, minTimestamp, maxTimestamp uint64, revertingTxHashes []common.Hash) error {
601+
pool.mu.Lock()
602+
defer pool.mu.Unlock()
603+
604+
pool.mevBundles = append(pool.mevBundles, types.MevBundle{
605+
Txs: txs,
606+
BlockNumber: blockNumber,
607+
MinTimestamp: minTimestamp,
608+
MaxTimestamp: maxTimestamp,
609+
RevertingTxHashes: revertingTxHashes,
610+
})
611+
return nil
612+
}
613+
560614
// Locals retrieves the accounts currently considered local by the pool.
561615
func (pool *TxPool) Locals() []common.Address {
562616
pool.mu.Lock()

core/types/transaction.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,3 +651,11 @@ func copyAddressPtr(a *common.Address) *common.Address {
651651
cpy := *a
652652
return &cpy
653653
}
654+
655+
type MevBundle struct {
656+
Txs Transactions
657+
BlockNumber *big.Int
658+
MinTimestamp uint64
659+
MaxTimestamp uint64
660+
RevertingTxHashes []common.Hash
661+
}

eth/api_backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
246246
return b.eth.txPool.AddLocal(signedTx)
247247
}
248248

249+
func (b *EthAPIBackend) SendBundle(ctx context.Context, txs types.Transactions, blockNumber rpc.BlockNumber, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error {
250+
return b.eth.txPool.AddMevBundle(txs, big.NewInt(blockNumber.Int64()), minTimestamp, maxTimestamp, revertingTxHashes)
251+
}
252+
249253
func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
250254
pending := b.eth.txPool.Pending(false)
251255
var txs types.Transactions

infra/Dockerfile.node

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Build Geth in a stock Go builder container
2+
FROM golang:1.15-alpine as builder
3+
4+
RUN apk add --no-cache make gcc musl-dev linux-headers git
5+
6+
ADD . /go-ethereum
7+
RUN cd /go-ethereum && make geth
8+
9+
# Pull Geth into a second stage deploy alpine container
10+
FROM alpine:latest
11+
12+
ENV PYTHONUNBUFFERED=1
13+
RUN apk add --update --no-cache groff less python3 curl jq ca-certificates && ln -sf python3 /usr/bin/python
14+
RUN python3 -m ensurepip
15+
RUN pip3 install --no-cache --upgrade pip setuptools awscli
16+
17+
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
18+
19+
COPY ./infra/start-mev-geth-node.sh /root/start-mev-geth-node.sh
20+
RUN chmod 755 /root/start-mev-geth-node.sh
21+
22+
EXPOSE 8545 8546 30303 30303/udp
23+
ENTRYPOINT ["/root/start-mev-geth-node.sh"]

infra/Dockerfile.updater

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Build Geth in a stock Go builder container
2+
FROM golang:1.15-alpine as builder
3+
4+
RUN apk add --no-cache make gcc musl-dev linux-headers git
5+
6+
ADD . /go-ethereum
7+
RUN cd /go-ethereum && make geth
8+
9+
# Pull Geth into a second stage deploy alpine container
10+
FROM alpine:latest
11+
12+
ENV PYTHONUNBUFFERED=1
13+
RUN apk add --update --no-cache groff less python3 curl jq ca-certificates && ln -sf python3 /usr/bin/python
14+
RUN python3 -m ensurepip
15+
RUN pip3 install --no-cache --upgrade pip setuptools awscli
16+
17+
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
18+
19+
COPY ./infra/start-mev-geth-updater.sh /root/start-mev-geth-updater.sh
20+
RUN chmod 755 /root/start-mev-geth-updater.sh
21+
22+
EXPOSE 8545 8546 30303 30303/udp
23+
ENTRYPOINT ["/root/start-mev-geth-updater.sh"]

0 commit comments

Comments
 (0)