Skip to content

Commit

Permalink
RFQ API: add GET /ack endpoint (#2643)
Browse files Browse the repository at this point in the history
* WIP: add relay ack cache and GetRelayAck endpoint

* Feat: register AckRoute

* Feat: add ackMux

* Feat: add GetRelayAck test

* Feat: add GetRelayAck to UnauthenticatedClient

* Feat: relayer fetches ack before updating to CommittedPending

* [goreleaser]

* Feat: move GET /ack to PUT /ack

* WIP: generalize AuthMiddleware()

* Fix: working refactor for auth

* Feat: add PutAckRequest and parse in auth middleware

* Feat: impl PUT /ack request with json req body

* Feat: bump default timeout from 5 to 10

* Feat: add swagger comments

* Cleanup: pass API client into quoter

* Feat: return RelayerAddress in PutRelayAckResponse

* Cleanup: add clarifying comment

* [goreleaser]

* Cleanup: lint

* [goreleaser]

* Cleanup: add tracing

* [goreleaser]

* Config: bump relay ack timeout to 30 seconds

* [goreleaser]
  • Loading branch information
dwasse authored May 20, 2024
1 parent 85e40c9 commit f9b6d45
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 59 deletions.
20 changes: 20 additions & 0 deletions services/rfq/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
// It provides methods for creating, retrieving and updating quotes.
type AuthenticatedClient interface {
PutQuote(ctx context.Context, q *model.PutQuoteRequest) error
PutRelayAck(ctx context.Context, req *model.PutAckRequest) (*model.PutRelayAckResponse, error)
UnauthenticatedClient
}

Expand Down Expand Up @@ -124,6 +125,25 @@ func (c *clientImpl) PutQuote(ctx context.Context, q *model.PutQuoteRequest) err
return err
}

func (c *clientImpl) PutRelayAck(ctx context.Context, req *model.PutAckRequest) (*model.PutRelayAckResponse, error) {
var ack *model.PutRelayAckResponse
resp, err := c.rClient.R().
SetContext(ctx).
SetBody(req).
SetResult(&ack).
Put(rest.AckRoute)

if err != nil {
return nil, fmt.Errorf("error from server: %s %w", resp.Status(), err)
}

if resp.IsError() {
return nil, fmt.Errorf("error from server: %s", resp.Status())
}

return ack, nil
}

// GetAllQuotes retrieves all quotes from the RFQ quoting API.
func (c *unauthenticatedClient) GetAllQuotes(ctx context.Context) ([]*model.GetQuoteResponse, error) {
var quotes []*model.GetQuoteResponse
Expand Down
16 changes: 14 additions & 2 deletions services/rfq/api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/jftuga/ellipsis"
"gopkg.in/yaml.v2"
Expand All @@ -21,8 +22,19 @@ type Config struct {
Database DatabaseConfig `yaml:"database"`
OmniRPCURL string `yaml:"omnirpc_url"`
// bridges is a map of chainid->address
Bridges map[uint32]string `yaml:"bridges"`
Port string `yaml:"port"`
Bridges map[uint32]string `yaml:"bridges"`
Port string `yaml:"port"`
RelayAckTimeout time.Duration `yaml:"relay_ack_timeout"`
}

const defaultRelayAckTimeout = 30 * time.Second

// GetRelayAckTimeout returns the relay ack timeout.
func (c Config) GetRelayAckTimeout() time.Duration {
if c.RelayAckTimeout == 0 {
return defaultRelayAckTimeout
}
return c.RelayAckTimeout
}

// LoadConfig loads the config from the given path.
Expand Down
31 changes: 31 additions & 0 deletions services/rfq/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/ack": {
"put": {
"description": "cache an ack request to synchronize relayer actions.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ack"
],
"summary": "Relay ack",
"parameters": [
{
"description": "query params",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.PutQuoteRequest"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/quotes": {
"get": {
"description": "get quotes from all relayers.",
Expand Down
31 changes: 31 additions & 0 deletions services/rfq/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
"contact": {}
},
"paths": {
"/ack": {
"put": {
"description": "cache an ack request to synchronize relayer actions.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ack"
],
"summary": "Relay ack",
"parameters": [
{
"description": "query params",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.PutQuoteRequest"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/quotes": {
"get": {
"description": "get quotes from all relayers.",
Expand Down
20 changes: 20 additions & 0 deletions services/rfq/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ definitions:
info:
contact: {}
paths:
/ack:
put:
consumes:
- application/json
description: cache an ack request to synchronize relayer actions.
parameters:
- description: query params
in: body
name: request
required: true
schema:
$ref: '#/definitions/model.PutQuoteRequest'
produces:
- application/json
responses:
"200":
description: OK
summary: Relay ack
tags:
- ack
/quotes:
get:
consumes:
Expand Down
6 changes: 6 additions & 0 deletions services/rfq/api/model/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ type PutQuoteRequest struct {
DestFastBridgeAddress string `json:"dest_fast_bridge_address"`
}

// PutAckRequest contains the schema for a PUT /ack request.
type PutAckRequest struct {
TxID string `json:"tx_id"`
DestChainID int `json:"dest_chain_id"`
}

// GetQuoteSpecificRequest contains the schema for a GET /quote request with specific params.
type GetQuoteSpecificRequest struct {
OriginChainID int `json:"originChainId"`
Expand Down
10 changes: 10 additions & 0 deletions services/rfq/api/model/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ type GetQuoteResponse struct {
// UpdatedAt is the time that the quote was last upserted
UpdatedAt string `json:"updated_at"`
}

// PutRelayAckResponse contains the schema for a PUT /relay/ack response.
type PutRelayAckResponse struct {
// TxID is the transaction ID
TransactionID string `json:"tx_id"`
// ShouldRelay is a boolean indicating whether the transaction should be relayed
ShouldRelay bool `json:"should_relay"`
// RelayerAddress is the address of the relayer that is currently acked
RelayerAddress string `json:"relayer_address"`
}
Loading

0 comments on commit f9b6d45

Please sign in to comment.