Skip to content

Commit

Permalink
Use proper value for register validator preferences
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Georges Francois <luca.georges-francois@epitech.eu>
  • Loading branch information
0xpanoramix committed Jun 14, 2022
1 parent 616013f commit e1d6572
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/mev-boost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func main() {

relayTimeout := time.Duration(*relayTimeoutMs) * time.Millisecond
registerValidatorInterval := time.Duration(*registerValidatorIntervalSec) * time.Second
server, err := server.NewBoostService(*listenAddr, relays, log, genesisForkVersionHex, relayTimeout, registerValidatorInterval)
server, err := server.NewBoostService(*listenAddr, relays, log, genesisForkVersionHex, relayTimeout)
if err != nil {
log.WithError(err).Fatal("failed creating the server")
}

log.Println("listening on", *listenAddr)
log.Fatal(server.StartServer())
log.Fatal(server.StartServer(registerValidatorInterval))
}

func getEnv(key string, defaultValue string) string {
Expand Down
6 changes: 3 additions & 3 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type BoostService struct {
}

// NewBoostService created a new BoostService
func NewBoostService(listenAddr string, relays []RelayEntry, log *logrus.Entry, genesisForkVersionHex string, relayRequestTimeout, validatorPreferencesResendInterval time.Duration) (*BoostService, error) {
func NewBoostService(listenAddr string, relays []RelayEntry, log *logrus.Entry, genesisForkVersionHex string, relayRequestTimeout time.Duration) (*BoostService, error) {
if len(relays) == 0 {
return nil, errors.New("no relays")
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func (m *BoostService) getRouter() http.Handler {
}

// StartServer starts the HTTP server for this boost service instance
func (m *BoostService) StartServer() error {
func (m *BoostService) StartServer(registerValidatorInterval time.Duration) error {
if m.srv != nil {
return errServerAlreadyRunning
}
Expand All @@ -123,7 +123,7 @@ func (m *BoostService) StartServer() error {
}

// Start separate process to send validator preferences at regular interval.
go m.registerValidatorAtInterval(time.Second*384, m.done)
go m.registerValidatorAtInterval(registerValidatorInterval, m.done)
defer m.shutdown()

err := m.srv.ListenAndServe()
Expand Down
10 changes: 4 additions & 6 deletions server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func newTestBackend(t *testing.T, numRelays int, relayTimeout time.Duration) *te
relayEntries[i] = backend.relays[i].RelayEntry
}

registerValidatorInterval := time.Second * 5

service, err := NewBoostService("localhost:12345", relayEntries, testLog, "0x00000000", relayTimeout, registerValidatorInterval)
service, err := NewBoostService("localhost:12345", relayEntries, testLog, "0x00000000", relayTimeout)
require.NoError(t, err)

go service.registerValidatorAtInterval(time.Second*384, service.done)
Expand Down Expand Up @@ -68,7 +66,7 @@ func (be *testBackend) request(t *testing.T, method string, path string, payload

func TestNewBoostServiceErrors(t *testing.T) {
t.Run("errors when no relays", func(t *testing.T) {
_, err := NewBoostService(":123", []RelayEntry{}, testLog, "0x00000000", time.Second, time.Second)
_, err := NewBoostService(":123", []RelayEntry{}, testLog, "0x00000000", time.Second)
require.Error(t, err)
})
}
Expand All @@ -79,7 +77,7 @@ func TestWebserver(t *testing.T) {
defer backend.boost.shutdown()

backend.boost.srv = &http.Server{}
err := backend.boost.StartServer()
err := backend.boost.StartServer(time.Second * 384)
require.Error(t, err)
})

Expand All @@ -88,7 +86,7 @@ func TestWebserver(t *testing.T) {
defer backend.boost.shutdown()

backend.boost.listenAddr = "localhost:876543"
err := backend.boost.StartServer()
err := backend.boost.StartServer(time.Second * 384)
require.Error(t, err)
})

Expand Down

0 comments on commit e1d6572

Please sign in to comment.