diff --git a/backend/src/api/fee-api.ts b/backend/src/api/fee-api.ts index 0914a1098..56106c7f5 100644 --- a/backend/src/api/fee-api.ts +++ b/backend/src/api/fee-api.ts @@ -34,7 +34,17 @@ class FeeApi { const mPool = mempool.getMempoolInfo(); // minimum non-zero minrelaytxfee / incrementalrelayfee is 1 sat/kvB = 0.001 sat/vB - return this.calculateRecommendedFee(pBlocks, mPool, 0.001); + const recommendations = this.calculateRecommendedFee(pBlocks, mPool, 0.001); + // enforce floor & offset for highest priority recommendations while <100% hashrate accepts sub-sat fees + recommendations.fastestFee = Math.max(recommendations.fastestFee + this.priorityFactor, this.minFastestFee); + recommendations.halfHourFee = Math.max(recommendations.halfHourFee + (this.priorityFactor / 2), this.minHalfHourFee); + return { + 'fastestFee': Math.round(recommendations.fastestFee * 1000) / 1000, + 'halfHourFee': Math.round(recommendations.halfHourFee * 1000) / 1000, + 'hourFee': Math.round(recommendations.hourFee * 1000) / 1000, + 'economyFee': Math.round(recommendations.economyFee * 1000) / 1000, + 'minimumFee': Math.round(recommendations.minimumFee * 1000) / 1000, + }; } public calculateRecommendedFee(pBlocks: MempoolBlock[], mPool: IBitcoinApi.MempoolInfo, minIncrement: number = this.minimumIncrement): RecommendedFees { @@ -70,8 +80,8 @@ class FeeApi { hourFee = Math.max(hourFee, economyFee); return { - 'fastestFee': Math.max(this.roundToNearest(fastestFee + this.priorityFactor, minIncrement), this.minFastestFee), - 'halfHourFee': Math.max(this.roundToNearest(halfHourFee + (this.priorityFactor / 2), minIncrement), this.minHalfHourFee), + 'fastestFee': this.roundToNearest(fastestFee, minIncrement), + 'halfHourFee': this.roundToNearest(halfHourFee, minIncrement), 'hourFee': this.roundToNearest(hourFee, minIncrement), 'economyFee': this.roundToNearest(economyFee, minIncrement), 'minimumFee': this.roundToNearest(minimumFee, minIncrement), diff --git a/backend/src/indexer.ts b/backend/src/indexer.ts index b3bfd2521..ca0b2303c 100644 --- a/backend/src/indexer.ts +++ b/backend/src/indexer.ts @@ -26,6 +26,7 @@ class Indexer { private indexerRunning = false; private tasksRunning: { [key in TaskName]?: boolean; } = {}; private tasksScheduled: { [key in TaskName]?: NodeJS.Timeout; } = {}; + private reindexTimeout: NodeJS.Timeout | undefined; private coreIndexes: CoreIndex[] = []; public indexerIsRunning(): boolean { @@ -76,10 +77,23 @@ class Indexer { public reindex(): void { if (Common.indexingEnabled()) { + if (this.reindexTimeout) { + clearTimeout(this.reindexTimeout); + this.reindexTimeout = undefined; + } this.runIndexer = true; } } + private scheduleNextRun(timeout: number): void { + if (!this.reindexTimeout) { // Only one future run should be planned, ignore if already scheduled + this.reindexTimeout = setTimeout(() => { + this.reindexTimeout = undefined; + this.reindex(); + }, timeout); + } + } + /** * schedules a single task to run in `timeout` ms * only one task of each type may be scheduled @@ -156,34 +170,40 @@ class Indexer { return; } - if (config.FIAT_PRICE.ENABLED) { - try { - await priceUpdater.$run(); - } catch (e) { - logger.err(`Running priceUpdater failed. Reason: ` + (e instanceof Error ? e.message : e)); - } - } - - // Do not attempt to index anything unless Bitcoin Core is fully synced - const blockchainInfo = await bitcoinClient.getBlockchainInfo(); - if (blockchainInfo.blocks !== blockchainInfo.headers) { - return; - } - this.runIndexer = false; this.indexerRunning = true; - logger.debug(`Running mining indexer`); - - await this.checkAvailableCoreIndexes(); + const retryDelay = 10000; + const runEvery = 1000 * 3600; // 1 hour + let nextRunDelay = runEvery; + let runSuccessful = false; try { + if (config.FIAT_PRICE.ENABLED) { + try { + await priceUpdater.$run(); + } catch (e) { + logger.err(`Running priceUpdater failed. Reason: ` + (e instanceof Error ? e.message : e)); + } + } + + // Do not attempt to index anything unless Bitcoin Core is fully synced + const blockchainInfo = await bitcoinClient.getBlockchainInfo(); + if (blockchainInfo.blocks !== blockchainInfo.headers) { + logger.debug(`Bitcoin Core not fully synced, retrying index run in 10 seconds.`); + nextRunDelay = retryDelay; + return; + } + + logger.debug(`Running mining indexer`); + + await this.checkAvailableCoreIndexes(); + const chainValid = await blocks.$generateBlockDatabase(); if (chainValid === false) { // Chain of block hash was invalid, so we need to reindex. Stop here and continue at the next iteration logger.warn(`The chain of block hash is invalid, re-indexing invalid data in 10 seconds.`, logger.tags.mining); - setTimeout(() => this.reindex(), 10000); - this.indexerRunning = false; + nextRunDelay = retryDelay; return; } @@ -202,19 +222,20 @@ class Indexer { await BlocksRepository.$migrateBlocks(); // do not wait for classify blocks to finish blocks.$classifyBlocks(); + runSuccessful = true; } catch (e) { - this.indexerRunning = false; + nextRunDelay = retryDelay; logger.err(`Indexer failed, trying again in 10 seconds. Reason: ` + (e instanceof Error ? e.message : e)); - setTimeout(() => this.reindex(), 10000); + } finally { this.indexerRunning = false; - return; + const nextRunAt = new Date(Date.now() + nextRunDelay).toUTCString(); + if (runSuccessful) { + logger.debug(`Indexing completed. Next run planned at ${nextRunAt}`); + } else { + logger.debug(`Indexing did not complete, next run planned at ${nextRunAt}`); + } + this.scheduleNextRun(nextRunDelay); } - - this.indexerRunning = false; - - const runEvery = 1000 * 3600; // 1 hour - logger.debug(`Indexing completed. Next run planned at ${new Date(new Date().getTime() + runEvery).toUTCString()}`); - setTimeout(() => this.reindex(), runEvery); } } diff --git a/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts b/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts index 2888965a2..0240fe00c 100644 --- a/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts +++ b/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts @@ -216,8 +216,9 @@ export class AccelerateCheckout implements OnInit, OnDestroy { } if (this._step === 'checkout' && this.canPayWithBitcoin) { this.btcpayInvoiceFailed = false; - this.invoice = null; + this.invoice = undefined; this.requestBTCPayInvoice(); + this.scrollToElementWithTimeout('acceleratePreviewAnchor', 'start', 100); } else if (this._step === 'cashapp') { this.loadingCashapp = true; this.setupSquare(); diff --git a/frontend/src/app/components/acceleration/acceleration-fees-graph/acceleration-fees-graph.component.html b/frontend/src/app/components/acceleration/acceleration-fees-graph/acceleration-fees-graph.component.html index 9146c8e34..114a20913 100644 --- a/frontend/src/app/components/acceleration/acceleration-fees-graph/acceleration-fees-graph.component.html +++ b/frontend/src/app/components/acceleration/acceleration-fees-graph/acceleration-fees-graph.component.html @@ -11,12 +11,6 @@