Skip to content

Commit 7c38088

Browse files
committed
refactor: use highest mempool.space fee estimation
1 parent fbd6403 commit 7c38088

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/chain/MempoolSpace.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ class MempoolSpace {
101101
};
102102

103103
public latestFee = (): number | undefined => {
104-
for (const api of this.apis) {
105-
if (api.latestFee !== undefined) {
106-
return api.latestFee;
107-
}
104+
const fees = this.apis
105+
.map((c) => c.latestFee)
106+
.filter((val): val is number => val !== undefined);
107+
108+
if (fees.length === 0) {
109+
this.logger.warn(`All ${this.symbol} MempoolSpace endpoints failed`);
110+
return undefined;
108111
}
109112

110-
this.logger.warn(`All ${this.symbol} MempoolSpace endpoints failed`);
111-
return undefined;
113+
return Math.max(...fees);
112114
};
113115

114116
public stop = () => {

test/integration/chain/MempoolSpace.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ describe('MempoolSpace', () => {
2727
expect(mempool.latestFee()).not.toBeUndefined();
2828
});
2929

30-
test('should pick results in order', async () => {
30+
test('should pick highest returned fee', async () => {
3131
mempool.stop();
3232

3333
const expectedFee = 42;
3434

35-
mempool['apis'][0]['latestFee'] = expectedFee;
36-
mempool['apis'][1]['latestFee'] = expectedFee - 12;
35+
mempool['apis'][0]['latestFee'] = expectedFee - 12;
36+
mempool['apis'][1]['latestFee'] = expectedFee;
3737
expect(mempool.latestFee()).toEqual(expectedFee);
3838

3939
mempool['apis'][0]['latestFee'] = undefined;

0 commit comments

Comments
 (0)