diff --git a/lib/handlers/hard-quote/injector.ts b/lib/handlers/hard-quote/injector.ts index 8045b3c..b03649f 100644 --- a/lib/handlers/hard-quote/injector.ts +++ b/lib/handlers/hard-quote/injector.ts @@ -56,7 +56,10 @@ export class QuoteInjector extends ApiInjector { if ( - this.fillerHashes.length === 0 || + this.fillerEndpoints.length === 0 || Date.now() - this.lastUpdatedTimestamp > DynamoCircuitBreakerConfigurationProvider.UPDATE_PERIOD_MS ) { await this.fetchConfigurations(); @@ -44,7 +44,7 @@ export class DynamoCircuitBreakerConfigurationProvider implements CircuitBreaker } async fetchConfigurations(): Promise { - this.timestamps = await this.timestampDB.getFillerTimestampsMap(this.fillerHashes); + this.timestamps = await this.timestampDB.getFillerTimestampsMap(this.fillerEndpoints); } /* add filler if it's not blocked until a future timestamp */ @@ -55,9 +55,15 @@ export class DynamoCircuitBreakerConfigurationProvider implements CircuitBreaker if (fillerTimestamps.size) { this.log.info({ fillerTimestamps: [...fillerTimestamps.entries()] }, `Circuit breaker config used`); const enabledEndpoints = endpoints.filter((e) => { - return !(fillerTimestamps.has(e.hash) && fillerTimestamps.get(e.hash)!.blockUntilTimestamp > now); + return !(fillerTimestamps.has(e.endpoint) && fillerTimestamps.get(e.endpoint)!.blockUntilTimestamp > now); }); - this.log.info({ endpoints: enabledEndpoints }, `Endpoint enabled`); + const disabledEndpoints = endpoints.filter((e) => { + return fillerTimestamps.has(e.endpoint) && fillerTimestamps.get(e.endpoint)!.blockUntilTimestamp > now; + }); + + this.log.info({ num: enabledEndpoints.length, endpoints: enabledEndpoints }, `Endpoints enabled`); + this.log.info({ num: disabledEndpoints.length, endpoints: disabledEndpoints }, `Endpoints disabled`); + return enabledEndpoints; } diff --git a/lib/providers/circuit-breaker/mock.ts b/lib/providers/circuit-breaker/mock.ts index 7f6aa91..1c6f8e8 100644 --- a/lib/providers/circuit-breaker/mock.ts +++ b/lib/providers/circuit-breaker/mock.ts @@ -14,7 +14,7 @@ export class MockV2CircuitBreakerConfigurationProvider implements CircuitBreaker const fillerTimestamps = await this.getConfigurations(); if (fillerTimestamps.size) { const enabledEndpoints = endpoints.filter((e) => { - return !(fillerTimestamps.has(e.hash) && fillerTimestamps.get(e.hash)!.blockUntilTimestamp > now); + return !(fillerTimestamps.has(e.endpoint) && fillerTimestamps.get(e.endpoint)!.blockUntilTimestamp > now); }); return enabledEndpoints; } diff --git a/test/providers/circuit-breaker/cb-provider.test.ts b/test/providers/circuit-breaker/cb-provider.test.ts index 4a19079..cbc4d81 100644 --- a/test/providers/circuit-breaker/cb-provider.test.ts +++ b/test/providers/circuit-breaker/cb-provider.test.ts @@ -14,28 +14,28 @@ const FILLER_TIMESTAMPS: FillerTimestamps = new Map([ const WEBHOOK_CONFIGS = [ { name: 'f1', - endpoint: 'http://localhost:3000', - hash: 'filler1', + endpoint: 'filler1', + hash: '0xfiller1', }, { name: 'f2', - endpoint: 'http://localhost:3000', - hash: 'filler2', + endpoint: 'filler2', + hash: '0xfiller2', }, { name: 'f3', - endpoint: 'http://localhost:3000', - hash: 'filler3', + endpoint: 'filler3', + hash: '0xfiller3', }, { name: 'f4', - endpoint: 'http://localhost:3000', - hash: 'filler4', + endpoint: 'filler4', + hash: '0xfiller4', }, { name: 'f5', - endpoint: 'http://localhost:3000', - hash: 'filler5', + endpoint: 'filler5', + hash: '0xfiller5', }, ]; @@ -46,18 +46,18 @@ describe('V2CircuitBreakerProvider', () => { expect(await provider.getEligibleEndpoints(WEBHOOK_CONFIGS)).toEqual([ { name: 'f1', - endpoint: 'http://localhost:3000', - hash: 'filler1', + endpoint: 'filler1', + hash: '0xfiller1', }, { name: 'f2', - endpoint: 'http://localhost:3000', - hash: 'filler2', + endpoint: 'filler2', + hash: '0xfiller2', }, { name: 'f4', - endpoint: 'http://localhost:3000', - hash: 'filler4', + endpoint: 'filler4', + hash: '0xfiller4', }, ]); }); diff --git a/test/providers/quoters/WebhookQuoter.test.ts b/test/providers/quoters/WebhookQuoter.test.ts index 9e56309..7b11320 100644 --- a/test/providers/quoters/WebhookQuoter.test.ts +++ b/test/providers/quoters/WebhookQuoter.test.ts @@ -326,10 +326,10 @@ describe('WebhookQuoter tests', () => { describe('circuit breaker v2 tests', () => { const now = Math.floor(Date.now() / 1000); const mockCBProvider = new MockV2CircuitBreakerConfigurationProvider( - ['0xuni', '0x1inch', '0xsearcher'], + [WEBHOOK_URL, WEBHOOK_URL_ONEINCH, WEBHOOK_URL_SEARCHER], new Map([ - ['0x1inch', { blockUntilTimestamp: now + 100000, lastPostTimestamp: now - 10 }], - ['0xsearcher', { blockUntilTimestamp: now - 10, lastPostTimestamp: now - 100 }], + [WEBHOOK_URL_ONEINCH, { blockUntilTimestamp: now + 100000, lastPostTimestamp: now - 10 }], + [WEBHOOK_URL_SEARCHER, { blockUntilTimestamp: now - 10, lastPostTimestamp: now - 100 }], ]) ); const webhookQuoter = new WebhookQuoter(