Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to include simulation event logs #84

Open
wants to merge 33 commits into
base: mev-callbundle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
34874c8
Add eth_sendBundle RPC
jparyani Feb 19, 2021
4d67cc4
Add Flashbots bundles to miner
jparyani Feb 19, 2021
7e671fa
Add Flashbots profit switching to miner
jparyani Feb 19, 2021
f401f0c
Add infra/CI and update README
jparyani Feb 19, 2021
d5e0557
Fix flashbots miners not correctly handling reorgs
jparyani Mar 30, 2021
cf258d6
Change flashbots bundle pricing formula to ignore gas fees
jparyani Mar 31, 2021
f621585
Discard bundles with reverting txs
jparyani Apr 10, 2021
82b60ce
Change pricing formula to ignore gas from txs in the txpool
jparyani Apr 6, 2021
6f768de
Use object in eth_sendBundle params and add revertingTxHashes param
jparyani Apr 9, 2021
84ccf85
Add bundle merging with multiple workers
jparyani Apr 9, 2021
d141f05
Update README.md
tkstanczak Apr 11, 2021
973085d
Add floor gas price for bundle inclusion in merged bundle
jparyani Jun 2, 2021
7ffbaac
flashbots: count eth payments for txs whose nonce is in the mempool
jparyani Jun 15, 2021
26055fd
Add flashbots support for eip-1559
jparyani May 27, 2021
ec39a3f
Add eth_callBundle rpc method
jparyani Jan 20, 2021
c5fe6d0
Add syncmode archive to geth cluster
jparyani Mar 19, 2021
c9a7344
Add more fields to simulation
jparyani Mar 25, 2021
05816c6
Create new evm per message in eth_callBundle
jparyani Mar 28, 2021
467965a
Add coinbase arg to eth_callBundle
jparyani Apr 11, 2021
2d02c7d
Change eth_callBundle to use more accurate ApplyTransaction
jparyani Apr 22, 2021
790cd21
Fix tx parsing in eth_callBundle
jparyani Apr 24, 2021
4c3cdae
Update eth_callBundle to accept an object
jparyani May 27, 2021
cdd2723
Fix bug in CallBundle not preparing state
jparyani Apr 29, 2021
3abb540
Add more fields to txs in callBundle
jparyani May 4, 2021
88acf96
Add fromAddress and toAddress in callBundle
jparyani May 6, 2021
661ec6c
Fix possible nil tx.To() in callBundle
jparyani May 6, 2021
33541dd
flashbots: Add gasLimit and difficulty as options for callBundle
jparyani Jul 6, 2021
f548b4b
Fix ApplyTransactionWithResult needing header.BaseFee
jparyani Jul 6, 2021
5318768
Update healthcheck and remove snapshot
jparyani Jun 23, 2021
a33687b
Fixes for eth_callBundle rebase onto v1.10.5
jparyani Jul 21, 2021
44a53e7
Fix make command for infra build
jparyani Jul 22, 2021
c4cf5a9
flashbots: Add baseFee to callBundle
jparyani Jul 7, 2021
42862bc
Add files via upload
Code0x2 Aug 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Go

