Skip to content

Commit

Permalink
relayrace lost bulletproof [goreleaser]
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Jul 8, 2024
1 parent 03d95f9 commit 4afaee1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion services/rfq/relayer/reldb/base/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s Store) UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status
if prevStatus == nil {
req, err := s.GetQuoteRequestByID(ctx, id)
if err != nil {
return fmt.Errorf("could not get quote: %w", err)
return fmt.Errorf("could not get quote: %w", reldb.ErrNoQuoteForID)

Check warning on line 96 in services/rfq/relayer/reldb/base/quote.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L96

Added line #L96 was not covered by tests
}
prevStatus = &req.Status
}
Expand Down
20 changes: 17 additions & 3 deletions services/rfq/relayer/service/chainindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package service

import (
"context"
"errors"
"fmt"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -85,7 +87,7 @@ func (r *Relayer) runChainIndexer(ctx context.Context, chainID int) (err error)
// it wasn't me
if event.Relayer != r.signer.Address() {
//nolint: wrapcheck
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost, nil)
return r.setRelayRaceLost(ctx, event.TransactionId)

Check warning on line 90 in services/rfq/relayer/service/chainindexer.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/chainindexer.go#L90

Added line #L90 was not covered by tests
}

err = r.handleRelayLog(ctx, event)
Expand All @@ -99,7 +101,7 @@ func (r *Relayer) runChainIndexer(ctx context.Context, chainID int) (err error)
// it wasn't me
if event.Relayer != r.signer.Address() {
//nolint: wrapcheck
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost, nil)
return r.setRelayRaceLost(ctx, event.TransactionId)

Check warning on line 104 in services/rfq/relayer/service/chainindexer.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/chainindexer.go#L104

Added line #L104 was not covered by tests
}

err = r.handleProofProvided(ctx, event)
Expand All @@ -113,7 +115,7 @@ func (r *Relayer) runChainIndexer(ctx context.Context, chainID int) (err error)
// it wasn't me
if event.Relayer != r.signer.Address() {
//nolint: wrapcheck
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost, nil)
return r.setRelayRaceLost(ctx, event.TransactionId)

Check warning on line 118 in services/rfq/relayer/service/chainindexer.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/chainindexer.go#L118

Added line #L118 was not covered by tests
}

err = r.handleDepositClaimed(ctx, event)
Expand Down Expand Up @@ -212,3 +214,15 @@ func (r *Relayer) handleDepositClaimed(ctx context.Context, event *fastbridge.Fa
}
return nil
}

func (r *Relayer) setRelayRaceLost(ctx context.Context, transactionID [32]byte) error {
err := r.db.UpdateQuoteRequestStatus(ctx, transactionID, reldb.RelayRaceLost, nil)
// quote does not exist, no need to update status
if err != nil && (errors.Is(err, reldb.ErrNoQuoteForID) || strings.Contains(err.Error(), reldb.ErrNoQuoteForID.Error())) {
return nil
}
if err != nil {
return fmt.Errorf("could not set relay race lost: %w", err)
}
return nil

Check warning on line 227 in services/rfq/relayer/service/chainindexer.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/chainindexer.go#L218-L227

Added lines #L218 - L227 were not covered by tests
}

0 comments on commit 4afaee1

Please sign in to comment.