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

RFQ Relayer: restrict state transitions #2787

Merged
merged 23 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
16 changes: 15 additions & 1 deletion core/mapmutex/mapmutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package mapmutex

import (
"fmt"
"github.com/LK4d4/trylock"
"sync"

"github.com/LK4d4/trylock"
Copy link
Contributor

@trajan0x trajan0x Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should remove this dep actually?

See: LK4D4/trylock#3 seems like this functionality is built into sync.Mutex since 1.18

(Random aside: we're not using a canonical url for this either. canonical import url is github.com/LK4D4
image

and we use github.com/LK4d4 (notice the casing difference:

image

I was curious about this since this seemed like a bug in x/pkgsite, but apparentely this is intended behavior when packages existed pre-go.mod:

See golang/go#45409

Apparently, this was a huge issue with logrus when they renamed the package from sirupsen/logrus to Sirupsen/logrus (see sirupsen/logrus#384 followed by sirupsen/logrus#570)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, i've decided we should address this in a different pr (only bc this requires make tidy)

tracking in #2814

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 0d573f2

)

// untypedMapMutex wraps a map of mutexes. Each key locks separately.
Expand All @@ -13,6 +14,7 @@ import (
type untypedMapMutex interface {
Lock(key interface{}) Unlocker
TryLock(key interface{}) (Unlocker, bool)
Keys() []interface{}
}

type untypedMapMutexImpl struct {
Expand Down Expand Up @@ -82,6 +84,18 @@ func (m *untypedMapMutexImpl) TryLock(key interface{}) (Unlocker, bool) {
return nil, false
}

// Keys returns all keys in the map.
func (m *untypedMapMutexImpl) Keys() []interface{} {
m.ml.Lock()
defer m.ml.Unlock()

keys := make([]interface{}, 0, len(m.ma))
for k := range m.ma {
keys = append(keys, k)
}
return keys
}

// Unlock releases the lock for this entry.
func (me *mentry) Unlock() {
m := me.m
Expand Down
22 changes: 22 additions & 0 deletions core/mapmutex/mapmutex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ func (s MapMutexSuite) TestExampleMapMutex() {
NotPanics(s.T(), ExampleStringMapMutex)
}

func (s MapMutexSuite) TestKeys() {
s.T().Run("StringMapMutexKeys", func(t *testing.T) {
mapMutex := mapmutex.NewStringMapMutex()
mapMutex.Lock("lock1")
Equal(t, "lock1", mapMutex.Keys()[0])
Equal(t, 1, len(mapMutex.Keys()))
})
s.T().Run("StringerMapMutexKeys", func(t *testing.T) {
mapMutex := mapmutex.NewStringerMapMutex()
vitalik := common.HexToAddress("0xab5801a7d398351b8be11c439e05c5b3259aec9b")
mapMutex.Lock(vitalik)
Equal(t, vitalik.String(), mapMutex.Keys()[0])
Equal(t, 1, len(mapMutex.Keys()))
})
s.T().Run("IntMapMutexKeys", func(t *testing.T) {
mapMutex := mapmutex.NewIntMapMutex()
mapMutex.Lock(1)
Equal(t, 1, mapMutex.Keys()[0])
Equal(t, 1, len(mapMutex.Keys()))
})
}

func (s MapMutexSuite) TestMapMutex() {
//nolint:gosec
r := rand.New(rand.NewSource(42))
Expand Down
37 changes: 36 additions & 1 deletion core/mapmutex/stringer.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package mapmutex

import "fmt"
import (
"fmt"
)

// StringerMapMutex is an implementation of mapMutex for the fmt.Stringer conforming types.
type StringerMapMutex interface {
Lock(key fmt.Stringer) Unlocker
TryLock(key fmt.Stringer) (Unlocker, bool)
Keys() []string
}

// stringerLockerImpl is the implementation of StringerMapMutex.
Expand All @@ -22,6 +25,16 @@ func (s stringerLockerImpl) Lock(key fmt.Stringer) Unlocker {
return s.mapMux.Lock(key.String())
}

// Keys returns the keys of the map.
func (s stringerLockerImpl) Keys() []string {
var keys []string
for _, key := range s.mapMux.Keys() {
// nolint: forcetypeassert
keys = append(keys, key.(string))
}
return keys
}

// NewStringerMapMutex creates an initialized locker that locks on fmt.String.
func NewStringerMapMutex() StringerMapMutex {
return &stringerLockerImpl{
Expand All @@ -33,6 +46,7 @@ func NewStringerMapMutex() StringerMapMutex {
type StringMapMutex interface {
Lock(key string) Unlocker
TryLock(key string) (Unlocker, bool)
Keys() []string
}

// stringMutexImpl locks on a string type.
Expand All @@ -57,10 +71,21 @@ func (s stringMutexImpl) TryLock(key string) (Unlocker, bool) {
return s.mapMux.TryLock(key)
}

// Keys returns the keys of the map.
func (s stringMutexImpl) Keys() []string {
keys := []string{}
for _, key := range s.mapMux.Keys() {
// nolint: forcetypeassert
keys = append(keys, key.(string))
}
return keys
}

// IntMapMutex is a map mutex that allows locking on an int.
type IntMapMutex interface {
Lock(key int) Unlocker
TryLock(key int) (Unlocker, bool)
Keys() []int
}

// intMapMux locks on an int.
Expand All @@ -77,6 +102,16 @@ func (i intMapMux) Lock(key int) Unlocker {
return i.mapMux.Lock(key)
}

// Keys returns the keys of the map.
func (i intMapMux) Keys() []int {
var keys []int
for _, key := range i.mapMux.Keys() {
// nolint: forcetypeassert
keys = append(keys, key.(int))
}
return keys
}

// NewIntMapMutex creates a map mutex for locking on an integer.
func NewIntMapMutex() IntMapMutex {
return &intMapMux{
Expand Down
24 changes: 23 additions & 1 deletion services/rfq/relayer/reldb/base/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
"errors"
"fmt"

"github.com/ipfs/go-log"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)

var logger = log.Logger("relayer-db")

Check failure on line 17 in services/rfq/relayer/reldb/base/quote.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

`logger` is unused (deadcode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused logger

The logger variable is declared but not used in the file.

Consider using the logger to log relevant information or remove the unused variable.

Tools
GitHub Check: Lint (services/rfq)

[failure] 17-17:
logger is unused (deadcode)


// StoreQuoteRequest stores a quote request.
func (s Store) StoreQuoteRequest(ctx context.Context, request reldb.QuoteRequest) error {
rq := FromQuoteRequest(request)
Expand Down Expand Up @@ -89,7 +93,18 @@
}

// UpdateQuoteRequestStatus todo: db test.
func (s Store) UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status reldb.QuoteRequestStatus) error {
func (s Store) UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status reldb.QuoteRequestStatus, prevStatus *reldb.QuoteRequestStatus) error {
if prevStatus == nil {
req, err := s.GetQuoteRequestByID(ctx, id)
if err != nil {
return fmt.Errorf("could not get quote: %w", err)
}
prevStatus = &req.Status

Check warning on line 102 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-L102

Added lines #L96 - L102 were not covered by tests
Comment on lines +92 to +98
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The added lines for the UpdateQuoteRequestStatus function and the isValidStateTransition function are not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Also applies to: 104-106, 139-143

Tools
GitHub Check: codecov/patch

[warning] 96-102: services/rfq/relayer/reldb/base/quote.go#L96-L102
Added lines #L96 - L102 were not covered by tests

}
if !isValidStateTransition(*prevStatus, status) {
return nil
}

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L104-L106

Added lines #L104 - L106 were not covered by tests
Comment on lines +92 to +102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation logic in isValidStateTransition seems limited

The function checks if the new status is greater than the previous status or matches specific statuses. This might be too restrictive or not adequately capture valid transitions, depending on business rules. If more complex rules are needed, consider expanding this logic or using a state machine library.

Tools
GitHub Check: codecov/patch

[warning] 96-102: services/rfq/relayer/reldb/base/quote.go#L96-L102
Added lines #L96 - L102 were not covered by tests


[warning] 104-106: services/rfq/relayer/reldb/base/quote.go#L104-L106
Added lines #L104 - L106 were not covered by tests

Comment on lines +100 to +102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the logic for state transition validation and error handling

The method UpdateQuoteRequestStatus now includes logic to handle state transitions validation. While the use of prevStatus to fetch the current status if not provided is logical, the function returns nil when an invalid state transition is detected, which might silently ignore errors. Consider returning an error instead to make the failure explicit.

- return nil
+ return fmt.Errorf("invalid state transition from %s to %s [txid=%s]", *prevStatus, status, hexutil.Encode(id[:]))
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !isValidStateTransition(*prevStatus, status) {
return nil
}
if !isValidStateTransition(*prevStatus, status) {
return fmt.Errorf("invalid state transition from %s to %s [txid=%s]", *prevStatus, status, hexutil.Encode(id[:]))
}
Tools
GitHub Check: codecov/patch

[warning] 104-106: services/rfq/relayer/reldb/base/quote.go#L104-L106
Added lines #L104 - L106 were not covered by tests


tx := s.DB().WithContext(ctx).Model(&RequestForQuote{}).
Where(fmt.Sprintf("%s = ?", transactionIDFieldName), hexutil.Encode(id[:])).
Update(statusFieldName, status)
Expand Down Expand Up @@ -120,3 +135,10 @@
}
return nil
}

func isValidStateTransition(prevStatus, status reldb.QuoteRequestStatus) bool {
if status == reldb.DeadlineExceeded || status == reldb.WillNotProcess {
return true
}
return status >= prevStatus

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L139-L143

Added lines #L139 - L143 were not covered by tests
Comment on lines +135 to +139
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limited validation logic in isValidStateTransition

The function only checks if the new status is greater than the previous status or matches specific statuses. This might be too restrictive or not adequately capture valid transitions, depending on business rules. Consider expanding this logic or using a state machine library.

Tools
GitHub Check: codecov/patch

[warning] 139-143: services/rfq/relayer/reldb/base/quote.go#L139-L143
Added lines #L139 - L143 were not covered by tests


Missing test coverage

The isValidStateTransition function is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 139-143: services/rfq/relayer/reldb/base/quote.go#L139-L143
Added lines #L139 - L143 were not covered by tests

}
2 changes: 1 addition & 1 deletion services/rfq/relayer/reldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Writer interface {
// StoreRebalance stores a rebalance.
StoreRebalance(ctx context.Context, rebalance Rebalance) error
// UpdateQuoteRequestStatus updates the status of a quote request
UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status QuoteRequestStatus) error
UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status QuoteRequestStatus, prevStatus *QuoteRequestStatus) error
// UpdateRebalance updates the status of a rebalance action.
// If the origin is supplied, it will be used to update the ID for the corresponding rebalance model.
UpdateRebalance(ctx context.Context, rebalance Rebalance, updateID bool) error
Expand Down
14 changes: 7 additions & 7 deletions services/rfq/relayer/service/chainindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,41 @@
}
case *fastbridge.FastBridgeBridgeRelayed:
// blocking lock on the txid mutex to ensure state transitions are not overrwitten
unlocker := r.relayMtx.Lock(hexutil.Encode(event.TransactionId[:]))
unlocker := r.handlerMtx.Lock(hexutil.Encode(event.TransactionId[:]))

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L82 was not covered by tests
defer unlocker.Unlock()

// it wasn't me
if event.Relayer != r.signer.Address() {
//nolint: wrapcheck
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost)
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost, nil)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L88 was not covered by tests
}

err = r.handleRelayLog(ctx, event)
if err != nil {
return fmt.Errorf("could not handle relay: %w", err)
}
case *fastbridge.FastBridgeBridgeProofProvided:
unlocker := r.relayMtx.Lock(hexutil.Encode(event.TransactionId[:]))
unlocker := r.handlerMtx.Lock(hexutil.Encode(event.TransactionId[:]))

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L96 was not covered by tests
defer unlocker.Unlock()

// it wasn't me
if event.Relayer != r.signer.Address() {
//nolint: wrapcheck
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost)
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost, nil)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L102 was not covered by tests
}

err = r.handleProofProvided(ctx, event)
if err != nil {
return fmt.Errorf("could not handle proof provided: %w", err)
}
case *fastbridge.FastBridgeBridgeDepositClaimed:
unlocker := r.relayMtx.Lock(hexutil.Encode(event.TransactionId[:]))
unlocker := r.handlerMtx.Lock(hexutil.Encode(event.TransactionId[:]))

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L110 was not covered by tests
defer unlocker.Unlock()

// it wasn't me
if event.Relayer != r.signer.Address() {
//nolint: wrapcheck
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost)
return r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.RelayRaceLost, nil)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L116 was not covered by tests
}

err = r.handleDepositClaimed(ctx, event)
Expand Down Expand Up @@ -206,7 +206,7 @@
}

func (r *Relayer) handleDepositClaimed(ctx context.Context, event *fastbridge.FastBridgeBridgeDepositClaimed) error {
err := r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.ClaimCompleted)
err := r.db.UpdateQuoteRequestStatus(ctx, event.TransactionId, reldb.ClaimCompleted, nil)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L209 was not covered by tests
if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand Down
26 changes: 13 additions & 13 deletions services/rfq/relayer/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
metrics.EndSpanWithErr(span, err)
}()

