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

Add DestTxHash field and use it in relayer Prove() call #1726

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions services/rfq/relayer/reldb/base/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func init() {
blockNumberFieldName = namer.GetConsistentName("BlockNumber")
statusFieldName = namer.GetConsistentName("Status")
transactionIDFieldName = namer.GetConsistentName("TransactionID")
destTxHashFieldName = namer.GetConsistentName("DestTxHash")
}

var (
Expand All @@ -33,6 +34,8 @@ var (
statusFieldName string
// transactionIDFieldName is the transactions id field name.
transactionIDFieldName string
// destTxHashFieldName is the dest tx hash field name.
destTxHashFieldName string
)

// LastIndexed is used to make sure we haven't missed any events while offline.
Expand Down Expand Up @@ -85,7 +88,8 @@ type RequestForQuote struct {
DestAmountOriginal string
// DestAmountOriginal is the original destination amount
DestAmount decimal.Decimal `gorm:"index"`
Deadline time.Time `gorm:"index"`
DestTxHash string
Deadline time.Time `gorm:"index"`
// OriginNonce is the nonce on the origin chain in the app.
// this is not effected by the message.sender nonce.
OriginNonce int `gorm:"index"`
Expand Down Expand Up @@ -115,6 +119,7 @@ func FromQuoteRequest(request reldb.QuoteRequest) RequestForQuote {
SendChainGas: request.Transaction.SendChainGas,
DestTokenDecimals: request.DestTokenDecimals,
DestToken: request.Transaction.DestToken.String(),
DestTxHash: request.DestTxHash.String(),
OriginAmountOriginal: request.Transaction.OriginAmount.String(),
OriginAmount: decimal.NewFromBigInt(request.Transaction.OriginAmount, int32(request.OriginTokenDecimals)),
DestAmountOriginal: request.Transaction.DestAmount.String(),
Expand Down Expand Up @@ -164,7 +169,8 @@ func (r RequestForQuote) ToQuoteRequest() (*reldb.QuoteRequest, error) {
Deadline: big.NewInt(r.Deadline.Unix()),
Nonce: big.NewInt(int64(r.OriginNonce)),
},
Status: r.Status,
Status: r.Status,
DestTxHash: common.HexToHash(r.DestTxHash),
}, nil
}

Expand Down
13 changes: 13 additions & 0 deletions services/rfq/relayer/reldb/base/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"context"
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
"gorm.io/gorm"
Expand Down Expand Up @@ -78,3 +80,14 @@
}
return nil
}

// UpdateDestTxHash todo: db test.
func (s Store) UpdateDestTxHash(ctx context.Context, id [32]byte, destTxHash common.Hash) error {
tx := s.DB().WithContext(ctx).Model(&RequestForQuote{}).
Where(fmt.Sprintf("%s = ?", transactionIDFieldName), hexutil.Encode(id[:])).
Update(destTxHashFieldName, destTxHash)
if tx.Error != nil {
return fmt.Errorf("could not update: %w", tx.Error)
}
return nil

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L85-L92

Added lines #L85 - L92 were not covered by tests
}
6 changes: 5 additions & 1 deletion services/rfq/relayer/reldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql/driver"
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/core/dbcommon"
submitterDB "github.com/synapsecns/sanguine/ethergo/submitter/db"
Expand All @@ -20,6 +21,8 @@ type Writer interface {
StoreQuoteRequest(ctx context.Context, request QuoteRequest) error
// UpdateQuoteRequestStatus updates the status of a quote request
UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status QuoteRequestStatus) error
// UpdateDestTxHash updates the dest tx hash of a quote request
UpdateDestTxHash(ctx context.Context, id [32]byte, destTxHash common.Hash) error
}

// Reader is the interface for reading from the database.
Expand Down Expand Up @@ -57,7 +60,8 @@ type QuoteRequest struct {
Sender common.Address
Transaction fastbridge.IFastBridgeBridgeTransaction
// Status is the quote request status
Status QuoteRequestStatus
Status QuoteRequestStatus
DestTxHash common.Hash
}

// GetOriginIDPair gets the origin chain id and token address pair.
Expand Down
9 changes: 7 additions & 2 deletions services/rfq/relayer/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"context"
"errors"
"fmt"
"github.com/synapsecns/sanguine/core"
"math/big"

"github.com/synapsecns/sanguine/core"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -219,6 +220,10 @@
if err != nil {
return fmt.Errorf("could not update request status: %w", err)
}
err = r.db.UpdateDestTxHash(ctx, req.TransactionId, req.Raw.TxHash)
if err != nil {
return fmt.Errorf("could not update dest tx hash: %w", err)
}

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

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/handlers.go#L223-L226

Added lines #L223 - L226 were not covered by tests
return nil
}

Expand All @@ -230,7 +235,7 @@
// relays been completed, it's time to go back to the origin chain and try to prove
_, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
// MAJO MAJOR TODO should be dest tx hash
tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.TransactionID)
tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.DestTxHash)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L238 was not covered by tests
if err != nil {
return nil, fmt.Errorf("could not relay: %w", err)
}
Expand Down
Loading