Skip to content

Commit 9db6f04

Browse files
Ruteriavalonche
authored andcommitted
Flashbots changes v0.4 to v0.5
* fix issue with geth not shutting down (flashbots#97) * Add eth_callBundle rpc method (flashbots#14) * flashbots: add eth_estimateGasBundle (flashbots#102) * feat(ethash): flashbots_getWork RPC with profit (flashbots#106) * Calculate megabundle as soon as it's received (flashbots#112) * Add v0.5 specification link (flashbots#118)
1 parent a935bec commit 9db6f04

16 files changed

Lines changed: 485 additions & 30 deletions

File tree

consensus/beacon/consensus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
382382
//
383383
// Note, the method returns immediately and will send the result async. More
384384
// than one result may also be returned depending on the consensus algorithm.
385-
func (beacon *Beacon) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
385+
func (beacon *Beacon) Seal(chain consensus.ChainHeaderReader, block *types.Block, profit *big.Int, results chan<- *types.Block, stop <-chan struct{}) error {
386386
if !beacon.IsPoSHeader(block.Header()) {
387-
return beacon.ethone.Seal(chain, block, results, stop)
387+
return beacon.ethone.Seal(chain, block, profit, results, stop)
388388
}
389389
// The seal verification is done by the external consensus engine,
390390
// return directly without pushing any block back. In another word

consensus/clique/clique.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ func (c *Clique) Authorize(signer common.Address, signFn SignerFn) {
598598

599599
// Seal implements consensus.Engine, attempting to create a sealed block using
600600
// the local signing credentials.
601-
func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
601+
func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, profit *big.Int, results chan<- *types.Block, stop <-chan struct{}) error {
602602
header := block.Header()
603603

604604
// Sealing the genesis block is not supported

consensus/consensus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ type Engine interface {
104104
//
105105
// Note, the method returns immediately and will send the result async. More
106106
// than one result may also be returned depending on the consensus algorithm.
107-
Seal(chain ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error
107+
Seal(chain ChainHeaderReader, block *types.Block, profit *big.Int, results chan<- *types.Block, stop <-chan struct{}) error
108108

109109
// SealHash returns the hash of a block prior to it being sealed.
110110
SealHash(header *types.Header) common.Hash

consensus/ethash/flashbots_api.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ethash
2+
3+
import "errors"
4+
5+
// FlashbotsAPI exposes Flashbots related methods for the RPC interface.
6+
type FlashbotsAPI struct {
7+
ethash *Ethash
8+
}
9+
10+
// GetWork returns a work package for external miner.
11+
//
12+
// The work package consists of 5 strings:
13+
// result[0] - 32 bytes hex encoded current block header pow-hash
14+
// result[1] - 32 bytes hex encoded seed hash used for DAG
15+
// result[2] - 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
16+
// result[3] - hex encoded block number
17+
// result[4] - hex encoded profit generated from this block
18+
func (api *FlashbotsAPI) GetWork() ([5]string, error) {
19+
if api.ethash.remote == nil {
20+
return [5]string{}, errors.New("not supported")
21+
}
22+
23+
var (
24+
workCh = make(chan [5]string, 1)
25+
errc = make(chan error, 1)
26+
)
27+
select {
28+
case api.ethash.remote.fetchWorkCh <- &sealWork{errc: errc, res: workCh}:
29+
case <-api.ethash.remote.exitCh:
30+
return [5]string{}, errEthashStopped
31+
}
32+
select {
33+
case work := <-workCh:
34+
return work, nil
35+
case err := <-errc:
36+
return [5]string{}, err
37+
}
38+
}

core/state_processor.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,51 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
145145
return receipt, err
146146
}
147147

148+
func applyTransactionWithResult(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, *ExecutionResult, error) {
149+
// Create a new context to be used in the EVM environment.
150+
txContext := NewEVMTxContext(msg)
151+
evm.Reset(txContext, statedb)
152+
153+
// Apply the transaction to the current state (included in the env).
154+
result, err := ApplyMessage(evm, msg, gp)
155+
if err != nil {
156+
return nil, nil, err
157+
}
158+
159+
// Update the state with pending changes.
160+
var root []byte
161+
if config.IsByzantium(header.Number) {
162+
statedb.Finalise(true)
163+
} else {
164+
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
165+
}
166+
*usedGas += result.UsedGas
167+
168+
// Create a new receipt for the transaction, storing the intermediate root and gas used
169+
// by the tx.
170+
receipt := &types.Receipt{Type: tx.Type(), PostState: root, CumulativeGasUsed: *usedGas}
171+
if result.Failed() {
172+
receipt.Status = types.ReceiptStatusFailed
173+
} else {
174+
receipt.Status = types.ReceiptStatusSuccessful
175+
}
176+
receipt.TxHash = tx.Hash()
177+
receipt.GasUsed = result.UsedGas
178+
179+
// If the transaction created a contract, store the creation address in the receipt.
180+
if msg.To() == nil {
181+
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
182+
}
183+
184+
// Set the receipt logs and create the bloom filter.
185+
receipt.Logs = statedb.GetLogs(tx.Hash(), header.Hash())
186+
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
187+
receipt.BlockHash = header.Hash()
188+
receipt.BlockNumber = header.Number
189+
receipt.TransactionIndex = uint(statedb.TxIndex())
190+
return receipt, result, err
191+
}
192+
148193
// ApplyTransaction attempts to apply a transaction to the given state database
149194
// and uses the input parameters for its environment. It returns the receipt
150195
// for the transaction, gas used and an error if the transaction failed,
@@ -159,3 +204,14 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
159204
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
160205
return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv)
161206
}
207+
208+
func ApplyTransactionWithResult(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, *ExecutionResult, error) {
209+
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number), header.BaseFee)
210+
if err != nil {
211+
return nil, nil, err
212+
}
213+
// Create a new context to be used in the EVM environment
214+
blockContext := NewEVMBlockContext(header, bc, author)
215+
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
216+
return applyTransactionWithResult(msg, config, bc, author, gp, statedb, header, tx, usedGas, vmenv)
217+
}

