Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ali/forta-1375-impl…
Browse files Browse the repository at this point in the history
…ementing-pipeline-for-processing-embeddings
  • Loading branch information
aomerk committed Nov 30, 2023
2 parents f6924dd + 84a1ca7 commit 74a63a6
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 201 deletions.
12 changes: 8 additions & 4 deletions ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,17 @@ func NewStreamEthClient(ctx context.Context, apiName, apiURL string) (*streamEth
}
rClient.SetHeader("Content-Type", "application/json")

client := &rpcClient{Client: rClient}
return NewStreamEthClientWithRPCClient(ctx, apiName, isWebsocket(apiURL), &rpcClient{Client: rClient})
}

// NewStreamEthClientWithRPCClient creates a new ethereum client
func NewStreamEthClientWithRPCClient(ctx context.Context, apiName string, isWs bool, rpcClient Subscriber) (*streamEthClient, error) {
return &streamEthClient{
apiName: apiName,
rpcClient: client,
subscriber: client,
rpcClient: rpcClient,
subscriber: rpcClient,
retryInterval: defaultRetryInterval,
isWebsocket: isWebsocket(apiURL),
isWebsocket: isWs,
}, nil
}

Expand Down
18 changes: 11 additions & 7 deletions ethereum/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@ const testBlockHash = "0x4fc0862e76691f5312964883954d5c2db35e2b8f7a4f191775a4f50

var testErr = errors.New("test err")

func initClient(t *testing.T) (*streamEthClient, *mocks.MockRPCClient, *mocks.MockSubscriber, context.Context) {
func initClient(t *testing.T) (*streamEthClient, *mocks.MockSubscriber, context.Context) {
r := require.New(t)

minBackoff = 1 * time.Millisecond
maxBackoff = 1 * time.Millisecond
ctx := context.Background()
ctrl := gomock.NewController(t)
client := mocks.NewMockRPCClient(ctrl)
subscriber := mocks.NewMockSubscriber(ctrl)
client := mocks.NewMockSubscriber(ctrl)

ethClient, err := NewStreamEthClientWithRPCClient(context.Background(), "", true, client)
r.NoError(err)

return &streamEthClient{rpcClient: client, subscriber: subscriber}, client, subscriber, ctx
return ethClient, client, ctx
}

func TestEthClient_BlockByHash(t *testing.T) {
r := require.New(t)

ethClient, client, _, ctx := initClient(t)
ethClient, client, ctx := initClient(t)
hash := testBlockHash
// verify retry
client.EXPECT().CallContext(gomock.Any(), gomock.Any(), blocksByHash, testBlockHash).Return(testErr).Times(1)
Expand All @@ -51,10 +55,10 @@ func TestEthClient_BlockByHash(t *testing.T) {
func TestEthClient_SubscribeToHeader_Err(t *testing.T) {
r := require.New(t)

ethClient, _, subscriber, ctx := initClient(t)
ethClient, client, ctx := initClient(t)
sub := mock_domain.NewMockClientSubscription(gomock.NewController(t))

subscriber.EXPECT().Subscribe(gomock.Any(), "eth", gomock.Any(), "newHeads").Return(sub, nil).Times(2)
client.EXPECT().Subscribe(gomock.Any(), "eth", gomock.Any(), "newHeads").Return(sub, nil).Times(2)
errCh := make(chan error, 1)
errCh <- errors.New("subscription encountered some error")
sub.EXPECT().Err().Return(errCh).Times(2)
Expand Down
3 changes: 2 additions & 1 deletion feeds/timeline/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestTimeline_CalculateLag(t *testing.T) {
r := require.New(t)

blockTimeline := NewBlockTimeline(1, 1000000)
blockTimeline.threshold = 10

start := time.Now().UTC().Truncate(time.Minute)

Expand Down Expand Up @@ -169,7 +170,7 @@ func TestTimeline_CalculateLag(t *testing.T) {
r.Equal(float64(1+5+9+13+15+2)/float64(6), lag)
estimate, ok := blockTimeline.EstimateBlockScore()
r.True(ok)
r.Equal(0.0625, estimate)
r.Equal(0.25, estimate)

testDelay := time.Second
blockTimeline.delay = &testDelay
Expand Down
356 changes: 216 additions & 140 deletions protocol/batch.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions protocol/batch.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ message AlertBatch {
InspectionResults inspectionResults = 13;
repeated CombinationAlertResults combinationAlerts = 14;
Provider provider = 15;
Estimation estimation = 16;
}

message BlockResults {
Expand Down Expand Up @@ -119,3 +120,7 @@ message InspectionInputs {
string ensContractAddress = 7;
string scannerAddress = 8;
}

message Estimation {
double blockScore = 1;
}
104 changes: 56 additions & 48 deletions protocol/settings/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ var defaultRateLimiting = &RateLimit{

// ChainSettings contains chain-specific settings.
type ChainSettings struct {
ChainID int
Name string
EnableTrace bool
JsonRpcRateLimiting *RateLimit
InspectionInterval int // in block number
BlockThreshold int
ChainID int
Name string
EnableTrace bool
JsonRpcRateLimiting *RateLimit
InspectionInterval int // in block number
BlockThreshold int
JSONRPCRetryIntervalSeconds int
}

// RateLimit is token bucket algorithm parameters.
Expand All @@ -27,60 +28,67 @@ type RateLimit struct {
// safe offsets are adjusted to be 5-10% of the block threshold (at least 1)
var allChainSettings = []ChainSettings{
{
ChainID: 1,
Name: "Ethereum Mainnet",
EnableTrace: true,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 50,
BlockThreshold: 8,
ChainID: 1,
Name: "Ethereum Mainnet",
EnableTrace: true,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 50,
BlockThreshold: 5,
JSONRPCRetryIntervalSeconds: 8,
},
{
ChainID: 10,
Name: "Optimism",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 100,
BlockThreshold: 8,
ChainID: 10,
Name: "Optimism",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 100,
BlockThreshold: 10,
JSONRPCRetryIntervalSeconds: 4,
},
{
ChainID: 56,
Name: "BSC",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 250,
BlockThreshold: 20,
ChainID: 56,
Name: "BSC",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 250,
BlockThreshold: 10,
JSONRPCRetryIntervalSeconds: 4,
},
{
ChainID: 137,
Name: "Polygon",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 70,
BlockThreshold: 30,
ChainID: 137,
Name: "Polygon",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 70,
BlockThreshold: 10,
JSONRPCRetryIntervalSeconds: 4,
},
{
ChainID: 250,
Name: "Fantom",
EnableTrace: true,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 750,
BlockThreshold: 35,
ChainID: 250,
Name: "Fantom",
EnableTrace: true,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 750,
BlockThreshold: 10,
JSONRPCRetryIntervalSeconds: 4,
},
{
ChainID: 42161,
Name: "Arbitrum",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 1500,
BlockThreshold: 80,
ChainID: 42161,
Name: "Arbitrum",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 1500,
BlockThreshold: 40,
JSONRPCRetryIntervalSeconds: 4,
},
{
ChainID: 43114,
Name: "Avalanche",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 350,
BlockThreshold: 30,
ChainID: 43114,
Name: "Avalanche",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 350,
BlockThreshold: 10,
JSONRPCRetryIntervalSeconds: 4,
},
}

Expand Down
2 changes: 1 addition & 1 deletion release/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Release defaults
const (
DefaultDeprecationHours = 168 // 1 week
DefaultDeprecationHours = 48 // 2 days
DefaultAutoUpdateHours = 24
)

Expand Down

0 comments on commit 74a63a6

Please sign in to comment.