mirror of
https://github.com/mempool/mempool.git
synced 2025-03-03 17:47:01 +01:00
Fix for fee estimate not being correct when block is almost full with more projected blocks in queue.
fixes #278
This commit is contained in:
parent
3256198ab0
commit
371433b2da
2 changed files with 10 additions and 10 deletions
|
@ -18,9 +18,9 @@ class FeeApi {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstMedianFee = this.optimizeMedianFee(pBlocks[0]);
|
const firstMedianFee = this.optimizeMedianFee(pBlocks[0], pBlocks[1]);
|
||||||
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], firstMedianFee) : this.defaultFee;
|
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], pBlocks[2], firstMedianFee) : this.defaultFee;
|
||||||
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], secondMedianFee) : this.defaultFee;
|
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], pBlocks[3], secondMedianFee) : this.defaultFee;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'fastestFee': firstMedianFee,
|
'fastestFee': firstMedianFee,
|
||||||
|
@ -29,12 +29,12 @@ class FeeApi {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private optimizeMedianFee(pBlock: MempoolBlock, previousFee?: number): number {
|
private optimizeMedianFee(pBlock: MempoolBlock, nextBlock: MempoolBlock | undefined, previousFee?: number): number {
|
||||||
const useFee = previousFee ? (pBlock.medianFee + previousFee) / 2 : pBlock.medianFee;
|
const useFee = previousFee ? (pBlock.medianFee + previousFee) / 2 : pBlock.medianFee;
|
||||||
if (pBlock.blockVSize <= 500000) {
|
if (pBlock.blockVSize <= 500000) {
|
||||||
return this.defaultFee;
|
return this.defaultFee;
|
||||||
}
|
}
|
||||||
if (pBlock.blockVSize <= 950000) {
|
if (pBlock.blockVSize <= 950000 && nextBlock) {
|
||||||
const multiplier = (pBlock.blockVSize - 500000) / 500000;
|
const multiplier = (pBlock.blockVSize - 500000) / 500000;
|
||||||
return Math.max(Math.round(useFee * multiplier), this.defaultFee);
|
return Math.max(Math.round(useFee * multiplier), this.defaultFee);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ export class FeesBoxComponent implements OnInit {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstMedianFee = this.optimizeMedianFee(pBlocks[0]);
|
const firstMedianFee = this.optimizeMedianFee(pBlocks[0], pBlocks[1]);
|
||||||
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], firstMedianFee) : this.defaultFee;
|
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], pBlocks[2], firstMedianFee) : this.defaultFee;
|
||||||
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], secondMedianFee) : this.defaultFee;
|
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], pBlocks[3], secondMedianFee) : this.defaultFee;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'fastestFee': firstMedianFee,
|
'fastestFee': firstMedianFee,
|
||||||
|
@ -53,12 +53,12 @@ export class FeesBoxComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
optimizeMedianFee(pBlock: MempoolBlock, previousFee?: number): number {
|
private optimizeMedianFee(pBlock: MempoolBlock, nextBlock: MempoolBlock | undefined, previousFee?: number): number {
|
||||||
const useFee = previousFee ? (pBlock.medianFee + previousFee) / 2 : pBlock.medianFee;
|
const useFee = previousFee ? (pBlock.medianFee + previousFee) / 2 : pBlock.medianFee;
|
||||||
if (pBlock.blockVSize <= 500000) {
|
if (pBlock.blockVSize <= 500000) {
|
||||||
return this.defaultFee;
|
return this.defaultFee;
|
||||||
}
|
}
|
||||||
if (pBlock.blockVSize <= 950000) {
|
if (pBlock.blockVSize <= 950000 && nextBlock) {
|
||||||
const multiplier = (pBlock.blockVSize - 500000) / 500000;
|
const multiplier = (pBlock.blockVSize - 500000) / 500000;
|
||||||
return Math.max(Math.round(useFee * multiplier), this.defaultFee);
|
return Math.max(Math.round(useFee * multiplier), this.defaultFee);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue