From b8be1223211457dc79903cd4f6311b5c3042d200 Mon Sep 17 00:00:00 2001 From: Manu NALEPA Date: Wed, 28 Jun 2023 09:14:16 +0200 Subject: [PATCH] Add genesis time for testnets (#540) * Add genesis time for testnets * Remove deprecated Zhejiang testnet * Use `uint64` for genesis times * Add `genesis-timestamp` flag * Remove `switch` specific to genesis time --- README.md | 8 -------- cli/main.go | 44 +++++++++++++++++++++++++++--------------- common/common.go | 1 - config/vars.go | 3 +-- server/service.go | 15 ++++++++------ server/service_test.go | 15 +++++++++++++- 6 files changed, 52 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 77bc71c8..9ecc4b45 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/cli/main.go b/cli/main.go index 761940a7..79a49a19 100644 --- a/cli/main.go +++ b/cli/main.go @@ -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 ( @@ -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 @@ -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()) @@ -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, ",") { @@ -206,6 +217,7 @@ func Main() { Relays: relays, RelayMonitors: relayMonitors, GenesisForkVersionHex: genesisForkVersionHex, + GenesisTime: genesisTime, RelayCheck: *relayCheck, RelayMinBid: *relayMinBidWei, RequestTimeoutGetHeader: time.Duration(*relayTimeoutMsGetHeader) * time.Millisecond, diff --git a/common/common.go b/common/common.go index ffeb812b..c8c0a914 100644 --- a/common/common.go +++ b/common/common.go @@ -9,7 +9,6 @@ import ( ) const ( - GenesisTimeMainnet = 1606824023 SlotTimeSecMainnet = 12 ) diff --git a/config/vars.go b/config/vars.go index e1b2e02e..0130d1c6 100644 --- a/config/vars.go +++ b/config/vars.go @@ -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)) ) diff --git a/server/service.go b/server/service.go index 57693186..14b85073 100644 --- a/server/service.go +++ b/server/service.go @@ -67,6 +67,7 @@ type BoostServiceOpts struct { Relays []RelayEntry RelayMonitors []*url.URL GenesisForkVersionHex string + GenesisTime uint64 RelayCheck bool RelayMinBid types.U256Str @@ -85,6 +86,7 @@ type BoostService struct { srv *http.Server relayCheck bool relayMinBid types.U256Str + genesisTime uint64 builderSigningDomain phase0.Domain httpClientGetHeader http.Client @@ -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{}, @@ -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) @@ -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) diff --git a/server/service_test.go b/server/service_test.go index b38e5773..01bcc9db 100644 --- a/server/service_test.go +++ b/server/service_test.go @@ -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) }) }