Skip to content

Commit

Permalink
RFQ: drop requests for unsupported chains (#2563)
Browse files Browse the repository at this point in the history
* Feat: check for unsupported chain in inventory manager

* Cleanup: lint
  • Loading branch information
dwasse authored May 3, 2024
1 parent a089e1a commit f08f8a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion services/rfq/relayer/inventory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inventory

import (
"context"
"errors"
"fmt"
"math/big"
"strconv"
Expand Down Expand Up @@ -82,6 +83,9 @@ type inventoryManagerImpl struct {
pendingHist metric.Float64Histogram
}

// ErrUnsupportedChain is the error for an unsupported chain.
var ErrUnsupportedChain = errors.New("could not get gas balance for unsupported chain")

// GetCommittableBalance gets the committable balances.
func (i *inventoryManagerImpl) GetCommittableBalance(ctx context.Context, chainID int, token common.Address, options ...BalanceFetchArgOption) (*big.Int, error) {
committableBalances, err := i.GetCommittableBalances(ctx, options...)
Expand All @@ -94,7 +98,7 @@ func (i *inventoryManagerImpl) GetCommittableBalance(ctx context.Context, chainI
if balance == nil && token == chain.EthAddress {
gasBalance, ok := i.gasBalances[chainID]
if !ok || gasBalance == nil {
return nil, fmt.Errorf("could not get gas balance for chain %d", chainID)
return nil, ErrUnsupportedChain

Check warning on line 101 in services/rfq/relayer/inventory/manager.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/inventory/manager.go#L101

Added line #L101 was not covered by tests
}
balance = i.gasBalances[chainID]
}
Expand Down
15 changes: 14 additions & 1 deletion services/rfq/relayer/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge"
"github.com/synapsecns/sanguine/services/rfq/relayer/inventory"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -93,6 +94,8 @@ func (r *Relayer) handleBridgeRequestedLog(parentCtx context.Context, req *fastb
//
// This is the second step in the bridge process. It is emitted when the relayer sees the request.
// We check if we have enough inventory to process the request and mark it as committed pending.
//
//nolint:cyclop
func (q *QuoteRequestHandler) handleSeen(ctx context.Context, span trace.Span, request reldb.QuoteRequest) (err error) {
shouldProcess, err := q.Quoter.ShouldProcess(ctx, request)
if err != nil {
Expand Down Expand Up @@ -120,11 +123,21 @@ func (q *QuoteRequestHandler) handleSeen(ctx context.Context, span trace.Span, r
return nil
}

// get destination committable balancs
// get destination committable balance
committableBalance, err := q.Inventory.GetCommittableBalance(ctx, int(q.Dest.ChainID), request.Transaction.DestToken)
if errors.Is(err, inventory.ErrUnsupportedChain) {
// don't process request if chain is currently unsupported
span.AddEvent("dropping unsupported chain")
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.WillNotProcess)
if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
return nil

Check warning on line 135 in services/rfq/relayer/service/handlers.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L128-L135

Added lines #L128 - L135 were not covered by tests
}
if err != nil {
return fmt.Errorf("could not get committable balance: %w", err)
}

// if committableBalance > destAmount
if committableBalance.Cmp(request.Transaction.DestAmount) < 0 {
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.NotEnoughInventory)
Expand Down

0 comments on commit f08f8a9

Please sign in to comment.