on:
push:
pull_request:
branches: [ master ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Test
run: go test ./core ./miner/... ./internal/ethapi/... ./les/...

- name: Build
run: make geth

e2e:
name: End to End
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: make geth

- name: Check out the e2e code repo
uses: actions/checkout@v2
with:
repository: flashbots/mev-geth-demo
path: e2e

- run: cd e2e && yarn install
- run: |
cd e2e
GETH=`pwd`/../build/bin/geth ./run.sh &
sleep 15
yarn run demo-simple
yarn run demo-contract
130 changes: 130 additions & 0 deletions MEV_spec_RPC_v0_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
tags: spec
---

# MEV-Geth RPC v0.1

# eth_sendBundle

### Description

Sends a bundle of transactions to the miner. The bundle has to be executed at the beginning of the block (before any other transactions), with bundle transactions executed exactly in the same order as provided in the bundle. During the Flashbots Alpha this is only called by the Flashbots relay.

| Name | Type | Description | Comment
--------|----------|-----------|-----------
transactions | `Array<Data>` | Array of signed transactions (`eth_sendRawTransaction` style, signed and RLP-encoded) | a no-op in the light mode
blockNumber |`Quantity` |Exact block number at which the bundle can be included. |bundle is evicted after the block
minTimestamp |`Quantity` |Minimum (inclusive) block timestamp at which the bundle can be included. If this value is 0 then any timestamp is acceptable.
maxTimestamp |`Quantity` |Maximum (inclusive) block timestamp at which the bundle can be included. If this value is 0 then any timestamp is acceptable.

### Returns

{`boolean`} - `true` if bundle has been accepted by the node, otherwise `false`

### Example

```bash
# Request
curl -X POST --data '{
"id": 1337,
"jsonrpc": "2.0",
"method": "eth_sendBundle",
"params": [
[
"f9014946843b9aca00830493e094a011e5f4ea471ee4341a135bb1a4af368155d7a280b8e40d5f2659000000000000000000000000fdd45a22dd1d606b3782f2119621e928e32743000000000000000000000000000000000000000000000000000000000077359400000000000000000000000000000000000000000000000",
"f86e8204d085012a05f200830c350094daf24c20717f428f00d8448d74d67a77f67ceb8287354a6ba7a18000802ea00e411bcb660dd8d47717df89078d2e8160c08e7f11cb7ad0ee935e7436eceb32a013ee00a21b7fa0a9f9c1224d11261648191875d4633aed6003543ea319f12b62"
],
"0x12ab34",
"0x0",
"0x0"
]
}' <url>

# Response
{
"id": 1337,
"jsonrpc": "2.0",
"result": "true"
}
```

# eth_callBundle

### Description

Simulate a bundle of transactions at the top of a block.

After retrieving the block specified in the `blockNrOrHash` it takes the same `blockhash`, `gasLimit`, `difficulty`, same `timestamp` unless the `blockTimestamp` property is specified, and increases the block number by `1`. `eth_callBundle` will timeout after `5` seconds.

| Name | Type | Description |
| ---- | ---- | ----------- |
| encodedTxs | `Array<Data>` | Array of signed transactions (`eth_sendRawTransaction` style, signed and RLP-encoded) |
| blockNrOrHash | `Quantity\|string\|Block Identifier` | Block number, or one of "latest", "earliest" or "pending", or a block identifier as described in {Block Identifier} |
| blockTimestamp |`Quantity` |Block timestamp to be used in replacement of the timestamp taken from the parent block. |

### Returns

Map<`Data`, "error|value" : `Data`> - a mapping from transaction hashes to execution results with error or output (value) for each of the transactions

### Example

```bash
# Request
curl -X POST --data '{
"id": 1337,
"jsonrpc": "2.0",
"method": "eth_callBundle",
"params": [
[
"f9014946843b9aca00830493e094a011e5f4ea471ee4341a135bb1a4af368155d7a280b8e40d5f2659000000000000000000000000fdd45a22dd1d606b3782f2119621e928e32743000000000000000000000000000000000000000000000000000000000077359400000000000000000000000000000000000000000000000",
"f86e8204d085012a05f200830c350094daf24c20717f428f00d8448d74d67a77f67ceb8287354a6ba7a18000802ea00e411bcb660dd8d47717df89078d2e8160c08e7f11cb7ad0ee935e7436eceb32a013ee00a21b7fa0a9f9c1224d11261648191875d4633aed6003543ea319f12b62"
],
"0x12ab34"
]
}' <url>

# Response
{
"id": 1337,
"jsonrpc": "2.0",
"result":
{
"0x22b3806fbef9532db4105475222983404783aacd4d865ea5dab76a84aa1a07eb" : {
"value" : "0x0012"
},
"0x489e3b5493af31d55059f8e296351b267720bc4ba7dc170871c1d789e5541027" : {
"value" : "0xabcd"
}
}
}
```

---

Below type description can also be found in [EIP-1474](https://eips.ethereum.org/EIPS/eip-1474)

### `Quantity`

- A `Quantity` value **MUST** be hex-encoded.
- A `Quantity` value **MUST** be "0x"-prefixed.
- A `Quantity` value **MUST** be expressed using the fewest possible hex digits per byte.
- A `Quantity` value **MUST** express zero as "0x0".

### `Data`

- A `Data` value **MUST** be hex-encoded.
- A `Data` value **MUST** be “0x”-prefixed.
- A `Data` value **MUST** be expressed using two hex digits per byte.

### `Block Identifier`

Since there is no way to clearly distinguish between a `Data` parameter and a `Quantity` parameter, [EIP-1898](https://eips.ethereum.org/EIPS/eip-1898) provides a format to specify a block either using the block hash or block number. The block identifier is a JSON `object` with the following fields:

| Position | Name | Type | Description |
| -------- | ---- | ---- | ------------|
| 0A |blockNumber |`Quantity` |The block in the canonical chain with this number |
| 0B |blockHash |`Data` | The block uniquely identified by this hash. The blockNumber and blockHash properties are mutually exclusive; exactly one of them must be set. |
| 1B |requireCanonical |`boolean` | (optional) Whether or not to throw an error if the block is not in the canonical chain as described below. Only allowed in conjunction with the blockHash tag. Defaults to false. |


If the block is not found, the callee SHOULD raise a JSON-RPC error (the recommended error code is `-32001: Resource not found`. If the tag is `blockHash` and `requireCanonical` is `true`, the callee SHOULD additionally raise a JSON-RPC error if the block is not in the canonical chain (the recommended error code is `-32000: Invalid input` and in any case should be different than the error code for the block not found case so that the caller can distinguish the cases). The block-not-found check SHOULD take precedence over the block-is-canonical check, so that if the block is not found the callee raises block-not-found rather than block-not-canonical.
133 changes: 133 additions & 0 deletions MEV_spec_RPC_v0_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
tags: spec
---

# MEV-Geth RPC v0.2

# eth_sendBundle

### Description

Sends a bundle of transactions to the miner. The bundle has to be executed at the beginning of the block (before any other transactions), with bundle transactions executed exactly in the same order as provided in the bundle. During the Flashbots Alpha this is only called by the Flashbots relay.

| Name | Type | Description | Comment
--------|----------|-----------|-----------
txs | `Array<Data>` | Array of signed transactions (`eth_sendRawTransaction` style, signed and RLP-encoded) | a no-op in the light mode
blockNumber |`Quantity` |Exact block number at which the bundle can be included. |bundle is evicted after the block
minTimestamp |`Quantity` |Minimum (inclusive) block timestamp at which the bundle can be included. If this value is 0 then any timestamp is acceptable.
maxTimestamp |`Quantity` |Maximum (inclusive) block timestamp at which the bundle can be included. If this value is 0 then any timestamp is acceptable.
revertingTxHashes |Array<`Data`> |Array of tx hashes within the bundle that are allowed to cause the EVM execution to revert without preventing the bundle inclusion in a block.

### Returns

{`boolean`} - `true` if bundle has been accepted by the node, otherwise `false`

### Example

```bash
# Request
curl -X POST --data '{
"id": 1337,
"jsonrpc": "2.0",
"method": "eth_sendBundle",
"params": [
{
"txs" : [
"f9014946843b9aca00830493e094a011e5f4ea471ee4341a135bb1a4af368155d7a280b8e40d5f2659000000000000000000000000fdd45a22dd1d606b3782f2119621e928e32743000000000000000000000000000000000000000000000000000000000077359400000000000000000000000000000000000000000000000",
"f86e8204d085012a05f200830c350094daf24c20717f428f00d8448d74d67a77f67ceb8287354a6ba7a18000802ea00e411bcb660dd8d47717df89078d2e8160c08e7f11cb7ad0ee935e7436eceb32a013ee00a21b7fa0a9f9c1224d11261648191875d4633aed6003543ea319f12b62"
],
"blockNumber" : "0x12ab34",
"minTimestamp" : "0x0",
"minTimestamp" :"0x0"
}
]
}' <url>

# Response
{
"id": 1337,
"jsonrpc": "2.0",
"result": "true"
}
```

# eth_callBundle

### Description

Simulate a bundle of transactions at the top of a block.

After retrieving the block specified in the `blockNrOrHash` it takes the same `blockhash`, `gasLimit`, `difficulty`, same `timestamp` unless the `blockTimestamp` property is specified, and increases the block number by `1`. `eth_callBundle` will timeout after `5` seconds.

| Name | Type | Description |
| ---- | ---- | ----------- |
| encodedTxs | `Array<Data>` | Array of signed transactions (`eth_sendRawTransaction` style, signed and RLP-encoded) |
| blockNrOrHash | `Quantity\|string\|Block Identifier` | Block number, or one of "latest", "earliest" or "pending", or a block identifier as described in {Block Identifier} |
| blockTimestamp |`Quantity` |Block timestamp to be used in replacement of the timestamp taken from the parent block. |

### Returns

Map<`Data`, "error|value" : `Data`> - a mapping from transaction hashes to execution results with error or output (value) for each of the transactions

### Example

```bash
# Request
curl -X POST --data '{
"id": 1337,
"jsonrpc": "2.0",
"method": "eth_callBundle",
"params": [
[
"f9014946843b9aca00830493e094a011e5f4ea471ee4341a135bb1a4af368155d7a280b8e40d5f2659000000000000000000000000fdd45a22dd1d606b3782f2119621e928e32743000000000000000000000000000000000000000000000000000000000077359400000000000000000000000000000000000000000000000",
"f86e8204d085012a05f200830c350094daf24c20717f428f00d8448d74d67a77f67ceb8287354a6ba7a18000802ea00e411bcb660dd8d47717df89078d2e8160c08e7f11cb7ad0ee935e7436eceb32a013ee00a21b7fa0a9f9c1224d11261648191875d4633aed6003543ea319f12b62"
],
"0x12ab34"
]
}' <url>

# Response
{
"id": 1337,
"jsonrpc": "2.0",
"result":
{
"0x22b3806fbef9532db4105475222983404783aacd4d865ea5dab76a84aa1a07eb" : {
"value" : "0x0012"
},
"0x489e3b5493af31d55059f8e296351b267720bc4ba7dc170871c1d789e5541027" : {
"value" : "0xabcd"
}
}
}
```

---

Below type description can also be found in [EIP-1474](https://eips.ethereum.org/EIPS/eip-1474)

### `Quantity`

- A `Quantity` value **MUST** be hex-encoded.
- A `Quantity` value **MUST** be "0x"-prefixed.
- A `Quantity` value **MUST** be expressed using the fewest possible hex digits per byte.
- A `Quantity` value **MUST** express zero as "0x0".

### `Data`

- A `Data` value **MUST** be hex-encoded.
- A `Data` value **MUST** be “0x”-prefixed.
- A `Data` value **MUST** be expressed using two hex digits per byte.

### `Block Identifier`

Since there is no way to clearly distinguish between a `Data` parameter and a `Quantity` parameter, [EIP-1898](https://eips.ethereum.org/EIPS/eip-1898) provides a format to specify a block either using the block hash or block number. The block identifier is a JSON `object` with the following fields:

| Position | Name | Type | Description |
| -------- | ---- | ---- | ------------|
| 0A |blockNumber |`Quantity` |The block in the canonical chain with this number |
| 0B |blockHash |`Data` | The block uniquely identified by this hash. The blockNumber and blockHash properties are mutually exclusive; exactly one of them must be set. |
| 1B |requireCanonical |`boolean` | (optional) Whether or not to throw an error if the block is not in the canonical chain as described below. Only allowed in conjunction with the blockHash tag. Defaults to false. |


If the block is not found, the callee SHOULD raise a JSON-RPC error (the recommended error code is `-32001: Resource not found`. If the tag is `blockHash` and `requireCanonical` is `true`, the callee SHOULD additionally raise a JSON-RPC error if the block is not in the canonical chain (the recommended error code is `-32000: Invalid input` and in any case should be different than the error code for the block not found case so that the caller can distinguish the cases). The block-not-found check SHOULD take precedence over the block-is-canonical check, so that if the block is not found the callee raises block-not-found rather than block-not-canonical.
Loading