Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Go
on:
push:
pull_request:
branches: [ master ]
branches: [ main ]

env:
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
Expand Down
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,69 @@ Configure geth for your network, it will become the block builder.
Builder-related options:
```
$ geth --help
BUILDER API OPTIONS:

BUILDER

--builder (default: false)
Enable the builder

--builder.beacon_endpoint value (default: "http://127.0.0.1:5052")
Beacon endpoint to connect to for beacon chain data [$BUILDER_BEACON_ENDPOINT]

--builder.bellatrix_fork_version value (default: "0x02000000")
Bellatrix fork version. [$BUILDER_BELLATRIX_FORK_VERSION]

--builder.dry-run (default: false)
Builder only validates blocks without submission to the relay

--builder.genesis_fork_version value (default: "0x00000000")
Gensis fork version. [$BUILDER_GENESIS_FORK_VERSION]

--builder.genesis_validators_root value (default: "0x0000000000000000000000000000000000000000000000000000000000000000")
Genesis validators root of the network. [$BUILDER_GENESIS_VALIDATORS_ROOT]

--builder.listen_addr value (default: ":28545")
Listening address for builder endpoint [$BUILDER_LISTEN_ADDR]

--builder.local_relay (default: false)
Enable the local relay

--builder.no_bundle_fetcher (default: false)
Disable the bundle fetcher

--builder.relay_secret_key value (default: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11")
Builder local relay API key used for signing headers [$BUILDER_RELAY_SECRET_KEY]

--builder.remote_relay_endpoint value
Relay endpoint to connect to for validator registration data, if not provided
will expose validator registration locally [$BUILDER_REMOTE_RELAY_ENDPOINT]

--builder.secondary_remote_relay_endpoints value
Comma separated relay endpoints to connect to for validator registration data
missing from the primary remote relay, and to push blocks for registrations
missing from or matching the primary [$BUILDER_SECONDARY_REMOTE_RELAY_ENDPOINTS]

--builder.secret_key value (default: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11")
Builder key used for signing blocks [$BUILDER_SECRET_KEY]

--builder.validation_blacklist value (default: "ofac_blacklist.json")
Path to file containing blacklisted addresses, json-encoded list of strings.
Default assumes CWD is repo's root

--builder.validator_checks (default: false)
--builder.validation_blacklist value
Enable the validator checks

MINER

--miner.algotype value (default: "mev-geth")
--miner.blocklist value
--miner.extradata value
Block building algorithm to use [=mev-geth] (mev-geth, greedy)

--miner.blocklist value
flashbots - Path to JSON file with list of blocked addresses. Miner will ignore
txs that touch mentioned addresses.

--miner.extradata value
Block extra data set by the miner (default = client version)
```

Environment variables:
Expand Down
16 changes: 8 additions & 8 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type IBeaconClient interface {
}

