Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 5d25e8b

Browse files
committed
Add submitting and requesting registrations from multiple relays
1 parent 6cdb430 commit 5d25e8b

File tree

13 files changed

+440
-111
lines changed

13 files changed

+440
-111
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Go
33
on:
44
push:
55
pull_request:
6-
branches: [ master ]
6+
branches: [ main ]
77

88
env:
99
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"

README.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,69 @@ Configure geth for your network, it will become the block builder.
3535
Builder-related options:
3636
```
3737
$ geth --help
38-
BUILDER API OPTIONS:
38+
39+
BUILDER
40+
3941
--builder (default: false)
4042
Enable the builder
43+
4144
--builder.beacon_endpoint value (default: "http://127.0.0.1:5052")
45+
Beacon endpoint to connect to for beacon chain data [$BUILDER_BEACON_ENDPOINT]
46+
4247
--builder.bellatrix_fork_version value (default: "0x02000000")
48+
Bellatrix fork version. [$BUILDER_BELLATRIX_FORK_VERSION]
49+
4350
--builder.dry-run (default: false)
51+
Builder only validates blocks without submission to the relay
52+
4453
--builder.genesis_fork_version value (default: "0x00000000")
54+
Gensis fork version. [$BUILDER_GENESIS_FORK_VERSION]
55+
4556
--builder.genesis_validators_root value (default: "0x0000000000000000000000000000000000000000000000000000000000000000")
57+
Genesis validators root of the network. [$BUILDER_GENESIS_VALIDATORS_ROOT]
58+
4659
--builder.listen_addr value (default: ":28545")
4760
Listening address for builder endpoint [$BUILDER_LISTEN_ADDR]
61+
4862
--builder.local_relay (default: false)
63+
Enable the local relay
64+
4965
--builder.no_bundle_fetcher (default: false)
66+
Disable the bundle fetcher
67+
5068
--builder.relay_secret_key value (default: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11")
69+
Builder local relay API key used for signing headers [$BUILDER_RELAY_SECRET_KEY]
70+
5171
--builder.remote_relay_endpoint value
72+
Relay endpoint to connect to for validator registration data, if not provided
73+
will expose validator registration locally [$BUILDER_REMOTE_RELAY_ENDPOINT]
74+
75+
--builder.secondary_remote_relay_endpoints value
76+
Comma separated relay endpoints to connect to for validator registration data
77+
missing from the primary remote relay, and to push blocks for registrations
78+
missing from or matching the primary [$BUILDER_SECONDARY_REMOTE_RELAY_ENDPOINTS]
79+
5280
--builder.secret_key value (default: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11")
81+
Builder key used for signing blocks [$BUILDER_SECRET_KEY]
82+
83+
--builder.validation_blacklist value (default: "ofac_blacklist.json")
84+
Path to file containing blacklisted addresses, json-encoded list of strings.
85+
Default assumes CWD is repo's root
86+
5387
--builder.validator_checks (default: false)
54-
--builder.validation_blacklist value
88+
Enable the validator checks
89+
90+
MINER
91+
5592
--miner.algotype value (default: "mev-geth")
56-
--miner.blocklist value
57-
--miner.extradata value
93+
Block building algorithm to use [=mev-geth] (mev-geth, greedy)
94+
95+
--miner.blocklist value
96+
flashbots - Path to JSON file with list of blocked addresses. Miner will ignore
97+
txs that touch mentioned addresses.
98+
99+
--miner.extradata value
100+
Block extra data set by the miner (default = client version)
58101
```
59102

60103
Environment variables:

builder/builder.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type IBeaconClient interface {
3737
}
3838

3939
type IRelay interface {
40-
SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error
40+
SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, vd ValidatorData) error
4141
GetValidatorForSlot(nextSlot uint64) (ValidatorData, error)
4242
}
4343

@@ -97,7 +97,7 @@ func (b *Builder) Stop() error {
9797
return nil
9898
}
9999

