Skip to content

Commit 5767f05

Browse files
authored
Add feature flags for backwards compatibility (#521)
* Add feature flags for backwards compatibility * improve readability of flags * renaming flags * remove fork schedule checks and flag
1 parent 419c778 commit 5767f05

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ redis-cli DEL boost-relay/sepolia:validators-registration boost-relay/sepolia:va
152152
* `DISABLE_LOWPRIO_BUILDERS` - reject block submissions by low-prio builders
153153
* `FORCE_GET_HEADER_204` - force 204 as getHeader response
154154
* `ENABLE_IGNORABLE_VALIDATION_ERRORS` - enable ignorable validation errors
155+
* `USE_V2_PUBLISH_BLOCK_ENDPOINT` - uses the v2 publish block endpoint on the beacon node
155156

156157
#### Development Environment Variables
157158

beaconclient/prod_beacon_instance.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"os"
78
"time"
89

910
"github.com/attestantio/go-eth2-client/spec/capella"
@@ -16,14 +17,26 @@ import (
1617
type ProdBeaconInstance struct {
1718
log *logrus.Entry
1819
beaconURI string
20+
21+
// feature flags
22+
ffUseV2PublishBlockEndpoint bool
1923
}
2024

2125
func NewProdBeaconInstance(log *logrus.Entry, beaconURI string) *ProdBeaconInstance {
2226
_log := log.WithFields(logrus.Fields{
2327
"component": "beaconInstance",
2428
"beaconURI": beaconURI,
2529
})
26-
return &ProdBeaconInstance{_log, beaconURI}
30+
31+
client := &ProdBeaconInstance{_log, beaconURI, false}
32+
33+
// feature flags
34+
if os.Getenv("USE_V2_PUBLISH_BLOCK_ENDPOINT") != "" {
35+
_log.Warn("env: USE_V2_PUBLISH_BLOCK_ENDPOINT: use the v2 publish block endpoint")
36+
client.ffUseV2PublishBlockEndpoint = true
37+
}
38+
39+
return client
2740
}
2841

2942
// HeadEventData represents the data of a head event
@@ -257,9 +270,14 @@ func (c *ProdBeaconInstance) GetURI() string {
257270
}
258271

259272
func (c *ProdBeaconInstance) PublishBlock(block *common.SignedBeaconBlock, broadcastMode BroadcastMode) (code int, err error) {
260-
uri := fmt.Sprintf("%s/eth/v2/beacon/blocks?broadcast_validation=%s", c.beaconURI, broadcastMode.String())
273+
var uri string
274+
if c.ffUseV2PublishBlockEndpoint {
275+
uri = fmt.Sprintf("%s/eth/v2/beacon/blocks?broadcast_validation=%s", c.beaconURI, broadcastMode.String())
276+
} else {
277+
uri = fmt.Sprintf("%s/eth/v1/beacon/blocks", c.beaconURI)
278+
}
261279
headers := http.Header{}
262-
headers.Add("Eth-Consensus-Version", common.ForkVersionStringCapella)
280+
headers.Add("Eth-Consensus-Version", common.ForkVersionStringCapella) // optional in v1, required in v2
263281
return fetchBeacon(http.MethodPost, uri, block, nil, nil, headers)
264282
}
265283

services/api/service.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ var (
5353
ErrRelayPubkeyMismatch = errors.New("relay pubkey does not match existing one")
5454
ErrServerAlreadyStarted = errors.New("server was already started")
5555
ErrBuilderAPIWithoutSecretKey = errors.New("cannot start builder API without secret key")
56-
ErrMismatchedForkVersions = errors.New("can not find matching fork versions as retrieved from beacon node")
57-
ErrMissingForkVersions = errors.New("invalid fork version from beacon node")
5856
)
5957

6058
var (
@@ -408,6 +406,7 @@ func (api *RelayAPI) StartServer() (err error) {
408406
if err != nil {
409407
return err
410408
}
409+
411410
var foundCapellaEpoch, foundDenebEpoch bool
412411
for _, fork := range forkSchedule.Data {
413412
log.Infof("forkSchedule: version=%s / epoch=%d", fork.CurrentVersion, fork.Epoch)
@@ -421,14 +420,10 @@ func (api *RelayAPI) StartServer() (err error) {
421420
}
422421
}
423422

424-
if !foundCapellaEpoch || !foundDenebEpoch {
425-
return ErrMissingForkVersions
426-
}
427-
428423
// Print fork version information
429-
if hasReachedFork(currentSlot, api.denebEpoch) {
424+
if foundDenebEpoch && hasReachedFork(currentSlot, api.denebEpoch) {
430425
log.Infof("deneb fork detected (currentEpoch: %d / denebEpoch: %d)", common.SlotToEpoch(currentSlot), api.denebEpoch)
431-
} else if hasReachedFork(currentSlot, api.capellaEpoch) {
426+
} else if foundCapellaEpoch && hasReachedFork(currentSlot, api.capellaEpoch) {
432427
log.Infof("capella fork detected (currentEpoch: %d / capellaEpoch: %d)", common.SlotToEpoch(currentSlot), api.capellaEpoch)
433428
}
434429

0 commit comments

Comments
 (0)