Skip to content
Open
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
7 changes: 7 additions & 0 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Builder struct {
payloadMu sync.Mutex
payload IPayload

extraData []byte

stop chan struct{}
}

Expand All @@ -75,6 +77,7 @@ type BuilderArgs struct {
eth IEthereumService
ignoreLatePayloadAttributes bool
beaconClient IBeaconClient
extraData []byte
}

func NewBuilder(args BuilderArgs) (*Builder, error) {
Expand All @@ -91,6 +94,8 @@ func NewBuilder(args BuilderArgs) (*Builder, error) {
slotCtx: slotCtx,
slotCtxCancel: slotCtxCancel,

extraData: args.extraData,

stop: make(chan struct{}, 1),
}, nil
}
Expand Down Expand Up @@ -364,6 +369,8 @@ func (b *Builder) handlePayloadAttributes(attrs *builderTypes.PayloadAttributes)
b.slotCtxCancel()
}

attrs.ExtraData = b.extraData

slotCtx, slotCtxCancel := context.WithTimeout(context.Background(), b.builderBlockTime)
b.slotAttrs = *attrs
b.slotCtx = slotCtx
Expand Down
2 changes: 2 additions & 0 deletions builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
RetryInterval string `toml:",omitempty"`
BlockTime time.Duration `toml:",omitempty"`
ProposerAddress string `toml:",omitempty"`
ExtraData string `toml:",omitempty"`
}

// DefaultConfig is the default config for the builder.
Expand All @@ -29,4 +30,5 @@ var DefaultConfig = Config{
BeaconEndpoints: []string{"http://127.0.0.1:5052"},
RetryInterval: RetryIntervalDefault.String(),
BlockTime: BlockTimeDefault,
ExtraData: "",
}
3 changes: 2 additions & 1 deletion builder/eth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func (s *EthereumService) BuildBlock(attrs *builderTypes.PayloadAttributes) (IPa
Transactions: attrs.Transactions,
NoTxPool: attrs.NoTxPool,
}
return s.eth.Miner().BuildPayload(args)

return s.eth.Miner().BuildPayloadWithExtraData(args, attrs.ExtraData)
}

func (s *EthereumService) GetBlockByHash(hash common.Hash) *types.Block {
Expand Down
1 change: 1 addition & 0 deletions builder/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error {
ignoreLatePayloadAttributes: cfg.IgnoreLatePayloadAttributes,
beaconClient: beaconClient,
blockTime: cfg.BlockTime,
extraData: []byte(cfg.ExtraData),
}

builderBackend, err := NewBuilder(builderArgs)
Expand Down
6 changes: 6 additions & 0 deletions builder/types/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type PayloadAttributes struct {

NoTxPool bool `json:"noTxPool,omitempty"` // Optimism addition: option to disable tx pool contents from being included
Transactions []*types.Transaction `json:"transactions"` // Optimism addition: txs forced into the block via engine API

ExtraData []byte `json:"extraData,omitempty"` // Flashbots addition: extra data to include in the block
}

func (attrs *PayloadAttributes) Equal(other *PayloadAttributes) bool {
Expand All @@ -41,5 +43,9 @@ func (attrs *PayloadAttributes) Equal(other *PayloadAttributes) bool {
return false
}

if !slices.Equal(attrs.ExtraData, other.ExtraData) {
return false
}

return true
}
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ var (
utils.BuilderBeaconEndpointsFlag,
utils.BuilderBlockTimeFlag,
utils.BuilderProposerSigningAddressFlag,
utils.BuilderExtraData,
}

rpcFlags = []cli.Flag{
Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,12 @@ var (
EnvVars: []string{"BUILDER_PROPOSER_SIGNING_ADDRESS"},
Category: flags.BuilderCategory,
}
BuilderExtraData = &cli.StringFlag{
Name: "builder.extra_data",
Usage: "Extra data to include in the block",
EnvVars: []string{"BUILDER_EXTRA_DATA"},
Category: flags.BuilderCategory,
}

CustomChainFlag = &cli.StringFlag{
Name: "chain",
Expand Down Expand Up @@ -1581,6 +1587,7 @@ func SetBuilderConfig(ctx *cli.Context, cfg *builder.Config) {

cfg.BlockTime = ctx.Duration(BuilderBlockTimeFlag.Name)
cfg.ProposerAddress = ctx.String(BuilderProposerSigningAddressFlag.Name)
cfg.ExtraData = ctx.String(BuilderExtraData.Name)
}

// SetNodeConfig applies node-related command line flags to the config.
Expand Down
7 changes: 6 additions & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ func (miner *Miner) SetGasTip(tip *big.Int) error {

// BuildPayload builds the payload according to the provided parameters.
func (miner *Miner) BuildPayload(args *BuildPayloadArgs) (*Payload, error) {
return miner.buildPayload(args)
return miner.buildPayload(args, nil)
}

// BuildPayloadWithExtraData builds the payload according to the provided parameters and extra data.
func (miner *Miner) BuildPayloadWithExtraData(args *BuildPayloadArgs, extra []byte) (*Payload, error) {
return miner.buildPayload(args, extra)
}

// getPending retrieves the pending block based on the current head block.
Expand Down
4 changes: 3 additions & 1 deletion miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (payload *Payload) stopBuilding() {
}

// buildPayload builds the payload according to the provided parameters.
func (miner *Miner) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
func (miner *Miner) buildPayload(args *BuildPayloadArgs, extraData []byte) (*Payload, error) {
if args.NoTxPool { // don't start the background payload updating job if there is no tx pool to pull from
// Build the initial version with no transaction included. It should be fast
// enough to run. The empty payload can at least make sure there is something
Expand All @@ -287,6 +287,7 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
noTxs: true,
txs: args.Transactions,
gasLimit: args.GasLimit,
extraData: extraData,
}
empty := miner.generateWork(emptyParams)
if empty.err != nil {
Expand All @@ -311,6 +312,7 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
noTxs: false,
txs: args.Transactions,
gasLimit: args.GasLimit,
extraData: extraData,
}

// Since we skip building the empty block when using the tx pool, we need to explicitly
Expand Down
9 changes: 6 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ type generateParams struct {
gasLimit *uint64 // Optional gas limit override
interrupt *atomic.Int32 // Optional interruption signal to pass down to worker.generateWork
isUpdate bool // Optional flag indicating that this is building a discardable update

extraData []byte // Extra data to include in the block
}

// generateWork generates a sealing block based on the given parameters.
Expand Down Expand Up @@ -197,9 +199,10 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error)
Time: timestamp,
Coinbase: genParams.coinbase,
}
// Set the extra field.
if len(miner.config.ExtraData) != 0 && miner.chainConfig.Optimism == nil { // Optimism chains must not set any extra data.
header.Extra = miner.config.ExtraData
// Set the extra field if specified.
if len(genParams.extraData) != 0 {
log.Debug("Setting extra data", "extraData", genParams.extraData)
header.Extra = genParams.extraData
}
// Set the randomness field from the beacon chain if it's available.
if genParams.random != (common.Hash{}) {
Expand Down