type IRelay interface {
SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error
SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, vd ValidatorData) error
GetValidatorForSlot(nextSlot uint64) (ValidatorData, error)
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func (b *Builder) Stop() error {
return nil
}

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 {
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 {
executableData := beacon.BlockToExecutableData(block)
payload, err := executableDataToExecutionPayload(executableData)
if err != nil {
Expand All @@ -118,7 +118,7 @@ func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, se
BlockHash: payload.BlockHash,
BuilderPubkey: b.builderPublicKey,
ProposerPubkey: proposerPubkey,
ProposerFeeRecipient: proposerFeeRecipient,
ProposerFeeRecipient: vd.FeeRecipient,
GasLimit: executableData.GasLimit,
GasUsed: executableData.GasUsed,
Value: *value,
Expand All @@ -137,13 +137,13 @@ func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, se
}

if b.dryRun {
err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{blockSubmitReq, proposerRegisteredGasLimit})
err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{blockSubmitReq, vd.GasLimit})
if err != nil {
log.Error("could not validate block", "err", err)
}
} else {
go b.ds.ConsumeBuiltBlock(block, ordersClosedAt, sealedAt, commitedBundles, allBundles, &blockBidMsg)
err = b.relay.SubmitBlock(&blockSubmitReq)
err = b.relay.SubmitBlock(&blockSubmitReq, vd)
if err != nil {
log.Error("could not submit block", "err", err, "#commitedBundles", len(commitedBundles))
return err
Expand Down Expand Up @@ -208,7 +208,7 @@ func (b *Builder) OnPayloadAttribute(attrs *BuilderPayloadAttributes) error {
}
b.slotAttrs = append(b.slotAttrs, *attrs)

go b.runBuildingJob(b.slotCtx, proposerPubkey, vd.FeeRecipient, vd.GasLimit, attrs)
go b.runBuildingJob(b.slotCtx, proposerPubkey, vd, attrs)
return nil
}

Expand All @@ -220,7 +220,7 @@ type blockQueueEntry struct {
allBundles []types.SimulatedBundle
}

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

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

if err != nil {
log.Error("could not run sealed block hook", "err", err)
Expand Down
2 changes: 1 addition & 1 deletion builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestOnPayloadAttributes(t *testing.T) {

feeRecipient, _ := boostTypes.HexToAddress("0xabcf8e0d4e9587369b2301d0790347320302cc00")
testRelay := testRelay{
validator: ValidatorData{
gvsVd: ValidatorData{
Pubkey: PubkeyHex(testBeacon.validator.Pk.String()),
FeeRecipient: feeRecipient,
GasLimit: 10,
Expand Down
58 changes: 30 additions & 28 deletions builder/config.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
package builder

type Config struct {
Enabled bool `toml:",omitempty"`
EnableValidatorChecks bool `toml:",omitempty"`
EnableLocalRelay bool `toml:",omitempty"`
DisableBundleFetcher bool `toml:",omitempty"`
DryRun bool `toml:",omitempty"`
BuilderSecretKey string `toml:",omitempty"`
RelaySecretKey string `toml:",omitempty"`
ListenAddr string `toml:",omitempty"`
GenesisForkVersion string `toml:",omitempty"`
BellatrixForkVersion string `toml:",omitempty"`
GenesisValidatorsRoot string `toml:",omitempty"`
BeaconEndpoint string `toml:",omitempty"`
RemoteRelayEndpoint string `toml:",omitempty"`
ValidationBlocklist string `toml:",omitempty"`
Enabled bool `toml:",omitempty"`
EnableValidatorChecks bool `toml:",omitempty"`
EnableLocalRelay bool `toml:",omitempty"`
DisableBundleFetcher bool `toml:",omitempty"`
DryRun bool `toml:",omitempty"`
BuilderSecretKey string `toml:",omitempty"`
RelaySecretKey string `toml:",omitempty"`
ListenAddr string `toml:",omitempty"`
GenesisForkVersion string `toml:",omitempty"`
BellatrixForkVersion string `toml:",omitempty"`
GenesisValidatorsRoot string `toml:",omitempty"`
BeaconEndpoint string `toml:",omitempty"`
RemoteRelayEndpoint string `toml:",omitempty"`
SecondaryRemoteRelayEndpoints []string `toml:",omitempty"`
ValidationBlocklist string `toml:",omitempty"`
}

// DefaultConfig is the default config for the builder.
var DefaultConfig = Config{
Enabled: false,
EnableValidatorChecks: false,
EnableLocalRelay: false,
DisableBundleFetcher: false,
DryRun: false,
BuilderSecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
RelaySecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
ListenAddr: ":28545",
GenesisForkVersion: "0x00000000",
BellatrixForkVersion: "0x02000000",
GenesisValidatorsRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
BeaconEndpoint: "http://127.0.0.1:5052",
RemoteRelayEndpoint: "",
ValidationBlocklist: "",
Enabled: false,
EnableValidatorChecks: false,
EnableLocalRelay: false,
DisableBundleFetcher: false,
DryRun: false,
BuilderSecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
RelaySecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
ListenAddr: ":28545",
GenesisForkVersion: "0x00000000",
BellatrixForkVersion: "0x02000000",
GenesisValidatorsRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
BeaconEndpoint: "http://127.0.0.1:5052",
RemoteRelayEndpoint: "",
SecondaryRemoteRelayEndpoints: nil,
ValidationBlocklist: "",
}
7 changes: 6 additions & 1 deletion builder/local_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ func NewLocalRelay(sk *bls.SecretKey, beaconClient IBeaconClient, builderSigning
}
}

func (r *LocalRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
func (r *LocalRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, _ ValidatorData) error {
log.Info("submitting block to local relay", "block", msg.ExecutionPayload.BlockHash.String())
return r.submitBlock(msg)
}

func (r *LocalRelay) submitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
payloadHeader, err := boostTypes.PayloadToPayloadHeader(msg.ExecutionPayload)
if err != nil {
log.Error("could not convert payload to header", "err", err)
Expand Down
26 changes: 7 additions & 19 deletions builder/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,7 @@ import (
"github.com/flashbots/mev-boost/server"
)

type testRelay struct {
validator ValidatorData
requestedSlot uint64
submittedMsg *boostTypes.BuilderSubmitBlockRequest
}

func (r *testRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
r.submittedMsg = msg
return nil
}
func (r *testRelay) GetValidatorForSlot(nextSlot uint64) (ValidatorData, error) {
r.requestedSlot = nextSlot
return r.validator, nil
}
var ErrValidatorNotFound = errors.New("validator not found")

type RemoteRelay struct {
endpoint string
Expand Down Expand Up @@ -135,20 +122,21 @@ func (r *RemoteRelay) GetValidatorForSlot(nextSlot uint64) (ValidatorData, error
return vd, nil
}

return ValidatorData{}, errors.New("validator not found")
return ValidatorData{}, ErrValidatorNotFound
}

func (r *RemoteRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest) error {
func (r *RemoteRelay) SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, _ ValidatorData) error {
log.Info("submitting block to remote relay", "endpoint", r.endpoint)
code, err := server.SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, r.endpoint+"/relay/v1/builder/blocks", msg, nil)
if err != nil {
return err
return fmt.Errorf("error sending http request to relay %s. err: %w", r.endpoint, err)
}
if code > 299 {
return fmt.Errorf("non-ok response code %d from relay ", code)
return fmt.Errorf("non-ok response code %d from relay %s", code, r.endpoint)
}

if r.localRelay != nil {
r.localRelay.SubmitBlock(msg)
r.localRelay.submitBlock(msg)
}

return nil
Expand Down
Loading