From 709783280a54925db2145c9cf3f294c7ff6c3e43 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 19 Jul 2023 15:05:40 +0900 Subject: [PATCH 1/8] Fix liquid fees & remove minimum fee rate --- backend/src/api/blocks.ts | 6 ++++-- backend/src/api/transaction-utils.ts | 18 +++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index fdf32f438..7cd37f637 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -171,7 +171,9 @@ class Blocks { private convertLiquidFees(block: IBitcoinApi.VerboseBlock): IBitcoinApi.VerboseBlock { block.tx.forEach(tx => { - tx.fee = Object.values(tx.fee || {}).reduce((total, output) => total + output, 0); + if (!isFinite(Number(tx.fee))) { + tx.fee = Object.values(tx.fee || {}).reduce((total, output) => total + output, 0); + } }); return block; } @@ -877,7 +879,7 @@ class Blocks { let height = blockHeight; let summary: BlockSummary; - if (cpfpSummary) { + if (cpfpSummary && !Common.isLiquid()) { summary = { id: hash, transactions: cpfpSummary.transactions.map(tx => { diff --git a/backend/src/api/transaction-utils.ts b/backend/src/api/transaction-utils.ts index 8bebc42d8..849aff8f3 100644 --- a/backend/src/api/transaction-utils.ts +++ b/backend/src/api/transaction-utils.ts @@ -35,6 +35,13 @@ class TransactionUtils { } else { transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts, lazyPrevouts); } + + if (Common.isLiquid()) { + if (!isFinite(Number(transaction.fee))) { + transaction.fee = Object.values(transaction.fee || {}).reduce((total, output) => total + output, 0); + } + } + if (addMempoolData || !transaction?.status?.confirmed) { return this.extendMempoolTransaction(transaction); } else { @@ -52,8 +59,7 @@ class TransactionUtils { // @ts-ignore return transaction; } - const feePerVbytes = Math.max(Common.isLiquid() ? 0.1 : 1, - (transaction.fee || 0) / (transaction.weight / 4)); + const feePerVbytes = (transaction.fee || 0) / (transaction.weight / 4); const transactionExtended: TransactionExtended = Object.assign({ vsize: Math.round(transaction.weight / 4), feePerVsize: feePerVbytes, @@ -68,13 +74,11 @@ class TransactionUtils { public extendMempoolTransaction(transaction: IEsploraApi.Transaction): MempoolTransactionExtended { const vsize = Math.ceil(transaction.weight / 4); const fractionalVsize = (transaction.weight / 4); - const sigops = this.countSigops(transaction); + const sigops = Common.isLiquid() ? this.countSigops(transaction) : 0; // https://github.com/bitcoin/bitcoin/blob/e9262ea32a6e1d364fb7974844fadc36f931f8c6/src/policy/policy.cpp#L295-L298 const adjustedVsize = Math.max(fractionalVsize, sigops * 5); // adjusted vsize = Max(weight, sigops * bytes_per_sigop) / witness_scale_factor - const feePerVbytes = Math.max(Common.isLiquid() ? 0.1 : 1, - (transaction.fee || 0) / fractionalVsize); - const adjustedFeePerVsize = Math.max(Common.isLiquid() ? 0.1 : 1, - (transaction.fee || 0) / adjustedVsize); + const feePerVbytes = (transaction.fee || 0) / fractionalVsize; + const adjustedFeePerVsize = (transaction.fee || 0) / adjustedVsize; const transactionExtended: MempoolTransactionExtended = Object.assign(transaction, { order: this.txidToOrdering(transaction.txid), vsize: Math.round(transaction.weight / 4), From 87e39b838951e1949986cf27388345821085a79b Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 19 Jul 2023 16:24:05 +0900 Subject: [PATCH 2/8] Fix liquid blockchain bar --- .../blockchain-blocks.component.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts index 245973885..ba066d10a 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts @@ -113,8 +113,10 @@ export class BlockchainBlocksComponent implements OnInit, OnChanges, OnDestroy { const animate = this.chainTip != null && latestHeight > this.chainTip; for (const block of blocks) { - block.extras.minFee = this.getMinBlockFee(block); - block.extras.maxFee = this.getMaxBlockFee(block); + if (block?.extras) { + block.extras.minFee = this.getMinBlockFee(block); + block.extras.maxFee = this.getMaxBlockFee(block); + } } this.blocks = blocks; @@ -251,7 +253,7 @@ export class BlockchainBlocksComponent implements OnInit, OnChanges, OnDestroy { if (height >= 0) { this.cacheService.loadBlock(height); block = this.cacheService.getCachedBlock(height) || null; - if (block) { + if (block?.extras) { block.extras.minFee = this.getMinBlockFee(block); block.extras.maxFee = this.getMaxBlockFee(block); } @@ -293,8 +295,10 @@ export class BlockchainBlocksComponent implements OnInit, OnChanges, OnDestroy { onBlockLoaded(block: BlockExtended) { const blockIndex = this.height - block.height; if (blockIndex >= 0 && blockIndex < this.blocks.length) { - block.extras.minFee = this.getMinBlockFee(block); - block.extras.maxFee = this.getMaxBlockFee(block); + if (block?.extras) { + block.extras.minFee = this.getMinBlockFee(block); + block.extras.maxFee = this.getMaxBlockFee(block); + } this.blocks[blockIndex] = block; this.blockStyles[blockIndex] = this.getStyleForBlock(block, blockIndex); } From 943dc6f5e6bae8c3fdbc2cd7233a7cb4edaee30a Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 20 Jul 2023 17:30:26 +0900 Subject: [PATCH 3/8] Fix blocks list observable --- .../src/app/components/blocks-list/blocks-list.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.ts b/frontend/src/app/components/blocks-list/blocks-list.component.ts index 2b54058e8..725b6dc74 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.ts +++ b/frontend/src/app/components/blocks-list/blocks-list.component.ts @@ -84,10 +84,10 @@ export class BlocksList implements OnInit { .pipe( switchMap((blocks) => { if (blocks[0].height <= this.lastBlockHeight) { - return [null]; // Return an empty stream so the last pipe is not executed + return null; // Return an empty stream so the last pipe is not executed } this.lastBlockHeight = blocks[0].height; - return blocks; + return of(blocks); }) ) ]) From 6b453ef0186f816486a2ca1fef42ef136c9ecd6d Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 20 Jul 2023 17:24:13 +0100 Subject: [PATCH 4/8] sign contributor agreement --- contributors/pedromvpg.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 contributors/pedromvpg.txt diff --git a/contributors/pedromvpg.txt b/contributors/pedromvpg.txt new file mode 100644 index 000000000..ce98c4167 --- /dev/null +++ b/contributors/pedromvpg.txt @@ -0,0 +1,3 @@ +I hereby accept the terms of the Contributor License Agreement in the CONTRIBUTING.md file of the mempool/mempool git repository as of July 20, 2023. + +Signed: pedromvpg From 61eeb82694e8cb2df57a92d2bd82a5f2c6011984 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn Date: Fri, 21 Jul 2023 17:09:57 +0900 Subject: [PATCH 5/8] Expose the GITHUB_SECRET to the frontend build step --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6bd3941d..8a9ad248f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,8 @@ jobs: - name: Build run: npm run build working-directory: ${{ matrix.node }}/${{ matrix.flavor }}/backend + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} frontend: if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')" From 0f77fb88bf011604712cf37b089cd8ad45c856b7 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Fri, 21 Jul 2023 17:18:45 +0900 Subject: [PATCH 6/8] handle missing block.extras on liquid --- .../src/app/components/block/block.component.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/components/block/block.component.ts b/frontend/src/app/components/block/block.component.ts index 4be6e3aff..ce3317255 100644 --- a/frontend/src/app/components/block/block.component.ts +++ b/frontend/src/app/components/block/block.component.ts @@ -144,10 +144,12 @@ export class BlockComponent implements OnInit, OnDestroy { for (const block of blocks) { if (block.id === this.blockHash) { this.block = block; - block.extras.minFee = this.getMinBlockFee(block); - block.extras.maxFee = this.getMaxBlockFee(block); - if (block?.extras?.reward != undefined) { - this.fees = block.extras.reward / 100000000 - this.blockSubsidy; + if (block.extras) { + block.extras.minFee = this.getMinBlockFee(block); + block.extras.maxFee = this.getMaxBlockFee(block); + if (block?.extras?.reward != undefined) { + this.fees = block.extras.reward / 100000000 - this.blockSubsidy; + } } } else if (block.height === this.block?.height) { this.block.stale = true; @@ -246,8 +248,10 @@ export class BlockComponent implements OnInit, OnDestroy { } this.updateAuditAvailableFromBlockHeight(block.height); this.block = block; - block.extras.minFee = this.getMinBlockFee(block); - block.extras.maxFee = this.getMaxBlockFee(block); + if (block.extras) { + block.extras.minFee = this.getMinBlockFee(block); + block.extras.maxFee = this.getMaxBlockFee(block); + } this.blockHeight = block.height; this.lastBlockHeight = this.blockHeight; this.nextBlockHeight = block.height + 1; From d91fa5c6effb59180f23d2097725d0c64942c3ba Mon Sep 17 00:00:00 2001 From: Mononaut Date: Fri, 21 Jul 2023 18:10:13 +0900 Subject: [PATCH 7/8] null => of([]) --- .../src/app/components/blocks-list/blocks-list.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.ts b/frontend/src/app/components/blocks-list/blocks-list.component.ts index 725b6dc74..1af6572fc 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.ts +++ b/frontend/src/app/components/blocks-list/blocks-list.component.ts @@ -84,7 +84,7 @@ export class BlocksList implements OnInit { .pipe( switchMap((blocks) => { if (blocks[0].height <= this.lastBlockHeight) { - return null; // Return an empty stream so the last pipe is not executed + return of([]); // Return an empty stream so the last pipe is not executed } this.lastBlockHeight = blocks[0].height; return of(blocks); From ca69d19bf7739d7a7f9482f6c4ddced76906ac3a Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn Date: Fri, 21 Jul 2023 18:14:32 +0900 Subject: [PATCH 8/8] Use the GITHUB_SECRET to authenticate with the API Fix the environment variable Add extra logging when using the authentication Use the GITHUB_TOKEN on the frontend build step --- .github/workflows/ci.yml | 5 +++-- frontend/sync-assets.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a9ad248f..02131d800 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,8 +55,6 @@ jobs: - name: Build run: npm run build working-directory: ${{ matrix.node }}/${{ matrix.flavor }}/backend - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} frontend: if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')" @@ -101,3 +99,6 @@ jobs: - name: Build run: npm run build working-directory: ${{ matrix.node }}/${{ matrix.flavor }}/frontend + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/frontend/sync-assets.js b/frontend/sync-assets.js index 26d84e319..49618dea3 100644 --- a/frontend/sync-assets.js +++ b/frontend/sync-assets.js @@ -26,6 +26,8 @@ try { } } +const githubSecret = process.env.GITHUB_TOKEN; + function download(filename, url) { https.get(url, (response) => { if (response.statusCode < 200 || response.statusCode > 299) { @@ -55,6 +57,12 @@ function downloadMiningPoolLogos$() { headers: {'user-agent': 'node.js'} }; + if (githubSecret) { + console.log('Downloading the mining pool logos with authentication'); + options.headers['authorization'] = `Bearer ${githubSecret}`; + options.headers['X-GitHub-Api-Version'] = '2022-11-28'; + } + https.get(options, (response) => { const chunks_of_data = []; @@ -109,6 +117,13 @@ function downloadPromoVideoSubtiles$() { headers: {'user-agent': 'node.js'} }; + if (githubSecret) { + console.log('Downloading the promo video subtitles with authentication'); + options.headers['authorization'] = `Bearer ${githubSecret}`; + options.headers['X-GitHub-Api-Version'] = '2022-11-28'; + } + + https.get(options, (response) => { const chunks_of_data = []; @@ -163,6 +178,12 @@ function downloadPromoVideo$() { headers: {'user-agent': 'node.js'} }; + if (githubSecret) { + console.log('Downloading the promo videos with authentication'); + options.headers['authorization'] = `Bearer ${githubSecret}`; + options.headers['X-GitHub-Api-Version'] = '2022-11-28'; + } + https.get(options, (response) => { const chunks_of_data = [];