Skip to content

Commit

Permalink
remove duplicate countAndThrowDBError in domains request table wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
alecps committed Aug 29, 2023
1 parent 6f6a8ea commit 4a9f50f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/phone-number-privacy/signer/.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ALFAJORES_ODIS_BLOCKCHAIN_PROVIDER=https://alfajores-forno.celo-testnet.org
MAINNET_ODIS_BLOCKCHAIN_PROVIDER=https://forno.celo.org
ODIS_DOMAINS_TEST_KEY_VERSION=1
ODIS_PNP_TEST_KEY_VERSION=1
DEPLOYED_SIGNER_SERVICE_VERSION=3.0.0-beta.14
DEPLOYED_SIGNER_SERVICE_VERSION=3.0.0-beta.16
# PUBKEYS
STAGING_DOMAINS_PUBKEY=7FsWGsFnmVvRfMDpzz95Np76wf/1sPaK0Og9yiB+P8QbjiC8FV67NBans9hzZEkBaQMhiapzgMR6CkZIZPvgwQboAxl65JWRZecGe5V3XO4sdKeNemdAZ2TzQuWkuZoA
ALFAJORES_DOMAINS_PUBKEY=+ZrxyPvLChWUX/DyPw6TuGwQH0glDJEbSrSxUARyP5PuqYyP/U4WZTV1e0bAUioBZ6QCJMiLpDwTaFvy8VnmM5RBbLQUMrMg5p4+CBCqj6HhsMfcyUj8V0LyuNdStlCB
Expand Down
2 changes: 1 addition & 1 deletion packages/phone-number-privacy/signer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
collectCoverageFrom: ['./src/**'],
coverageThreshold: {
global: {
lines: 68,
lines: 68, // TODO increase this threshold
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DomainRequestRecord,
toDomainRequestRecord,
} from '../models/domain-request'
import { countAndThrowDBError, doMeteredSql } from '../utils'
import { doMeteredSql } from '../utils'

// TODO implement replay handling; this file is currently unused
// https://github.com/celo-org/celo-monorepo/issues/9909
Expand All @@ -20,13 +20,13 @@ export async function getDomainRequestRecordExists<D extends Domain>(
trx: Knex.Transaction<DomainRequestRecord>,
logger: Logger
): Promise<boolean> {
const hash = domainHash(domain).toString('hex')
logger.debug({ domain, blindedMessage, hash }, 'Checking if domain request exists')
return doMeteredSql(
'getDomainRequestRecordExists',
ErrorMessage.DATABASE_GET_FAILURE,
logger,
async () => {
const hash = domainHash(domain).toString('hex')
logger.debug({ domain, blindedMessage, hash }, 'Checking if domain request exists')
const existingRequest = await db<DomainRequestRecord>(DOMAIN_REQUESTS_TABLE)
.transacting(trx)
.where({
Expand All @@ -47,20 +47,16 @@ export async function storeDomainRequestRecord<D extends Domain>(
trx: Knex.Transaction<DomainRequestRecord>,
logger: Logger
) {
logger.debug({ domain, blindedMessage }, 'Storing domain restricted signature request')
return doMeteredSql(
'storeDomainRequestRecord',
ErrorMessage.DATABASE_INSERT_FAILURE,
logger,
async () => {
try {
logger.debug({ domain, blindedMessage }, 'Storing domain restricted signature request')
await db<DomainRequestRecord>(DOMAIN_REQUESTS_TABLE)
.transacting(trx)
.insert(toDomainRequestRecord(domain, blindedMessage))
.timeout(config.db.timeout)
} catch (err) {
countAndThrowDBError(err, logger, ErrorMessage.DATABASE_INSERT_FAILURE)
}
await db<DomainRequestRecord>(DOMAIN_REQUESTS_TABLE)
.transacting(trx)
.insert(toDomainRequestRecord(domain, blindedMessage))
.timeout(config.db.timeout)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export async function setDomainDisabled<D extends Domain>(
trx: Knex.Transaction<DomainStateRecord>,
logger: Logger
): Promise<void> {
const hash = domainHash(domain).toString('hex')
logger.debug({ hash, domain }, 'Disabling domain')
return doMeteredSql('disableDomain', ErrorMessage.DATABASE_UPDATE_FAILURE, logger, async () => {
const hash = domainHash(domain).toString('hex')
logger.debug({ hash, domain }, 'Disabling domain')
await db<DomainStateRecord>(DOMAIN_STATE_TABLE)
.transacting(trx)
.where(DOMAIN_STATE_COLUMNS.domainHash, hash)
Expand Down Expand Up @@ -54,14 +54,13 @@ export async function getDomainStateRecord<D extends Domain>(
logger: Logger,
trx?: Knex.Transaction<DomainStateRecord>
): Promise<DomainStateRecord | null> {
const hash = domainHash(domain).toString('hex')
logger.debug({ hash, domain }, 'Getting domain state from db')
return doMeteredSql(
'getDomainStateRecord',
ErrorMessage.DATABASE_GET_FAILURE,
logger,
async () => {
const hash = domainHash(domain).toString('hex')
logger.debug({ hash, domain }, 'Getting domain state from db')

const sql = db<DomainStateRecord>(DOMAIN_STATE_TABLE)
.where(DOMAIN_STATE_COLUMNS.domainHash, hash)
.first()
Expand All @@ -85,13 +84,13 @@ export async function updateDomainStateRecord<D extends Domain>(
trx: Knex.Transaction<DomainStateRecord>,
logger: Logger
): Promise<void> {
const hash = domainHash(domain).toString('hex')
logger.debug({ hash, domain, domainState }, 'Update domain state')
return doMeteredSql(
'updateDomainStateRecord',
ErrorMessage.DATABASE_UPDATE_FAILURE,
logger,
async () => {
const hash = domainHash(domain).toString('hex')
logger.debug({ hash, domain, domainState }, 'Update domain state')
// Check whether the domain is already in the database.
// The current signature flow results in redundant queries of the domain state.
// Consider optimizing in the future: https://github.com/celo-org/celo-monorepo/issues/9855
Expand All @@ -117,12 +116,12 @@ export async function insertDomainStateRecord(
trx: Knex.Transaction<DomainStateRecord>,
logger: Logger
): Promise<DomainStateRecord> {
logger.debug({ domainState }, 'Insert domain state')
return doMeteredSql(
'insertDomainState',
ErrorMessage.DATABASE_INSERT_FAILURE,
logger,
async () => {
logger.debug({ domainState }, 'Insert domain state')
await db<DomainStateRecord>(DOMAIN_STATE_TABLE)
.transacting(trx)
.insert(domainState)
Expand Down

0 comments on commit 4a9f50f

Please sign in to comment.