Skip to content

Commit

Permalink
Minor log improvements (#265)
Browse files Browse the repository at this point in the history
* Improve logs

* Improve logs

* Fix tests
  • Loading branch information
Siegrift authored Apr 25, 2024
1 parent 43c41ed commit d82f1b7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/gas-price/gas-price.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe(getRecommendedGasPrice.name, () => {
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenNthCalledWith(1, 'Sanitizing gas price.', {
gasPrice: '120000000000',
ratio: '6.98',
sanitizationGasPriceCap: '17200000000',
});
});
Expand Down Expand Up @@ -298,6 +299,7 @@ describe(getRecommendedGasPrice.name, () => {
});
expect(logger.warn).toHaveBeenNthCalledWith(2, 'Sanitizing gas price.', {
gasPrice: '20900000000',
ratio: '1.08',
sanitizationGasPriceCap: '19400000000',
});
});
Expand Down
1 change: 1 addition & 0 deletions src/gas-price/gas-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const getRecommendedGasPrice = (chainId: string, providerName: string, sp
logger.warn('Sanitizing gas price.', {
gasPrice: gasPriceToUse.toString(),
sanitizationGasPriceCap: sanitizationGasPriceCap.toString(),
ratio: (Number(gasPriceToUse) / Number(sanitizationGasPriceCap)).toFixed(2),
});
return sanitizationGasPriceCap;
}
Expand Down
7 changes: 5 additions & 2 deletions src/update-feeds-loops/submit-transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ describe(submitTransactionsModule.submitTransaction.name, () => {
jest.spyOn(gasPriceModule, 'getRecommendedGasPrice').mockReturnValue(BigInt(100_000_000));
jest.spyOn(updatabilityTimestampModule, 'isAlreadyUpdatable').mockReturnValue(false);
const api3ServerV1 = generateMockApi3ServerV1();
jest.spyOn(api3ServerV1.tryMulticall, 'send').mockReturnValue({ hash: '0xTransactionHash' });
jest.spyOn(api3ServerV1, 'connect').mockReturnValue(api3ServerV1);
jest.spyOn(stateModule, 'getState').mockReturnValue(
allowPartial<stateModule.State>({
Expand Down Expand Up @@ -432,9 +433,11 @@ describe(submitTransactionsModule.submitTransaction.name, () => {
gasLimit: '500000',
gasPrice: '100000000',
nonce: 0,
sponsorAddress: '0xA772F7b103BBecA3Bb6C74Be41fCc2c192C8146c',
sponsorWalletAddress: '0xA772F7b103BBecA3Bb6C74Be41fCc2c192C8146c',
});
expect(logger.info).toHaveBeenNthCalledWith(2, 'Successfully submitted the multicall transaction.', {
txHash: '0xTransactionHash',
});
expect(logger.info).toHaveBeenNthCalledWith(2, 'Successfully submitted the multicall transaction.');

// Verify the flow of the update process via the debug logs. Note, that some debug log calls are not here because
// many functions are mocked.
Expand Down
4 changes: 2 additions & 2 deletions src/update-feeds-loops/submit-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const submitTransaction = async (
if (!gasPrice) return null;

logger.info('Updating data feed.', {
sponsorAddress: sponsorWalletAddress,
sponsorWalletAddress,
gasPrice: gasPrice.toString(),
gasLimit: gasLimit.toString(),
nonce,
Expand Down Expand Up @@ -129,7 +129,7 @@ export const submitTransaction = async (
}
}

logger.info('Successfully submitted the multicall transaction.');
logger.info('Successfully submitted the multicall transaction.', { txHash: goMulticall.data.hash });
return goMulticall.data;
},
{ totalTimeoutMs: dataFeedUpdateIntervalMs }
Expand Down
4 changes: 4 additions & 0 deletions src/update-feeds-loops/update-feeds-loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export const processBatch = async (
walletDerivationScheme,
signedApiUrls: configSignedApiBaseUrls,
},
firstMarkedUpdatableTimestamps,
} = getState();
const { contracts } = chains[chainId]!;

Expand Down Expand Up @@ -330,6 +331,9 @@ export const processBatch = async (
logger.info(`Clearing data feed update timestamp because it no longer needs an update.`, {
dapiName: decodedDapiName,
dataFeedId,
totalPendingPeriod:
Math.floor(Date.now() / 1000) -
firstMarkedUpdatableTimestamps[chainId]![providerName]![sponsorWalletAddress]!,
});
clearFirstMarkedUpdatableTimestamp(chainId, providerName, sponsorWalletAddress);
}
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/update-feeds.feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ it('updates blockchain data', async () => {
expect(logger.debug).toHaveBeenNthCalledWith(7, 'Getting recommended gas price.');
expect(logger.info).toHaveBeenCalledTimes(2);
expect(logger.info).toHaveBeenNthCalledWith(1, 'Updating data feed.', expect.anything());
expect(logger.info).toHaveBeenNthCalledWith(2, 'Successfully submitted the multicall transaction.');
expect(logger.info).toHaveBeenNthCalledWith(
2,
'Successfully submitted the multicall transaction.',
expect.anything()
);
expect(logger.warn).toHaveBeenCalledTimes(0);
});

0 comments on commit d82f1b7

Please sign in to comment.