Skip to content

Commit cdf90a7

Browse files
authored
perf: reduce bid confidence values (#912)
1 parent 1b76d6b commit cdf90a7

File tree

5 files changed

+38
-27
lines changed

5 files changed

+38
-27
lines changed

tools/preconf-rpc/handlers/handlers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (h *rpcMethodHandler) RegisterMethods(server *rpcserver.JSONRPCServer) {
230230

231231
func getNextBlockPrice(blockPrices map[int64]float64) *big.Int {
232232
for confidence, price := range blockPrices {
233-
if confidence == 99 {
233+
if confidence == 85 {
234234
priceInWei := price * 1e9 // Convert Gwei to Wei
235235
return new(big.Int).Mul(new(big.Int).SetUint64(uint64(priceInWei)), big.NewInt(21000))
236236
}
@@ -244,11 +244,11 @@ func getMinMaxPrice(blockPrices map[int64]float64) (*big.Int, *big.Int) {
244244
maxPrice := big.NewInt(0)
245245

246246
for confidence, price := range blockPrices {
247-
if confidence == 90 {
247+
if confidence == 70 {
248248
minPriceInWei := price * 1e9 // Convert Gwei to Wei
249249
minPrice = new(big.Int).SetUint64(uint64(minPriceInWei))
250250
}
251-
if confidence == 99 {
251+
if confidence == 85 {
252252
maxPriceInWei := price * 1e9 // Convert Gwei to Wei
253253
maxPrice = new(big.Int).SetUint64(uint64(maxPriceInWei))
254254
}

tools/preconf-rpc/pricer/pricer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/prometheus/client_golang/prometheus"
1515
)
1616

17-
var apiURL = "https://api.blocknative.com/gasprices/blockprices?chainid=1"
17+
var apiURL = "https://api.blocknative.com/gasprices/blockprices?chainid=1&confidenceLevels=70,75,80,85"
1818

1919
type EstimatedPrice struct {
2020
Confidence int `json:"confidence"`
@@ -142,11 +142,13 @@ func (b *BidPricer) syncEstimate(ctx context.Context) error {
142142
b.mu.Lock()
143143
for _, estimatedPrice := range price.EstimatedPrices {
144144
switch estimatedPrice.Confidence {
145-
case 90:
145+
case 70:
146146
b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei
147-
case 95:
147+
case 75:
148148
b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei
149-
case 99:
149+
case 80:
150+
b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei
151+
case 85:
150152
b.currentEstimates[int64(estimatedPrice.Confidence)] = estimatedPrice.PriorityFeePerGasGwei
151153
}
152154
b.metrics.bidPrices.WithLabelValues(fmt.Sprintf("%d", estimatedPrice.Confidence)).Set(estimatedPrice.PriorityFeePerGasGwei)

tools/preconf-rpc/pricer/pricer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func TestEstimatePrice(t *testing.T) {
2222

2323
prices := bp.EstimatePrice(ctx)
2424

25-
if len(prices) != 3 {
26-
t.Fatalf("expected 3 confidence levels, got %d", len(prices))
25+
if len(prices) != 4 {
26+
t.Fatalf("expected 4 confidence levels, got %d", len(prices))
2727
}
2828

2929
for confidence, price := range prices {

tools/preconf-rpc/sender/sender.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ const (
4848
const (
4949
blockTime = 12 // seconds, typical Ethereum block time
5050
bidTimeout = 3 * time.Second // timeout for bid operation
51-
defaultConfidence = 90 // default confidence level for the next block
52-
confidenceSecondAttempt = 95 // confidence level for the second attempt
53-
confidenceSubsequentAttempts = 99 // confidence level for subsequent attempts
51+
defaultConfidence = 75 // default confidence level for the next block
52+
defaultSwapConfidence = 70 // default confidence level for fastswap transactions
53+
confidenceSecondAttempt = 80 // confidence level for the second attempt
54+
confidenceSubsequentAttempts = 85 // confidence level for subsequent attempts
5455
transactionTimeout = 10 * time.Minute // timeout for transaction processing
5556
maxAttemptsPerBlock = 10 // maximum attempts per block
5657
defaultRetryDelay = 500 * time.Millisecond
@@ -1083,6 +1084,9 @@ func (t *TxSender) calculatePriceForNextBlock(
10831084

10841085
// default confidence level for the next block
10851086
confidence := defaultConfidence
1087+
if txn.Type == TxTypeFastSwap {
1088+
confidence = defaultSwapConfidence
1089+
}
10861090
isRetry := false
10871091

10881092
for i := len(attempts.attempts) - 1; i >= 0; i-- {

tools/preconf-rpc/sender/sender_test.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,10 @@ func TestSender(t *testing.T) {
396396

397397
// Simulate a price estimate
398398
testPricer.out <- map[int64]float64{
399-
90: 1.0,
400-
95: 1.5,
401-
99: 2.0,
399+
70: 0.8,
400+
75: 1.0,
401+
80: 1.5,
402+
85: 2.0,
402403
}
403404

404405
// Simulate transaction inclusion
@@ -486,9 +487,10 @@ func TestSender(t *testing.T) {
486487

487488
// Simulate a price estimate
488489
testPricer.out <- map[int64]float64{
489-
90: 1.0,
490-
95: 1.5,
491-
99: 2.0,
490+
70: 0.8,
491+
75: 1.0,
492+
80: 1.5,
493+
85: 2.0,
492494
}
493495

494496
// Simulate a bid response
@@ -512,9 +514,10 @@ func TestSender(t *testing.T) {
512514

513515
// Simulate a price estimate
514516
testPricer.out <- map[int64]float64{
515-
90: 1.0,
516-
95: 1.5,
517-
99: 2.0,
517+
70: 0.8,
518+
75: 1.0,
519+
80: 1.5,
520+
85: 2.0,
518521
}
519522

520523
// Simulate transaction inclusion
@@ -735,9 +738,10 @@ func TestIgnoreProvidersOnRetry(t *testing.T) {
735738

736739
// Simulate a price estimate
737740
testPricer.out <- map[int64]float64{
738-
90: 1.0,
739-
95: 1.5,
740-
99: 2.0,
741+
70: 0.8,
742+
75: 1.0,
743+
80: 1.5,
744+
85: 2.0,
741745
}
742746

743747
// Simulate a bid response
@@ -769,9 +773,10 @@ func TestIgnoreProvidersOnRetry(t *testing.T) {
769773

770774
// Simulate a price estimate
771775
testPricer.out <- map[int64]float64{
772-
90: 1.0,
773-
95: 1.5,
774-
99: 2.0,
776+
70: 0.8,
777+
75: 1.0,
778+
80: 1.5,
779+
85: 2.0,
775780
}
776781

777782
bidOp = <-bidderImpl.in

0 commit comments

Comments
 (0)