Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Closed
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
52 changes: 48 additions & 4 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ 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"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
boostTypes "github.com/flashbots/go-boost-utils/types"
)

//go:generate go run github.com/fjl/gencodec -type PayloadAttributes -field-override payloadAttributesMarshaling -out gen_blockparams.go
Expand Down Expand Up @@ -141,7 +143,7 @@ func encodeTransactions(txs []*types.Transaction) [][]byte {
return enc
}

func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
func DecodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
var txs = make([]*types.Transaction, len(enc))
for i, encTx := range enc {
var tx types.Transaction
Expand All @@ -164,7 +166,7 @@ func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
// Withdrawals value will propagate through the returned block. Empty
// Withdrawals value must be passed via non-nil, length 0 value in params.
func ExecutableDataToBlock(params ExecutableData) (*types.Block, error) {
txs, err := decodeTransactions(params.Transactions)
txs, err := DecodeTransactions(params.Transactions)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -246,7 +248,7 @@ func ExecutionPayloadToBlock(payload *bellatrix.ExecutionPayload) (*types.Block,
for i, txHexBytes := range payload.Transactions {
transactionBytes[i] = txHexBytes[:]
}
txs, err := decodeTransactions(transactionBytes)
txs, err := DecodeTransactions(transactionBytes)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -286,7 +288,7 @@ func ExecutionPayloadV2ToBlock(payload *capella.ExecutionPayload) (*types.Block,
for i, txHexBytes := range payload.Transactions {
transactionBytes[i] = txHexBytes[:]
}
txs, err := decodeTransactions(transactionBytes)
txs, err := DecodeTransactions(transactionBytes)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -331,3 +333,45 @@ func ExecutionPayloadV2ToBlock(payload *capella.ExecutionPayload) (*types.Block,
block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */).WithWithdrawals(withdrawals)
return block, nil
}

// bchain: copied this here to avoid circular dependency
func ExecutableDataToCapellaExecutionPayload(data *ExecutableData) (*capella.ExecutionPayload, error) {
transactionData := make([]bellatrix.Transaction, len(data.Transactions))
for i, tx := range data.Transactions {
transactionData[i] = tx
}

withdrawalData := make([]*capella.Withdrawal, len(data.Withdrawals))
for i, wd := range data.Withdrawals {
withdrawalData[i] = &capella.Withdrawal{
Index: capella.WithdrawalIndex(wd.Index),
ValidatorIndex: phase0.ValidatorIndex(wd.Validator),
Address: bellatrix.ExecutionAddress(wd.Address),
Amount: phase0.Gwei(wd.Amount),
}
}

baseFeePerGas := new(boostTypes.U256Str)
err := baseFeePerGas.FromBig(data.BaseFeePerGas)
if err != nil {
return nil, err
}

return &capella.ExecutionPayload{
ParentHash: [32]byte(data.ParentHash),
FeeRecipient: [20]byte(data.FeeRecipient),
StateRoot: data.StateRoot,
ReceiptsRoot: data.ReceiptsRoot,
LogsBloom: types.BytesToBloom(data.LogsBloom),
PrevRandao: data.Random,
BlockNumber: data.Number,
GasLimit: data.GasLimit,
GasUsed: data.GasUsed,
Timestamp: data.Timestamp,
ExtraData: data.ExtraData,
BaseFeePerGas: *baseFeePerGas,
BlockHash: [32]byte(data.BlockHash),
Transactions: transactionData,
Withdrawals: withdrawalData,
}, nil
}
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker build -t pepc-boost-builder .;
docker tag pepc-boost-builder:latest public.ecr.aws/t1d5h1w5/pepc-boost-builder:latest;
docker push public.ecr.aws/t1d5h1w5/pepc-boost-builder:latest;
50 changes: 5 additions & 45 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
capellaapi "github.com/attestantio/go-builder-client/api/capella"
apiv1 "github.com/attestantio/go-builder-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -47,6 +46,8 @@ type ValidatorData struct {

type IRelay interface {
SubmitBlock(msg *bellatrixapi.SubmitBlockRequest, vd ValidatorData) error
// this is for the builder to be aware of pepc boost specific features
IsPepcRelayer() (bool, error)
SubmitBlockCapella(msg *capellaapi.SubmitBlockRequest, vd ValidatorData) error
GetValidatorForSlot(nextSlot uint64) (ValidatorData, error)
Config() RelayConfig
Expand Down Expand Up @@ -282,7 +283,7 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or
commitedBundles, allBundles []types.SimulatedBundle, usedSbundles []types.UsedSBundle,
proposerPubkey phase0.BLSPubKey, vd ValidatorData, attrs *types.BuilderPayloadAttributes) error {
executableData := engine.BlockToExecutableData(block, blockValue)
payload, err := executableDataToCapellaExecutionPayload(executableData.ExecutionPayload)
payload, err := engine.ExecutableDataToCapellaExecutionPayload(executableData.ExecutionPayload)
if err != nil {
log.Error("could not format execution payload", "err", err)
return err
Expand Down Expand Up @@ -345,9 +346,9 @@ func (b *Builder) OnPayloadAttribute(attrs *types.BuilderPayloadAttributes) erro
if err != nil {
return fmt.Errorf("could not get validator while submitting block for slot %d - %w", attrs.Slot, err)
}

attrs.SuggestedFeeRecipient = [20]byte(vd.FeeRecipient)
attrs.GasLimit = vd.GasLimit
attrs.IsPepcRelayer = true

proposerPubkey, err := utils.HexToPubkey(string(vd.Pubkey))
if err != nil {
Expand Down Expand Up @@ -413,7 +414,7 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey phase0.
queueBestEntry blockQueueEntry
)

log.Debug("runBuildingJob", "slot", attrs.Slot, "parent", attrs.HeadHash, "payloadTimestamp", uint64(attrs.Timestamp))
log.Debug("runBuildingJob", "slot", attrs.Slot, "parent", attrs.HeadHash, "payloadTimestamp", uint64(attrs.Timestamp), "gasLimit", attrs.GasLimit)

submitBestBlock := func() {
queueMu.Lock()
Expand Down Expand Up @@ -510,44 +511,3 @@ func executableDataToExecutionPayload(data *engine.ExecutableData) (*bellatrix.E
Transactions: transactionData,
}, nil
}

func executableDataToCapellaExecutionPayload(data *engine.ExecutableData) (*capella.ExecutionPayload, error) {
transactionData := make([]bellatrix.Transaction, len(data.Transactions))
for i, tx := range data.Transactions {
transactionData[i] = bellatrix.Transaction(tx)
}

withdrawalData := make([]*capella.Withdrawal, len(data.Withdrawals))
for i, wd := range data.Withdrawals {
withdrawalData[i] = &capella.Withdrawal{
Index: capella.WithdrawalIndex(wd.Index),
ValidatorIndex: phase0.ValidatorIndex(wd.Validator),
Address: bellatrix.ExecutionAddress(wd.Address),
Amount: phase0.Gwei(wd.Amount),
}
}

baseFeePerGas := new(boostTypes.U256Str)
err := baseFeePerGas.FromBig(data.BaseFeePerGas)
if err != nil {
return nil, err
}

return &capella.ExecutionPayload{
ParentHash: [32]byte(data.ParentHash),
FeeRecipient: [20]byte(data.FeeRecipient),
StateRoot: [32]byte(data.StateRoot),
ReceiptsRoot: [32]byte(data.ReceiptsRoot),
LogsBloom: types.BytesToBloom(data.LogsBloom),
PrevRandao: [32]byte(data.Random),
BlockNumber: data.Number,
GasLimit: data.GasLimit,
GasUsed: data.GasUsed,
Timestamp: data.Timestamp,
ExtraData: data.ExtraData,
BaseFeePerGas: *baseFeePerGas,
BlockHash: [32]byte(data.BlockHash),
Transactions: transactionData,
Withdrawals: withdrawalData,
}, nil
}
4 changes: 4 additions & 0 deletions builder/local_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (r *LocalRelay) SubmitBlock(msg *bellatrixapi.SubmitBlockRequest, _ Validat
return r.submitBlock(msg)
}

func (r *LocalRelay) IsPepcRelayer() (bool, error) {
return true, nil
}

func (r *LocalRelay) SubmitBlockCapella(msg *capellaapi.SubmitBlockRequest, _ ValidatorData) error {
log.Info("submitting block to local relay", "block", msg.ExecutionPayload.BlockHash.String())

Expand Down
18 changes: 17 additions & 1 deletion builder/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (r *RemoteRelay) updateValidatorsMap(currentSlot uint64, retries int) error
r.validatorSyncOngoing = true
r.validatorsLock.Unlock()

log.Info("requesting ", "currentSlot", currentSlot)
newMap, err := r.getSlotValidatorMapFromRelay()
for err != nil && retries > 0 {
log.Error("could not get validators map from relay, retrying", "err", err)
Expand Down Expand Up @@ -193,6 +192,23 @@ func (r *RemoteRelay) SubmitBlockCapella(msg *capella.SubmitBlockRequest, _ Vali
return nil
}

func (r *RemoteRelay) IsPepcRelayer() (bool, error) {
log.Info("submitting rob block to remote relay", "endpoint", r.config.Endpoint)

endpoint := r.config.Endpoint + "/relay/v1/data/is_pepc_relayer"

var isPepcRelayer bool
code, err := SendHTTPRequest(context.TODO(), *http.DefaultClient, http.MethodPost, endpoint, nil, isPepcRelayer)
if err != nil {
return false, fmt.Errorf("error sending http request to relay %s. err: %w", r.config.Endpoint, err)
}
if code > 299 {
return false, fmt.Errorf("non-ok response code %d from relay %s", code, r.config.Endpoint)
}

return isPepcRelayer, 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
4 changes: 4 additions & 0 deletions builder/relay_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type RemoteRelayAggregator struct {
registrationsCache map[ValidatorData][]IRelay
}

func (r *RemoteRelayAggregator) IsPepcRelayer() (bool, error) {
return false, fmt.Errorf("not implemented")
}

func NewRemoteRelayAggregator(primary IRelay, secondary []IRelay) *RemoteRelayAggregator {
relays := []IRelay{primary}
return &RemoteRelayAggregator{
Expand Down
4 changes: 4 additions & 0 deletions builder/relay_aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (r *testRelay) GetValidatorForSlot(nextSlot uint64) (ValidatorData, error)
return r.gvsVd, r.gvsErr
}

func (r *testRelay) IsPepcRelayer() (bool, error) {
return false, nil
}

func (r *testRelay) Start() error {
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion core/types/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type BuilderPayloadAttributes struct {
HeadHash common.Hash `json:"blockHash"`
Withdrawals Withdrawals `json:"withdrawals"`
GasLimit uint64
IsPepcRelayer bool `json:"isPepcRelayer"`
}

func (attrs *BuilderPayloadAttributes) Equal(other *BuilderPayloadAttributes) bool {
Expand All @@ -22,7 +23,8 @@ func (attrs *BuilderPayloadAttributes) Equal(other *BuilderPayloadAttributes) bo
attrs.SuggestedFeeRecipient != other.SuggestedFeeRecipient ||
attrs.Slot != other.Slot ||
attrs.HeadHash != other.HeadHash ||
attrs.GasLimit != other.GasLimit {
attrs.GasLimit != other.GasLimit ||
attrs.IsPepcRelayer != other.IsPepcRelayer {
return false
}

Expand Down
4 changes: 4 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, e
// Transactions implements DerivableList for transactions.
type Transactions []*Transaction

func (s Transactions) Index(i int) *Transaction {
return s[i]
}

// Len returns the length of s.
func (s Transactions) Len() int { return len(s) }

Expand Down
Loading