Skip to content

Commit

Permalink
Merge branch 'master' into feat/rfq-guard [goreleaser]
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Jul 6, 2024
2 parents 9b22148 + ea2520e commit e576f34
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math/big"
"strconv"
"strings"
"sync"
"sync/atomic"

"github.com/synapsecns/sanguine/contrib/screener-api/client"
Expand Down Expand Up @@ -324,26 +325,40 @@ func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address
if err != nil {
return nil, fmt.Errorf("error getting destination RFQ address: %w", err)
}

destTokenID := fmt.Sprintf("%d-%s", chainID, address.Hex())

// generate quotes in parallel
g, gctx := errgroup.WithContext(ctx)
quoteMtx := &sync.Mutex{}
quotes = []model.PutQuoteRequest{}
for keyTokenID, itemTokenIDs := range m.quotableTokens {
for k, itemTokenIDs := range m.quotableTokens {
for _, tokenID := range itemTokenIDs {
//nolint:nestif
if tokenID == destTokenID {
quote, quoteErr := m.generateQuote(ctx, keyTokenID, chainID, address, balance, destRFQAddr)
if quoteErr != nil {
// continue generating quotes even if one fails
span.AddEvent("error generating quote", trace.WithAttributes(
attribute.String("key_token_id", keyTokenID),
attribute.String("error", quoteErr.Error()),
))
continue
}
quotes = append(quotes, *quote)
keyTokenID := k
g.Go(func() error {
quote, quoteErr := m.generateQuote(gctx, keyTokenID, chainID, address, balance, destRFQAddr)
if quoteErr != nil {
// continue generating quotes even if one fails
span.AddEvent("error generating quote", trace.WithAttributes(
attribute.String("key_token_id", keyTokenID),
attribute.String("error", quoteErr.Error()),
))
return nil
}
quoteMtx.Lock()
defer quoteMtx.Unlock()
quotes = append(quotes, *quote)
return nil
})
}
}
}
err = g.Wait()
if err != nil {
return nil, fmt.Errorf("error generating quotes: %w", err)
}

m.currentQuotes = quotes
return quotes, nil
}
Expand Down

0 comments on commit e576f34

Please sign in to comment.