100-
func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, sealedAt time.Time, commitedBundles []types.SimulatedBundle, allBundles []types.SimulatedBundle, proposerPubkey boostTypes.PublicKey, proposerFeeRecipient boostTypes.Address, proposerRegisteredGasLimit uint64, attrs *BuilderPayloadAttributes) error {
100+
func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, sealedAt time.Time, commitedBundles []types.SimulatedBundle, allBundles []types.SimulatedBundle, proposerPubkey boostTypes.PublicKey, vd ValidatorData, attrs *BuilderPayloadAttributes) error {
101101
executableData := beacon.BlockToExecutableData(block)
102102
payload, err := executableDataToExecutionPayload(executableData)
103103
if err != nil {
@@ -118,7 +118,7 @@ func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, se
118118
BlockHash: payload.BlockHash,
119119
BuilderPubkey: b.builderPublicKey,
120120
ProposerPubkey: proposerPubkey,
121-
ProposerFeeRecipient: proposerFeeRecipient,
121+
ProposerFeeRecipient: vd.FeeRecipient,
122122
GasLimit: executableData.GasLimit,
123123
GasUsed: executableData.GasUsed,
124124
Value: *value,
@@ -137,13 +137,13 @@ func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, se
137137
}
138138

139139
if b.dryRun {
140-
err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{blockSubmitReq, proposerRegisteredGasLimit})
140+
err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{blockSubmitReq, vd.GasLimit})
141141
if err != nil {
142142
log.Error("could not validate block", "err", err)
143143
}
144144
} else {
145145
go b.ds.ConsumeBuiltBlock(block, ordersClosedAt, sealedAt, commitedBundles, allBundles, &blockBidMsg)
146-
err = b.relay.SubmitBlock(&blockSubmitReq)
146+
err = b.relay.SubmitBlock(&blockSubmitReq, vd)
147147
if err != nil {
148148
log.Error("could not submit block", "err", err, "#commitedBundles", len(commitedBundles))
149149
return err
@@ -208,7 +208,7 @@ func (b *Builder) OnPayloadAttribute(attrs *BuilderPayloadAttributes) error {
208208
}
209209
b.slotAttrs = append(b.slotAttrs, *attrs)
210210

211-
go b.runBuildingJob(b.slotCtx, proposerPubkey, vd.FeeRecipient, vd.GasLimit, attrs)
211+
go b.runBuildingJob(b.slotCtx, proposerPubkey, vd, attrs)
212212
return nil
213213
}
214214

@@ -220,7 +220,7 @@ type blockQueueEntry struct {
220220
allBundles []types.SimulatedBundle
221221
}
222222

223-
func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTypes.PublicKey, feeRecipient boostTypes.Address, proposerRegisteredGasLimit uint64, attrs *BuilderPayloadAttributes) {
223+
func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTypes.PublicKey, vd ValidatorData, attrs *BuilderPayloadAttributes) {
224224
ctx, cancel := context.WithTimeout(slotCtx, 12*time.Second)
225225
defer cancel()
226226

@@ -245,7 +245,7 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTy
245245
submitBestBlock := func() {
246246
queueMu.Lock()
247247
if queueLastSubmittedProfit.Cmp(queueBestProfit) < 0 {
248-
err := b.onSealedBlock(queueBestEntry.block, queueBestEntry.ordersCloseTime, queueBestEntry.sealedAt, queueBestEntry.commitedBundles, queueBestEntry.allBundles, proposerPubkey, feeRecipient, proposerRegisteredGasLimit, attrs)
248+
err := b.onSealedBlock(queueBestEntry.block, queueBestEntry.ordersCloseTime, queueBestEntry.sealedAt, queueBestEntry.commitedBundles, queueBestEntry.allBundles, proposerPubkey, vd, attrs)
249249

250250
if err != nil {
251251
log.Error("could not run sealed block hook", "err", err)

builder/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestOnPayloadAttributes(t *testing.T) {
3030

3131
feeRecipient, _ := boostTypes.HexToAddress("0xabcf8e0d4e9587369b2301d0790347320302cc00")
3232
testRelay := testRelay{
33-
validator: ValidatorData{
33+
gvsVd: ValidatorData{
3434
Pubkey: PubkeyHex(testBeacon.validator.Pk.String()),
3535
FeeRecipient: feeRecipient,
3636
GasLimit: 10,

builder/config.go

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
package builder
22

33
type Config struct {
4-
Enabled bool `toml:",omitempty"`
5-
EnableValidatorChecks bool `toml:",omitempty"`
6-
EnableLocalRelay bool `toml:",omitempty"`
7-
DisableBundleFetcher bool `toml:",omitempty"`
8-
DryRun bool `toml:",omitempty"`
9-
BuilderSecretKey string `toml:",omitempty"`
10-
RelaySecretKey string `toml:",omitempty"`
11-
ListenAddr string `toml:",omitempty"`
12-
GenesisForkVersion string `toml:",omitempty"`
13-
BellatrixForkVersion string `toml:",omitempty"`
14-
GenesisValidatorsRoot string `toml:",omitempty"`
15-
BeaconEndpoint string `toml:",omitempty"`
16-
RemoteRelayEndpoint string `toml:",omitempty"`
17-
ValidationBlocklist string `toml:",omitempty"`
4+
Enabled bool `toml:",omitempty"`
5+
EnableValidatorChecks bool `toml:",omitempty"`
6+
EnableLocalRelay bool `toml:",omitempty"`
7+
DisableBundleFetcher bool `toml:",omitempty"`
8+
DryRun bool `toml:",omitempty"`
9+
BuilderSecretKey string `toml:",omitempty"`
10+
RelaySecretKey string `toml:",omitempty"`
11+
ListenAddr string `toml:",omitempty"`
12+
GenesisForkVersion string `toml:",omitempty"`
13+
BellatrixForkVersion string `toml:",omitempty"`
14+
GenesisValidatorsRoot string `toml:",omitempty"`
15+
BeaconEndpoint string `toml:",omitempty"`
16+
RemoteRelayEndpoint string `toml:",omitempty"`
17+
SecondaryRemoteRelayEndpoints []string `toml:",omitempty"`
18+
ValidationBlocklist string `toml:",omitempty"`
1819
}
1920

2021
// DefaultConfig is the default config for the builder.
2122
var DefaultConfig = Config{
22-
Enabled: false,
23-
EnableValidatorChecks: false,
24-
EnableLocalRelay: false,
25-
DisableBundleFetcher: false,
26-
DryRun: false,
27-
BuilderSecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
28-
RelaySecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
29-
ListenAddr: ":28545",
30-
GenesisForkVersion: "0x00000000",
31-
BellatrixForkVersion: "0x02000000",
32-
GenesisValidatorsRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
33-
BeaconEndpoint: "http://127.0.0.1:5052",
34-
RemoteRelayEndpoint: "",
35-
ValidationBlocklist: "",
23+
Enabled: false,
24+
EnableValidatorChecks: false,
25+
EnableLocalRelay: false,
26+
DisableBundleFetcher: false,
27+
DryRun: false,
28+
BuilderSecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
29+
RelaySecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
30+
ListenAddr: ":28545",
31+
GenesisForkVersion: "0x00000000",
32+
BellatrixForkVersion: "0x02000000",
33+
GenesisValidatorsRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
34+
BeaconEndpoint: "http://127.0.0.1:5052",
35+
RemoteRelayEndpoint: "",
36+
SecondaryRemoteRelayEndpoints: nil,
37+
ValidationBlocklist: "",
3638
}

builder/local_relay.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ func NewLocalRelay(sk *bls.SecretKey, beaconClient IBeaconClient, builderSigning
7979
}
8080
}
8181

82-
func (r *LocalRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
82+
func (r *LocalRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, _ ValidatorData) error {
83+
return r.submitBlock(msg)
84+
}
85+
86+
func (r *LocalRelay) submitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
8387
payloadHeader, err := boostTypes.PayloadToPayloadHeader(msg.ExecutionPayload)
8488
if err != nil {
8589
log.Error("could not convert payload to header", "err", err)

builder/relay.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,7 @@ import (
1515
"github.com/flashbots/mev-boost/server"
1616
)
1717

18-
type testRelay struct {
19-
validator ValidatorData
20-
requestedSlot uint64
21-
submittedMsg *boostTypes.BuilderSubmitBlockRequest
22-
}
23-
24-
func (r *testRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
25-
r.submittedMsg = msg
26-
return nil
27-
}
28-
func (r *testRelay) GetValidatorForSlot(nextSlot uint64) (ValidatorData, error) {
29-
r.requestedSlot = nextSlot
30-
return r.validator, nil
31-
}
18+
var ErrValidatorNotFound = errors.New("validator not found")
3219

3320
type RemoteRelay struct {
3421
endpoint string
@@ -135,10 +122,10 @@ func (r *RemoteRelay) GetValidatorForSlot(nextSlot uint64) (ValidatorData, error
135122
return vd, nil
136123
}
137124

138-
return ValidatorData{}, errors.New("validator not found")
125+
return ValidatorData{}, ErrValidatorNotFound
139126
}
140127

141-
func (r *RemoteRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
128+
func (r *RemoteRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, _ ValidatorData) error {
142129
code, err := server.SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, r.endpoint+"/relay/v1/builder/blocks", msg, nil)
143130
if err != nil {
144131
return err
@@ -148,7 +135,7 @@ func (r *RemoteRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) err
148135
}
149136

150137
if r.localRelay != nil {
151-
r.localRelay.SubmitBlock(msg)
138+
r.localRelay.submitBlock(msg)
152139
}
153140

154141
return nil

0 commit comments

Comments
 (0)