diff --git a/packages/pusher/src/api-requests/signed-api.ts b/packages/pusher/src/api-requests/signed-api.ts index c586ef41..581dce9c 100644 --- a/packages/pusher/src/api-requests/signed-api.ts +++ b/packages/pusher/src/api-requests/signed-api.ts @@ -1,7 +1,6 @@ import { deriveBeaconId } from '@api3/airnode-node'; import { go } from '@api3/promise-utils'; import axios, { type AxiosError } from 'axios'; -import { ethers } from 'ethers'; import { isEmpty, isNil, pick } from 'lodash'; import { logger } from '../logger'; @@ -11,13 +10,14 @@ import { type SignedApiPayload, signedApiResponseSchema } from '../validation/sc export const postSignedApiData = async (group: SignedApiNameUpdateDelayGroup) => { const { - config: { signedApis, airnodeWalletMnemonic }, + config: { signedApis }, templateValues, + airnodeWallet, } = getState(); const { signedApiName, templateIds, updateDelay } = group; const logContext = { signedApiName, updateDelay }; - const airnode = ethers.Wallet.fromMnemonic(airnodeWalletMnemonic).address; + const airnode = airnodeWallet.address; const batchPayloadOrNull = templateIds.map((templateId): SignedApiPayload | null => { // Calculate the reference timestamp based on the current time and update delay. const referenceTimestamp = Date.now() / 1000 - updateDelay; diff --git a/packages/pusher/src/sign-template-data.ts b/packages/pusher/src/sign-template-data.ts index 7415a017..de75004b 100644 --- a/packages/pusher/src/sign-template-data.ts +++ b/packages/pusher/src/sign-template-data.ts @@ -1,6 +1,5 @@ import type { ExtractedAndEncodedResponse } from '@api3/airnode-adapter'; import { go } from '@api3/promise-utils'; -import { ethers } from 'ethers'; import { isNil } from 'lodash'; import { logger } from './logger'; @@ -19,8 +18,9 @@ export const signTemplateResponses = async (templateResponses: TemplateResponse[ const { encodedValue } = response; const timestamp = Math.floor(Date.now() / 1000).toString(); - const wallet = ethers.Wallet.fromMnemonic(getState().config.airnodeWalletMnemonic); - const goSignWithTemplateId = await go(async () => signWithTemplateId(wallet, templateId, timestamp, encodedValue)); + const goSignWithTemplateId = await go(async () => + signWithTemplateId(getState().airnodeWallet, templateId, timestamp, encodedValue) + ); if (!goSignWithTemplateId.success) { const message = `Failed to sign response. Error: "${goSignWithTemplateId.error.message}"`; logger.warn(message, { diff --git a/packages/pusher/src/state.ts b/packages/pusher/src/state.ts index 283b0d43..5d41c4f2 100644 --- a/packages/pusher/src/state.ts +++ b/packages/pusher/src/state.ts @@ -1,4 +1,5 @@ import Bottleneck from 'bottleneck'; +import { ethers } from 'ethers'; import { last } from 'lodash'; import { OIS_MAX_CONCURRENCY_DEFAULT, OIS_MIN_TIME_DEFAULT_MS } from './constants'; @@ -11,6 +12,8 @@ export interface State { config: Config; templateValues: TemplateValueStorage; apiLimiters: Record; + // We persist the derived Airnode wallet in memory as a performance optimization. + airnodeWallet: ethers.Wallet; } let state: State; @@ -81,6 +84,7 @@ export const getInitialState = (config: Config): State => { config, templateValues: buildTemplateStorages(config), apiLimiters: buildApiLimiters(config), + airnodeWallet: ethers.Wallet.fromMnemonic(config.airnodeWalletMnemonic), }; };