Skip to content

Commit 70126f8

Browse files
authored
Merge pull request #19 from bitcoinerlab/electrum-fee-resilience
feat: improve resilience of fetchFeeEstimates by adding retry mechanism
2 parents ed2a89e + 894d570 commit 70126f8

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@bitcoinerlab/explorer",
33
"description": "Bitcoin Blockchain Explorer: Client Interface featuring Esplora and Electrum Implementations.",
44
"homepage": "https://github.com/bitcoinerlab/explorer",
5-
"version": "0.3.8",
5+
"version": "0.3.9",
66
"author": "Jose-Luis Landabaso",
77
"license": "MIT",
88
"prettier": "@bitcoinerlab/configs/prettierConfig.json",

src/electrum.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,24 @@ export class ElectrumExplorer implements Explorer {
368368
const feeEstimates: { [target: number]: number } = {};
369369
for (const target of T) {
370370
//100000 = 10 ^ 8 sats/BTC / 10 ^3 bytes/kbyte
371+
//Don't throw. Instead try twice just in case the fist try was a spuripus error.
372+
//The reason for not throwing is blockchainEstimatefee throws
373+
//even if the call is successful but for some reason the electrum server
374+
//cannot provide the fee for a certain target time. This has been observed to
375+
//occur on electrs on testnet.
376+
let fee: number | undefined = undefined;
371377
try {
372378
const client = this.#getClientOrThrow();
373-
const fee = await client.blockchainEstimatefee(target);
379+
fee = await client.blockchainEstimatefee(target);
374380
feeEstimates[target] = 100000 * fee;
375-
} catch (error: unknown) {
376-
throw new Error(`Failed to fetch fee estimates: ${getErrorMsg(error)}`);
381+
} catch (error: unknown) {}
382+
if (fee === undefined) {
383+
try {
384+
await new Promise(resolve => setTimeout(resolve, 100)); //sleep 0.1 sec
385+
const client = this.#getClientOrThrow();
386+
fee = await client.blockchainEstimatefee(target);
387+
feeEstimates[target] = 100000 * fee;
388+
} catch (error: unknown) {}
377389
}
378390
}
379391
checkFeeEstimates(feeEstimates);

0 commit comments

Comments
 (0)