document MEV/mergemock test script (#3694)

This commit is contained in:
tersec 2022-06-06 13:55:02 +00:00 committed by GitHub
parent 399afd89e9
commit 1262e50fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 140 additions and 152 deletions

View File

@ -106,6 +106,7 @@ type
DataEnclosedObject |
DataMetaEnclosedObject |
DataRootEnclosedObject |
DataVersionEnclosedObject |
GetBlockV2Response |
GetKeystoresResponse |
GetRemoteKeystoresResponse |

View File

@ -425,6 +425,10 @@ type
data*: T
meta*: JsonNode
DataVersionEnclosedObject*[T] = object
data*: T
version*: JsonNode
DataRootEnclosedObject*[T] = object
dependent_root*: Eth2Digest
data*: T
@ -537,7 +541,7 @@ type
GetEpochCommitteesResponse* = DataEnclosedObject[seq[RestBeaconStatesCommittees]]
GetForkScheduleResponse* = DataEnclosedObject[seq[Fork]]
GetGenesisResponse* = DataEnclosedObject[RestGenesis]
GetHeaderResponse* = DataEnclosedObject[SignedBuilderBid]
GetHeaderResponse* = DataVersionEnclosedObject[SignedBuilderBid]
GetNetworkIdentityResponse* = DataEnclosedObject[RestNetworkIdentity]
GetPeerCountResponse* = DataMetaEnclosedObject[RestPeerCount]
GetPeerResponse* = DataMetaEnclosedObject[RestNodePeer]

View File

@ -10,7 +10,7 @@ import ".."/datatypes/[altair, bellatrix]
{.push raises: [Defect].}
type
# https://github.com/ethereum/builder-specs/blob/v0.0.0/specs/README.md#validatorregistrationv1
# https://github.com/ethereum/builder-specs/blob/v0.1.0/specs/README.md#validatorregistrationv1
ValidatorRegistrationV1 = object
fee_recipient*: ExecutionAddress
gas_limit*: uint64
@ -22,18 +22,18 @@ type
message*: ValidatorRegistrationV1
signature*: ValidatorSig
# https://github.com/ethereum/builder-specs/blob/v0.0.0/specs/README.md#builderbid
# https://github.com/ethereum/builder-specs/blob/v0.1.0/specs/README.md#builderbid
BuilderBid = object
header*: ExecutionPayloadHeader
value*: Eth2Digest # uint256
value*: UInt256
pubkey*: ValidatorPubKey
# https://github.com/ethereum/builder-specs/blob/v0.0.0/specs/README.md#signedbuilderbid
# https://github.com/ethereum/builder-specs/blob/v0.1.0/specs/README.md#signedbuilderbid
SignedBuilderBid* = object
message*: BuilderBid
signature*: ValidatorSig
# https://github.com/ethereum/builder-specs/blob/v0.0.0/specs/README.md#blindedbeaconblockbody
# https://github.com/ethereum/builder-specs/blob/v0.1.0/specs/README.md#blindedbeaconblockbody
BlindedBeaconBlockBody = object
randao_reveal*: ValidatorSig
eth1_data*: Eth1Data
@ -46,7 +46,7 @@ type
sync_aggregate*: SyncAggregate
execution_payload_header*: ExecutionPayloadHeader
# https://github.com/ethereum/builder-specs/blob/v0.0.0/specs/README.md#blindedbeaconblock
# https://github.com/ethereum/builder-specs/blob/v0.1.0/specs/README.md#blindedbeaconblock
BlindedBeaconBlock* = object
slot*: Slot
proposer_index*: uint64
@ -54,7 +54,7 @@ type
state_root*: Eth2Digest
body*: BlindedBeaconBlockBody
# https://github.com/ethereum/builder-specs/blob/v0.0.0/specs/README.md#signedblindedbeaconblock
# https://github.com/ethereum/builder-specs/blob/v0.1.0/specs/README.md#signedblindedbeaconblock
SignedBlindedBeaconBlock* = object
message*: BlindedBeaconBlock
signature*: ValidatorSig

View File

@ -12,10 +12,11 @@ import
export chronos, client, rest_types, eth2_rest_serialization
proc registerValidators*(body: SignedValidatorRegistrationV1
proc registerValidator*(body: SignedValidatorRegistrationV1
): RestPlainResponse {.
rest, endpoint: "/eth/v1/builder/validators",
meth: MethodPost.}
## https://github.com/ethereum/beacon-APIs/blob/master/apis/validator/register_validator.yaml
## https://github.com/ethereum/builder-specs/blob/v0.0.0/apis/builder/validators.yaml
proc getHeader*(slot: Slot,
@ -24,15 +25,15 @@ proc getHeader*(slot: Slot,
): RestResponse[GetHeaderResponse] {.
rest, endpoint: "/eth/v1/builder/header/{slot}/{parent_hash}/{pubkey}",
meth: MethodGet.}
## https://github.com/ethereum/builder-specs/blob/v0.0.0/apis/builder/header.yaml
## https://github.com/ethereum/builder-specs/blob/v0.1.0/apis/builder/header.yaml
proc submitBlindedBlock*(body: SignedBlindedBeaconBlock
): RestResponse[SubmitBlindedBlockResponse] {.
rest, endpoint: "/eth/v1/builder/blinded_blocks",
meth: MethodPost.}
## https://github.com/ethereum/builder-specs/blob/v0.0.0/apis/builder/blinded_blocks.yaml
## https://github.com/ethereum/builder-specs/blob/v0.1.0/apis/builder/blinded_blocks.yaml
proc checkBuilderStatus*(): RestPlainResponse {.
rest, endpoint: "/eth/v1/builder/status",
meth: MethodGet.}
## https://github.com/ethereum/builder-specs/blob/v0.0.0/apis/builder/status.yaml
## https://github.com/ethereum/builder-specs/blob/v0.1.0/apis/builder/status.yaml

View File

@ -88,7 +88,7 @@ proc verify_epoch_signature*(
func compute_block_signing_root*(
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
blck: Eth2Digest | SomeForkyBeaconBlock | BeaconBlockHeader |
# https://github.com/ethereum/builder-specs/blob/v0.0.0/specs/README.md#signing
# https://github.com/ethereum/builder-specs/blob/v0.1.0/specs/README.md#signing
BlindedBeaconBlock): Eth2Digest =
let
epoch = epoch(slot)

View File

@ -1,123 +0,0 @@
# Clone repos
```
git clone https://github.com/flashbots/mev-boost.git
# On the thegostep/docs branch
git checkout 977d487e6eae38afbc9e4108e8c5c24689a8c222
```
Apply
```diff
diff --git a/lib/service.go b/lib/service.go
index cd3e88e..b477fb5 100644
--- a/lib/service.go
+++ b/lib/service.go
@@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"log"
+ "math/big"
"net/http"
"github.com/ethereum/go-ethereum/common"
@@ -165,6 +166,11 @@ func (m *RelayService) ProposeBlindedBlockV1(r *http.Request, args *SignedBlinde
blockHash = body.ExecutionPayloadCamel.BlockHashCamel
}
+ var foo ExecutionPayloadWithTxRootV1
+ foo = ExecutionPayloadWithTxRootV1{BaseFeePerGas: big.NewInt(4)}
+ *result = foo
+ return nil
+
payloadCached := m.store.Get(common.HexToHash(blockHash))
if payloadCached != nil {
log.Println(green("ProposeBlindedBlockV1: ✓ revealing previous payload from execution client: "), payloadCached.BlockHash, payloadCached.Number, payloadCached.TransactionsRoot)
@@ -197,6 +203,11 @@ var nilHash = common.Hash{}
// GetPayloadHeaderV1 TODO
func (m *RelayService) GetPayloadHeaderV1(r *http.Request, args *string, result *ExecutionPayloadWithTxRootV1) error {
+ var foo ExecutionPayloadWithTxRootV1
+ foo = ExecutionPayloadWithTxRootV1{BaseFeePerGas: big.NewInt(4)}
+ *result = foo
+ return nil;
+
executionResp, executionErr := makeRequest(m.executionURL, "engine_getPayloadV1", []interface{}{*args})
relayResp, relayErr := makeRequest(m.relayURL, "engine_getPayloadV1", []interface{}{*args})
```
if one wants to just test the RPC without a relay or execution client, only the builder.
# Build and run the mev-boost command
In the `mev-boost/cmd/mev-boost` directory, run `go build . && ./mev_boost`:
```
$ go build . && ./mev-boost
mev-boost: 2022/02/23 06:45:07 main.go:29: listening on: 18550
```
# Run the Nimbus-side RPC test
This currently accesses a field in eth1_monitor directly:
```nim
diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim
index b2cebda8..06d55f15 100644
--- a/beacon_chain/eth1/eth1_monitor.nim
+++ b/beacon_chain/eth1/eth1_monitor.nim
@@ -127,3 +127,3 @@ type
url: string
- web3: Web3
+ web3*: Web3
ns: Sender[DepositContract]
```
Pending further integration into eth1_monitor.
If that's in place, run:
```
$ ./env.sh nim c --hints:off -r scripts/test_mev_boost
[Suite] mev-boost RPC
DBG 2022-02-23 06:47:19.710+01:00 Message sent to RPC server topics="JSONRPC-HTTP-CLIENT" tid=635228 file=httpclient.nim:68 address="ok((id: \"127.0.0.1:18550\", scheme: NonSecure, hostname: \"127.0.0.1\", port: 18550, path: \"\", query: \"\", anchor: \"\", username: \"\", password: \"\", addresses: @[127.0.0.1:18550]))" msg_len=553
[OK] builder_ProposeBlindedBlockV1
DBG 2022-02-23 06:47:19.713+01:00 Message sent to RPC server topics="JSONRPC-HTTP-CLIENT" tid=635228 file=httpclient.nim:68 address="ok((id: \"127.0.0.1:18550\", scheme: NonSecure, hostname: \"127.0.0.1\", port: 18550, path: \"\", query: \"\", anchor: \"\", username: \"\", password: \"\", addresses: @[127.0.0.1:18550]))" msg_len=94
[OK] builder_getPayloadHeaderV1
$
```
The RPC traffic looks like:
```
POST / HTTP/1.1\r
Accept: */*\r
Content-Length: 553\r
Content-Type: application/json\r
Host: 127.0.0.1\r
Connection: keep-alive\r
User-Agent: nim-chronos/3.0.2 (amd64/linux)\r
\r
{"jsonrpc":"2.0","method":"builder_proposeBlindedBlockV1","params":[{"message":{"slot":"0x0","proposer_index":"0x0","parent_root":"0x0000000000000000000000000000000000000000000000000000000000000000","state_root":"0x0000000000000000000000000000000000000000000000000000000000000000","body":{"execution_payload_header":{"blockHash":""}}},"signature":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}],"id":1}< 2022/02/23 06:28:43.588446 length=887 from=0 to=886
HTTP/1.1 200 OK\r
Content-Type: application/json; charset=utf-8\r
X-Content-Type-Options: nosniff\r
Date: Wed, 23 Feb 2022 05:28:43 GMT\r
Content-Length: 730\r
\r
{"jsonrpc":"2.0","result":{"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","logsBloom":"0x","random":"0x0000000000000000000000000000000000000000000000000000000000000000","blockNumber":"0x0","gasLimit":"0x0","gasUsed":"0x0","timestamp":"0x0","extraData":"0x","baseFeePerGas":"0x4","blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000"},"error":null,"id":1}
> 2022/02/23 06:28:43.590617 length=264 from=0 to=263
POST / HTTP/1.1\r
Accept: */*\r
Content-Length: 94\r
Content-Type: application/json\r
Host: 127.0.0.1\r
Connection: keep-alive\r
User-Agent: nim-chronos/3.0.2 (amd64/linux)\r
\r
{"jsonrpc":"2.0","method":"builder_getPayloadHeaderV1","params":["0x0000000000000000"],"id":1}< 2022/02/23 06:28:43.591736 length=887 from=0 to=886
HTTP/1.1 200 OK\r
Content-Type: application/json; charset=utf-8\r
X-Content-Type-Options: nosniff\r
Date: Wed, 23 Feb 2022 05:28:43 GMT\r
Content-Length: 730\r
\r
{"jsonrpc":"2.0","result":{"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","logsBloom":"0x","random":"0x0000000000000000000000000000000000000000000000000000000000000000","blockNumber":"0x0","gasLimit":"0x0","gasUsed":"0x0","timestamp":"0x0","extraData":"0x","baseFeePerGas":"0x4","blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000"},"error":null,"id":1}
```
This exercises the RPC serialization and deserialization.

View File

@ -0,0 +1,66 @@
# How to run and clone Merge Mock
- Clone and run Merge Mock using https://github.com/protolambda/mergemock#quick-start
```
$ git clone https://github.com/protolambda/mergemock # tested with commit 114c25ad2f07c9bc6c16d2223d3e84c3c512dc9e from 2022-05-25
$ cd mergemock
$ wget https://gist.githubusercontent.com/lightclient/799c727e826483a2804fc5013d0d3e3d/raw/2e8824fa8d9d9b040f351b86b75c66868fb9b115/genesis.json
$ openssl rand -hex 32 | tr -d "\n" > jwt.hex
$ go run . relay
INFO [2022-06-03T08:12:50Z] Loaded JWT secret val="5b63d4c3c389d43809553a3747bce72b13711db8f3501d3e4d6f18a312064eb0"
INFO [2022-06-03T08:12:50Z] Persisted trie from memory database fields.time="5.478µs" gcnodes="0" gcsize="0.00 B" gctime="0s" livenodes="1" livesize="0.00 B" nodes="1" size="151.00 B"
INFO [2022-06-03T08:12:50Z] Loaded most recent local header age="53y2mo6d" hash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" number="0" td="17179869184"
INFO [2022-06-03T08:12:50Z] Loaded most recent local full block age="53y2mo6d" hash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" number="0" td="17179869184"
INFO [2022-06-03T08:12:50Z] Loaded most recent local fast block age="53y2mo6d" hash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" number="0" td="17179869184"
WARNING[2022-06-03T08:12:50Z] Failed to load snapshot, regenerating err="missing or corrupted snapshot"
INFO [2022-06-03T08:12:50Z] Rebuilding state snapshot
INFO [2022-06-03T08:12:50Z] Resuming state snapshot generation accounts="0" elapsed="245.706µs" root="0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45" slots="0" storage="0.00 B"
INFO [2022-06-03T08:12:50Z] Generated state snapshot accounts="1" elapsed="400.253µs" slots="0" storage="50.00 B"
INFO [2022-06-03T08:12:50Z] Engine started listenAddr="127.0.0.1:8551"
INFO [2022-06-03T08:12:50Z] Relay started listenAddr="127.0.0.1:28545"
```
# Run Nimbus's MEV/Merge Mock test script
```
$ ./env nim c -r scripts/test_mev_vector
NOT 2022-06-03 08:15:06.648+00:00 New database from snapshot tid=1389294 file=blockchain_dag.nim:1800 genesisBlockRoot=9058609e genesisStateRoot=0fef5721 tailBlockRoot=9058609e tailStateRoot=0fef5721 fork="(previous_version: 00000000, current_version: 00000000, epoch: 0)" validators=64 tailStateSlot=0 genesisStateSlot=0
DBG 2022-06-03 08:15:06.649+00:00 Message sent to RPC server topics="JSONRPC-HTTP-CLIENT" tid=1389294 file=httpclient.nim:104 address="ok((id: \"127.0.0.1:8551\", scheme: NonSecure, hostname: \"127.0.0.1\", port: 8551, path: \"\", query: \"\", anchor: \"\", username: \"\", password: \"\", addresses: @[127.0.0.1:8551]))" msg_len=79
DBG 2022-06-03 08:15:06.650+00:00 Message sent to RPC server topics="JSONRPC-HTTP-CLIENT" tid=1389294 file=httpclient.nim:104 address="ok((id: \"127.0.0.1:8551\", scheme: NonSecure, hostname: \"127.0.0.1\", port: 8551, path: \"\", query: \"\", anchor: \"\", username: \"\", password: \"\", addresses: @[127.0.0.1:8551]))" msg_len=506
DBG 2022-06-03 08:15:06.650+00:00 Sending REST request to remote server tid=1389294 file=client.nim:418 remote=127.0.0.1:28545 request=/eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7 http_method=GET
DBG 2022-06-03 08:15:06.651+00:00 Got REST response headers from remote server tid=1389294 file=client.nim:421 status=200 http_method=GET remote=127.0.0.1:28545 request=/eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7 connection=1
DBG 2022-06-03 08:15:06.652+00:00 Received REST response body from remote server tid=1389294 file=client.nim:462 status=200 http_method=GET remote=127.0.0.1:28545 request=/eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7 connection=1 contentType=application/json size=1672
DBG 2022-06-03 08:15:06.652+00:00 Sending REST request to remote server tid=1389294 file=client.nim:508 remote=127.0.0.1:28545 request=/eth/v1/builder/blinded_blocks http_method=POST
DBG 2022-06-03 08:15:06.653+00:00 Opened connection to remote server tid=1389294 file=client.nim:512 remote=127.0.0.1:28545 request=/eth/v1/builder/blinded_blocks http_method=POST connection=2
DBG 2022-06-03 08:15:06.653+00:00 REST request body has been sent tid=1389294 file=client.nim:521 remote=127.0.0.1:28545 request=/eth/v1/builder/blinded_blocks size=2734 http_method=POST connection=2
DBG 2022-06-03 08:15:06.655+00:00 Got REST response headers from remote server tid=1389294 file=client.nim:528 status=200 http_method=POST remote=127.0.0.1:28545 request=/eth/v1/builder/blinded_blocks connection=2
DBG 2022-06-03 08:15:06.655+00:00 Received REST response body from remote server tid=1389294 file=client.nim:567 contentType=application/json size=1247 remote=127.0.0.1:28545 request=/eth/v1/builder/blinded_blocks connection=2
[OK] forkchoiceUpdated, getHeader, and submitBlindedBlock
```
While on the Merge Mock side:
```
INFO [2022-06-03T08:14:57Z] Forkchoice updated attributes="&{12 0x0000000000000000000000000000000000000000000000000000000000000000 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B}" finalized="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" head="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" safe="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131"
INFO [2022-06-03T08:14:57Z] Preparing new payload payload_id="0x0000000000000001" prev_randao="0x0000000000000000000000000000000000000000000000000000000000000000" suggested_fee_recipient="0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B" timestamp="12"
INFO [2022-06-03T08:14:57Z] getHeader parentHash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" pubkey="0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" slot="1"
INFO [2022-06-03T08:14:57Z] Consensus client retrieved prepared payload header parentHash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" pubkey="0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" slot="1"
2022/06/03 08:14:57 http: superfluous response.WriteHeader call from main.(*responseWriter).WriteHeader (utils.go:34)
INFO [2022-06-03T08:14:57Z] http: GET /eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7 200 durationMs="0" method="GET" path="/eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" status="200"
INFO [2022-06-03T08:14:57Z] &{0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B 0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 0x0000000000000000000000000000000000000000000000000000000000000000 1 10000000 0 12 [] 7 0x6bc31fed8860b9b4b907cc994f16ffa32f9b08d229cb1767f0d50c299eb137e2 []} method="getPayload"
INFO [2022-06-03T08:14:57Z] http: POST /eth/v1/builder/blinded_blocks 0 durationMs="1" method="POST" path="/eth/v1/builder/blinded_blocks" status="0"
INFO [2022-06-03T08:15:04Z] Forkchoice updated attributes="&{12 0x0000000000000000000000000000000000000000000000000000000000000000 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B}" finalized="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" head="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" safe="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131"
INFO [2022-06-03T08:15:04Z] Preparing new payload payload_id="0x0000000000000002" prev_randao="0x0000000000000000000000000000000000000000000000000000000000000000" suggested_fee_recipient="0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B" timestamp="12"
INFO [2022-06-03T08:15:04Z] getHeader parentHash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" pubkey="0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" slot="1"
INFO [2022-06-03T08:15:04Z] Consensus client retrieved prepared payload header parentHash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" pubkey="0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" slot="1"
2022/06/03 08:15:04 http: superfluous response.WriteHeader call from main.(*responseWriter).WriteHeader (utils.go:34)
INFO [2022-06-03T08:15:04Z] http: GET /eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7 200 durationMs="0" method="GET" path="/eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" status="200"
INFO [2022-06-03T08:15:04Z] &{0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B 0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 0x0000000000000000000000000000000000000000000000000000000000000000 1 10000000 0 12 [] 7 0x6bc31fed8860b9b4b907cc994f16ffa32f9b08d229cb1767f0d50c299eb137e2 []} method="getPayload"
INFO [2022-06-03T08:15:04Z] http: POST /eth/v1/builder/blinded_blocks 0 durationMs="1" method="POST" path="/eth/v1/builder/blinded_blocks" status="0"
INFO [2022-06-03T08:15:06Z] Forkchoice updated attributes="&{12 0x0000000000000000000000000000000000000000000000000000000000000000 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B}" finalized="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" head="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" safe="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131"
INFO [2022-06-03T08:15:06Z] Preparing new payload payload_id="0x0000000000000003" prev_randao="0x0000000000000000000000000000000000000000000000000000000000000000" suggested_fee_recipient="0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B" timestamp="12"
INFO [2022-06-03T08:15:06Z] getHeader parentHash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" pubkey="0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" slot="1"
INFO [2022-06-03T08:15:06Z] Consensus client retrieved prepared payload header parentHash="0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131" pubkey="0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" slot="1"
2022/06/03 08:15:06 http: superfluous response.WriteHeader call from main.(*responseWriter).WriteHeader (utils.go:34)
INFO [2022-06-03T08:15:06Z] http: GET /eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7 200 durationMs="0" method="GET" path="/eth/v1/builder/header/1/0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131/0xa6d310dbbfab9a22450f59993f87a4ce5db6223f3b5f1f30d2c4ec718922d400e0b3c7741de8e59960f72411a0ee10a7" status="200"
INFO [2022-06-03T08:15:06Z] &{0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B 0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 0x0000000000000000000000000000000000000000000000000000000000000000 1 10000000 0 12 [] 7 0x6bc31fed8860b9b4b907cc994f16ffa32f9b08d229cb1767f0d50c299eb137e2 []} method="getPayload"
INFO [2022-06-03T08:15:06Z] http: POST /eth/v1/builder/blinded_blocks 0 durationMs="1" method="POST" path="/eth/v1/builder/blinded_blocks" status="0"
```

View File

@ -1,21 +1,60 @@
# Monitor traffic: socat -v TCP-LISTEN:19550,fork TCP-CONNECT:127.0.0.1:18550
import
unittest2,
chronos, web3/[builder_api, builder_api_types, engine_api_types, ethtypes],
../beacon_chain/eth1/eth1_monitor,
../beacon_chain/spec/[digest, presets],
./testutil
chronos, presto/client, web3/ethtypes,
../beacon_chain/spec/mev/rest_bellatrix_mev_calls,
../tests/testutil
suite "mev-boost RPC":
from ../beacon_chain/beacon_chain_db import DepositContractSnapshot
from ../beacon_chain/eth1/eth1_monitor import
Eth1Monitor, Web3DataProvider, asEth2Digest, ensureDataProvider,
forkchoiceUpdated, getBlockByNumber, init, new
from ../beacon_chain/networking/network_metadata import Eth1Network
from ../beacon_chain/spec/helpers import compute_signing_root
from ../tests/testdbutil import makeTestDB
suite "MEV tests":
setup:
let web3Provider = (waitFor Web3DataProvider.new(
default(Eth1Address), "http://127.0.0.1:18550")).get.web3.provider
const
feeRecipient =
Eth1Address.fromHex("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")
web3Url = "http://127.0.0.1:8551"
restUrl = "http://127.0.0.1:28545"
test "builder_ProposeBlindedBlockV1":
let proposedBlindedBlockResp =
waitFor web3Provider.builder_proposeBlindedBlockV1(default(SignedBlindedBeaconBlock))
let
db = makeTestDB(64)
eth1Monitor = Eth1Monitor.init(
defaultRuntimeConfig, db, nil, @[web3Url],
none(DepositContractSnapshot), none(Eth1Network), false, none(seq[byte]))
web3Provider = (waitFor Web3DataProvider.new(
default(Eth1Address), web3Url, some(@[0xcdu8, 0xcau8, 0xe4u8, 0xecu8, 0x6au8, 0x3du8, 0x0bu8, 0x4bu8, 0x97u8, 0x00u8, 0x21u8, 0x21u8, 0xb0u8, 0x5bu8, 0x22u8, 0xe2u8, 0xd6u8, 0xd5u8, 0x7fu8, 0xaau8, 0x51u8, 0x53u8, 0x84u8, 0x5fu8, 0xe0u8, 0x4fu8, 0x06u8, 0xb5u8, 0xf3u8, 0xadu8, 0xc4u8, 0x0bu8]))).get
restClient = RestClientRef.new(restUrl).get
privKey = ValidatorPrivKey.init(
"0x066e3bdc0415530e5c7fed6382d5c822c192b620203cf669903e1810a8c67d06")
pubKey = privKey.toPubKey.toPubKey
test "builder_getPayloadHeaderV1":
let getPayloadHeaderResp =
waitFor web3Provider.builder_getPayloadHeaderV1(default(PayloadID))
test "forkchoiceUpdated, getHeader, and submitBlindedBlock":
waitFor eth1Monitor.ensureDataProvider()
let
existingBlock = waitFor web3Provider.getBlockByNumber(0)
payloadId = waitFor eth1Monitor.forkchoiceUpdated(
existingBlock.hash.asEth2Digest,
existingBlock.hash.asEth2Digest,
existingBlock.timestamp.uint64 + 12,
default(Eth2Digest).data, # Random
feeRecipient)
blindedHeader = waitFor restClient.getHeader(
1.Slot, existingBlock.hash.asEth2Digest, pubKey)
# construct block
var blck: SignedBlindedBeaconBlock
blck.message.body.execution_payload_header = blindedHeader.data.data.message.header
# sign block
let domain: Eth2Domain = [
byte 0x00, 0x00, 0x00, 0x00, 0x8a, 0x02, 0x3a, 0x9e, 0x4a, 0xff, 0xbb, 0x25, 0x5a, 0x6b, 0x48, 0xae, 0x85, 0xcc, 0x4a, 0x7d, 0x1a, 0x1b, 0x9e, 0x8e, 0x68, 0x09, 0xfe, 0x9e, 0x48, 0x53, 0x5c, 0x01]
blck.signature = blsSign(
privKey,
compute_signing_root(hash_tree_root(blck.message), domain).data).
toValidatorSig
let signedBuilderBid = waitFor restClient.submitBlindedBlock(blck)