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 11 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{} {
// note that we don't lock here in case the map is already locked.
Copy link
Contributor

Choose a reason for hiding this comment

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

@dwasse yeah this is just wrong imo.

This is definitely going to nil pointer- if it was only used for tests ifne but this method is unsafe b/c if could lead to iterating over a non-existent slice element

The lock here isn't global anyway and won't block anything else for long at all. The whole point of mapmutex is the Locks are not global even - the lock here is internal only

// the idea is that this function can be used for debugging-
// there may be read inconsistencies.
keys := make([]interface{}, 0, len(m.ma))
for k := range m.ma {
keys = append(keys, k)
}
return keys
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementation of Keys() in untypedMapMutexImpl lacks synchronization.

The implementation does not lock the mutex map when accessing it, which can lead to race conditions and inconsistent reads. This should be addressed to ensure thread safety.

+	m.ml.Lock()
+	defer m.ml.Unlock()
	keys := make([]interface{}, 0, len(m.ma))
	for k := range m.ma {
		keys = append(keys, k)
	}
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
// Keys returns all keys in the map.
func (m *untypedMapMutexImpl) Keys() []interface{} {
// note that we don't lock here in case the map is already locked.
// the idea is that this function can be used for debugging-
// there may be read inconsistencies.
keys := make([]interface{}, 0, len(m.ma))
for k := range m.ma {
keys = append(keys, k)
}
return keys
}
// Keys returns all keys in the map.
func (m *untypedMapMutexImpl) Keys() []interface{} {
// note that we don't lock here in case the map is already locked.
// the idea is that this function can be used for debugging-
// there may be read inconsistencies.
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
23 changes: 23 additions & 0 deletions core/mapmutex/mapmutex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
. "github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/core/mapmutex"
"gotest.tools/assert"
Copy link

Choose a reason for hiding this comment

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

🪶 style: Redundant import of gotest.tools/assert. Consider using only one assertion library for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dwasse also a good take

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 e867a9b

)

// ExampleMapMutex provides an example implementation of a map mutex.
Expand Down Expand Up @@ -52,6 +53,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")
assert.Equal(t, "lock1", mapMutex.Keys()[0])
assert.Equal(t, 1, len(mapMutex.Keys()))
})
s.T().Run("StringerMapMutexKeys", func(t *testing.T) {
mapMutex := mapmutex.NewStringerMapMutex()
vitalik := common.HexToAddress("0xab5801a7d398351b8be11c439e05c5b3259aec9b")
mapMutex.Lock(vitalik)
assert.Equal(t, vitalik.String(), mapMutex.Keys()[0])
assert.Equal(t, 1, len(mapMutex.Keys()))
})
s.T().Run("IntMapMutexKeys", func(t *testing.T) {
mapMutex := mapmutex.NewIntMapMutex()
mapMutex.Lock(1)
assert.Equal(t, 1, mapMutex.Keys()[0])
assert.Equal(t, 1, len(mapMutex.Keys()))
})
}

func (s MapMutexSuite) TestMapMutex() {
//nolint:gosec
r := rand.New(rand.NewSource(42))
Expand Down
34 changes: 33 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,15 @@
return s.mapMux.Lock(key.String())
}

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

Check failure on line 32 in core/mapmutex/stringer.go

View workflow job for this annotation

GitHub Actions / Lint (core)

type assertion must be checked (forcetypeassert)
}
return keys
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementation of Keys() in stringerLockerImpl needs safe type assertion.

The method uses a type assertion that could panic if the underlying type is not a string. This should be handled more safely.

-		keys = append(keys, key.(string))
+		strKey, ok := key.(string)
+		if !ok {
+		    return nil, fmt.Errorf("type assertion to string failed")
+		}
+		keys = append(keys, strKey)

Committable suggestion was skipped due to low confidence.

Tools
GitHub Check: Lint (core)

[failure] 32-32:
type assertion must be checked (forcetypeassert)


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

// stringMutexImpl locks on a string type.
Expand All @@ -57,10 +70,20 @@
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() {
keys = append(keys, key.(string))

Check failure on line 77 in core/mapmutex/stringer.go

View workflow job for this annotation

GitHub Actions / Lint (core)

type assertion must be checked (forcetypeassert)
}
return keys
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementation of Keys() in stringMutexImpl needs safe type assertion.

