Skip to content

Commit

Permalink
adds whitelist logic to ODIS signers for load testing (#7624)
Browse files Browse the repository at this point in the history
* adds requestID to logger in common pkg

* assign sessionID in combiner if not provided by client

* adds request whitelisting
  • Loading branch information
alecps authored Apr 6, 2021
1 parent 135ec55 commit 0a5353f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.alfajores
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ LOG_FORMAT=stackdriver
# Options: fatal, error, warn, info (default), debug, trace
LOG_LEVEL=info

WHITELIST_PERCENTAGE=50

# ODIS signer 1 Azure info
AZURE_ODIS_EASTUS_1_AZURE_SUBSCRIPTION_ID=97e2b592-255b-4f92-bce0-127257163c36
Expand Down
4 changes: 4 additions & 0 deletions packages/phone-number-privacy/signer/src/common/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const Counters = {
help:
'Counter for the number of requests in which the account is not verified but meets min balance',
}),
whitelistedRequests: new Counter({
name: 'whitelisted_requests',
help: 'Counter for the number of whitelisted requests not requiring quota (testing only)',
}),
}
const buckets = [
0.001,
Expand Down
2 changes: 2 additions & 0 deletions packages/phone-number-privacy/signer/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ interface Config {
secretKey: string
}
}
whitelist_percentage: number
}

const env = process.env as any
Expand Down Expand Up @@ -131,5 +132,6 @@ const config: Config = {
secretKey: env.KEYSTORE_AWS_SECRET_KEY,
},
},
whitelist_percentage: Number(env.WHITELIST_PERCENTAGE) || 0,
}
export default config
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import allSettled from 'promise.allsettled'
import { computeBlindedSignature } from '../bls/bls-cryptography-client'
import { respondWithError } from '../common/error-utils'
import { Counters, Histograms, Labels } from '../common/metrics'
import { getVersion } from '../config'
import config, { getVersion } from '../config'
import { incrementQueryCount } from '../database/wrappers/account'
import { getRequestExists, storeRequest } from '../database/wrappers/request'
import { getKeyProvider } from '../key-management/key-provider'
Expand Down Expand Up @@ -111,16 +111,21 @@ export async function handleGetBlindedMessagePartialSig(

if (_queryCount.status === 'fulfilled' && performedQueryCount >= totalQuota) {
logger.debug('No remaining query count')
respondWithError(
Endpoints.GET_BLINDED_MESSAGE_PARTIAL_SIG,
response,
403,
WarningMessage.EXCEEDED_QUOTA,
performedQueryCount,
totalQuota,
blockNumber
)
return
if (isWhitelisted(request.body)) {
Counters.whitelistedRequests.inc()
logger.info({ request: request.body }, 'Request whitelisted')
} else {
respondWithError(
Endpoints.GET_BLINDED_MESSAGE_PARTIAL_SIG,
response,
403,
WarningMessage.EXCEEDED_QUOTA,
performedQueryCount,
totalQuota,
blockNumber
)
return
}
}

const meterGenerateSignature = Histograms.getBlindedSigInstrumentation
Expand Down Expand Up @@ -195,3 +200,8 @@ function isValidGetSignatureInput(requestBody: GetBlindedMessagePartialSigReques
hasValidTimestamp(requestBody)
)
}

function isWhitelisted(requestBody: GetBlindedMessagePartialSigRequest) {
const sessionID = Number(requestBody.sessionID)
return sessionID && sessionID % 100 < config.whitelist_percentage
}

0 comments on commit 0a5353f

Please sign in to comment.