Skip to content

Commit

Permalink
Merge pull request #371 from Uniswap/allsettled
Browse files Browse the repository at this point in the history
fix: use allSettled instead so that we dont throw
  • Loading branch information
ConjunctiveNormalForm authored Aug 28, 2024
2 parents cfa10d5 + 96d6366 commit 443eb84
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ export const DYNAMO_TABLE_KEY = {
export const POST_ORDER_ERROR_REASON = {
INSUFFICIENT_FUNDS: 'Onchain validation failed: InsufficientFunds',
};

export const WEBHOOK_TIMEOUT_MS = 500;
export const NOTIFICATION_TIMEOUT_MS = 10;
9 changes: 3 additions & 6 deletions lib/quoters/WebhookQuoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Logger from 'bunyan';
import { v4 as uuidv4 } from 'uuid';

import { Quoter, QuoterType } from '.';
import { NOTIFICATION_TIMEOUT_MS, WEBHOOK_TIMEOUT_MS } from '../constants';
import {
AnalyticsEvent,
AnalyticsEventType,
Expand All @@ -22,9 +23,6 @@ import { FillerComplianceConfigurationProvider } from '../providers/compliance';
import { FillerAddressRepository } from '../repositories/filler-address-repository';
import { timestampInMstoISOString } from '../util/time';

// TODO: shorten, maybe take from env config
const WEBHOOK_TIMEOUT_MS = 500;

// Quoter which fetches quotes from http endpoints
// endpoints must return well-formed QuoteResponse JSON
export class WebhookQuoter implements Quoter {
Expand Down Expand Up @@ -60,7 +58,7 @@ export class WebhookQuoter implements Quoter {
const quotes = await Promise.all(enabledEndpoints.map((e) => this.fetchQuote(e, request)));

// should not await and block
Promise.all(disabledEndpoints.map((e) => this.notifyBlock(e)));
Promise.allSettled(disabledEndpoints.map((e) => this.notifyBlock(e)));

return quotes.filter((q) => q !== null) as QuoteResponse[];
}
Expand Down Expand Up @@ -310,9 +308,8 @@ export class WebhookQuoter implements Quoter {
}

private async notifyBlock(status: { webhook: WebhookConfiguration; blockUntil: number }): Promise<void> {
const timeoutOverride = status.webhook.overrides?.timeout;
const axiosConfig = {
timeout: timeoutOverride ? Number(timeoutOverride) : WEBHOOK_TIMEOUT_MS,
timeout: NOTIFICATION_TIMEOUT_MS,
...(!!status.webhook.headers && { headers: status.webhook.headers }),
};
try {
Expand Down
6 changes: 4 additions & 2 deletions test/providers/quoters/WebhookQuoter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TradeType } from '@uniswap/sdk-core';
import axios from 'axios';
import { BigNumber, ethers } from 'ethers';

import { NOTIFICATION_TIMEOUT_MS } from '../../../lib/constants';
import { AnalyticsEventType, QuoteRequest, WebhookResponseType } from '../../../lib/entities';
import { MockWebhookConfigurationProvider, ProtocolVersion } from '../../../lib/providers';
import { FirehoseLogger } from '../../../lib/providers/analytics';
Expand Down Expand Up @@ -262,7 +263,7 @@ describe('WebhookQuoter tests', () => {
},
{
headers: {},
timeout: 500,
timeout: NOTIFICATION_TIMEOUT_MS,
}
);
});
Expand Down Expand Up @@ -306,10 +307,11 @@ describe('WebhookQuoter tests', () => {
});

await webhookQuoter.quote(request);
// blocked
expect(mockedAxios.post).toBeCalledWith(
WEBHOOK_URL_ONEINCH,
{ blockUntilTimestamp: expect.any(Number) },
{ headers: {}, timeout: 500 }
{ headers: {}, timeout: NOTIFICATION_TIMEOUT_MS }
);
expect(mockedAxios.post).toBeCalledWith(
WEBHOOK_URL_SEARCHER,
Expand Down

0 comments on commit 443eb84

Please sign in to comment.