Skip to content

Commit

Permalink
use v2 publish endpoint by default
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Oct 27, 2023
1 parent 716165c commit 46330e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ redis-cli DEL boost-relay/sepolia:validators-registration boost-relay/sepolia:va
* `DISABLE_LOWPRIO_BUILDERS` - reject block submissions by low-prio builders
* `FORCE_GET_HEADER_204` - force 204 as getHeader response
* `ENABLE_IGNORABLE_VALIDATION_ERRORS` - enable ignorable validation errors
* `USE_V2_PUBLISH_BLOCK_ENDPOINT` - uses the v2 publish block endpoint on the beacon node
* `USE_V1_PUBLISH_BLOCK_ENDPOINT` - uses the v1 publish block endpoint on the beacon node

#### Development Environment Variables

Expand Down
20 changes: 12 additions & 8 deletions beaconclient/prod_beacon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ProdBeaconInstance struct {
beaconURI string

// feature flags
ffUseV2PublishBlockEndpoint bool
ffUseV1PublishBlockEndpoint bool
}

func NewProdBeaconInstance(log *logrus.Entry, beaconURI string) *ProdBeaconInstance {
Expand All @@ -30,9 +30,9 @@ func NewProdBeaconInstance(log *logrus.Entry, beaconURI string) *ProdBeaconInsta
client := &ProdBeaconInstance{_log, beaconURI, false}

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

return client
Expand Down Expand Up @@ -274,12 +274,16 @@ func (c *ProdBeaconInstance) PublishBlock(block *common.VersionedSignedBlockRequ
headers := http.Header{}
headers.Add("Eth-Consensus-Version", block.Version.String()) // optional in v1, required in v2

if c.ffUseV2PublishBlockEndpoint {
uri = fmt.Sprintf("%s/eth/v2/beacon/blocks?broadcast_validation=%s", c.beaconURI, broadcastMode.String())
return fetchBeacon(http.MethodPost, uri, block, nil, nil, headers, true)
} else {
if c.ffUseV1PublishBlockEndpoint {
uri = fmt.Sprintf("%s/eth/v1/beacon/blocks", c.beaconURI)
return fetchBeacon(http.MethodPost, uri, block, nil, nil, headers, false)
} else {
blockSSZ, err := block.MarshalSSZ()
if err != nil {
return 0, fmt.Errorf("could not marshal block to SSZ: %w", err)
}
uri = fmt.Sprintf("%s/eth/v2/beacon/blocks?broadcast_validation=%s", c.beaconURI, broadcastMode.String())
return fetchBeacon(http.MethodPost, uri, blockSSZ, nil, nil, headers, true)
}
}

Expand Down

0 comments on commit 46330e6

Please sign in to comment.