Skip to content

Commit

Permalink
feat: add coinbase data (#37)
Browse files Browse the repository at this point in the history
add temporary debug data to coinbases
  • Loading branch information
leet4tari authored Sep 13, 2024
2 parents 0d34ac4 + 7fdd454 commit aa3e47c
Show file tree
Hide file tree
Showing 10 changed files with 511 additions and 52 deletions.
4 changes: 4 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var favicon = require("serve-favicon");
var indexRouter = require("./routes/index");
var blockDataRouter = require("./routes/block_data");
var blocksRouter = require("./routes/blocks");
var exportRouter = require("./routes/export");
var mempoolRouter = require("./routes/mempool");
var minersRouter = require("./routes/miners");
var searchCommitmentsRouter = require("./routes/search_commitments");
var searchKernelsRouter = require("./routes/search_kernels");
var healthz = require("./routes/healthz");
Expand Down Expand Up @@ -102,7 +104,9 @@ app.use("/", indexRouter);
app.use("/blocks", blocksRouter);
app.use("/block_data", blockDataRouter);
app.use("/assets", assetsRouter);
// app.use("/export", exportRouter);
app.use("/mempool", mempoolRouter);
app.use("/miners", minersRouter);
app.use("/search_commitments", searchCommitmentsRouter);
app.use("/search_kernels", searchKernelsRouter);
app.use("/healthz", healthz);
Expand Down
7 changes: 5 additions & 2 deletions applications/minotari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ message NetworkDifficultyResponse {
uint64 pow_algo = 5;
uint64 sha3x_estimated_hash_rate = 6;
uint64 randomx_estimated_hash_rate = 7;
uint64 num_coinbases = 8;
bytes first_coinbase_extra = 9;
}

// A generic single value response for a specific height
Expand Down Expand Up @@ -339,10 +341,11 @@ message MetaData {
uint64 best_block_height = 1;
// The block hash of the current tip of the longest valid chain, or `None` for an empty chain
bytes best_block_hash = 2;
// This is the min height this node can provide complete blocks for. A 0 here means this node is archival and can provide complete blocks for every height.
uint64 pruned_height = 6;
// The current geometric mean of the pow of the chain tip, or `None` if there is no chain
bytes accumulated_difficulty = 5;
// This is the min height this node can provide complete blocks for. A 0 here means this node is archival and can provide complete blocks for every height.
uint64 pruned_height = 6;
uint64 timestamp = 7;
}

message SyncInfoResponse {
Expand Down
152 changes: 152 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"express": "~4.16.1",
"fast-csv": "^5.0.1",
"hbs": "^4.1.2",
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
Expand Down
35 changes: 35 additions & 0 deletions routes/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var { createClient } = require("../baseNodeClient");

var express = require("express");
const { format } = require("@fast-csv/format");
var router = express.Router();

router.get("/", async function (req, res) {
try {
let client = createClient();
let lastDifficulties = await client.getNetworkDifficulty({
from_tip: 1000,
});

const csvStream = format({ headers: true });
res.setHeader("Content-Disposition", 'attachment; filename="data.csv"');
res.setHeader("Content-Type", "text/csv");

csvStream.pipe(res);

// Example data

for (let i = 0; i < lastDifficulties.length; i++) {
csvStream.write(lastDifficulties[i]);
}

csvStream.end();
} catch (error) {
res.status(500);
if (req.query.json !== undefined) {
res.json({ error: error });
} else {
res.render("error", { error: error });
}
}
});
19 changes: 11 additions & 8 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ router.get("/", async function (req, res) {
let mempool = await client.getMempoolTransactions({});

// estimated hash rates
let lastDifficulties = await client.getNetworkDifficulty({ from_tip: 100 });
let lastDifficulties = await client.getNetworkDifficulty({ from_tip: 180 });
let totalHashRates = getHashRates(lastDifficulties, [
"estimated_hash_rate",
]);
Expand Down Expand Up @@ -123,14 +123,16 @@ router.get("/", async function (req, res) {
limit,
from,
algoSplit,
blockTimes: getBlockTimes(last100Headers),
moneroTimes: getBlockTimes(last100Headers, "0"),
shaTimes: getBlockTimes(last100Headers, "1"),
blockTimes: getBlockTimes(last100Headers, null, 2),
moneroTimes: getBlockTimes(last100Headers, "0", 4),
shaTimes: getBlockTimes(last100Headers, "1", 4),
currentHashRate: totalHashRates[totalHashRates.length - 1],
totalHashRates,
currentShaHashRate: shaHashRates[shaHashRates.length - 1],
shaHashRates,
averageShaMiners: shaHashRates[shaHashRates.length - 1] / 200_000_000, // Hashrate of an NVidia 1070
currentMoneroHashRate: moneroHashRates[moneroHashRates.length - 1],
averageMoneroMiners: moneroHashRates[moneroHashRates.length - 1] / 2700, // Average apple m1 hashrate
moneroHashRates,
activeVns,
};
Expand All @@ -151,7 +153,7 @@ router.get("/", async function (req, res) {

function getHashRates(difficulties, properties) {
const end_idx = difficulties.length - 1;
const start_idx = end_idx - 60;
const start_idx = end_idx - 720;

return difficulties
.map((d) =>
Expand All @@ -163,7 +165,7 @@ function getHashRates(difficulties, properties) {
.slice(start_idx, end_idx);
}

function getBlockTimes(last100Headers, algo) {
function getBlockTimes(last100Headers, algo, targetTime) {
let blocktimes = [];
let i = 0;
if (algo === "0" || algo === "1") {
Expand All @@ -184,11 +186,12 @@ function getBlockTimes(last100Headers, algo) {
while (i < last100Headers.length && blocktimes.length < 60) {
if (!algo || last100Headers[i].pow.pow_algo === algo) {
blocktimes.push(
(lastBlockTime - parseInt(last100Headers[i].timestamp)) / 60
(lastBlockTime - parseInt(last100Headers[i].timestamp)) / 60 -
targetTime
);
lastBlockTime = parseInt(last100Headers[i].timestamp);
} else {
blocktimes.push(0);
blocktimes.push(targetTime);
}
i++;
}
Expand Down
Loading

0 comments on commit aa3e47c

Please sign in to comment.