Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rfq-relayer): extra checks around canClaim() #2899

Merged
merged 10 commits into from
Aug 8, 2024
37 changes: 33 additions & 4 deletions services/rfq/relayer/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,14 @@
//
// This is the fifth step in the bridge process. Here we check if the relay has been completed on the destination chain.
// Notably, this is polled from the chain listener rather than the database since we wait for the log to show up.
func (r *Relayer) handleRelayLog(ctx context.Context, req *fastbridge.FastBridgeBridgeRelayed) (err error) {
func (r *Relayer) handleRelayLog(parentCtx context.Context, req *fastbridge.FastBridgeBridgeRelayed) (err error) {
ctx, span := r.metrics.Tracer().Start(parentCtx, "handleRelayLog",
trace.WithAttributes(attribute.String("transaction_id", hexutil.Encode(req.TransactionId[:]))),
)
defer func() {
metrics.EndSpanWithErr(span, err)
}()

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L321-L327

Added lines #L321 - L327 were not covered by tests

reqID, err := r.db.GetQuoteRequestByID(ctx, req.TransactionId)
if err != nil {
return fmt.Errorf("could not get quote request: %w", err)
Expand All @@ -336,6 +343,7 @@
if err != nil {
return fmt.Errorf("could not update dest tx hash: %w", err)
}
span.SetAttributes(attribute.String("dest_tx_hash", hexutil.Encode(req.Raw.TxHash[:])))

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L346

Added line #L346 was not covered by tests

err = r.db.UpdateQuoteRequestStatus(ctx, req.TransactionId, reldb.RelayCompleted, nil)
if err != nil {
Expand Down Expand Up @@ -391,7 +399,9 @@
// Step 8: ClaimPending
//
// we'll wait until optimistic period is over to check if we can claim.
func (q *QuoteRequestHandler) handleProofPosted(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
//
//nolint:cyclop
func (q *QuoteRequestHandler) handleProofPosted(ctx context.Context, span trace.Span, request reldb.QuoteRequest) (err error) {

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L404

Added line #L404 was not covered by tests
// we shouldnt' check the claim yet
if !q.shouldCheckClaim(request) {
return nil
Expand All @@ -411,15 +421,34 @@
if err != nil {
return fmt.Errorf("could not make contract call: %w", err)
}

if bs == fastbridge.RelayerClaimed.Int() {
switch bs {
case fastbridge.RelayerProved.Int():

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L424-L425

Added lines #L424 - L425 were not covered by tests
// no op
case fastbridge.RelayerClaimed.Int():

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L427

Added line #L427 was not covered by tests
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.ClaimCompleted, &request.Status)
if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
default:
if span != nil {
span.SetAttributes(attribute.Int("claim_bridge_status", int(bs)))
span.AddEvent("unexpected bridge status for claim")
}

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L432-L436

Added lines #L432 - L436 were not covered by tests
return nil
}

proofs, err := q.Origin.Bridge.BridgeProofs(&bind.CallOpts{Context: ctx}, request.TransactionID)
if err != nil {
return fmt.Errorf("could not get bridge proofs: %w", err)
}
if proofs.Relayer != q.RelayerAddress {
if span != nil {
span.SetAttributes(attribute.String("proof_relayer", proofs.Relayer.String()))
span.AddEvent("unexpected relayer in proof")
}
return fmt.Errorf("onchain proof does not match our relayer")

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L440-L449

Added lines #L440 - L449 were not covered by tests
}

var canClaim bool
claimCall := func(ctx context.Context) error {
canClaim, err = q.Origin.Bridge.CanClaim(&bind.CallOpts{Context: ctx}, request.TransactionID, q.RelayerAddress)
Expand Down
Loading