From d711571a68c44b5a0d3aa953f78c673ee9072a79 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 2 Apr 2024 22:25:35 +0200 Subject: [PATCH 1/5] cli: refactor sanitizeMinBid --- cli/main.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cli/main.go b/cli/main.go index de5e93f9..9005e79f 100644 --- a/cli/main.go +++ b/cli/main.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/flashbots/go-boost-utils/types" "github.com/flashbots/mev-boost/common" "github.com/flashbots/mev-boost/config" "github.com/flashbots/mev-boost/server" @@ -174,21 +175,9 @@ func Main() { } } - if *relayMinBidEth < 0.0 { - log.Fatal("Please specify a non-negative minimum bid") - } - - if *relayMinBidEth > 1000000.0 { - log.Fatal("Minimum bid is too large, please ensure min-bid is denominated in Ethers") - } - - if *relayMinBidEth > 0.0 { - log.Infof("minimum bid: %v eth", *relayMinBidEth) - } - - relayMinBidWei, err := common.FloatEthTo256Wei(*relayMinBidEth) + relayMinBidWei, err := sanitizeMinBid(*relayMinBidEth) if err != nil { - log.WithError(err).Fatal("failed converting min bid") + log.WithError(err).Fatal("failed sanitizing min bid") } opts := server.BoostServiceOpts{ @@ -256,3 +245,16 @@ func setupLogging() error { log.Debug("debug logging enabled") return nil } + +func sanitizeMinBid(minBid float64) (*types.U256Str, error) { + if minBid < 0.0 { + log.Fatal("Please specify a non-negative minimum bid") + } + if minBid > 1000000.0 { + log.Fatal("Minimum bid is too large, please ensure min-bid is denominated in Ethers") + } + if minBid > 0.0 { + log.Infof("Minimum bid: %v eth", minBid) + } + return common.FloatEthTo256Wei(minBid) +} From aa5a3b22d4d491a26202aac1d6b51935bd0519ec Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 2 Apr 2024 23:29:00 +0200 Subject: [PATCH 2/5] cli: return error --- cli/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/main.go b/cli/main.go index 9005e79f..5471fbac 100644 --- a/cli/main.go +++ b/cli/main.go @@ -177,7 +177,7 @@ func Main() { relayMinBidWei, err := sanitizeMinBid(*relayMinBidEth) if err != nil { - log.WithError(err).Fatal("failed sanitizing min bid") + log.WithError(err).Fatal("Failed sanitizing min bid") } opts := server.BoostServiceOpts{ @@ -248,10 +248,10 @@ func setupLogging() error { func sanitizeMinBid(minBid float64) (*types.U256Str, error) { if minBid < 0.0 { - log.Fatal("Please specify a non-negative minimum bid") + return nil, errors.New("please specify a non-negative minimum bid") } if minBid > 1000000.0 { - log.Fatal("Minimum bid is too large, please ensure min-bid is denominated in Ethers") + return nil, errors.New("minimum bid is too large, please ensure min-bid is denominated in Ethers") } if minBid > 0.0 { log.Infof("Minimum bid: %v eth", minBid) From 3dad82635f9b95cc59872e4a546b98dfc37b7563 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 3 Apr 2024 00:58:29 +0200 Subject: [PATCH 3/5] cli: log min bid --- cli/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/main.go b/cli/main.go index 5471fbac..9a8ec063 100644 --- a/cli/main.go +++ b/cli/main.go @@ -179,6 +179,9 @@ func Main() { if err != nil { log.WithError(err).Fatal("Failed sanitizing min bid") } + if relayMinBidWei.BigInt().Sign() > 0 { + log.Infof("Min bid set to %v wei", relayMinBidWei) + } opts := server.BoostServiceOpts{ Log: log, @@ -253,8 +256,5 @@ func sanitizeMinBid(minBid float64) (*types.U256Str, error) { if minBid > 1000000.0 { return nil, errors.New("minimum bid is too large, please ensure min-bid is denominated in Ethers") } - if minBid > 0.0 { - log.Infof("Minimum bid: %v eth", minBid) - } return common.FloatEthTo256Wei(minBid) } From 809944546ccbce13b574e72dd04494edb13878a6 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 3 Apr 2024 08:43:38 +0200 Subject: [PATCH 4/5] cli: happy lint, happy life --- cli/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/main.go b/cli/main.go index 9a8ec063..2865a41a 100644 --- a/cli/main.go +++ b/cli/main.go @@ -249,12 +249,17 @@ func setupLogging() error { return nil } +var ( + errNegativeBid = errors.New("please specify a non-negative minimum bid") + errLargeMinBid = errors.New("minimum bid is too large, please ensure min-bid is denominated in Ethers") +) + func sanitizeMinBid(minBid float64) (*types.U256Str, error) { if minBid < 0.0 { - return nil, errors.New("please specify a non-negative minimum bid") + return nil, errNegativeBid } if minBid > 1000000.0 { - return nil, errors.New("minimum bid is too large, please ensure min-bid is denominated in Ethers") + return nil, errLargeMinBid } return common.FloatEthTo256Wei(minBid) } From ec74c6b1ba826b9f9f2a7990bb5b14f6a8dbca12 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 3 Apr 2024 16:03:28 +0200 Subject: [PATCH 5/5] cli: better log --- cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/main.go b/cli/main.go index 2865a41a..cc16b1bb 100644 --- a/cli/main.go +++ b/cli/main.go @@ -180,7 +180,7 @@ func Main() { log.WithError(err).Fatal("Failed sanitizing min bid") } if relayMinBidWei.BigInt().Sign() > 0 { - log.Infof("Min bid set to %v wei", relayMinBidWei) + log.Infof("Min bid set to %v eth (%v wei)", relayMinBidEth, relayMinBidWei) } opts := server.BoostServiceOpts{