From d82f1b79fdc94078012f3569e1bba425782b0fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Tesa=C5=99?= Date: Thu, 25 Apr 2024 10:32:14 +0200 Subject: [PATCH] Minor log improvements (#265) * Improve logs * Improve logs * Fix tests --- src/gas-price/gas-price.test.ts | 2 ++ src/gas-price/gas-price.ts | 1 + src/update-feeds-loops/submit-transactions.test.ts | 7 +++++-- src/update-feeds-loops/submit-transactions.ts | 4 ++-- src/update-feeds-loops/update-feeds-loops.ts | 4 ++++ test/e2e/update-feeds.feature.ts | 6 +++++- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/gas-price/gas-price.test.ts b/src/gas-price/gas-price.test.ts index 95afc8ac..94c46237 100644 --- a/src/gas-price/gas-price.test.ts +++ b/src/gas-price/gas-price.test.ts @@ -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', }); }); @@ -298,6 +299,7 @@ describe(getRecommendedGasPrice.name, () => { }); expect(logger.warn).toHaveBeenNthCalledWith(2, 'Sanitizing gas price.', { gasPrice: '20900000000', + ratio: '1.08', sanitizationGasPriceCap: '19400000000', }); }); diff --git a/src/gas-price/gas-price.ts b/src/gas-price/gas-price.ts index 9346b3ee..726ccf2a 100644 --- a/src/gas-price/gas-price.ts +++ b/src/gas-price/gas-price.ts @@ -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; } diff --git a/src/update-feeds-loops/submit-transactions.test.ts b/src/update-feeds-loops/submit-transactions.test.ts index aeae0da2..b868eaa4 100644 --- a/src/update-feeds-loops/submit-transactions.test.ts +++ b/src/update-feeds-loops/submit-transactions.test.ts @@ -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({ @@ -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. diff --git a/src/update-feeds-loops/submit-transactions.ts b/src/update-feeds-loops/submit-transactions.ts index bd756eca..3e7ce05f 100644 --- a/src/update-feeds-loops/submit-transactions.ts +++ b/src/update-feeds-loops/submit-transactions.ts @@ -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, @@ -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 } diff --git a/src/update-feeds-loops/update-feeds-loops.ts b/src/update-feeds-loops/update-feeds-loops.ts index 747117ba..6ad46b6e 100644 --- a/src/update-feeds-loops/update-feeds-loops.ts +++ b/src/update-feeds-loops/update-feeds-loops.ts @@ -292,6 +292,7 @@ export const processBatch = async ( walletDerivationScheme, signedApiUrls: configSignedApiBaseUrls, }, + firstMarkedUpdatableTimestamps, } = getState(); const { contracts } = chains[chainId]!; @@ -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); } diff --git a/test/e2e/update-feeds.feature.ts b/test/e2e/update-feeds.feature.ts index 47d77ded..8b140838 100644 --- a/test/e2e/update-feeds.feature.ts +++ b/test/e2e/update-feeds.feature.ts @@ -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); });