Skip to content

Commit

Permalink
Add genesis time for testnets (#540)
Browse files Browse the repository at this point in the history
* Add genesis time for testnets

* Remove deprecated Zhejiang testnet

* Use `uint64` for genesis times

* Add `genesis-timestamp` flag

* Remove `switch` specific to genesis time
  • Loading branch information
nalepae authored Jun 28, 2023
1 parent 3c26cd7 commit b8be122
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,6 @@ Run MEV-Boost pointed at a Sepolia relay:
./mev-boost -sepolia -relay-check -relay URL-OF-TRUSTED-RELAY
```

## Zhejiang testnet

Run MEV-Boost pointed at a Zhejiang relay:

```
./mev-boost -zhejiang -relay-check -relay URL-OF-TRUSTED-RELAY
```

## `test-cli`

`test-cli` is a utility to execute all proposer requests against MEV-Boost + relay. See also the [test-cli readme](cmd/test-cli/README.md).
Expand Down
44 changes: 28 additions & 16 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import (
)

const (
genesisForkVersionMainnet = "0x00000000"
genesisForkVersionSepolia = "0x90000069"
genesisForkVersionGoerli = "0x00001020"
genesisForkVersionZhejiang = "0x00000069"
genesisForkVersionMainnet = "0x00000000"
genesisForkVersionSepolia = "0x90000069"
genesisForkVersionGoerli = "0x00001020"

genesisTimeMainnet uint64 = 1606824023
genesisTimeSepolia uint64 = 1655733600
genesisTimeGoerli uint64 = 1614588812
)

var (
Expand All @@ -35,9 +38,9 @@ var (
defaultMaxRetries = common.GetEnvInt("REQUEST_MAX_RETRIES", 5)

defaultGenesisForkVersion = common.GetEnv("GENESIS_FORK_VERSION", "")
defaultGenesisTime = common.GetEnvInt("GENESIS_TIMESTAMP", -1)
defaultUseSepolia = os.Getenv("SEPOLIA") != ""
defaultUseGoerli = os.Getenv("GOERLI") != ""
defaultUseZhejiang = os.Getenv("ZHEJIANG") != ""

// mev-boost relay request timeouts (see also https://github.com/flashbots/mev-boost/issues/287)
defaultTimeoutMsGetHeader = common.GetEnvInt("RELAY_TIMEOUT_MS_GETHEADER", 950) // timeout for getHeader requests
Expand Down Expand Up @@ -68,11 +71,12 @@ var (
relayRequestMaxRetries = flag.Int("request-max-retries", defaultMaxRetries, "maximum number of retries for a relay get payload request")

// helpers
useGenesisForkVersionMainnet = flag.Bool("mainnet", true, "use Mainnet")
useGenesisForkVersionSepolia = flag.Bool("sepolia", defaultUseSepolia, "use Sepolia")
useGenesisForkVersionGoerli = flag.Bool("goerli", defaultUseGoerli, "use Goerli")
useGenesisForkVersionZhejiang = flag.Bool("zhejiang", defaultUseZhejiang, "use Zhejiang")
useCustomGenesisForkVersion = flag.String("genesis-fork-version", defaultGenesisForkVersion, "use a custom genesis fork version")
mainnet = flag.Bool("mainnet", true, "use Mainnet")
sepolia = flag.Bool("sepolia", defaultUseSepolia, "use Sepolia")
goerli = flag.Bool("goerli", defaultUseGoerli, "use Goerli")

useCustomGenesisForkVersion = flag.String("genesis-fork-version", defaultGenesisForkVersion, "use a custom genesis fork version")
useCustomGenesisTime = flag.Int("genesis-timestamp", defaultGenesisTime, "use a custom genesis timestamp (unix seconds)")
)

var log = logrus.NewEntry(logrus.New())
Expand Down Expand Up @@ -130,23 +134,30 @@ func Main() {
log.Debug("debug logging enabled")

genesisForkVersionHex := ""
var genesisTime uint64

switch {
case *useCustomGenesisForkVersion != "":
genesisForkVersionHex = *useCustomGenesisForkVersion
case *useGenesisForkVersionSepolia:
case *sepolia:
genesisForkVersionHex = genesisForkVersionSepolia
case *useGenesisForkVersionGoerli:
genesisTime = genesisTimeSepolia
case *goerli:
genesisForkVersionHex = genesisForkVersionGoerli
case *useGenesisForkVersionZhejiang:
genesisForkVersionHex = genesisForkVersionZhejiang
case *useGenesisForkVersionMainnet:
genesisTime = genesisTimeGoerli
case *mainnet:
genesisForkVersionHex = genesisForkVersionMainnet
genesisTime = genesisTimeMainnet
default:
flag.Usage()
log.Fatal("please specify a genesis fork version (eg. -mainnet / -sepolia / -goerli / -zhejiang / -genesis-fork-version flags)")
log.Fatal("please specify a genesis fork version (eg. -mainnet / -sepolia / -goerli / -genesis-fork-version flags)")
}
log.Infof("using genesis fork version: %s", genesisForkVersionHex)

if *useCustomGenesisTime > -1 {
genesisTime = uint64(*useCustomGenesisTime)
}

// For backwards compatibility with the -relays flag.
if *relayURLs != "" {
for _, relayURL := range strings.Split(*relayURLs, ",") {
Expand Down Expand Up @@ -206,6 +217,7 @@ func Main() {
Relays: relays,
RelayMonitors: relayMonitors,
GenesisForkVersionHex: genesisForkVersionHex,
GenesisTime: genesisTime,
RelayCheck: *relayCheck,
RelayMinBid: *relayMinBidWei,
RequestTimeoutGetHeader: time.Duration(*relayTimeoutMsGetHeader) * time.Millisecond,
Expand Down
1 change: 0 additions & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

const (
GenesisTimeMainnet = 1606824023
SlotTimeSecMainnet = 12
)

Expand Down
3 changes: 1 addition & 2 deletions config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ var (
// SkipRelaySignatureCheck can be used to disable relay signature check
SkipRelaySignatureCheck = os.Getenv("SKIP_RELAY_SIGNATURE_CHECK") == "1"

GenesisTime = int64(common.GetEnvInt("GENESIS_TIMESTAMP", common.GenesisTimeMainnet))
SlotTimeSec = int64(common.GetEnvInt("SLOT_SEC", common.SlotTimeSecMainnet))
SlotTimeSec = uint64(common.GetEnvInt("SLOT_SEC", common.SlotTimeSecMainnet))
)
15 changes: 9 additions & 6 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type BoostServiceOpts struct {
Relays []RelayEntry
RelayMonitors []*url.URL
GenesisForkVersionHex string
GenesisTime uint64
RelayCheck bool
RelayMinBid types.U256Str

Expand All @@ -85,6 +86,7 @@ type BoostService struct {
srv *http.Server
relayCheck bool
relayMinBid types.U256Str
genesisTime uint64

builderSigningDomain phase0.Domain
httpClientGetHeader http.Client
Expand Down Expand Up @@ -117,6 +119,7 @@ func NewBoostService(opts BoostServiceOpts) (*BoostService, error) {
log: opts.Log,
relayCheck: opts.RelayCheck,
relayMinBid: opts.RelayMinBid,
genesisTime: opts.GenesisTime,
bids: make(map[bidRespKey]bidResp),
slotUID: &slotUID{},

Expand Down Expand Up @@ -347,10 +350,10 @@ func (m *BoostService) handleGetHeader(w http.ResponseWriter, req *http.Request)
log = log.WithField("slotUID", slotUID)

// Log how late into the slot the request starts
slotStartTimestamp := config.GenesisTime + (int64(_slot) * config.SlotTimeSec)
msIntoSlot := time.Now().UTC().UnixMilli() - (slotStartTimestamp * 1000)
slotStartTimestamp := m.genesisTime + _slot*config.SlotTimeSec
msIntoSlot := uint64(time.Now().UTC().UnixMilli()) - slotStartTimestamp*1000
log.WithFields(logrus.Fields{
"genesisTime": config.GenesisTime,
"genesisTime": m.genesisTime,
"slotTimeSec": config.SlotTimeSec,
"msIntoSlot": msIntoSlot,
}).Infof("getHeader request start - %d milliseconds into slot %d", msIntoSlot, _slot)
Expand Down Expand Up @@ -537,10 +540,10 @@ func (m *BoostService) processCapellaPayload(w http.ResponseWriter, req *http.Re
})

// Log how late into the slot the request starts
slotStartTimestamp := config.GenesisTime + (int64(payload.Message.Slot) * config.SlotTimeSec)
msIntoSlot := time.Now().UTC().UnixMilli() - (slotStartTimestamp * 1000)
slotStartTimestamp := m.genesisTime + uint64(payload.Message.Slot)*config.SlotTimeSec
msIntoSlot := uint64(time.Now().UTC().UnixMilli()) - slotStartTimestamp*1000
log.WithFields(logrus.Fields{
"genesisTime": config.GenesisTime,
"genesisTime": m.genesisTime,
"slotTimeSec": config.SlotTimeSec,
"msIntoSlot": msIntoSlot,
}).Infof("submitBlindedBlock request start - %d milliseconds into slot %d", msIntoSlot, payload.Message.Slot)
Expand Down
15 changes: 14 additions & 1 deletion server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,20 @@ func blindedBlockToExecutionPayloadCapella(signedBlindedBeaconBlock *apiv1capell

func TestNewBoostServiceErrors(t *testing.T) {
t.Run("errors when no relays", func(t *testing.T) {
_, err := NewBoostService(BoostServiceOpts{testLog, ":123", []RelayEntry{}, []*url.URL{}, "0x00000000", true, types.IntToU256(0), time.Second, time.Second, time.Second, 1})
_, err := NewBoostService(BoostServiceOpts{
Log: testLog,
ListenAddr: ":123",
Relays: []RelayEntry{},
RelayMonitors: []*url.URL{},
GenesisForkVersionHex: "0x00000000",
GenesisTime: 0,
RelayCheck: true,
RelayMinBid: types.IntToU256(0),
RequestTimeoutGetHeader: time.Second,
RequestTimeoutGetPayload: time.Second,
RequestTimeoutRegVal: time.Second,
RequestMaxRetries: 1,
})
require.Error(t, err)
})
}
Expand Down

0 comments on commit b8be122

Please sign in to comment.