Similar to the stringerLockerImpl, this implementation also needs to handle type assertions safely to prevent potential runtime panics.

-		keys = append(keys, key.(string))
+		strKey, ok := key.(string)
+		if !ok {
+		    return nil, fmt.Errorf("type assertion to string failed")
+		}
+		keys = append(keys, strKey)
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
// Keys returns the keys of the map.
func (s stringMutexImpl) Keys() []string {
keys := []string{}
for _, key := range s.mapMux.Keys() {
keys = append(keys, key.(string))
}
return keys
}
// Keys returns the keys of the map.
func (s stringMutexImpl) Keys() ([]string, error) {
keys := []string{}
for _, key := range s.mapMux.Keys() {
strKey, ok := key.(string)
if !ok {
return nil, fmt.Errorf("type assertion to string failed")
}
keys = append(keys, strKey)
}
return keys, nil
}
Tools
GitHub Check: Lint (core)

[failure] 77-77:
type assertion must be checked (forcetypeassert)


// 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 +100,15 @@
return i.mapMux.Lock(key)
}

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

Check failure on line 107 in core/mapmutex/stringer.go

View workflow job for this annotation

GitHub Actions / Lint (core)

type assertion must be checked (forcetypeassert)
}
return keys
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementation of Keys() in intMapMux needs safe type assertion.

This method also requires safe handling of type assertions to ensure robustness and prevent runtime errors.

-		keys = append(keys, key.(int))
+		intKey, ok := key.(int)
+		if !ok {
+		    return nil, fmt.Errorf("type assertion to int failed")
+		}
+	 keys = append(keys, intKey)

Committable suggestion was skipped due to low confidence.

Tools
GitHub Check: Lint (core)

[failure] 107-107:
type assertion must be checked (forcetypeassert)


// NewIntMapMutex creates a map mutex for locking on an integer.
func NewIntMapMutex() IntMapMutex {
return &intMapMux{
Expand Down
25 changes: 24 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")
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,19 @@
}

// 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) {
logger.Warnf("invalid state transition from %s to %s [txid=%s]", *prevStatus, status, hexutil.Encode(id[:]))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Chose not to return error here since we presumably don't want to panic on this, and checking errors.Is() on the result introduces a bit of code bloat

Copy link
Contributor

Choose a reason for hiding this comment

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

Completely understand the hesitation to do this, but in this case I'll be renaming the method to UpdateQuoteRequestStatusIFValid or somethign.

return nil
}

Check warning on line 107 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-L107

Added lines #L104 - L107 were 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.

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
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
}
if !isValidStateTransition(*prevStatus, status) {
logger.Warnf("invalid state transition from %s to %s [txid=%s]", *prevStatus, status, hexutil.Encode(id[:]))
return nil
}
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
}
if !isValidStateTransition(*prevStatus, status) {
logger.Warnf("invalid state transition from %s to %s [txid=%s]", *prevStatus, status, hexutil.Encode(id[:]))
return fmt.Errorf("invalid state transition from %s to %s [txid=%s]", *prevStatus, status, hexutil.Encode(id[:]))
}

tx := s.DB().WithContext(ctx).Model(&RequestForQuote{}).
Where(fmt.Sprintf("%s = ?", transactionIDFieldName), hexutil.Encode(id[:])).
Update(statusFieldName, status)
Expand Down Expand Up @@ -120,3 +136,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 144 in services/rfq/relayer/reldb/base/quote.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L140-L144

Added lines #L140 - L144 were 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.

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.

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
28 changes: 14 additions & 14 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 @@ -453,14 +453,14 @@
// Error Handlers Only from this point below.
//
// handleNotEnoughInventory handles the not enough inventory status.
func (q *QuoteRequestHandler) handleNotEnoughInventory(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
func (q *QuoteRequestHandler) handleNotEnoughInventory(ctx context.Context, span trace.Span, request reldb.QuoteRequest) (err error) {

Check failure on line 456 in services/rfq/relayer/service/handlers.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

unused-parameter: parameter 'span' seems to be unused, consider removing or renaming it as _ (revive)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L456 was not covered by tests
committableBalance, err := q.Inventory.GetCommittableBalance(ctx, int(q.Dest.ChainID), request.Transaction.DestToken)
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.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