Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot #448

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Plot #448

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
20 changes: 20 additions & 0 deletions resources/public/js/plotfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function createDirLine(dirElement, index) {
activePlotDir = dirElement;
colorConfirmedPlotfiles();
current_selected = dirElement;
$("#plot-folder").val(dirElement["path"])
});

return line;
Expand Down Expand Up @@ -149,6 +150,25 @@ function parsePlots() {
});
}

function startPlotting() {
console.log("Plotting nonces " + $("#start-nonce").val() + "-" + (Number($("#start-nonce").val())+Number($("#num-nonces").val())-1).toString() + " for ID "+ $("#account-id").val() + " to folder " + $("#plot-folder").val());
var plotFolder=$("#plot-folder").val();
if(plotFolder[1]==":")
plotFolder=plotFolder.replace(/\//g,"\\");
$.post(encodeURI("/plotter/"+$("#account-id").val()+"/"+$("#start-nonce").val()+"/"+$("#num-nonces").val()+"/"+plotFolder));
}

function calcPlotSize() {
var plotSize = $("#num-nonces").val()*262144;
if (plotSize > 1099511627776)
plotSize = (Math.round(plotSize/1099511627776*1000)/1000).toString()+ " TB";
else if (plotSize > 1073741824)
plotSize = (Math.round(plotSize/1073741824*1000)/1000).toString()+ " GB";
else
plotSize = (Math.round(plotSize/1048576*1000)/1000).toString()+ " MB";
$("#fileSize").val(plotSize);
}

function checkPlotFile(account, start_nonce, nonces, staggersize, path) {
if(!isChecking && !isCheckingAll)
{
Expand Down
75 changes: 57 additions & 18 deletions resources/public/plotfiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,61 @@ <h4 class="card-header bg-success text-white">Directories</h4>
</div>
</div>

<!-- plot files -->
<div class="col-md-9">
<div class="card mb-12">
<h4 class="card-header text-white bg-primary">Files</h4>
<div class="col-lg-12">
<div class="row card-header" style="padding-left:0;padding-right:0">
<div class="col-xs-3 col-md-3">Account</div>
<div class="col-xs-2 col-md-2">Start nonce</div>
<div class="col-xs-2 col-md-1">Nonces</div>
<div class="col-xs-2 col-md-1">Stagger</div>
<div class="col-xs-1 col-md-2">Size</div>
<div class="col-xs-2 col-md-3" data-toggle='tooltip' data-placement='top' data-original-title='Pressing the button will Validate the integrity of 32 random scoops of 32 random nonces in the plot file'>Integrity</div>
</div>
</div>
<ul class="list-group" id="plotFileDiv">
</ul>
</div>
</div>
<!-- plot files -->
<div class="col-md-9">
<div class="card mb-12">
<h4 class="card-header text-white bg-primary">Files</h4>
<div class="col-lg-12">
<div class="row card-header" style="padding-left:0;padding-right:0">
<div class="col-xs-3 col-md-3">Account</div>
<div class="col-xs-2 col-md-2">Start nonce</div>
<div class="col-xs-2 col-md-1">Nonces</div>
<div class="col-xs-2 col-md-1">Stagger</div>
<div class="col-xs-1 col-md-2">Size</div>
<div class="col-xs-2 col-md-3">Integrity</div>
</div>
</div>
<ul class="list-group" id="plotFileDiv">
</ul>
</div>
<div class="card mb-12">
<h4 class="card-header text-white bg-primary">Plotter</h4>
<div class="card-body">
<div class="col-lg-12">
<div class="col-md-12">
<div class="form-group row">
<label for="plot-folder" class="col-md-12 col-lg-3 col-form-label">Plot folder</label>
<div class="col-md-12 col-lg-9">
<input class="form-control" type="text" id="plot-folder" name="plot-folder" readonly>
</div>
</div>
<div class="form-group row">
<label for="account-id" class="col-md-12 col-lg-3 col-form-label">Account ID</label>
<div class="col-md-12 col-lg-9">
<input class="form-control" type="text" id="account-id" name="account-id">
</div>
</div>
<div class="form-group row">
<label for="start-nonce" class="col-md-12 col-lg-3 col-form-label">Start Nonce</label>
<div class="col-md-12 col-lg-9">
<input class="form-control" type="number" id="start-nonce" name="start-nonce">
</div>
</div>
<div class="form-group row">
<label for="num-nonces" class="col-md-12 col-lg-3 col-form-label">Number of Nonces</label>
<div class="col-md-6 col-lg-5">
<input class="form-control" type="number" id="num-nonces" name="num-nonces" onkeyup="calcPlotSize();" onchange="calcPlotSize();">
</div>
<div class="col-md-6 col-lg-4">
<input class="form-control" type="text" id="fileSize" name="fileSize" readonly>
</div>
</div>
<button type="button" class="btn btn-primary float-right" id="startPlotButton" onclick="startPlotting();">Start Plotting</button>
</div>
</div>
</div>
<ul class="list-group" id="plotFileDiv">
</ul>
</div>
</div>
</div>
25 changes: 25 additions & 0 deletions src/plots/PlotGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "webserver/MinerServer.hpp"
#include <future>
#include <thread>
#include "Poco/File.h"
#include "Poco/Path.h"

Poco::UInt64 Burst::PlotGenerator::generateAndCheck(Poco::UInt64 account, Poco::UInt64 nonce, const Miner& miner)
{
Expand Down Expand Up @@ -200,6 +202,29 @@ double Burst::PlotGenerator::checkPlotfileIntegrity(std::string plotPath, Miner&
return totalIntegrity / noncesChecked;
}

void Burst::PlotGenerator::generatePlotfile(std::string plotPath, Miner& miner, MinerServer& server, std::string account, std::string sNonce, std::string nNonces)
{
const auto accountId = Poco::NumberParser::parseUnsigned64(account);
const auto startNonce = Poco::NumberParser::parseUnsigned64(sNonce);
const auto nonceCount = Poco::NumberParser::parseUnsigned64(nNonces);
log_success(MinerLogger::general, "Starting to plot %s nonces beginning at nonce %s for accountID %s to folder %s", nNonces, sNonce, account, plotPath);
Poco::Path plotFilePath;
plotFilePath.parse(plotPath, Poco::Path::PATH_NATIVE);
plotFilePath.setFileName(account + "_" + sNonce + "_" + nNonces + "_" + nNonces);
log_success(MinerLogger::general, "Full plot path: %s", plotFilePath.toString());
Poco::File plotFile(plotFilePath);
if (!plotFile.exists())
{
plotFile.createFile();
plotFile.setSize(nonceCount * Settings::PlotSize);
}
else
log_system(MinerLogger::general, "File already exists.");


//log_success(MinerLogger::general, "Free Space on this device: %s", std::to_string(plotFile.freeSpace())+" GB");
}

std::array<std::vector<char>, Burst::Shabal256_SSE2::HashSize> Burst::PlotGenerator::generateSse2(const Poco::UInt64 account, const Poco::UInt64 startNonce)
{
return generate<Shabal256_SSE2, PlotGeneratorOperations1<Shabal256_SSE2>>(account, startNonce);
Expand Down
1 change: 1 addition & 0 deletions src/plots/PlotGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Burst
public:
static Poco::UInt64 generateAndCheck(Poco::UInt64 account, Poco::UInt64 nonce, const Miner& miner);
static double checkPlotfileIntegrity(std::string plotPath, Miner& miner, MinerServer& server);
static void generatePlotfile(std::string plotPath, Miner& miner, MinerServer& server, std::string account, std::string sNonce, std::string nNonces);

static std::array<std::vector<char>, Shabal256_SSE2::HashSize> generateSse2(Poco::UInt64 account, Poco::UInt64 startNonce);
static std::array<std::vector<char>, Shabal256_AVX::HashSize> generateAvx(Poco::UInt64 account, Poco::UInt64 startNonce);
Expand Down
11 changes: 11 additions & 0 deletions src/webserver/MinerServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ Poco::Net::HTTPRequestHandler* Burst::MinerServer::RequestFactory::createRequest
});
}

// plot new file
if (path_segments.front() == "plotter")
if (path_segments.size() > 4) {
using Poco::replace;
std::string plotPath = "";
Poco::URI::decode(replace(request.getURI(), "/" + path_segments[0] + "/" + path_segments[1] + "/" + path_segments[2] + "/" + path_segments[3] + "/", plotPath), plotPath, false);
return new LambdaRequestHandler([&, pPath = move(plotPath), account = move(path_segments[1]), sNonce = move(path_segments[2]), nNonces = move(path_segments[3])](req_t& req, res_t& res)
{
RequestHandler::plotNewFile(req, res, *server_->miner_, *server_, pPath, account, sNonce, nNonces);
});
}

// show/change plot files
if (path_segments.front() == "plotdir")
Expand Down
17 changes: 17 additions & 0 deletions src/webserver/RequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,23 @@ void Burst::RequestHandler::checkPlotfile(Poco::Net::HTTPServerRequest& request,

}

void Burst::RequestHandler::plotNewFile(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner, MinerServer& server,
std::string plotPath, std::string account, std::string sNonce, std::string nNonces)
{
// first check the credentials
if (!checkCredentials(request, response))
return;

response.setStatus(Poco::Net::HTTPResponse::HTTP_OK);
response.setContentLength(0);
response.send();

log_information(MinerLogger::server, "Got request to plot new file...");

PlotGenerator::generatePlotfile(plotPath, miner, server, account, sNonce, nNonces);

}

void Burst::RequestHandler::checkAllPlotfiles(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner, MinerServer& server)
{
// first check the credentials
Expand Down
14 changes: 14 additions & 0 deletions src/webserver/RequestHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ namespace Burst
void checkPlotfile(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner,
MinerServer& server, std::string plotPath);

/**
* \brief Checks a plot file for corruption
* \param request The HTTP request.
* \param response The HTTP response.
* \param miner The miner, which will propagate the changed config to his connected users.
* \param plotPath The path to the folder where to plot the new file
* \param account Account for which to plot the file.
* \param sNonce Starting nonce of the plotfile.
* \param nNonces Number of nonces to plot into this file.
* \param server The server instance, that is shut down.
*/
void plotNewFile(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner,
MinerServer& server, std::string plotPath, std::string account, std::string sNonce, std::string nNonces);

/**
* \brief Checks all plot files for corruption
* \param request The HTTP request.
Expand Down