From ab7ce641a095d1a37fd1bf6fb4999ec6f9a68ad3 Mon Sep 17 00:00:00 2001 From: owen-eth Date: Tue, 31 Mar 2026 00:10:59 -0400 Subject: [PATCH] perf: reduce bid confidence values --- tools/preconf-rpc/handlers/handlers.go | 6 ++--- tools/preconf-rpc/pricer/pricer.go | 10 ++++--- tools/preconf-rpc/pricer/pricer_test.go | 4 +-- tools/preconf-rpc/sender/sender.go | 10 ++++--- tools/preconf-rpc/sender/sender_test.go | 35 ++++++++++++++----------- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/tools/preconf-rpc/handlers/handlers.go b/tools/preconf-rpc/handlers/handlers.go index 9d518f77b..d3d8fe9cb 100644 --- a/tools/preconf-rpc/handlers/handlers.go +++ b/tools/preconf-rpc/handlers/handlers.go @@ -230,7 +230,7 @@ func (h *rpcMethodHandler) RegisterMethods(server *rpcserver.JSONRPCServer) { func getNextBlockPrice(blockPrices map[int64]float64) *big.Int { for confidence, price := range blockPrices { - if confidence == 99 { + if confidence == 85 { priceInWei := price * 1e9 // Convert Gwei to Wei return new(big.Int).Mul(new(big.Int).SetUint64(uint64(priceInWei)), big.NewInt(21000)) } @@ -244,11 +244,11 @@ func getMinMaxPrice(blockPrices map[int64]float64) (*big.Int, *big.Int) { maxPrice := big.NewInt(0) for confidence, price := range blockPrices { - if confidence == 90 { + if confidence == 70 { minPriceInWei := price * 1e9 // Convert Gwei to Wei minPrice = new(big.Int).SetUint64(uint64(minPriceInWei)) } - if confidence == 99 { + if confidence == 85 { maxPriceInWei := price * 1e9 // Convert Gwei to Wei maxPrice = new(big.Int).SetUint64(uint64(maxPriceInWei)) } diff --git a/tools/preconf-rpc/pricer/pricer.go b/tools/preconf-rpc/pricer/pricer.go index c45c21141..07e3dc5f0 100644 --- a/tools/preconf-rpc/pricer/pricer.go +++ b/tools/preconf-rpc/pricer/pricer.go @@ -14,7 +14,7 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -var apiURL = "https://api.blocknative.com/gasprices/blockprices?chainid=1" +var apiURL = "https://api.blocknative.com/gasprices/blockprices?chainid=1&confidenceLevels=70,75,80,85" type EstimatedPrice struct { Confidence int `json:"confidence"` @@ -142,11 +142,13 @@ func (b *BidPricer) syncEstimate(ctx context.Context) error { b.mu.Lock() for _, estimatedPrice := range price.EstimatedPrices { switch estimatedPrice.Confidence { - case 90: + case 70: b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei - case 95: + case 75: b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei - case 99: + case 80: + b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei + case 85: b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei } b.metrics.bidPrices.WithLabelValues(fmt.Sprintf("%d", estimatedPrice.Confidence)).Set(estimatedPrice.PriorityFeePerGasGwei) diff --git a/tools/preconf-rpc/pricer/pricer_test.go b/tools/preconf-rpc/pricer/pricer_test.go index 4b43613de..a795f36a4 100644 --- a/tools/preconf-rpc/pricer/pricer_test.go +++ b/tools/preconf-rpc/pricer/pricer_test.go @@ -22,8 +22,8 @@ func TestEstimatePrice(t *testing.T) { prices := bp.EstimatePrice(ctx) - if len(prices) != 3 { - t.Fatalf("expected 3 confidence levels, got %d", len(prices)) + if len(prices) != 4 { + t.Fatalf("expected 4 confidence levels, got %d", len(prices)) } for confidence, price := range prices { diff --git a/tools/preconf-rpc/sender/sender.go b/tools/preconf-rpc/sender/sender.go index 6ef8f3dc6..be10be9c7 100644 --- a/tools/preconf-rpc/sender/sender.go +++ b/tools/preconf-rpc/sender/sender.go @@ -48,9 +48,10 @@ const ( const ( blockTime = 12 // seconds, typical Ethereum block time bidTimeout = 3 * time.Second // timeout for bid operation - defaultConfidence = 90 // default confidence level for the next block - confidenceSecondAttempt = 95 // confidence level for the second attempt - confidenceSubsequentAttempts = 99 // confidence level for subsequent attempts + defaultConfidence = 75 // default confidence level for the next block + defaultSwapConfidence = 70 // default confidence level for fastswap transactions + confidenceSecondAttempt = 80 // confidence level for the second attempt + confidenceSubsequentAttempts = 85 // confidence level for subsequent attempts transactionTimeout = 10 * time.Minute // timeout for transaction processing maxAttemptsPerBlock = 10 // maximum attempts per block defaultRetryDelay = 500 * time.Millisecond @@ -1083,6 +1084,9 @@ func (t *TxSender) calculatePriceForNextBlock( // default confidence level for the next block confidence := defaultConfidence + if txn.Type == TxTypeFastSwap { + confidence = defaultSwapConfidence + } isRetry := false for i := len(attempts.attempts) - 1; i >= 0; i-- { diff --git a/tools/preconf-rpc/sender/sender_test.go b/tools/preconf-rpc/sender/sender_test.go index 9a6e0ebe9..ee79128e1 100644 --- a/tools/preconf-rpc/sender/sender_test.go +++ b/tools/preconf-rpc/sender/sender_test.go @@ -396,9 +396,10 @@ func TestSender(t *testing.T) { // Simulate a price estimate testPricer.out <- map[int64]float64{ - 90: 1.0, - 95: 1.5, - 99: 2.0, + 70: 0.8, + 75: 1.0, + 80: 1.5, + 85: 2.0, } // Simulate transaction inclusion @@ -486,9 +487,10 @@ func TestSender(t *testing.T) { // Simulate a price estimate testPricer.out <- map[int64]float64{ - 90: 1.0, - 95: 1.5, - 99: 2.0, + 70: 0.8, + 75: 1.0, + 80: 1.5, + 85: 2.0, } // Simulate a bid response @@ -512,9 +514,10 @@ func TestSender(t *testing.T) { // Simulate a price estimate testPricer.out <- map[int64]float64{ - 90: 1.0, - 95: 1.5, - 99: 2.0, + 70: 0.8, + 75: 1.0, + 80: 1.5, + 85: 2.0, } // Simulate transaction inclusion @@ -735,9 +738,10 @@ func TestIgnoreProvidersOnRetry(t *testing.T) { // Simulate a price estimate testPricer.out <- map[int64]float64{ - 90: 1.0, - 95: 1.5, - 99: 2.0, + 70: 0.8, + 75: 1.0, + 80: 1.5, + 85: 2.0, } // Simulate a bid response @@ -769,9 +773,10 @@ func TestIgnoreProvidersOnRetry(t *testing.T) { // Simulate a price estimate testPricer.out <- map[int64]float64{ - 90: 1.0, - 95: 1.5, - 99: 2.0, + 70: 0.8, + 75: 1.0, + 80: 1.5, + 85: 2.0, } bidOp = <-bidderImpl.in