Skip to content

Commit

Permalink
Self review
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Jan 8, 2024
1 parent 0f523d8 commit 24b1e40
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
23 changes: 15 additions & 8 deletions src/update-feeds-loops/get-updatable-feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { getState } from '../state';
import type { BeaconId, ChainId, SignedData } from '../types';
import { decodeBeaconValue, multiplyBigNumber } from '../utils';

import { getApi3ServerV1, type DecodedActiveDataFeedResponse, decodeGetChainIdResponse } from './contracts';
import {
getApi3ServerV1,
type DecodedActiveDataFeedResponse,
decodeGetChainIdResponse,
verifyMulticallResponse,
} from './contracts';

interface BeaconValue {
timestamp: ethers.BigNumber;
Expand Down Expand Up @@ -122,13 +127,15 @@ export const multicallBeaconValues = async (
// and using returndata directly. If the call fails (e.g. timeout or RPC error) we let the parent handle it.
const api3ServerV1 = getApi3ServerV1(contracts.Api3ServerV1, provider);
const voidSigner = new ethers.VoidSigner(ethers.constants.AddressZero, provider);
const { returndata } = await api3ServerV1
.connect(voidSigner)
.callStatic.tryMulticall([
api3ServerV1.interface.encodeFunctionData('getChainId'),
...batch.map((beaconId) => api3ServerV1.interface.encodeFunctionData('dataFeeds', [beaconId])),
]);
const [chainIdReturndata, ...dataFeedsReturndata] = returndata;
const returndatas = verifyMulticallResponse(
await api3ServerV1
.connect(voidSigner)
.callStatic.tryMulticall([
api3ServerV1.interface.encodeFunctionData('getChainId'),
...batch.map((beaconId) => api3ServerV1.interface.encodeFunctionData('dataFeeds', [beaconId])),
])
);
const [chainIdReturndata, ...dataFeedsReturndata] = returndatas;

const contractChainId = decodeGetChainIdResponse(chainIdReturndata!).toString();
if (contractChainId !== chainId) {
Expand Down
2 changes: 1 addition & 1 deletion src/update-feeds-loops/submit-transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ describe(submitTransactionsModule.submitTransaction.name, () => {
},
},
}),
1
123_456
);

// Verify that the data feed was updated successfully.
Expand Down
2 changes: 1 addition & 1 deletion src/update-feeds-loops/update-feeds-loops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe(updateFeedsLoopsModule.runUpdateFeeds.name, () => {
const chainId = ethers.BigNumber.from(31_337);
airseekerRegistry.callStatic.tryMulticall.mockResolvedValueOnce({
successes: [true, true, true, true],
returndata: [ethers.BigNumber.from(3), ethers.BigNumber.from(123), chainId, firstDataFeed],
returndata: [ethers.BigNumber.from(3), blockNumber, chainId, firstDataFeed],
});
airseekerRegistry.callStatic.tryMulticall.mockResolvedValueOnce({
successes: [true, true, false],
Expand Down
11 changes: 6 additions & 5 deletions src/update-feeds-loops/update-feeds-loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,18 @@ export const readActiveDataFeedBatch = async (
}
const [getBlockNumberReturndata, getChainIdReturndata, ...activeDataFeedReturndatas] = returndatas;

// Check that the chain ID is correct and throw an error if it's not because providers may switch chain ID. In case
// the chain ID is wrong, we want to skip all data feeds in the batch (or all of them in case this is the first
// batch). Another possibility is a wrong chain ID in the configuration (misconfiguration).
// Check that the chain ID is correct and log a warning if it's not because it's possible that providers switch chain
// ID at runtime by mistake. In case the chain ID is wrong, we want to skip all data feeds in the batch (or all of
// them in case this is the first batch). Another possibility of a wrong chain ID is misconfiguration in airseeker
// file.
const contractChainId = decodeGetChainIdResponse(getChainIdReturndata!).toString();
if (contractChainId !== chainId) {
logger.warn(`Chain ID mismatch.`, { chainId, contractChainId });
return null;
}

// In the first batch we may have asked for a non-existent data feed (index out of bounds). We need to slice them off
// based on the active data feed count.
// In the first batch we may have asked for a non-existent data feed. We need to slice them off based on the active
// data feed count.
let activeDataFeedCount: number | undefined;
let batchReturndata = activeDataFeedReturndatas;
if (fromIndex === 0) {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/update-feeds.feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ it('updates blockchain data', async () => {
);
expect(logger.debug).toHaveBeenNthCalledWith(10, 'Setting timestamp of the original update transaction.');
expect(logger.info).toHaveBeenCalledTimes(2);
expect(logger.info).toHaveBeenNthCalledWith(2, 'Updating data feed.', expect.anything());
expect(logger.info).toHaveBeenNthCalledWith(1, 'Successfully updated data feed.');
expect(logger.info).toHaveBeenNthCalledWith(1, 'Updating data feed.', expect.anything());
expect(logger.info).toHaveBeenNthCalledWith(2, 'Successfully updated data feed.');
});

0 comments on commit 24b1e40

Please sign in to comment.