Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions backend/src/api/bitcoin/bitcoin.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,36 +269,33 @@ class BitcoinRoutes {
return;
}

logger.debug('Fetching fresh Bitcoin Knots nodes stats from Bitnodes API');
const response = await axios.get('https://bitnodes.io/api/v1/snapshots/latest', {
timeout: 10000,
logger.debug('Fetching fresh Bitcoin Knots nodes stats from Luke Dashjr API');
const response = await axios.get('https://luke.dashjr.org/programs/bitcoin/files/charts/data/uainfo.json', {
timeout: 15000,
headers: {
'User-Agent': 'Mempool.space/1.0'
}
});

const snapshot = response.data;
const totalBitcoinNodes = snapshot.total_nodes;
const uainfo = response.data;
let totalBitcoinNodes = 0;
let totalKnotsNodesClearnet = 0;
let torNodeCount = 0;
let fullCount = 0;
let bipcount = 0;

Object.entries(snapshot.nodes).forEach(([address, nodeData]: [string, any]) => {
const userAgent = nodeData[1];
if (userAgent && userAgent.toLowerCase().includes('bip110')){
bipcount++;
Object.entries(uainfo).forEach(([ua, data]: [string, any]) => {
const nodeCount = (data.listening || 0) + (data.est_unreachable || 0);
totalBitcoinNodes += nodeCount;
const uaLower = ua.toLowerCase();
if (uaLower.includes('bip110')) {
bipcount += nodeCount;
}
if (userAgent && userAgent.toLowerCase().includes('knots')) {
if (address.includes('.onion')) {
torNodeCount++;
} else {
totalKnotsNodesClearnet++;
}
if (uaLower.includes('knots')) {
totalKnotsNodesClearnet += nodeCount;
}
});

fullCount = torNodeCount + totalKnotsNodesClearnet;
const fullCount = totalKnotsNodesClearnet + torNodeCount;
const knotsPercentageOfTotal = totalBitcoinNodes > 0 ? (fullCount / totalBitcoinNodes) * 100 : 0;

const result = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit {
this.knotsPercentage = knotsData.totals.percentageOfTotal;
this.totalKnotsNodes = knotsData.totals.totalNodes;
this.totalBitcoinNodes = Math.round(this.totalKnotsNodes / (this.knotsPercentage / 100));
this.bipPercentage = (knotsData.totals.bipCount * 100) / knotsData.totals.totalBitcoinNodes;
this.bipPercentage = knotsData.totals.totalBitcoinNodes > 0 ? (knotsData.totals.bipCount * 100) / knotsData.totals.totalBitcoinNodes : 0;
});
}

Expand Down