Skip to content

Commit

Permalink
Only retry failed creation of fwa wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik-Stas committed Feb 26, 2021
1 parent 767f738 commit d118ff6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
7 changes: 5 additions & 2 deletions easy-indysdk/src/indy-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

'use strict'

const indyErrorCodeWalletItemNotFound = '212'
const indyErrorWalletItemNotFound = {
indyCode: 212,
indyName: 'WalletItemNotFound',
}

module.exports = { indyErrorCodeWalletItemNotFound }
module.exports = { indyErrorWalletItemNotFound }
4 changes: 2 additions & 2 deletions easy-indysdk/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

const indy = require('indy-sdk')
const os = require('os')
const { indyErrorCodeWalletItemNotFound } = require('./indy-errors')
const { indyErrorWalletItemNotFound } = require('./indy-errors')

const extension = { darwin: '.dylib', linux: '.so', win32: '.dll' }
const libPath = { darwin: '/usr/local/lib/', linux: '/usr/lib/', win32: 'c:\\windows\\system32\\' }
Expand Down Expand Up @@ -132,7 +132,7 @@ async function indyDidExists (wh, did) {
try {
await indy.getMyDidWithMeta(wh, did)
} catch (err) {
if (err.message === indyErrorCodeWalletItemNotFound) {
if (err.indyName === indyErrorWalletItemNotFound.indyName) {
return false
} else {
throw err
Expand Down
15 changes: 9 additions & 6 deletions vcxagency-node/src/service/entities/fwa/entity-fwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ const sleep = require('sleep-promise')
const FWA_KDF = 'ARGON2I_MOD'

async function assureFwaWalletWasSetUp (serviceIndyWallets, agencyWalletName, agencyWalletKey, agencyDid, agencySeed) {
logger.info(`FWA Assuring its wallet '${agencyWalletName}' exists`)
await serviceIndyWallets.assureWallet(agencyWalletName, agencyWalletKey, FWA_KDF)

logger.info(`Getting '${agencyWalletName}' wallet handle.`)
const wh = await serviceIndyWallets.getWalletHandle(agencyWalletName, agencyWalletKey, FWA_KDF)
logger.info(`Checking if agency did ${agencyDid} exists in wallet`)
const agencyDidWasSetUp = await indyDidExists(wh, agencyDid)
if (!agencyDidWasSetUp) {
logger.info(`Agency DID '${agencyDid}' not found in wallet. Creating.`)
await indyCreateAndStoreMyDid(wh, agencyDid, agencySeed)
logger.debug(`Forward agent create ${agencyDid}`)
} else {
logger.info(`Agency DID '${agencyDid}' was found in wallet.`)
}

const agencyVerkey = await indyKeyForLocalDid(wh, agencyDid)
logger.info(`Agency DID '${agencyWalletName}' has assigned verkey ${agencyVerkey}`)
return agencyVerkey
Expand All @@ -60,17 +61,19 @@ async function assureFwaWalletWasSetUp (serviceIndyWallets, agencyWalletName, ag
* This is design trade off to have simple singleton.
*/
async function buildForwardAgent (serviceIndyWallets, serviceStorage, agencyWalletName, agencyWalletKey, agencyDid, agencySeed, waitTime = 1000, attempts = 10) {
let router, resolver, agencyVerkey
let router, resolver

for (let attempt = 0; attempt < attempts; attempt++) {
try {
agencyVerkey = await assureFwaWalletWasSetUp(serviceIndyWallets, agencyWalletName, agencyWalletKey, agencyDid, agencySeed)
logger.info(`FWA Assuring its wallet '${agencyWalletName}' exists`)
await serviceIndyWallets.assureWallet(agencyWalletName, agencyWalletKey, FWA_KDF)
break
} catch (err) {
console.warn(`Failed to build FWA agent: ${err}\nRemaining attempts: ${attempts - attempt - 1}`)
logger.warn(`Failed to assure FWA wallet due to error ${err.stack}. Remaining attempts: ${attempts - attempt - 1}`)
await sleep(waitTime)
}
}
const agencyVerkey = await assureFwaWalletWasSetUp(serviceIndyWallets, agencyWalletName, agencyWalletKey, agencyDid, agencySeed)

const whoami = `[ForwardAgent ${agencyDid}]`

Expand Down
11 changes: 7 additions & 4 deletions vcxagency-node/src/service/storage/redis-client-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,31 @@ module.exports.buildRedisClients = function buildRedisClients (redisUrl) {
redisClientRw.on('error', function (err) {
logger.error(`Redis rw-client encountered error: ${err}`)
})

redisClientSubscriber.on('error', function (err) {
logger.error(`Redis subscription-client encountered error: ${err}`)
})

redisClientRw.on('end', () => {
console.log('Redis rw-client disconnected')
logger.warn('Redis rw-client disconnected')
})

redisClientSubscriber.on('end', () => {
console.log('Redis subscription-client disconnected')
logger.warn('Redis subscription-client disconnected')
})

redisClientRw.on('reconnecting', () => {
console.log('Redis rw-client reconnecting')
logger.warn('Redis rw-client reconnecting')
})

redisClientSubscriber.on('reconnecting', () => {
console.log('Redis subscription-client reconnecting')
logger.warn('Redis subscription-client reconnecting')
})

redisClientRw.on('connect', function () {
logger.info('Redis rw-client connected.')
})

redisClientSubscriber.on('connect', function () {
logger.info('Redis subscription-client connected.')
})
Expand Down

0 comments on commit d118ff6

Please sign in to comment.