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

feat: bolt-relay changes #10

Merged
merged 7 commits into from
Jun 5, 2024
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
1 change: 1 addition & 0 deletions mev-boost-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ redis-cli DEL boost-relay/sepolia:validators-registration boost-relay/sepolia:va
* `FORCE_GET_HEADER_204` - force 204 as getHeader response
* `ENABLE_IGNORABLE_VALIDATION_ERRORS` - enable ignorable validation errors
* `USE_V1_PUBLISH_BLOCK_ENDPOINT` - uses the v1 publish block endpoint on the beacon node
* `USE_SSZ_ENCODING_PUBLISH_BLOCK` - uses the SSZ encoding for the publish block endpoint

#### Development Environment Variables

Expand Down
42 changes: 39 additions & 3 deletions mev-boost-relay/beaconclient/prod_beacon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type ProdBeaconInstance struct {
beaconURI string

// feature flags
ffUseV1PublishBlockEndpoint bool
ffUseV1PublishBlockEndpoint bool
ffUseSSZEncodingPublishBlock bool
}

func NewProdBeaconInstance(log *logrus.Entry, beaconURI string) *ProdBeaconInstance {
Expand All @@ -28,14 +29,19 @@ func NewProdBeaconInstance(log *logrus.Entry, beaconURI string) *ProdBeaconInsta
"beaconURI": beaconURI,
})

client := &ProdBeaconInstance{_log, beaconURI, false}
client := &ProdBeaconInstance{_log, beaconURI, false, false}

// feature flags
if os.Getenv("USE_V1_PUBLISH_BLOCK_ENDPOINT") != "" {
_log.Warn("env: USE_V1_PUBLISH_BLOCK_ENDPOINT: use the v1 publish block endpoint")
client.ffUseV1PublishBlockEndpoint = true
}

if os.Getenv("USE_SSZ_ENCODING_PUBLISH_BLOCK") != "" {
_log.Warn("env: USE_SSZ_ENCODING_PUBLISH_BLOCK: using SSZ encoding to publish blocks")
client.ffUseSSZEncodingPublishBlock = true
}

return client
}

Expand Down Expand Up @@ -251,7 +257,37 @@ func (c *ProdBeaconInstance) PublishBlock(block *common.VersionedSignedProposal,
}
headers := http.Header{}
headers.Add("Eth-Consensus-Version", strings.ToLower(block.Version.String())) // optional in v1, required in v2
return fetchBeacon(http.MethodPost, uri, block, nil, nil, headers, false)

slot, err := block.Slot()
if err != nil {
slot = 0
}

var payloadBytes []byte
useSSZ := c.ffUseSSZEncodingPublishBlock
log := c.log
encodeStartTime := time.Now().UTC()
if useSSZ {
log = log.WithField("publishContentType", "ssz")
payloadBytes, err = block.MarshalSSZ()
} else {
log = log.WithField("publishContentType", "json")
payloadBytes, err = json.Marshal(block)
}
if err != nil {
return 0, fmt.Errorf("could not marshal request: %w", err)
}
publishingStartTime := time.Now().UTC()
encodeDurationMs := publishingStartTime.Sub(encodeStartTime).Milliseconds()
code, err = fetchBeacon(http.MethodPost, uri, payloadBytes, nil, nil, headers, useSSZ)
publishDurationMs := time.Now().UTC().Sub(publishingStartTime).Milliseconds()
log.WithFields(logrus.Fields{
"slot": slot,
"encodeDurationMs": encodeDurationMs,
"publishDurationMs": publishDurationMs,
"payloadBytes": len(payloadBytes),
}).Info("finished publish block request")
return code, err
}

type GetGenesisResponse struct {
Expand Down
17 changes: 11 additions & 6 deletions mev-boost-relay/common/preconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import (
"github.com/attestantio/go-eth2-client/spec/phase0"
)

// VersionedSubmitBlockRequestWithPreconfsProofs is a wrapper struct
// VersionedSubmitBlockRequestWithProofs is a wrapper struct
// over `builderSpec.VersionedSubmitBlockRequest`
// to include preconfirmation proofs
type VersionedSubmitBlockRequestWithPreconfsProofs struct {
Inner *VersionedSubmitBlockRequest `json:"inner"`
Proofs []*PreconfirmationWithProof `json:"proofs"`
type VersionedSubmitBlockRequestWithProofs struct {
Inner *VersionedSubmitBlockRequest `json:"inner"`
// FIXME: this is not spec-aligned yet https://github.com/chainbound/bolt/issues/55
Proofs []*PreconfirmationWithProof `json:"proofs"`
}

func (v *VersionedSubmitBlockRequestWithPreconfsProofs) String() string {
func (v *VersionedSubmitBlockRequestWithProofs) String() string {
out, err := json.Marshal(v)
if err != nil {
return err.Error()
Expand Down Expand Up @@ -58,7 +59,7 @@ type HexBytes []byte

// MarshalJSON implements json.Marshaler.
func (h HexBytes) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%#x"`, h)), nil
return []byte(fmt.Sprintf(`"%#x"`, []byte(h))), nil
}

// UnmarshalJSON implements json.Unmarshaler.
Expand All @@ -85,6 +86,10 @@ func (h *HexBytes) UnmarshalJSON(input []byte) error {
return nil
}

func (h HexBytes) String() string {
return JSONStringify(h)
}

// SerializedMerkleProof contains a serialized Merkle proof of transaction inclusion.
// - `Index“ is the generalized index of the included transaction from the SSZ tree
// created from the list of transactions.
Expand Down
8 changes: 8 additions & 0 deletions mev-boost-relay/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,11 @@ func GetBlockSubmissionExecutionPayload(submission *VersionedSubmitBlockRequest)
}
return nil, ErrEmptyPayload
}

func JSONStringify(v interface{}) string {
out, err := json.Marshal(v)
if err != nil {
return err.Error()
}
return string(out)
}
Loading