Skip to content

Commit

Permalink
[SKI-26]: Prevent funding index update with no oracle prices from (#1321
Browse files Browse the repository at this point in the history
)

halting indexer
  • Loading branch information
Christopher-Li authored Apr 3, 2024
1 parent fbeeb7c commit 35df3b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stats } from '@dydxprotocol-indexer/base';
import { logger, stats } from '@dydxprotocol-indexer/base';
import {
FundingEventV1,
FundingEventV1_Type,
Expand Down Expand Up @@ -61,6 +61,9 @@ describe('fundingHandler', () => {
await perpetualMarketRefresher.updatePerpetualMarkets();
await assetRefresher.updateAssets();
updateBlockCache(defaultPreviousHeight);

jest.spyOn(logger, 'error');
jest.resetAllMocks();
});

afterEach(async () => {
Expand Down Expand Up @@ -168,6 +171,28 @@ describe('fundingHandler', () => {
);
});

it('successfully ignores funding rate and index for market with no oracle price', async () => {
const kafkaMessage: KafkaMessage = createKafkaMessageFromFundingEvents({
fundingEvents: [{
...defaultFundingRateEvent,
updates: [
{
perpetualId: 2,
fundingValuePpm: 10,
fundingIndex: bigIntToBytes(BigInt(0)),
},
],
}],
height: defaultHeight,
time: defaultTime,
});
await onMessage(kafkaMessage);
expect(logger.error).toHaveBeenCalledWith(expect.objectContaining({
at: 'FundingHandler#handleFundingSample',
message: 'oracle_price not found for marketId.',
}));
});

it('successfully processes and clears cache for a new funding rate with both existing/non-existent market',
async () => {
const kafkaMessage: KafkaMessage = createKafkaMessageFromFundingEvents({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ BEGIN
ORDER BY "effectiveAtHeight"
DESC LIMIT 1;
IF NOT FOUND THEN
RAISE EXCEPTION 'price not found for marketId %', perpetual_market_record."marketId";
errors_response = array_append(errors_response, '"oracle_price not found for marketId."'::jsonb);
CONTINUE;
END IF;

event_id = dydx_event_id_from_parts(block_height, transaction_index, event_index);
Expand Down

0 comments on commit 35df3b5

Please sign in to comment.