Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tools/preconf-rpc/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down
10 changes: 6 additions & 4 deletions tools/preconf-rpc/pricer/pricer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tools/preconf-rpc/pricer/pricer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions tools/preconf-rpc/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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-- {
Expand Down
35 changes: 20 additions & 15 deletions tools/preconf-rpc/sender/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading