Skip to content

Commit

Permalink
Add support for retrieving the harvester and farmer node id
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbrucker committed Sep 22, 2023
1 parent cf46ca0 commit f5f2ef9
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.19.0 / 2023-09-23
==================

* Adds support for retrieving the harvester and farmer node id.

1.18.1 / 2023-09-05
==================

Expand Down
21 changes: 21 additions & 0 deletions lib/chia-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { promises: fs } = require('fs');
const YAML = require('js-yaml');
const { join } = require('path');
const {calculateNodeIdForCert} = require('./util')

class ChiaConfig {
constructor(configDirectory) {
Expand All @@ -19,6 +20,26 @@ class ChiaConfig {
return fs.readFile(filePath, 'utf8');
}

async getHarvesterSslCertFile() {
const filePath = join(this.configDirectory, this.config.harvester.ssl.private_crt)

return fs.readFile(filePath, 'utf8')
}

async getHarvesterNodeId() {
return calculateNodeIdForCert(await this.getHarvesterSslCertFile())
}

async getFarmerPublicSslCertFile() {
const filePath = join(this.configDirectory, this.config.farmer.ssl.public_crt)

return fs.readFile(filePath, 'utf8')
}

async getFarmerNodeId() {
return calculateNodeIdForCert(await this.getFarmerPublicSslCertFile())
}

get daemonAddress() {
return `${this.config.self_hostname}:${this.config.daemon_port}`;
}
Expand Down
1 change: 1 addition & 0 deletions lib/extensions/extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./string-extensions')
7 changes: 7 additions & 0 deletions lib/extensions/string-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
String.prototype.ensureHexPrefix = function() {
return this.startsWith('0x') ? this : `0x${this}`
}

String.prototype.stripHexPrefix = function() {
return this.startsWith('0x') ? this.slice(2) : this
}
18 changes: 18 additions & 0 deletions lib/service/stats-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ class StatsCollection {
await this.plotterApiClient.init();
}
await this.tryUntilSucceeded(this.updateRunningServices.bind(this));
await this.tryUntilSucceeded(async () => {
if (!this.isServiceRunning.get(harvesterService)) {
return
}
const harvesterStats = this.stats.has(harvesterService) ? this.stats.get(harvesterService) : {}
const harvesterId = await chiaConfig.getHarvesterNodeId()
harvesterStats.nodeId = harvesterId
await this.setStatsForService(harvesterService, harvesterStats, { nodeId: harvesterId })
})
await this.tryUntilSucceeded(async () => {
if (!this.isServiceRunning.get(farmerService)) {
return
}
const farmerStats = this.stats.has(farmerService) ? this.stats.get(farmerService) : {}
const farmerId = await chiaConfig.getFarmerNodeId()
farmerStats.nodeId = farmerId
await this.setStatsForService(farmerService, farmerStats, { nodeId: farmerId })
})
await this.tryUntilSucceeded(this.updateStats.bind(this));
await this.tryUntilSucceeded(this.updateFullNodeStats.bind(this));
setInterval(async () => {
Expand Down
6 changes: 6 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const moment = require('moment');
const BigNumber = require('bignumber.js')
const {X509Certificate} = require('crypto')

const plottingTimestampRegex = /([0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\.[0-9]+)/
const FINISHED_LOG_LINES_128_BUCKETS = 2626
Expand Down Expand Up @@ -49,6 +50,11 @@ const util = {
.multipliedBy((new BigNumber(2)).exponentiatedBy(kSize - 1))
.multipliedBy(getActualSpaceConstantFactor(kSize))
},
calculateNodeIdForCert(cert) {
const x509Cert = new X509Certificate(cert)

return x509Cert.fingerprint256.replaceAll(':', '').toLowerCase().ensureHexPrefix()
},
}

module.exports = util
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

require('./lib/extensions/extensions')

const config = require('./lib/service/config');
const firstRunWizard = require('./lib/service/first-run-wizard');
const statsCollection = require('./lib/service/stats-collection');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chia-dashboard-satellite",
"version": "1.18.1",
"version": "1.19.0",
"repository": "https://github.com/felixbrucker/chia-dashboard-satellite.git",
"bugs": "https://github.com/felixbrucker/chia-dashboard-satellite/issues",
"license": "GPL-3.0",
Expand Down

0 comments on commit f5f2ef9

Please sign in to comment.