diff --git a/packages/phone-number-privacy/combiner/src/config.ts b/packages/phone-number-privacy/combiner/src/config.ts index da962d4ca15..f9cc2ecda24 100644 --- a/packages/phone-number-privacy/combiner/src/config.ts +++ b/packages/phone-number-privacy/combiner/src/config.ts @@ -1,4 +1,10 @@ -import { BlockchainConfig, rootLogger, TestUtils, toBool } from '@celo/phone-number-privacy-common' +import { + BlockchainConfig, + FULL_NODE_TIMEOUT_IN_MS, + rootLogger, + TestUtils, + toBool, +} from '@celo/phone-number-privacy-common' import * as functions from 'firebase-functions' export function getCombinerVersion(): string { return process.env.npm_package_version ?? require('../package.json').version ?? '0.0.0' @@ -29,6 +35,7 @@ export interface OdisConfig { currentVersion: number versions: string // parse as KeyVersionInfo[] } + fullNodeTimeoutMs: number } export interface CombinerConfig { @@ -94,6 +101,7 @@ if (DEV_MODE) { }, ]), }, + fullNodeTimeoutMs: FULL_NODE_TIMEOUT_IN_MS, }, domains: { serviceName: defaultServiceName, @@ -126,6 +134,7 @@ if (DEV_MODE) { }, ]), }, + fullNodeTimeoutMs: FULL_NODE_TIMEOUT_IN_MS, }, } } else { @@ -150,6 +159,7 @@ if (DEV_MODE) { currentVersion: Number(functionConfig.pnp_keys.current_version), versions: functionConfig.pnp_keys.versions, }, + fullNodeTimeoutMs: Number(functionConfig.pnp.full_node_timeout_ms ?? FULL_NODE_TIMEOUT_IN_MS), }, domains: { serviceName: functionConfig.domains.service_name ?? defaultServiceName, @@ -165,6 +175,7 @@ if (DEV_MODE) { currentVersion: Number(functionConfig.domains_keys.current_version), versions: functionConfig.domains_keys.versions, }, + fullNodeTimeoutMs: Number(functionConfig.pnp.full_node_timeout_ms ?? FULL_NODE_TIMEOUT_IN_MS), }, } } diff --git a/packages/phone-number-privacy/combiner/src/pnp/endpoints/quota/io.ts b/packages/phone-number-privacy/combiner/src/pnp/endpoints/quota/io.ts index 2680a560f29..64c402b7ebc 100644 --- a/packages/phone-number-privacy/combiner/src/pnp/endpoints/quota/io.ts +++ b/packages/phone-number-privacy/combiner/src/pnp/endpoints/quota/io.ts @@ -66,7 +66,14 @@ export class PnpQuotaIO extends IO { } async authenticate(request: Request<{}, {}, PnpQuotaRequest>, logger: Logger): Promise { - return authenticateUser(request, this.kit, logger, this.config.shouldFailOpen) + return authenticateUser( + request, + this.kit, + logger, + this.config.shouldFailOpen, + [], + this.config.fullNodeTimeoutMs + ) } sendSuccess( diff --git a/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.legacy.ts b/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.legacy.ts index f2926aed541..bfd15656083 100644 --- a/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.legacy.ts +++ b/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.legacy.ts @@ -85,7 +85,14 @@ export class LegacyPnpSignIO extends IO { request: Request<{}, {}, LegacySignMessageRequest>, logger: Logger ): Promise { - return authenticateUser(request, this.kit, logger, this.config.shouldFailOpen) + return authenticateUser( + request, + this.kit, + logger, + this.config.shouldFailOpen, + [], + this.config.fullNodeTimeoutMs + ) } sendSuccess( diff --git a/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.ts b/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.ts index f008597067b..ce02dc0321b 100644 --- a/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.ts +++ b/packages/phone-number-privacy/combiner/src/pnp/endpoints/sign/io.ts @@ -84,7 +84,14 @@ export class PnpSignIO extends IO { request: Request<{}, {}, SignMessageRequest>, logger: Logger ): Promise { - return authenticateUser(request, this.kit, logger, this.config.shouldFailOpen) + return authenticateUser( + request, + this.kit, + logger, + this.config.shouldFailOpen, + [], + this.config.fullNodeTimeoutMs + ) } sendSuccess( diff --git a/packages/phone-number-privacy/combiner/test/integration/domain.test.ts b/packages/phone-number-privacy/combiner/test/integration/domain.test.ts index 5641c2fcdde..5f7f1f1fe50 100644 --- a/packages/phone-number-privacy/combiner/test/integration/domain.test.ts +++ b/packages/phone-number-privacy/combiner/test/integration/domain.test.ts @@ -13,6 +13,7 @@ import { domainRestrictedSignatureRequestEIP712, DomainRestrictedSignatureResponse, ErrorMessage, + FULL_NODE_TIMEOUT_IN_MS, genSessionID, getContractKit, KEY_VERSION_HEADER, @@ -138,6 +139,7 @@ const signerConfig: SignerConfig = { }, timeout: 5000, test_quota_bypass_percentage: 0, + fullNodeTimeoutMs: FULL_NODE_TIMEOUT_IN_MS, } describe('domainService', () => { diff --git a/packages/phone-number-privacy/combiner/test/integration/legacypnp.test.ts b/packages/phone-number-privacy/combiner/test/integration/legacypnp.test.ts index 630959579ef..1506015c289 100644 --- a/packages/phone-number-privacy/combiner/test/integration/legacypnp.test.ts +++ b/packages/phone-number-privacy/combiner/test/integration/legacypnp.test.ts @@ -3,6 +3,7 @@ import { AuthenticationMethod, CombinerEndpoint, ErrorMessage, + FULL_NODE_TIMEOUT_IN_MS, genSessionID, KEY_VERSION_HEADER, LegacySignMessageRequest, @@ -142,6 +143,7 @@ const signerConfig: SignerConfig = { }, timeout: 5000, test_quota_bypass_percentage: 0, + fullNodeTimeoutMs: FULL_NODE_TIMEOUT_IN_MS, } const testBlockNumber = 1000000 diff --git a/packages/phone-number-privacy/combiner/test/integration/pnp.test.ts b/packages/phone-number-privacy/combiner/test/integration/pnp.test.ts index 54fd0884dd5..f74d4432bf5 100644 --- a/packages/phone-number-privacy/combiner/test/integration/pnp.test.ts +++ b/packages/phone-number-privacy/combiner/test/integration/pnp.test.ts @@ -3,6 +3,7 @@ import { AuthenticationMethod, CombinerEndpoint, ErrorMessage, + FULL_NODE_TIMEOUT_IN_MS, genSessionID, KEY_VERSION_HEADER, PnpQuotaRequest, @@ -146,6 +147,7 @@ const signerConfig: SignerConfig = { }, timeout: 5000, test_quota_bypass_percentage: 0, + fullNodeTimeoutMs: FULL_NODE_TIMEOUT_IN_MS, } const testBlockNumber = 1000000 diff --git a/packages/phone-number-privacy/common/src/utils/authentication.ts b/packages/phone-number-privacy/common/src/utils/authentication.ts index cc30def42d9..79c70acca0a 100644 --- a/packages/phone-number-privacy/common/src/utils/authentication.ts +++ b/packages/phone-number-privacy/common/src/utils/authentication.ts @@ -25,7 +25,8 @@ export async function authenticateUser( contractKit: ContractKit, logger: Logger, shouldFailOpen: boolean = false, - warnings: ErrorType[] = [] + warnings: ErrorType[] = [], + timeoutMs: number = FULL_NODE_TIMEOUT_IN_MS ): Promise { logger.debug('Authenticating user') @@ -42,7 +43,7 @@ export async function authenticateUser( if (authMethod && authMethod === AuthenticationMethod.ENCRYPTION_KEY) { let registeredEncryptionKey try { - registeredEncryptionKey = await getDataEncryptionKey(signer, contractKit, logger) + registeredEncryptionKey = await getDataEncryptionKey(signer, contractKit, logger, timeoutMs) } catch (err) { // getDataEncryptionKey should only throw if there is a full-node connection issue. // That is, it does not throw if the DEK is undefined or invalid @@ -127,7 +128,8 @@ export function verifyDEKSignature( export async function getDataEncryptionKey( address: string, contractKit: ContractKit, - logger: Logger + logger: Logger, + timeoutMs: number ): Promise { try { const res = await retryAsyncWithBackOffAndTimeout( @@ -139,7 +141,7 @@ export async function getDataEncryptionKey( [], RETRY_DELAY_IN_MS, 1.5, - FULL_NODE_TIMEOUT_IN_MS + timeoutMs ) return res } catch (error) { diff --git a/packages/phone-number-privacy/signer/src/config.ts b/packages/phone-number-privacy/signer/src/config.ts index cfa3881b91f..588a95dd3ee 100644 --- a/packages/phone-number-privacy/signer/src/config.ts +++ b/packages/phone-number-privacy/signer/src/config.ts @@ -1,4 +1,8 @@ -import { BlockchainConfig, toBool } from '@celo/phone-number-privacy-common' +import { + BlockchainConfig, + FULL_NODE_TIMEOUT_IN_MS, + toBool, +} from '@celo/phone-number-privacy-common' import BigNumber from 'bignumber.js' require('dotenv').config() @@ -94,6 +98,7 @@ export interface SignerConfig { } timeout: number test_quota_bypass_percentage: number + fullNodeTimeoutMs: number } const env = process.env as any @@ -175,4 +180,5 @@ export const config: SignerConfig = { }, timeout: Number(env.ODIS_SIGNER_TIMEOUT ?? 5000), test_quota_bypass_percentage: Number(env.TEST_QUOTA_BYPASS_PERCENTAGE ?? 0), + fullNodeTimeoutMs: Number(env.TIMEOUT_MS ?? FULL_NODE_TIMEOUT_IN_MS), } diff --git a/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.legacy.ts b/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.legacy.ts index b9cb4e9e7fc..7fd5ed0bb3d 100644 --- a/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.legacy.ts +++ b/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.legacy.ts @@ -28,6 +28,7 @@ export class LegacyPnpQuotaIO extends IO { constructor( readonly enabled: boolean, readonly shouldFailOpen: boolean, + readonly timeoutMs: number, readonly kit: ContractKit ) { super(enabled) @@ -64,7 +65,14 @@ export class LegacyPnpQuotaIO extends IO { warnings: ErrorType[], logger: Logger ): Promise { - return authenticateUser(request, this.kit, logger, this.shouldFailOpen, warnings) + return authenticateUser( + request, + this.kit, + logger, + this.shouldFailOpen, + warnings, + this.timeoutMs + ) } sendSuccess( diff --git a/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.ts b/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.ts index 3a367fae728..727ac3cdceb 100644 --- a/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.ts +++ b/packages/phone-number-privacy/signer/src/pnp/endpoints/quota/io.ts @@ -27,6 +27,7 @@ export class PnpQuotaIO extends IO { constructor( readonly enabled: boolean, readonly shouldFailOpen: boolean, + readonly timeoutMs: number, readonly kit: ContractKit ) { super(enabled) @@ -62,7 +63,14 @@ export class PnpQuotaIO extends IO { warnings: ErrorType[], logger: Logger ): Promise { - return authenticateUser(request, this.kit, logger, this.shouldFailOpen, warnings) + return authenticateUser( + request, + this.kit, + logger, + this.shouldFailOpen, + warnings, + this.timeoutMs + ) } sendSuccess( diff --git a/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.legacy.ts b/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.legacy.ts index 70d8068aa07..f4617119f74 100644 --- a/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.legacy.ts +++ b/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.legacy.ts @@ -32,6 +32,7 @@ export class LegacyPnpSignIO extends IO { constructor( readonly enabled: boolean, readonly shouldFailOpen: boolean, + readonly timeoutMs: number, readonly kit: ContractKit ) { super(enabled) @@ -76,7 +77,14 @@ export class LegacyPnpSignIO extends IO { warnings: ErrorType[], logger: Logger ): Promise { - return authenticateUser(request, this.kit, logger, this.shouldFailOpen, warnings) + return authenticateUser( + request, + this.kit, + logger, + this.shouldFailOpen, + warnings, + this.timeoutMs + ) } sendSuccess( diff --git a/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.ts b/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.ts index 7e522defd0a..6761fd797d2 100644 --- a/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.ts +++ b/packages/phone-number-privacy/signer/src/pnp/endpoints/sign/io.ts @@ -31,6 +31,7 @@ export class PnpSignIO extends IO { constructor( readonly enabled: boolean, readonly shouldFailOpen: boolean, + readonly timeoutMs: number, readonly kit: ContractKit ) { super(enabled) @@ -72,7 +73,14 @@ export class PnpSignIO extends IO { warnings: ErrorType[], logger: Logger ): Promise { - return authenticateUser(request, this.kit, logger, this.shouldFailOpen, warnings) + return authenticateUser( + request, + this.kit, + logger, + this.shouldFailOpen, + warnings, + this.timeoutMs + ) } sendSuccess( diff --git a/packages/phone-number-privacy/signer/src/server.ts b/packages/phone-number-privacy/signer/src/server.ts index 7b0ba8d472b..19558bfc396 100644 --- a/packages/phone-number-privacy/signer/src/server.ts +++ b/packages/phone-number-privacy/signer/src/server.ts @@ -98,6 +98,7 @@ export function startSigner( new PnpQuotaIO( config.api.phoneNumberPrivacy.enabled, config.api.phoneNumberPrivacy.shouldFailOpen, // TODO (https://github.com/celo-org/celo-monorepo/issues/9862) consider refactoring config to make the code cleaner + config.fullNodeTimeoutMs, kit ) ) @@ -111,6 +112,7 @@ export function startSigner( new PnpSignIO( config.api.phoneNumberPrivacy.enabled, config.api.phoneNumberPrivacy.shouldFailOpen, + config.fullNodeTimeoutMs, kit ) ) @@ -124,6 +126,7 @@ export function startSigner( new LegacyPnpSignIO( config.api.legacyPhoneNumberPrivacy.enabled, config.api.legacyPhoneNumberPrivacy.shouldFailOpen, + config.fullNodeTimeoutMs, kit ) ) @@ -135,6 +138,7 @@ export function startSigner( new LegacyPnpQuotaIO( config.api.legacyPhoneNumberPrivacy.enabled, config.api.legacyPhoneNumberPrivacy.shouldFailOpen, + config.fullNodeTimeoutMs, kit ) )