Skip to content

Commit

Permalink
[goreleaser] rewrite handler
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Dec 29, 2023
1 parent 3d56398 commit d08c2c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions services/rfq/relayer/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *Relayer) handleBridgeRequestedLog(parentCtx context.Context, req *fastb
//
// This is the second step in the bridge process. It is emitted when the relayer sees the request.
// We check if we have enough inventory to process the request and mark it as committed pending.
func (q *QuoteRequestHandler) handleSeen(ctx context.Context, request reldb.QuoteRequest) (err error) {
func (q *QuoteRequestHandler) handleSeen(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
if !q.Quoter.ShouldProcess(ctx, request) {
err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.WillNotProcess)
if err != nil {
Expand Down Expand Up @@ -124,7 +124,7 @@ func (q *QuoteRequestHandler) handleSeen(ctx context.Context, request reldb.Quot
// never relayed.
// Reorgs are rare enough that its questionable wether this is ever worth building or if we can just
// leave these in the queue.
func (q *QuoteRequestHandler) handleCommitPending(ctx context.Context, request reldb.QuoteRequest) (err error) {
func (q *QuoteRequestHandler) handleCommitPending(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
earliestConfirmBlock := request.BlockNumber + q.Origin.Confirmations
if earliestConfirmBlock < q.Origin.LatestBlock() {
// can't complete yet, do nothing
Expand All @@ -151,7 +151,7 @@ func (q *QuoteRequestHandler) handleCommitPending(ctx context.Context, request r
//
// This is the fourth step in the bridge process. Here we submit the relay transaction to the destination chain.
// TODO: just to be safe, we should probably check if another relayer has already relayed this.
func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, request reldb.QuoteRequest) (err error) {
func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
gasAmount := big.NewInt(0)

if request.Transaction.SendChainGas {
Expand Down Expand Up @@ -214,7 +214,7 @@ func (r *Relayer) handleRelayLog(ctx context.Context, req *fastbridge.FastBridge
// Step 6: ProvePosting
//
// This is the sixth step in the bridge process. Here we submit the claim transaction to the origin chain.
func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, request reldb.QuoteRequest) (err error) {
func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
// 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
Expand Down Expand Up @@ -254,7 +254,7 @@ func (r *Relayer) handleProofProvided(ctx context.Context, req *fastbridge.FastB
// Step 8: ClaimPending
//
// we'll wait until optimistic period is over to check if we can claim.
func (q *QuoteRequestHandler) handleProofPosted(ctx context.Context, request reldb.QuoteRequest) (err error) {
func (q *QuoteRequestHandler) handleProofPosted(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
// we shouldnt' check the claim yet
if !q.shouldCheckClaim(request) {
return nil
Expand Down Expand Up @@ -291,7 +291,7 @@ func (q *QuoteRequestHandler) handleProofPosted(ctx context.Context, request rel
// Error Handlers Only from this point belo
//
// handleNotEnoughInventory handles the not enough inventory status.
func (q *QuoteRequestHandler) handleNotEnoughInventory(ctx context.Context, request reldb.QuoteRequest) (err error) {
func (q *QuoteRequestHandler) handleNotEnoughInventory(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) {
commitableBalance, err := q.Inventory.GetCommittableBalance(ctx, int(q.Dest.ChainID), request.Transaction.DestToken)
if err != nil {
return fmt.Errorf("could not get commitable balance: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions services/rfq/relayer/service/statushandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type QuoteRequestHandler struct {
}

// Handler is the handler for a quote request.
type Handler func(ctx context.Context, req reldb.QuoteRequest) error
type Handler func(ctx context.Context, span trace.Span, req reldb.QuoteRequest) error

// Chain is a chain helper for relayer.
// lowercase fields are private, uppercase are public.
Expand Down Expand Up @@ -110,8 +110,8 @@ func (r *Relayer) requestToHandler(ctx context.Context, req reldb.QuoteRequest)
}

// TODO: this is where you need ot check the deadline.
func (r *Relayer) deadlineMiddleware(next func(ctx context.Context, req reldb.QuoteRequest) error) func(ctx context.Context, req reldb.QuoteRequest) error {
return func(ctx context.Context, req reldb.QuoteRequest) error {
func (r *Relayer) deadlineMiddleware(next func(ctx context.Context, span trace.Span, req reldb.QuoteRequest) error) func(ctx context.Context, span trace.Span, req reldb.QuoteRequest) error {
return func(ctx context.Context, span trace.Span, req reldb.QuoteRequest) error {
// if deadline < now, we don't even have to bother calling the underlying function
if req.Transaction.Deadline.Cmp(big.NewInt(time.Now().Unix())) < 0 {
err := r.db.UpdateQuoteRequestStatus(ctx, req.TransactionID, reldb.DeadlineExceeded)
Expand All @@ -121,7 +121,7 @@ func (r *Relayer) deadlineMiddleware(next func(ctx context.Context, req reldb.Qu
return nil
}

return next(ctx, req)
return next(ctx, span, req)
}
}

Expand Down Expand Up @@ -170,5 +170,5 @@ func (q *QuoteRequestHandler) Handle(ctx context.Context, request reldb.QuoteReq
metrics.EndSpanWithErr(span, err)
}()

return q.handlers[request.Status](ctx, request)
return q.handlers[request.Status](ctx, span, request)
}

0 comments on commit d08c2c6

Please sign in to comment.