diff --git a/services/rfq/relayer/reldb/base/model.go b/services/rfq/relayer/reldb/base/model.go index c98ad7dad2..2abc6a1fc2 100644 --- a/services/rfq/relayer/reldb/base/model.go +++ b/services/rfq/relayer/reldb/base/model.go @@ -22,6 +22,7 @@ func init() { blockNumberFieldName = namer.GetConsistentName("BlockNumber") statusFieldName = namer.GetConsistentName("Status") transactionIDFieldName = namer.GetConsistentName("TransactionID") + destTxHashFieldName = namer.GetConsistentName("DestTxHash") } var ( @@ -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. @@ -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"` @@ -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(), @@ -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 } diff --git a/services/rfq/relayer/reldb/base/quote.go b/services/rfq/relayer/reldb/base/quote.go index 9e442b9e04..e2f654bcfe 100644 --- a/services/rfq/relayer/reldb/base/quote.go +++ b/services/rfq/relayer/reldb/base/quote.go @@ -4,6 +4,8 @@ import ( "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" @@ -78,3 +80,14 @@ func (s Store) UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status } 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 +} diff --git a/services/rfq/relayer/reldb/db.go b/services/rfq/relayer/reldb/db.go index 1083e89a85..d2a9741601 100644 --- a/services/rfq/relayer/reldb/db.go +++ b/services/rfq/relayer/reldb/db.go @@ -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" @@ -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. @@ -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. diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index 201caf4b67..94b9fb02fd 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -4,9 +4,10 @@ import ( "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" @@ -219,6 +220,10 @@ func (r *Relayer) handleRelayLog(ctx context.Context, req *fastbridge.FastBridge 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) + } return nil } @@ -230,7 +235,7 @@ func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, _ trace. // 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) if err != nil { return nil, fmt.Errorf("could not relay: %w", err) }