unlocker, ok := r.relayMtx.TryLock(hexutil.Encode(req.TransactionId[:]))
unlocker, ok := r.handlerMtx.TryLock(hexutil.Encode(req.TransactionId[:]))

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L40 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The lock acquisition logic in handleBridgeRequestedLog is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 40-40: services/rfq/relayer/service/handlers.go#L40
Added line #L40 was not covered by tests

if !ok {
span.SetAttributes(attribute.Bool("locked", true))
// already processing this request
Expand Down Expand Up @@ -142,7 +142,7 @@
return fmt.Errorf("could not determine if should process: %w", err)
}
if !shouldProcess {
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.WillNotProcess)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.WillNotProcess, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L145 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleSeen is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 145-145: services/rfq/relayer/service/handlers.go#L145
Added line #L145 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand All @@ -167,7 +167,7 @@
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)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.WillNotProcess, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L170 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleSeen is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 170-170: services/rfq/relayer/service/handlers.go#L170
Added line #L170 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand All @@ -179,7 +179,7 @@

// check if we have enough inventory to handle the request
if committableBalance.Cmp(request.Transaction.DestAmount) < 0 {
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.NotEnoughInventory)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.NotEnoughInventory, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L182 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleSeen is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 182-182: services/rfq/relayer/service/handlers.go#L182
Added line #L182 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand All @@ -206,7 +206,7 @@
}

