Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolate extra data modification to builder module #21

Open
wants to merge 4 commits into
base: flashbots
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -61,6 +61,8 @@ type Builder struct {
bestBlockMu sync.Mutex
bestBlock *builderTypes.VersionedBuilderPayloadResponse

extraData []byte

stop chan struct{}
}

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

// SubmitBlockOpts is a struct that contains all the arguments needed to submit a block to the relay
Expand Down Expand Up @@ -101,6 +104,8 @@ func NewBuilder(args BuilderArgs) (*Builder, error) {
slotCtx: slotCtx,
slotCtxCancel: slotCtxCancel,

extraData: args.extraData,

stop: make(chan struct{}, 1),
}, nil
}
Expand Down Expand Up @@ -369,6 +374,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: "",
}
1 change: 1 addition & 0 deletions builder/eth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (s *EthereumService) BuildBlock(attrs *builderTypes.PayloadAttributes) (*en
BeaconRoot: attrs.ParentBeaconBlockRoot,
Transactions: attrs.Transactions,
NoTxPool: attrs.NoTxPool,
ExtraData: attrs.ExtraData,
}

payload, err := s.eth.Miner().BuildPayload(args)
Expand Down
1 change: 1 addition & 0 deletions builder/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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 @@ -185,6 +185,7 @@ var (
utils.BuilderBlockRetryInterval,
utils.BuilderBlockTime,
utils.BuilderProposerSigningAddress,
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 @@ -724,6 +724,12 @@ var (
EnvVars: []string{"BUILDER_PROPOSER_SIGNING_ADDRESS"},
Category: flags.BuilderCategory,
}
BuilderExtraData = &cli.StringFlag{
jinmel marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1589,6 +1595,7 @@ func SetBuilderConfig(ctx *cli.Context, cfg *builder.Config) {
cfg.RetryInterval = ctx.String(BuilderBlockRetryInterval.Name)
cfg.BlockTime = ctx.Duration(BuilderBlockTime.Name)
cfg.ProposerAddress = ctx.String(BuilderProposerSigningAddress.Name)
cfg.ExtraData = ctx.String(BuilderExtraData.Name)
}

// SetNodeConfig applies node-related command line flags to the config.
Expand Down
4 changes: 4 additions & 0 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type BuildPayloadArgs struct {
NoTxPool bool // Optimism addition: option to disable tx pool contents from being included
Transactions []*types.Transaction // Optimism addition: txs forced into the block via engine API
GasLimit *uint64 // Optimism addition: override gas limit of the block to build

ExtraData []byte // Flashbots addition: extra data to include in the block
jinmel marked this conversation as resolved.
Show resolved Hide resolved
}

// Id computes an 8-byte identifier by hashing the components of the payload arguments.
Expand Down Expand Up @@ -261,6 +263,7 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
noTxs: true,
txs: args.Transactions,
gasLimit: args.GasLimit,
extraData: args.ExtraData,
}
empty := miner.generateWork(emptyParams)
if empty.err != nil {
Expand All @@ -285,6 +288,7 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
noTxs: false,
txs: args.Transactions,
gasLimit: args.GasLimit,
extraData: args.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