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

v2 builder init commit #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
74 changes: 58 additions & 16 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/phase0"
utilbellatrix "github.com/attestantio/go-eth2-client/util/bellatrix"
utilcapella "github.com/attestantio/go-eth2-client/util/capella"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -48,6 +50,7 @@ type ValidatorData struct {
type IRelay interface {
SubmitBlock(msg *bellatrixapi.SubmitBlockRequest, vd ValidatorData) error
SubmitBlockCapella(msg *capellaapi.SubmitBlockRequest, vd ValidatorData) error
SubmitV2BlockCapella(msg *common.SubmitBlockRequestV2Optimistic, vd ValidatorData) error
GetValidatorForSlot(nextSlot uint64) (ValidatorData, error)
Config() RelayConfig
Start() error
Expand Down Expand Up @@ -306,30 +309,69 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or
Value: value,
}

/* --- makes a bad block hash.
log.Warn(fmt.Sprintf("*** current hash: %v, %v\n", blockBidMsg.BlockHash.String(), payload.BlockHash.String()))
modifiedHash := "0x0000" + blockBidMsg.BlockHash.String()[6:]
if err := payload.BlockHash.UnmarshalText([]byte(modifiedHash)); err != nil {
log.Error(fmt.Sprintf("unable to modify msg execution payload: %v", err))
}
if err := blockBidMsg.BlockHash.UnmarshalText([]byte(modifiedHash)); err != nil {
log.Error(fmt.Sprintf("unable to modify msg block hash: %v", err))
}
log.Warn(fmt.Sprintf("*** new hash: %v, %v\n", blockBidMsg.BlockHash.String(), payload.BlockHash.String()))
*/

signature, err := ssz.SignMessage(&blockBidMsg, b.builderSigningDomain, b.builderSecretKey)
if err != nil {
log.Error("could not sign builder bid", "err", err)
return err
}

blockSubmitReq := capellaapi.SubmitBlockRequest{
Signature: signature,
Message: &blockBidMsg,
ExecutionPayload: payload,
transactions := utilbellatrix.ExecutionPayloadTransactions{Transactions: payload.Transactions}
transactionsRoot, err := transactions.HashTreeRoot()
if err != nil {
log.Error("could not calculate transactions root", "err", err)
return err
}

if b.dryRun {
err = b.validator.ValidateBuilderSubmissionV2(&blockvalidation.BuilderBlockValidationRequestV2{SubmitBlockRequest: blockSubmitReq, RegisteredGasLimit: vd.GasLimit})
if err != nil {
log.Error("could not validate block for capella", "err", err)
}
} else {
go b.ds.ConsumeBuiltBlock(block, blockValue, ordersClosedAt, sealedAt, commitedBundles, allBundles, usedSbundles, &blockBidMsg)
err = b.relay.SubmitBlockCapella(&blockSubmitReq, vd)
if err != nil {
log.Error("could not submit capella block", "err", err, "#commitedBundles", len(commitedBundles))
return err
}
withdrawals := utilcapella.ExecutionPayloadWithdrawals{Withdrawals: payload.Withdrawals}
withdrawalsRoot, err := withdrawals.HashTreeRoot()
if err != nil {
log.Error("could not calculate withdrawals root", "err", err)
return err
}

eph := capella.ExecutionPayloadHeader{
ParentHash: payload.ParentHash,
FeeRecipient: payload.FeeRecipient,
StateRoot: payload.StateRoot,
ReceiptsRoot: payload.ReceiptsRoot,
LogsBloom: payload.LogsBloom,
PrevRandao: payload.PrevRandao,
BlockNumber: payload.BlockNumber,
GasLimit: payload.GasLimit,
GasUsed: payload.GasUsed,
Timestamp: payload.Timestamp,
ExtraData: payload.ExtraData,
BaseFeePerGas: payload.BaseFeePerGas,
BlockHash: payload.BlockHash,
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalsRoot,
}

blockSubmitReq := common.SubmitBlockRequestV2Optimistic{
Message: &blockBidMsg,
ExecutionPayloadHeader: &eph,
Signature: signature,
Transactions: payload.Transactions,
Withdrawals: payload.Withdrawals,
}

go b.ds.ConsumeBuiltBlock(block, blockValue, ordersClosedAt, sealedAt, commitedBundles, allBundles, usedSbundles, &blockBidMsg)
err = b.relay.SubmitV2BlockCapella(&blockSubmitReq, vd)
if err != nil {
log.Error("could not submit capella block", "err", err, "#commitedBundles", len(commitedBundles))
return err
}

log.Info("submitted capella block", "slot", blockBidMsg.Slot, "value", blockBidMsg.Value.String(), "parent", blockBidMsg.ParentHash, "hash", block.Hash(), "#commitedBundles", len(commitedBundles))
Expand Down
5 changes: 5 additions & 0 deletions builder/local_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/phase0"
bellatrixutil "github.com/attestantio/go-eth2-client/util/bellatrix"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/flashbots/go-boost-utils/bls"
Expand Down Expand Up @@ -121,6 +122,10 @@ func (r *LocalRelay) SubmitBlockCapella(msg *capellaapi.SubmitBlockRequest, _ Va
return r.submitBlockCapella(msg)
}

func (r *LocalRelay) SubmitV2BlockCapella(msg *common.SubmitBlockRequestV2Optimistic, vd ValidatorData) error {
return fmt.Errorf("capella v2 not supported on local relay")
}

func (r *LocalRelay) Config() RelayConfig {
// local relay does not need config as it is submitting to its own internal endpoint
return RelayConfig{}
Expand Down
25 changes: 25 additions & 0 deletions builder/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/attestantio/go-builder-client/api/bellatrix"
"github.com/attestantio/go-builder-client/api/capella"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/flashbots/go-boost-utils/utils"
)
Expand Down Expand Up @@ -193,6 +194,30 @@ func (r *RemoteRelay) SubmitBlockCapella(msg *capella.SubmitBlockRequest, _ Vali
return nil
}

func (r *RemoteRelay) SubmitV2BlockCapella(msg *common.SubmitBlockRequestV2Optimistic, vd ValidatorData) error {
log.Info("submitting block to remote relay", "endpoint", r.config.Endpoint)

endpoint := r.config.Endpoint + "/relay/v2/builder/blocks"
if r.cancellationsEnabled {
endpoint = endpoint + "?cancellations=true"
}

bodyBytes, err := msg.MarshalSSZ()
if err != nil {
return fmt.Errorf("error marshaling ssz: %w", err)
}
log.Debug("submitting block to remote relay", "endpoint", r.config.Endpoint)
code, err := SendSSZRequest(context.TODO(), *http.DefaultClient, http.MethodPost, endpoint, bodyBytes, r.config.GzipEnabled)
if err != nil {
return fmt.Errorf("error sending http request to relay %s. err: %w", r.config.Endpoint, err)
}
if code > 299 {
return fmt.Errorf("non-ok response code %d from relay %s", code, r.config.Endpoint)
}

return nil
}

func (r *RemoteRelay) getSlotValidatorMapFromRelay() (map[uint64]ValidatorData, error) {
var dst GetValidatorRelayResponse
code, err := SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodGet, r.config.Endpoint+"/relay/v1/builder/validators", nil, &dst)
Expand Down
21 changes: 21 additions & 0 deletions builder/relay_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/attestantio/go-builder-client/api/bellatrix"
"github.com/attestantio/go-builder-client/api/capella"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)

Expand Down Expand Up @@ -81,6 +82,26 @@ func (r *RemoteRelayAggregator) SubmitBlockCapella(msg *capella.SubmitBlockReque
return nil
}

func (r *RemoteRelayAggregator) SubmitV2BlockCapella(msg *common.SubmitBlockRequestV2Optimistic, registration ValidatorData) error {
r.registrationsCacheLock.RLock()
defer r.registrationsCacheLock.RUnlock()

relays, found := r.registrationsCache[registration]
if !found {
return fmt.Errorf("no relays for registration %s", registration.Pubkey)
}
for _, relay := range relays {
go func(relay IRelay) {
err := relay.SubmitV2BlockCapella(msg, registration)
if err != nil {
log.Error("could not submit block", "err", err)
}
}(relay)
}

return nil
}

type RelayValidatorRegistration struct {
vd ValidatorData
relayI int // index into relays array to preserve relative order
Expand Down
5 changes: 5 additions & 0 deletions builder/relay_aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/attestantio/go-builder-client/api/bellatrix"
"github.com/attestantio/go-builder-client/api/capella"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -68,6 +69,10 @@ func (r *testRelay) SubmitBlockCapella(msg *capella.SubmitBlockRequest, registra
return r.sbError
}

func (r *testRelay) SubmitV2BlockCapella(msg *common.SubmitBlockRequestV2Optimistic, vd ValidatorData) error {
return r.sbError
}

func (r *testRelay) GetValidatorForSlot(nextSlot uint64) (ValidatorData, error) {
r.requestedSlot = nextSlot
return r.gvsVd, r.gvsErr
Expand Down
Loading
Loading