Additional fee recommendation sanity checks

This commit is contained in:
Mononaut 2024-01-08 16:33:19 +00:00
parent f7e7072dbc
commit d5c5ae0e09
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E

View File

@ -39,15 +39,25 @@ class FeeApi {
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], pBlocks[2], firstMedianFee) : this.defaultFee; const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], pBlocks[2], firstMedianFee) : this.defaultFee;
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], pBlocks[3], secondMedianFee) : this.defaultFee; const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], pBlocks[3], secondMedianFee) : this.defaultFee;
let fastestFee = Math.max(minimumFee, firstMedianFee);
let halfHourFee = Math.max(minimumFee, secondMedianFee);
let hourFee = Math.max(minimumFee, thirdMedianFee);
const economyFee = Math.max(minimumFee, Math.min(2 * minimumFee, thirdMedianFee));
// ensure recommendations always increase w/ priority
fastestFee = Math.max(fastestFee, halfHourFee, hourFee, economyFee);
halfHourFee = Math.max(halfHourFee, hourFee, economyFee);
hourFee = Math.max(hourFee, economyFee);
// explicitly enforce a minimum of ceil(mempoolminfee) on all recommendations. // explicitly enforce a minimum of ceil(mempoolminfee) on all recommendations.
// simply rounding up recommended rates is insufficient, as the purging rate // simply rounding up recommended rates is insufficient, as the purging rate
// can exceed the median rate of projected blocks in some extreme scenarios // can exceed the median rate of projected blocks in some extreme scenarios
// (see https://bitcoin.stackexchange.com/a/120024) // (see https://bitcoin.stackexchange.com/a/120024)
return { return {
'fastestFee': Math.max(minimumFee, firstMedianFee), 'fastestFee': fastestFee,
'halfHourFee': Math.max(minimumFee, secondMedianFee), 'halfHourFee': halfHourFee,
'hourFee': Math.max(minimumFee, thirdMedianFee), 'hourFee': hourFee,
'economyFee': Math.max(minimumFee, Math.min(2 * minimumFee, thirdMedianFee)), 'economyFee': economyFee,
'minimumFee': minimumFee, 'minimumFee': minimumFee,
}; };
} }