request.Status = reldb.CommittedPending
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.CommittedPending)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.CommittedPending, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L209 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleSeen is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 209-209: services/rfq/relayer/service/handlers.go#L209
Added line #L209 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand Down Expand Up @@ -270,7 +270,7 @@
}

request.Status = reldb.CommittedConfirmed
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.CommittedConfirmed)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.CommittedConfirmed, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L273 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleCommitPending is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 273-273: services/rfq/relayer/service/handlers.go#L273
Added line #L273 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand Down Expand Up @@ -300,7 +300,7 @@
span.AddEvent("relay successfully submitted")
span.SetAttributes(attribute.Int("relay_nonce", int(nonce)))

err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.RelayStarted)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.RelayStarted, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L303 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleCommitConfirmed is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 303-303: services/rfq/relayer/service/handlers.go#L303
Added line #L303 was not covered by tests

if err != nil {
return fmt.Errorf("could not update quote request status: %w", err)
}
Expand Down Expand Up @@ -332,7 +332,7 @@
}

// TODO: this can still get re-orged
err = r.db.UpdateQuoteRequestStatus(ctx, req.TransactionId, reldb.RelayCompleted)
err = r.db.UpdateQuoteRequestStatus(ctx, req.TransactionId, reldb.RelayCompleted, nil)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L335 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleRelayLog is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 335-335: services/rfq/relayer/service/handlers.go#L335
Added line #L335 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand Down Expand Up @@ -361,7 +361,7 @@
return fmt.Errorf("could not submit transaction: %w", err)
}

err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.ProvePosting)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.ProvePosting, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L364 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleRelayCompleted is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 364-364: services/rfq/relayer/service/handlers.go#L364
Added line #L364 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand All @@ -375,7 +375,7 @@
func (r *Relayer) handleProofProvided(ctx context.Context, req *fastbridge.FastBridgeBridgeProofProvided) (err error) {
// TODO: this can still get re-orged
// ALso: we should make sure the previous status is ProvePosting
err = r.db.UpdateQuoteRequestStatus(ctx, req.TransactionId, reldb.ProvePosted)
err = r.db.UpdateQuoteRequestStatus(ctx, req.TransactionId, reldb.ProvePosted, nil)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L378 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleProofProvided is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 378-378: services/rfq/relayer/service/handlers.go#L378
Added line #L378 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand Down Expand Up @@ -408,7 +408,7 @@
}

if bs == fastbridge.RelayerClaimed.Int() {
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.ClaimCompleted)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.ClaimCompleted, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L411 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleProofPosted is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 411-411: services/rfq/relayer/service/handlers.go#L411
Added line #L411 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand Down Expand Up @@ -443,7 +443,7 @@
return fmt.Errorf("could not submit transaction: %w", err)
}

err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.ClaimPending)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.ClaimPending, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L446 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleProofPosted is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 446-446: services/rfq/relayer/service/handlers.go#L446
Added line #L446 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand All @@ -460,7 +460,7 @@
}
// if committableBalance > destAmount
if committableBalance.Cmp(request.Transaction.DestAmount) > 0 {
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.CommittedPending)
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.CommittedPending, &request.Status)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L463 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage

The status update logic in handleNotEnoughInventory is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 463-463: services/rfq/relayer/service/handlers.go#L463
Added line #L463 was not covered by tests

if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
Expand Down
Loading
Loading