Skip to content

Commit

Permalink
[rfq] add withdraw tracing (#2929)
Browse files Browse the repository at this point in the history

Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com>
  • Loading branch information
trajan0x and trajan0x authored Jul 28, 2024
1 parent 683fb3e commit f6f2226
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions contrib/promexporter/exporters/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (e *exporter) batchCalls(ctx context.Context, evmClient ethergoClient.EVM,

g, ctx := errgroup.WithContext(ctx)
for _, task := range tasks {
task := task // capture func literal
g.Go(func() error {
err = evmClient.BatchWithContext(ctx, task...)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions contrib/promexporter/internal/gql/explorer/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contrib/screener-api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/urfave/cli/v2 v2.27.2
github.com/valyala/fastjson v1.6.4
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/metric v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
golang.org/x/sync v0.7.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -168,7 +169,6 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect
go.opentelemetry.io/otel/log v0.3.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions services/rfq/relayer/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var withdrawCommand = &cli.Command{
return fmt.Errorf("could not get withdrawal tx hash: %w", err)
}
return nil
})
}, retry.WithMaxTotalTime(1*time.Minute))

if err != nil {
return
Expand All @@ -157,7 +157,7 @@ var withdrawCommand = &cli.Command{
return fmt.Errorf("could not get withdrawal tx hash: %w", err)
}
if errClient != nil {
return fmt.Errorf("client error: could not get withdrawal tx hash: %w", err)
return fmt.Errorf("client error: could not get withdrawal tx hash: %w", errClient)
}

fmt.Printf("Withdraw Tx Hash: %s\n", status.Hash)
Expand Down
24 changes: 17 additions & 7 deletions services/rfq/relayer/relapi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package relapi
import (
"encoding/json"
"fmt"
"github.com/synapsecns/sanguine/core/metrics"
"math/big"
"net/http"

Expand All @@ -22,15 +23,17 @@ import (

// Handler is the REST API handler.
type Handler struct {
metrics metrics.Handler
db reldb.Service
chains map[uint32]*chain.Chain
cfg relconfig.Config
submitter submitter.TransactionSubmitter
}

// NewHandler creates a new REST API handler.
func NewHandler(db reldb.Service, chains map[uint32]*chain.Chain, cfg relconfig.Config, txSubmitter submitter.TransactionSubmitter) *Handler {
func NewHandler(metricsHelper metrics.Handler, db reldb.Service, chains map[uint32]*chain.Chain, cfg relconfig.Config, txSubmitter submitter.TransactionSubmitter) *Handler {
return &Handler{
metrics: metricsHelper,
db: db, // Store the database connection in the handler
chains: chains,
cfg: cfg,
Expand Down Expand Up @@ -178,8 +181,14 @@ func (h *Handler) GetQuoteRequestByTxID(c *gin.Context) {
//
//nolint:cyclop
func (h *Handler) Withdraw(c *gin.Context) {
ctx, span := h.metrics.Tracer().Start(c, "withdraw")
var err error
defer func() {
metrics.EndSpanWithErr(span, err)
}()

var req WithdrawRequest
if err := c.ShouldBindJSON(&req); err != nil {
if err = c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
Expand All @@ -197,7 +206,6 @@ func (h *Handler) Withdraw(c *gin.Context) {
}

var nonce uint64
var err error

value, ok := new(big.Int).SetString(req.Amount, 10)
if !ok {
Expand All @@ -207,14 +215,15 @@ func (h *Handler) Withdraw(c *gin.Context) {

//nolint: nestif
if chain.IsGasToken(req.TokenAddress) {
nonce, err = h.submitter.SubmitTransaction(c, big.NewInt(int64(req.ChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
nonce, err = h.submitter.SubmitTransaction(ctx, big.NewInt(int64(req.ChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
bc := bind.NewBoundContract(req.To, abi.ABI{}, h.chains[req.ChainID].Client, h.chains[req.ChainID].Client, h.chains[req.ChainID].Client)
if transactor.GasPrice != nil {
transactor.Value = value
// nolint: wrapcheck
return bc.Transfer(transactor)
}
signer, err := transactor.Signer(h.submitter.Address(), tx)
var signer *types.Transaction
signer, err = transactor.Signer(h.submitter.Address(), tx)
if err != nil {
return nil, fmt.Errorf("could not get signer: %w", err)
}
Expand All @@ -225,13 +234,14 @@ func (h *Handler) Withdraw(c *gin.Context) {
return
}
} else {
erc20Contract, err := ierc20.NewIERC20(req.TokenAddress, h.chains[req.ChainID].Client)
var erc20Contract *ierc20.IERC20
erc20Contract, err = ierc20.NewIERC20(req.TokenAddress, h.chains[req.ChainID].Client)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not create erc20 contract: %s", err.Error())})
return
}

nonce, err = h.submitter.SubmitTransaction(c, big.NewInt(int64(req.ChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
nonce, err = h.submitter.SubmitTransaction(ctx, big.NewInt(int64(req.ChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
// nolint: wrapcheck
return erc20Contract.Transfer(transactor, req.To, value)
})
Expand Down
2 changes: 1 addition & 1 deletion services/rfq/relayer/relapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *RelayerAPIServer) Run(ctx context.Context) error {
engine := ginhelper.New(logger)
// default tracing middleware
engine.Use(r.handler.Gin()...)
h := NewHandler(r.db, r.chains, r.cfg, r.submitter)
h := NewHandler(r.handler, r.db, r.chains, r.cfg, r.submitter)

// Assign GET routes
engine.GET(getHealthRoute, h.GetHealth)
Expand Down

0 comments on commit f6f2226

Please sign in to comment.