Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only retry failed creation of fwa wallet #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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