flashbots / mev-geth

Go implementation of MEV-Auction for Ethereum
GNU Lesser General Public License v3.0
784 stars 197 forks source link

feat(ethash): flashbots_getWork RPC with profit #106

Closed shekhirin closed 2 years ago

shekhirin commented 2 years ago

https://github.com/flashbots/mev-geth/issues/103

Adds new RPC method flashbots_getWork which adds a new block reward including MEV to eth_getWork RPC result.

Block reward matches the profit number used in the mining worker https://github.com/flashbots/mev-geth/blob/516e2c3982109dd4176f3eae71015dd385f65ea2/miner/worker.go#L105


Not sure how I can test it, but running on Sepolia with (mainnet in the log is a bug, see https://github.com/ethereum/go-ethereum/pull/24147)

➜  mev-geth git:(feat/flashbots-get-work) ./build/bin/geth --sepolia --mine
INFO [12-22|09:45:39.458] Starting Geth on Ethereum mainnet... 

successfully returns both eth_getWork and flashbots_getWork RPCs

> web3.currentProvider.send({method: 'eth_getWork'})
{
  id: 0,
  jsonrpc: "2.0",
  result: ["0x61459bbdf3c56b8e7d281fca4210e440daf95526e59f7068ec61681980ac9da2", "0x9b2baad7528ecec612c5751a6bd525905892d7892e155c3b05e61363154a940b", "0x0000000a9f8ed07e7747b5db09228583fe0410d0c823bd414157935370bbe9fe", "0x50357"]
}
> web3.currentProvider.send({method: 'flashbots_getWork'})
{
  id: 0,
  jsonrpc: "2.0",
  result: ["0x61459bbdf3c56b8e7d281fca4210e440daf95526e59f7068ec61681980ac9da2", "0x9b2baad7528ecec612c5751a6bd525905892d7892e155c3b05e61363154a940b", "0x0000000a9f8ed07e7747b5db09228583fe0410d0c823bd414157935370bbe9fe", "0x50357", "0x0"]
}

Guess I could try syncing Ropsten and trying to mine it watching for profit value in flashbots_getWork response.

libevm commented 2 years ago

I'm curious to how you would test this feature, but in my mind, I'm thinking something like

./build/bin/geth --dev --dev.period 100

And then send some test transactions around then calling flashbots_getWork

shekhirin commented 2 years ago

--dev is PoA network with Clique consensus engine, so you can't really use ethash-based endpoints with it

> web3.currentProvider.send({method: 'eth_getWork'})
{
  error: {
    code: -32601,
    message: "the method eth_getWork does not exist/is not available"
  },
  id: 0,
  jsonrpc: "2.0"
}
> web3.currentProvider.send({method: 'flashbots_getWork'})
{
  error: {
    code: -32601,
    message: "the method flashbots_getWork does not exist/is not available"
  },
  id: 0,
  jsonrpc: "2.0"
}
shekhirin commented 2 years ago

Set up a local PoW net, everything seems to be working fine with simple transaction, will test with sendBundle a bit later

> function getWork() { for (let i = 0; i < 10; i++) { setTimeout(() => console.log(JSON.stringify(web3.currentProvider.send({method: 'flashbots_getWork'}).result)), i*1000) } }
undefined

> eth.sendTransaction({from: '0xe394dd7832d8a26c5b4c6205649f85df25617a45', to: '0xe394dd7832d8a26c5b4c6205649f85df25617a45'}); getWork()
undefined

["0x7521d7254c597ed37a6fa67c3eb879a952582c7599ce853046da99b7324d1b40","0x0000000000000000000000000000000000000000000000000000000000000000","0x00006246fe64d8fdb818328ad2c48d383bb531be34f4e5407374e75cf9ec1206","0x227","0x0"]
["0xfd6d5a1180060b6bc0eb8f02b01f39c6fb7bb71ad6b81d1ccc2938c21f08d223","0x0000000000000000000000000000000000000000000000000000000000000000","0x00006246fe64d8fdb818328ad2c48d383bb531be34f4e5407374e75cf9ec1206","0x227","0x1319718a5000"]
["0xfd6d5a1180060b6bc0eb8f02b01f39c6fb7bb71ad6b81d1ccc2938c21f08d223","0x0000000000000000000000000000000000000000000000000000000000000000","0x00006246fe64d8fdb818328ad2c48d383bb531be34f4e5407374e75cf9ec1206","0x227","0x1319718a5000"]
["0xf079d4a29cf2d1e272fc7aa91559cae370d7300051f44ba64d374f5a75f218e5","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000622259be21c99badfa5a0dddb286296e288b391bb16d8f358ce29ca28bf5","0x22a","0x0"]
...
metachris commented 2 years ago

The mev-callbundle changes have been squashed and picked into the master branch, which messed up this PR. I think best would be to cherry-pick your original commit(s) onto the latest master state, and pointing the PR towards the master branch.

shekhirin commented 2 years ago

@metachris oh that's nice that master is relevant now. Cherry-picked my commit and pointed branch towards the master.

shekhirin commented 2 years ago

I tested it with https://github.com/flashbots/mev-geth-demo and demo-simple-old script, everything seems to be working.

> print = () => { console.log(JSON.stringify(web3.currentProvider.send({method: 'flashbots_getWork'}).result.slice(3)) + '\n' + JSON.stringify(web3.currentProvider.send({method: 'eth_getWork'}).result.slice(3)) + '\n\n'); setTimeout(print, 1000) }
() =>
> print()

["0xcd","0x0"]
["0xcd"]
...
➜  mev-geth-demo git:(main) ✗ yarn demo-simple-old
...

["0xcd","0x0"]
["0xcd"]

["0xcd","0xecd8fae8c0fc20"]
["0xcd"]

...
jparyani commented 2 years ago

This looks great, thanks! Sorry for the delay getting it reviewed, I was distracted over the holidays