Skip to content

Commit bd656fb

Browse files
authored
Remove DApi data from the state (#101)
* Remove dapi data from state, general clean up * Remove unused export
1 parent b2d99fc commit bd656fb

File tree

9 files changed

+8
-62
lines changed

9 files changed

+8
-62
lines changed

jest-e2e.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module.exports = {
99
collectCoverage: false, // It doesn't make sense to collect coverage for e2e tests because they target high level features and interaction with other services.
1010
maxWorkers: 1, // We don't want to run tests in parallel because they might interfere with each other. This option is the same as --runInBand. See: https://stackoverflow.com/a/46489246.
1111

12-
mockReset: true,
1312
preset: 'ts-jest',
13+
resetMocks: true,
1414
restoreMocks: true,
1515
setupFiles: [join(__dirname, './jest.setup.js')],
1616
testEnvironment: 'jest-environment-node',

jest-unit.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module.exports = {
1111
coveragePathIgnorePatterns: ['node_modules', '<rootDir>/src/typechain-types'], // Coverage is collected for all files imported by the tests. We want to exclude files generated by Typechain.
1212
coverageProvider: 'v8',
1313

14-
mockReset: true,
1514
preset: 'ts-jest',
15+
resetMocks: true,
1616
restoreMocks: true,
1717
setupFiles: [join(__dirname, './jest.setup.js')],
1818
testEnvironment: 'jest-environment-node',

src/signed-api-fetch/data-fetcher.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jest.mock('axios');
1111

1212
describe('data fetcher', () => {
1313
beforeEach(() => {
14-
jest.resetAllMocks();
1514
initializeState();
1615
localDataStore.clear();
1716
updateState((draft) => {

src/signed-api-fetch/data-fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const stopDataFetcher = () => {
3939
/**
4040
* Calls a remote signed data URL.
4141
* @param url
42-
* @param signedDataFetchInterval
42+
* @param signedDataFetchIntervalMs
4343
*/
4444
export const callSignedDataApi = async (
4545
url: string,

src/signed-data-store/signed-data-store.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BigNumber, ethers } from 'ethers';
33

44
import { logger } from '../logger';
55
import { getState, updateState } from '../state';
6-
import type { SignedData, AirnodeAddress, TemplateId, BeaconId } from '../types';
6+
import type { SignedData, BeaconId } from '../types';
77
import { deriveBeaconId } from '../utils';
88

99
export const verifySignedData = ({ airnode, templateId, timestamp, signature, encodedValue }: SignedData) => {
@@ -92,9 +92,6 @@ export const setStoreDataPoint = (signedData: SignedData) => {
9292
});
9393
};
9494

95-
export const getStoreDataPointByAirnodeAndTemplate = (airnode: AirnodeAddress, template: TemplateId) =>
96-
getState().signedApiStore[deriveBeaconId(airnode, template)!];
97-
9895
export const getStoreDataPoint = (dataFeedId: BeaconId) => getState().signedApiStore[dataFeedId];
9996

10097
export const clear = () => {

src/state/state.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { Config } from '../config/schema';
55
import type {
66
DapiName,
77
PrivateKey,
8-
DecodedDataFeed,
98
ChainId,
109
SignedData,
1110
BeaconId,
@@ -19,31 +18,13 @@ interface GasState {
1918
sponsorLastUpdateTimestampMs: Record<string, number>;
2019
}
2120

22-
export interface DataFeedValue {
23-
value: BigNumber;
24-
timestamp: number;
25-
}
26-
27-
export interface DapiState {
28-
dataFeed: DecodedDataFeed;
29-
dataFeedValues: Record<ChainId, DataFeedValue>;
30-
updateParameters: Record<ChainId, UpdateParameters>;
31-
}
32-
33-
export interface UpdateParameters {
34-
deviationThresholdInPercentage: BigNumber;
35-
deviationReference: BigNumber;
36-
heartbeatInterval: number;
37-
}
38-
3921
export interface State {
4022
config: Config;
4123
dataFetcherInterval?: NodeJS.Timeout;
4224
gasPriceStore: Record<ChainId, Record<ProviderName, GasState>>;
4325
derivedSponsorWallets: Record<DapiName, PrivateKey>;
4426
signedApiStore: Record<BeaconId, SignedData>;
4527
signedApiUrlStore: Record<ChainId, Record<ProviderName, Record<AirnodeAddress, SignedApiUrl>>>;
46-
dapis: Record<DapiName, DapiState>;
4728
}
4829

4930
type StateUpdater = (draft: Draft<State>) => void;
@@ -65,7 +46,6 @@ export const setInitialState = (config: Config) => {
6546
signedApiStore: {},
6647
signedApiUrlStore: {},
6748
derivedSponsorWallets: {},
68-
dapis: {},
6949
};
7050
};
7151

src/update-feeds/update-feeds.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,6 @@ export const processBatch = async (
193193
for (const { airnodeAddress, url } of receivedUrls) {
194194
draft.signedApiUrlStore[chainId]![providerName]![airnodeAddress] = url;
195195
}
196-
197-
const cachedDapiResponse = draft.dapis[dapi.dapiName];
198-
draft.dapis[dapi.dapiName] = {
199-
dataFeed: cachedDapiResponse?.dataFeed ?? dapi.decodedDataFeed,
200-
dataFeedValues: { ...cachedDapiResponse?.dataFeedValues, [chainId]: dapi.dataFeedValue },
201-
updateParameters: { ...cachedDapiResponse?.updateParameters, [chainId]: dapi.updateParameters },
202-
};
203196
}
204197
});
205198

src/update-feeds/update-transactions.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,15 @@ export const updateFeeds = async (
4747
const goUpdate = await go(
4848
async () => {
4949
// Create calldata for all beacons of the particular data feed the dAPI points to.
50-
const beaconUpdateCalls = updatableBeacons.map((beacon) => {
51-
const { signedData } = beacon;
52-
53-
return api3ServerV1.interface.encodeFunctionData('updateBeaconWithSignedData', [
50+
const beaconUpdateCalls = updatableBeacons.map(({ signedData }) =>
51+
api3ServerV1.interface.encodeFunctionData('updateBeaconWithSignedData', [
5452
signedData.airnode,
5553
signedData.templateId,
5654
signedData.timestamp,
5755
signedData.encodedValue,
5856
signedData.signature,
59-
]);
60-
});
57+
])
58+
);
6159

6260
// If there are multiple beacons in the data feed it's a beacons set which we need to update as well.
6361
const dataFeedUpdateCalldatas =
@@ -155,23 +153,3 @@ export const getDerivedSponsorWallet = (sponsorWalletMnemonic: string, dapiName:
155153

156154
return sponsorWallet;
157155
};
158-
159-
export const createDummyBeaconUpdateData = async (dummyAirnode: ethers.Wallet = ethers.Wallet.createRandom()) => {
160-
const dummyBeaconTemplateId = ethers.utils.hexlify(ethers.utils.randomBytes(32));
161-
const dummyBeaconTimestamp = Math.floor(Date.now() / 1000);
162-
const randomBytes = ethers.utils.randomBytes(Math.floor(Math.random() * 27) + 1);
163-
const dummyBeaconData = ethers.utils.defaultAbiCoder.encode(
164-
['int224'],
165-
// Any random number that fits into an int224
166-
[ethers.BigNumber.from(randomBytes)]
167-
);
168-
const dummyBeaconSignature = await dummyAirnode.signMessage(
169-
ethers.utils.arrayify(
170-
ethers.utils.solidityKeccak256(
171-
['bytes32', 'uint256', 'bytes'],
172-
[dummyBeaconTemplateId, dummyBeaconTimestamp, dummyBeaconData]
173-
)
174-
)
175-
);
176-
return { dummyAirnode, dummyBeaconTemplateId, dummyBeaconTimestamp, dummyBeaconData, dummyBeaconSignature };
177-
};

test/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const encodeBeaconFeedSet = (dataFeed: Beacon[]) =>
3131
['address[]', 'bytes32[]'],
3232
[dataFeed.map((item) => item.airnodeAddress), dataFeed.map((item) => item.templateId)]
3333
);
34-
export const getUnixTimestamp = (dateString: string) => Math.floor(Date.parse(dateString) / 1000);
3534

3635
export const generateSignedData = async (
3736
airnodeWallet: Wallet,

0 commit comments

Comments
 (0)