core/txpool/txpool.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,20 @@ func (pool *TxPool) AddMegabundle(relayAddr common.Address, txs types.Transactio
639639
return errors.New("megabundle from non-trusted address")
640640
}
641641

642-
pool.megabundles[relayAddr] = types.MevBundle{
642+
megabundle := types.MevBundle{
643643
Txs: txs,
644644
BlockNumber: blockNumber,
645645
MinTimestamp: minTimestamp,
646646
MaxTimestamp: maxTimestamp,
647647
RevertingTxHashes: revertingTxHashes,
648648
}
649+
650+
pool.megabundles[relayAddr] = megabundle
651+
652+
for _, hook := range pool.NewMegabundleHooks {
653+
go hook(relayAddr, &megabundle)
654+
}
655+
649656
return nil
650657
}
651658

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func makeExtraData(extra []byte) []byte {
282282
// APIs return the collection of RPC services the ethereum package offers.
283283
// NOTE, some of these services probably need to be moved to somewhere else.
284284
func (s *Ethereum) APIs() []rpc.API {
285-
apis := ethapi.GetAPIs(s.APIBackend)
285+
apis := ethapi.GetAPIs(s.APIBackend, s.BlockChain())
286286

287287
// Append any APIs exposed explicitly by the consensus engine
288288
apis = append(apis, s.engine.APIs(s.BlockChain())...)

infra/Dockerfile.node

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM golang:1.15-alpine as builder
44
RUN apk add --no-cache make gcc musl-dev linux-headers git
55

66
ADD . /go-ethereum
7-
RUN cd /go-ethereum && make geth
7+
RUN cd /go-ethereum && GO111MODULE=on go run build/ci.go install ./cmd/geth
88

99
# Pull Geth into a second stage deploy alpine container
1010
FROM alpine:latest

infra/Dockerfile.updater

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM golang:1.15-alpine as builder
44
RUN apk add --no-cache make gcc musl-dev linux-headers git
55

66
ADD . /go-ethereum
7-
RUN cd /go-ethereum && make geth
7+
RUN cd /go-ethereum && GO111MODULE=on go run build/ci.go install ./cmd/geth
88

99
# Pull Geth into a second stage deploy alpine container
1010
FROM alpine:latest

infra/start-mev-geth-node.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ start_node() {
3333
--ws.api eth,net,web3 \
3434
--ws.origins '*' \
3535
--syncmode $syncmode \
36+
--gcmode archive \
3637
--cache 4096 \
3738
--maxpeers $connections \
3839
--goerli
@@ -41,7 +42,7 @@ start_node() {
4142
echo "Node failed to start; exiting."
4243
exit 1
4344
fi
44-
else
45+
else
4546
geth \
4647
--port $netport \
4748
--http \
@@ -59,7 +60,9 @@ start_node() {
5960
--ws.api eth,net,web3 \
6061
--ws.origins '*' \
6162
--syncmode $syncmode \
63+
--gcmode archive \
6264
--cache 4096 \
65+
--snapshot=false \
6366
--maxpeers $connections
6467
if [ $? -ne 0 ]
6568
then

0 commit comments

Comments
 (0)