Skip to content

Commit 107c399

Browse files
authored
Handle Mirror Node network fee errors (#240)
* Handle Mirror Node network fee errors Expand mirror node network fees fallback to encompass all errors - Add warning log - Expand test integration capabilities using `sinon` - Add `eth.spec.ts` coverage for mirror node failures for gas endpoints Signed-off-by: Nana-EC <[email protected]>
1 parent 8479372 commit 107c399

File tree

4 files changed

+273
-5
lines changed

4 files changed

+273
-5
lines changed

package-lock.json

Lines changed: 186 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/relay/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@types/mocha": "^9.1.0",
1515
"@types/node": "^17.0.14",
1616
"chai": "^4.3.6",
17+
"sinon": "^14.0.0",
1718
"ts-mocha": "^9.0.2",
1819
"typescript": "^4.6.4"
1920
},

packages/relay/src/lib/eth.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,18 @@ export class EthImpl implements Eth {
147147
}
148148

149149
private async getFeeWeibars() {
150-
let networkFees = await this.mirrorNodeClient.getNetworkFees();
150+
let networkFees;
151+
152+
try {
153+
networkFees = await this.mirrorNodeClient.getNetworkFees();
154+
if (_.isNil(networkFees)) {
155+
this.logger.debug(`Mirror Node returned no fees. Fallback to network`);
156+
}
157+
} catch (e: any) {
158+
this.logger.warn(e, `Mirror Node threw an error retrieving fees. Fallback to network`);
159+
}
151160

152161
if (_.isNil(networkFees)) {
153-
this.logger.debug(`Mirror Node returned no fees. Fallback to network`);
154162
networkFees = {
155163
fees: [
156164
{
@@ -631,7 +639,7 @@ export class EthImpl implements Eth {
631639
if (e.status && e.status._code) {
632640
resolvedError = new Error(e.message);
633641
}
634-
642+
635643
this.logger.error(resolvedError, 'Failed to successfully submit contractCallQuery');
636644
return predefined.INTERNAL_ERROR;
637645
}
@@ -701,7 +709,7 @@ export class EthImpl implements Eth {
701709

702710

703711
// support stricter go-eth client which requires the transaction hash property on logs
704-
const logs = receiptResponse.logs.map(log => ({ ...log, transactionHash: receiptResponse.hash}));
712+
const logs = receiptResponse.logs.map(log => ({ ...log, transactionHash: receiptResponse.hash }));
705713

706714
const receipt = {
707715
blockHash: receiptResponse.block_hash.substring(0, 66),

0 commit comments

Comments
 (0)