Skip to content

Commit

Permalink
Fix Stip (#2119)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Trajan0x <[email protected]>
  • Loading branch information
trajan0x and trajan0x authored Feb 27, 2024
1 parent 2967e0d commit fdef3fa
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 3 deletions.
2 changes: 2 additions & 0 deletions contrib/promexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ require (
github.com/grafana/pyroscope-go v1.1.1 // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.6 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/golang-lru/v2 v2.0.3 // indirect
Expand Down
16 changes: 15 additions & 1 deletion contrib/screener-api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// ScreenerClient is an interface for the Screener API.
type ScreenerClient interface {
ScreenAddress(ctx context.Context, ruleset, address string) (bool, error)
ScreenAddress(ctx context.Context, ruleset, address string) (blocked bool, err error)
}

type clientImpl struct {
Expand Down Expand Up @@ -53,3 +53,17 @@ func (c clientImpl) ScreenAddress(ctx context.Context, ruleset, address string)

return blockedRes.Blocked, nil
}

// NewNoOpClient creates a new no-op client for the Screener API.
// it returns false for every address.
func NewNoOpClient() (ScreenerClient, error) {
return &noOpClient{}, nil
}

type noOpClient struct{}

func (n noOpClient) ScreenAddress(_ context.Context, _, _ string) (bool, error) {
return false, nil
}

var _ ScreenerClient = noOpClient{}
2 changes: 1 addition & 1 deletion core/metrics/pyroscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package metrics

import (
otelpyroscope "github.com/grafana/otel-profiling-go"
pyroscope "github.com/grafana/pyroscope-go"
"github.com/grafana/pyroscope-go"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/config"
"github.com/synapsecns/sanguine/core/metrics/internal"
Expand Down
2 changes: 2 additions & 0 deletions ethergo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.5.0
github.com/googleapis/gax-go/v2 v2.11.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/imkira/go-interpol v1.1.0
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc
Expand Down Expand Up @@ -161,6 +162,7 @@ require (
github.com/grafana/pyroscope-go/godeltaprof v0.1.6 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
Expand Down
5 changes: 5 additions & 0 deletions ethergo/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,13 @@ github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY4
github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
2 changes: 2 additions & 0 deletions services/explorer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ require (
github.com/grafana/pyroscope-go/godeltaprof v0.1.6 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
Expand Down
2 changes: 1 addition & 1 deletion services/rfq/relayer/relconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Config struct {
SubmitterConfig submitterConfig.Config `yaml:"submitter_config"`
// FeePricer is the fee pricer config.
FeePricer FeePricerConfig `yaml:"fee_pricer"`
// ScreenerAPIUrl is the TRM API key.
// ScreenerAPIUrl is the TRM API url.
ScreenerAPIUrl string `yaml:"screener_api_url"`
// DBSelectorIntervalSeconds is the interval for the db selector.
DBSelectorIntervalSeconds int `yaml:"db_selector_interval_seconds"`
Expand Down
2 changes: 2 additions & 0 deletions services/stiprelayer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/ipfs/go-log v1.0.5
github.com/jftuga/ellipsis v1.0.0
github.com/stretchr/testify v1.8.4
github.com/synapsecns/sanguine/contrib/screener-api v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/core v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/ethergo v0.0.2
github.com/synapsecns/sanguine/services/omnirpc v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -87,6 +88,7 @@ require (
github.com/docker/docker v20.10.23+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dubonzi/otelresty v1.2.0 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/structtag v1.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions services/stiprelayer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dubonzi/otelresty v1.2.0 h1:tLWW1J0paY4Fugh5cD3qhMFHNWgM5LSXEfPCW03jyi0=
github.com/dubonzi/otelresty v1.2.0/go.mod h1:oMTNjqB31Fh8nFEWqrk+4diB4YwSmEy3zpBzxGHeLXA=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dvyukov/go-fuzz v0.0.0-20200318091601-be3528f3a813/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
Expand Down
30 changes: 30 additions & 0 deletions services/stiprelayer/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package relayer
import (
"context"
"fmt"
"github.com/synapsecns/sanguine/contrib/screener-api/client"
"math/big"
"strings"
"time"
Expand Down Expand Up @@ -40,6 +41,8 @@ type STIPRelayer struct {
submittter submitter.TransactionSubmitter
signer signer.Signer
apiServer *stipapi.Server
// screener is used to screen addresses using the screener-api client stub.
screener client.ScreenerClient
}

// NewSTIPRelayer creates a new STIPRelayer with the provided context and configuration.
Expand All @@ -60,6 +63,15 @@ func NewSTIPRelayer(ctx context.Context,
return nil, fmt.Errorf("could not get api server: %w", err)
}

screener, _ := client.NewNoOpClient()

if cfg.ScreenerAPIUrl != "" {
screener, err = client.NewClient(handler, cfg.ScreenerAPIUrl)
if err != nil {
return nil, fmt.Errorf("could not create screener client: %w", err)
}

Check warning on line 72 in services/stiprelayer/relayer/relayer.go

View check run for this annotation

Codecov / codecov/patch

services/stiprelayer/relayer/relayer.go#L69-L72

Added lines #L69 - L72 were not covered by tests
}

return &STIPRelayer{
cfg: cfg,
db: store,
Expand All @@ -68,6 +80,7 @@ func NewSTIPRelayer(ctx context.Context,
submittter: sm,
signer: sg,
apiServer: apiServer,
screener: screener,
}, nil
}

Expand Down Expand Up @@ -364,8 +377,25 @@ func (s *STIPRelayer) RelayAndRebateTransactions(ctx context.Context) error {
return nil
}

const stipRuleset = "stip"

// SubmitAndRebateTransaction handles the relaying and rebating of a single transaction.
// nolint: cyclop
func (s *STIPRelayer) SubmitAndRebateTransaction(ctx context.Context, transaction *db.STIPTransactions) error {
// Check if the address is blocked
blocked, err := s.screener.ScreenAddress(ctx, stipRuleset, transaction.Address)
if err != nil {
return fmt.Errorf("could not screen address: %w", err)
}

Check warning on line 389 in services/stiprelayer/relayer/relayer.go

View check run for this annotation

Codecov / codecov/patch

services/stiprelayer/relayer/relayer.go#L385-L389

Added lines #L385 - L389 were not covered by tests

if blocked {
err = s.db.UpdateSTIPTransactionDoNotProcess(ctx, transaction.Hash)
if err != nil {
return fmt.Errorf("could not update STIP transaction as do not process: %w", err)
}
return fmt.Errorf("address is blocked: %s", transaction.Address)

Check warning on line 396 in services/stiprelayer/relayer/relayer.go

View check run for this annotation

Codecov / codecov/patch

services/stiprelayer/relayer/relayer.go#L391-L396

Added lines #L391 - L396 were not covered by tests
}

// Calculate the transfer amount based on transaction details
// This function encapsulates the logic for determining the transfer amount
// You can define it elsewhere and call it here
Expand Down
2 changes: 2 additions & 0 deletions services/stiprelayer/stipconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Config struct {
ARBMinTransfer float64 `yaml:"ARB_min_transfer"`
DuneLookbackHours int `yaml:"dune_lookback_hours"`
StipQueryID int `yaml:"stip_query_id"`
// ScreenerAPIUrl is the TRM API url.
ScreenerAPIUrl string `yaml:"screener_api_url"`
}

const defaultArbCapPerAddress = 2000
Expand Down

0 comments on commit fdef3fa

Please sign in to comment.