Skip to content

Commit c311c65

Browse files
Alex Steleaclaude
andauthored
Add retry logic for gateway API client and fix lint issues (#205)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent b39cf0e commit c311c65

2 files changed

Lines changed: 58 additions & 15 deletions

File tree

packages/api/src/common/gateway/gatewayApiClient.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ export class GatewayApiClientService extends Effect.Service<GatewayApiClientServ
2424
'GATEWAY_RETRY_ATTEMPTS',
2525
).pipe(Config.withDefault(5));
2626

27-
/**
28-
* Enable retries for ALL requests including POST
29-
* - Retry on network errors and 4xx/5xx status codes
30-
* - Uses exponential backoff with randomization
31-
* - Supports retrying POST requests (unlike make-fetch-happen)
32-
*/
27+
const noRetryStatusCodes = new Set([400, 404]);
3328

3429
const fetchImpl = fetchRetry(fetch, {
3530
retries: gatewayRetryAttempts,
@@ -43,8 +38,11 @@ export class GatewayApiClientService extends Effect.Service<GatewayApiClientServ
4338
if (error !== null) {
4439
return false;
4540
}
41+
4642
// Retry on 4xx/5xx status codes (including for POST requests)
47-
if (response && response.status > 400) {
43+
if (response && !response.ok) {
44+
if (noRetryStatusCodes.has(response.status)) return false;
45+
4846
return true;
4947
}
5048

tools/calculate-points/src/snapshot.ts

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const NodeSdkLive = NodeSdk.layer(() => ({
1414
),
1515
}));
1616

17+
import { FetchService } from 'api/common';
1718
import { AddressValidationServiceLive } from '../../../packages/api/src/common/address-validation/addressValidation';
1819
import { GetCaviarnineResourcePoolPositionsLive } from '../../../packages/api/src/common/dapps/caviarnine/getCaviarnineResourcePoolPositions';
1920
import { GetHyperstakePositionsLive } from '../../../packages/api/src/common/dapps/caviarnine/getHyperstakePositions';
@@ -59,12 +60,13 @@ import { AggregateCaviarninePositionsLive } from '../../../packages/api/src/ince
5960
import { AggregateDefiPlazaPositionsLive } from '../../../packages/api/src/incentives/account-balance/aggregateDefiPlazaPositions';
6061
import { AggregateOciswapPositionsLive } from '../../../packages/api/src/incentives/account-balance/aggregateOciswapPositions';
6162
import { AggregatePoolPositionsService } from '../../../packages/api/src/incentives/account-balance/aggregatePoolPositions';
62-
import { AggregateRootFinancePositionsLive } from '../../../packages/api/src/incentives/account-balance/aggregateRootFinancePositions';
63+
import { AggregateRootFinancePositionsService } from '../../../packages/api/src/incentives/account-balance/aggregateRootFinancePositions';
6364
import { AggregateSurgePositionsLive } from '../../../packages/api/src/incentives/account-balance/aggregateSurgePositions';
64-
import { AggregateWeftFinancePositionsLive } from '../../../packages/api/src/incentives/account-balance/aggregateWeftFinancePositions';
65+
import { AggregateWeftFinancePositionsService } from '../../../packages/api/src/incentives/account-balance/aggregateWeftFinancePositions';
6566
import { XrdBalanceLive } from '../../../packages/api/src/incentives/account-balance/aggregateXrdBalance';
6667
import { GetAccountBalancesAtStateVersionLive } from '../../../packages/api/src/incentives/account-balance/getAccountBalancesAtStateVersion';
6768
import { UpsertAccountBalancesLive } from '../../../packages/api/src/incentives/account-balance/upsertAccountBalance';
69+
import { ConfigService } from '../../../packages/api/src/incentives/config/configService';
6870
// Snapshot services
6971
import { CreateSnapshotLive } from '../../../packages/api/src/incentives/snapshot/createSnapshot';
7072
import { UpdateSnapshotLive } from '../../../packages/api/src/incentives/snapshot/updateSnapshot';
@@ -278,10 +280,14 @@ const runnable = Effect.gen(function* () {
278280
);
279281

280282
const aggregateWeftFinancePositionsLive =
281-
AggregateWeftFinancePositionsLive.pipe(Layer.provide(getUsdValueLive));
283+
AggregateWeftFinancePositionsService.Default.pipe(
284+
Layer.provide(getUsdValueLive),
285+
);
282286

283287
const aggregateRootFinancePositionsLive =
284-
AggregateRootFinancePositionsLive.pipe(Layer.provide(getUsdValueLive));
288+
AggregateRootFinancePositionsService.Default.pipe(
289+
Layer.provide(getUsdValueLive),
290+
);
285291

286292
const aggregateDefiPlazaPositionsLive = AggregateDefiPlazaPositionsLive.pipe(
287293
Layer.provide(getUsdValueLive),
@@ -359,6 +365,9 @@ const runnable = Effect.gen(function* () {
359365
Layer.provide(addressValidationServiceLive),
360366
);
361367

368+
const configServiceLive = ConfigService.Default;
369+
const fetchServiceLive = FetchService.Default;
370+
362371
const snapshotLive = SnapshotService.Default.pipe(
363372
Layer.provide(gatewayApiClientLive),
364373
Layer.provide(getAccountBalancesAtStateVersionLive),
@@ -370,24 +379,60 @@ const runnable = Effect.gen(function* () {
370379
Layer.provide(aggregateAccountBalanceLive),
371380
Layer.provide(getAllValidatorsServiceLive),
372381
Layer.provide(aggregatePoolPositionsLive),
382+
Layer.provide(configServiceLive),
383+
Layer.provide(fetchServiceLive),
384+
Layer.provide(getLedgerStateLive),
385+
Layer.provide(dbClientLive),
373386
);
374387

375388
const service = yield* Effect.provide(SnapshotService, snapshotLive);
376389

377-
const addresses = yield* Effect.tryPromise(() =>
390+
const _addresses = yield* Effect.tryPromise(() =>
378391
db.query.accounts
379392
.findMany({
380393
limit: 10,
381394
})
382395
.then((res) => res.map((r) => r.address)),
383396
);
384397

385-
const testAccountAddress = process.env.TEST_ACCOUNT_ADDRESS;
398+
const _testAccountAddress = process.env.TEST_ACCOUNT_ADDRESS;
386399

387400
yield* service({
388-
timestamp: new Date('2025-07-20T00:00:00.000Z'),
401+
timestamp: new Date('2024-09-01T00:00:00.000Z'),
389402
batchSize: 10_000,
390-
addresses: testAccountAddress ? [testAccountAddress] : addresses,
403+
addresses: [
404+
'account_rdx1280003ttgydsuus9dl3ag4mn7l37lktqtt3z9rqun3cecx8spj0xmw',
405+
'account_rdx1280007fzy8wxjvlw2u23lge4p5kyttnuzezmww8j44rlcr708s75qs',
406+
'account_rdx128000lh2huxqyfjug5gux3tqgxs723693uu7dyfwkx9fsdpj9r7la7',
407+
],
408+
addDummyData: false,
409+
includeActivityIds: [
410+
'c9_ho_floop-xrd',
411+
'c9_ho_lsulp-reddicks',
412+
'c9_ho_lsulp-xrd',
413+
'c9_ho_xeth-xrd',
414+
'c9_ho_xrd-xusdc',
415+
'c9_ho_xrd-xusdt',
416+
'c9_ho_xrd-xwbtc',
417+
'dp_ho_dfp2-xrd',
418+
'dp_ho_xeth-xrd',
419+
'dp_ho_xrd-xusdc',
420+
'dp_ho_xrd-xusdt',
421+
'dp_ho_xrd-xwbtc',
422+
'oc_ho_early-xrd',
423+
'oc_ho_ilis-xrd',
424+
'oc_ho_oci-xrd',
425+
'oc_ho_xeth-xrd',
426+
'oc_ho_xrd-xusdc',
427+
'oc_ho_xrd-xusdt',
428+
'oc_ho_xrd-xwbtc',
429+
'ro_ho_lsulp',
430+
'ro_ho_xrd',
431+
'we_ho_lsulp',
432+
'we_ho_stakedXrd',
433+
'we_ho_unstakedXrd',
434+
'we_ho_xrd',
435+
],
391436
}).pipe(Effect.provide(NodeSdkLive));
392437
});
393438

0 commit comments

Comments
 (0)