Skip to content

Commit 893d08a

Browse files
authored
feat(API): retrieve transactionAnchor info in health report (#901)
Resolves: #832, #707 References: #901
1 parent 26afa46 commit 893d08a

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/API/API.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class API {
7373
const healthController = new HealthController({
7474
dependencies: {
7575
db: this.dbConnection,
76+
logger: this.logger,
7677
},
7778
})
7879

src/API/HealthController.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,52 @@
11
import { Db, Collection } from 'mongodb'
2+
import * as Pino from 'pino'
3+
4+
import { TransactionAnchorRetryInfo } from 'Interfaces'
25

36
export const isOkOne = ({ ok }: { ok: number }) => ok === 1
47

5-
interface HealthObject {
8+
export interface HealthObject {
69
readonly mongoIsConnected: boolean
710
readonly ipfsInfo: object
811
readonly walletInfo: object
912
readonly blockchainInfo: object
1013
readonly networkInfo: object
1114
readonly estimatedSmartFeeInfo: object
1215
readonly ipfsRetryInfo: object
16+
readonly transactionAnchorRetryInfo: TransactionAnchorRetryInfo
1317
}
1418

1519
export interface Dependencies {
1620
readonly db: Db
21+
readonly logger: Pino.Logger
1722
}
1823

1924
export interface Arguments {
2025
readonly dependencies: Dependencies
2126
}
2227

28+
interface EmptyTransactionAnchorRetryInfo {
29+
transactionAnchorRetryInfo: TransactionAnchorRetryInfo
30+
}
31+
32+
const emptyTransactionAnchorRetryInfo: EmptyTransactionAnchorRetryInfo = {
33+
transactionAnchorRetryInfo: [],
34+
}
35+
2336
export class HealthController {
2437
private readonly db: Db
2538
private readonly collection: Collection
39+
private readonly logger: Pino.Logger
2640

2741
constructor({
2842
dependencies: {
2943
db,
44+
logger,
3045
},
3146
}: Arguments) {
3247
this.db = db
3348
this.collection = this.db.collection('health')
49+
this.logger = logger
3450
}
3551

3652
private async checkMongo(): Promise<boolean> {
@@ -100,6 +116,30 @@ export class HealthController {
100116
}
101117
}
102118

119+
private async getTransactionRetryInfo(): Promise<TransactionAnchorRetryInfo> {
120+
this.logger.child({ message: 'getTransactionRetryInfo' })
121+
this.logger.trace('retrieving TransactionAnchorRetryInfo')
122+
try {
123+
const transactionAnchorRetryResults = await this.collection.findOne(
124+
{
125+
name: 'transactionAnchorRetryInfo',
126+
},
127+
{
128+
fields:
129+
{
130+
_id: false,
131+
name: false,
132+
},
133+
},
134+
) || emptyTransactionAnchorRetryInfo
135+
this.logger.trace({ transactionAnchorRetryResults }, 'getTransactionRetryInfo results')
136+
return transactionAnchorRetryResults.transactionAnchorRetryInfo
137+
} catch (error) {
138+
this.logger.error({ error }, 'error retrieving TransactionAnchorRetryInfo')
139+
return []
140+
}
141+
}
142+
103143
async getHealth(): Promise<HealthObject> {
104144
const mongoIsConnected = await this.checkMongo()
105145
const ipfsInfo = await this.getIPFSInfo()
@@ -108,6 +148,7 @@ export class HealthController {
108148
const networkInfo = await this.getNetworkInfo()
109149
const estimatedSmartFeeInfo = await this.getEstimatedSmartFeeInfo()
110150
const ipfsRetryInfo = await this.getIPFSRetryInfo()
151+
const transactionAnchorRetryInfo = await this.getTransactionRetryInfo()
111152
return {
112153
mongoIsConnected,
113154
ipfsInfo,
@@ -116,6 +157,7 @@ export class HealthController {
116157
networkInfo,
117158
estimatedSmartFeeInfo,
118159
ipfsRetryInfo,
160+
transactionAnchorRetryInfo,
119161
}
120162
}
121163
}

src/Health/HealthController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { pick, pipeP } from 'ramda'
55
import { childWithFileName } from 'Helpers/Logging'
66
import { HealthError, IPFSHashFailure, TransactionAnchorRetryInfo } from 'Interfaces'
77
import { IPFSHashTxId } from 'Messaging/Messages'
8+
89
import { BlockchainInfo, EstimatedSmartFeeInfo, HealthDAO, IPFSInfo, NetworkInfo, WalletInfo } from './HealthDAO'
910
import { IPFS } from './IPFS'
1011
import { IPFSDirectoryHashDAO } from './IPFSDirectoryHashDAO'

tests/functional/transaction_timeout.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { configureCreateVerifiableClaim, getVerifiableClaimSigner, isSignedVerifiableClaim } from '@po.et/poet-js'
33
import { allPass, is, isNil, lensPath, not, path, pipe, pipeP, view } from 'ramda'
44
import { describe } from 'riteway'
5+
import { HealthObject } from '../../src/API/HealthController'
56

67
import { issuer, privateKey } from '../helpers/Keys'
78
import {
@@ -11,6 +12,7 @@ import {
1112
waitForBlockchainSync,
1213
waitForBlockchainsToSync,
1314
} from '../helpers/bitcoin'
15+
import { getHealth } from '../helpers/endpoints'
1416
import { delayInSeconds, runtimeId, setUpServerAndDb } from '../helpers/utils'
1517
import { getWork, postWork } from '../helpers/works'
1618

@@ -119,6 +121,8 @@ describe('Transaction timout will reset the transaction id for the claim', async
119121
const secondResponse = await getWorkFromNode(claim.id)
120122
const secondGet = await secondResponse.json()
121123
const secondTxId = getTransactionId(secondGet)
124+
const healthResponse = await getHealth(NODE_PORT)
125+
const { transactionAnchorRetryInfo }: HealthObject = await healthResponse.json()
122126

123127
assert({
124128
given: 'transaction age max reached',
@@ -134,6 +138,13 @@ describe('Transaction timout will reset the transaction id for the claim', async
134138
expected: true,
135139
})
136140

141+
assert({
142+
given: 'a reset transaction id',
143+
should: 'show in the health report',
144+
actual: transactionAnchorRetryInfo.length > 0,
145+
expected: true,
146+
})
147+
137148
await bitcoinCoreClientA.generate(1)
138149
await delayInSeconds(
139150
blockchainSettings.BATCH_CREATION_INTERVAL_IN_SECONDS +

0 commit comments

Comments
 (0)