Skip to content

Commit

Permalink
Merge pull request #59 from LN-Zap/fix/feeminimum
Browse files Browse the repository at this point in the history
Ensure that fee minimum estimate is returned when no estimates
  • Loading branch information
mrfelton authored Jul 15, 2024
2 parents f814142 + ab380a5 commit 229429e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/DataProviderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export class DataProviderManager {
);
}

// If we don't have any estimates that are above the fee minimum, add a single estimate at the fee minimum.
if (Object.keys(feeEstimates).length === 0) {
feeEstimates["1"] = this.feeMinimum * 1000;
}

data = {
current_block_height: blockHeight,
current_block_hash: blockHash,
Expand Down
73 changes: 73 additions & 0 deletions test/DataProviderManager-minfee.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { expect, test } from "bun:test";
import { DataProviderManager } from "../src/lib/DataProviderManager";

test("should exclude estimates that are below the fee minimum", async () => {
const feeEstimates = {
"1": 3,
"2": 2,
"3": 1,
};
class MockProvider implements Provider {
getBlockHeight = () => Promise.resolve(1001);
getBlockHash = () => Promise.resolve("hash1001");
getFeeEstimates = () => Promise.resolve(feeEstimates);
getAllData = () =>
Promise.resolve({
blockHeight: 1001,
blockHash: "hash1001",
feeEstimates,
});
}

const maxHeightDelta = 1;
const feeMultiplier = 1;
const feeMinimum = 2;
const manager = new DataProviderManager(
{ stdTTL: 0, checkperiod: 0 },
maxHeightDelta,
feeMultiplier,
feeMinimum,
);
manager.registerProvider(new MockProvider());

const mergedData = await manager.getData();
expect(mergedData.fee_by_block_target).toEqual({
"1": 3000,
"2": 2000,
});
});

test("should return single estimate at fee minimum if no valid estimates are available", async () => {
const feeEstimates = {
"1": 1,
"2": 1,
"3": 1,
};
class MockProvider implements Provider {
getBlockHeight = () => Promise.resolve(1001);
getBlockHash = () => Promise.resolve("hash1001");
getFeeEstimates = () => Promise.resolve(feeEstimates);
getAllData = () =>
Promise.resolve({
blockHeight: 1001,
blockHash: "hash1001",
feeEstimates,
});
}

const maxHeightDelta = 1;
const feeMultiplier = 1;
const feeMinimum = 2;
const manager = new DataProviderManager(
{ stdTTL: 0, checkperiod: 0 },
maxHeightDelta,
feeMultiplier,
feeMinimum,
);
manager.registerProvider(new MockProvider());

const mergedData = await manager.getData();
expect(mergedData.fee_by_block_target).toEqual({
"1": 2000,
});
});

0 comments on commit 229429e

Please sign in to comment.