Skip to content

Commit

Permalink
v0.2.5: add logs for node mining
Browse files Browse the repository at this point in the history
  • Loading branch information
CoinFuMasterShifu committed Mar 14, 2024
1 parent 1004ed3 commit aa258d3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project( 'Warthog Miner (Janushash)', ['c','cpp'],
version : '0.2.5',
version : '0.2.6',
default_options : ['warning_level=3', 'cpp_std=c++20'])


Expand Down
4 changes: 4 additions & 0 deletions src/miner/api_call.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "api_call.hpp"
#include "crypto/address.hpp"
#include "general/hex.hpp"
#include "logs.hpp"
#include "nlohmann/json.hpp"
#include "spdlog/spdlog.h"
#include <iostream>
Expand Down Expand Up @@ -43,15 +44,18 @@ std::pair<std::string, int> API::submit_block(const Block& mt)
std::string b = j.dump();
while (true) {
try {
node_mining_log->info("Trying to submit mined block {}", mt.height.value());
std::string result = http_post(path, b);
json parsed = json::parse(result);
out.second = parsed["code"].get<int32_t>();
if (out.second != 0) {
out.first = parsed["error"].get<std::string>();
}
node_mining_log->info("Successfully submitted block {}", mt.height.value());
return out;
} catch (std::runtime_error& e) {
spdlog::error(e.what());
node_mining_log->warn("Could not supply block, retrying in 100 milliseconds...");
spdlog::warn("Could not supply block, retrying in 100 milliseconds...");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down
2 changes: 1 addition & 1 deletion src/miner/device_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void MiningCoordinator::submit(const stratum::Submission& s)
{
assert(stratumConnection);
stratumConnection->submit(s, stratumConnectionData.get_connection_id());
mining_log->info("Submitting to pool");
stratum_mining_log->info("Submitting to pool");
}

void MiningCoordinator::poll()
Expand Down
13 changes: 8 additions & 5 deletions src/miner/logs.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#include "logs.hpp"
#include "spdlog/sinks/rotating_file_sink.h"

std::shared_ptr<spdlog::logger> mining_log;
std::shared_ptr<spdlog::logger> stratum_mining_log;
std::shared_ptr<spdlog::logger> node_mining_log;

namespace{
auto create_mining_logger()
auto create_mining_logger(const std::string &logger_name, const std::string &filename)
{
auto max_size = 1048576 * 5; // 5 MB
auto max_files = 3;
return spdlog::rotating_logger_mt("stratum_connections", "stratum_connections.log", max_size, max_files);
return spdlog::rotating_logger_mt(logger_name, filename, max_size, max_files);
}


}
void initialize_mining_log(){
mining_log = create_mining_logger();;
mining_log->flush_on(spdlog::level::info);
stratum_mining_log = create_mining_logger("stratum_connections", "stratum_connections.log");
stratum_mining_log->flush_on(spdlog::level::info);
node_mining_log = create_mining_logger("node_mining_log", "node_mining.log");
node_mining_log->flush_on(spdlog::level::info);
};

3 changes: 2 additions & 1 deletion src/miner/logs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#include "spdlog/spdlog.h"
#include <memory>

extern std::shared_ptr<spdlog::logger> mining_log;
extern std::shared_ptr<spdlog::logger> stratum_mining_log;
extern std::shared_ptr<spdlog::logger> node_mining_log;
void initialize_mining_log();
8 changes: 4 additions & 4 deletions src/miner/stratum/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ void Connection::run()
tcp::resolver resolver(context);
spdlog::info("Connecting to pool {}, port {}...",connectionData.host, connectionData.port);
asio::connect(*socket, resolver.resolve(connectionData.host, connectionData.port));
mining_log->info("Stratum disconnected");
stratum_mining_log->info("Stratum disconnected");
spdlog::info("Stratum connected.");
mining_log->info("Stratum connected.");
stratum_mining_log->info("Stratum connected.");
async_read_line();

stratum_subscribe("janusminer/0.0.1");
stratum_authorize(connectionData.user, connectionData.pass);
} catch (std::exception& e) {
mining_log->error("Connection Error: {}", e.what());
stratum_mining_log->error("Connection Error: {}", e.what());
spdlog::error(e.what());
}
context.run();
mining_log->info("Stratum disconnected");
stratum_mining_log->info("Stratum disconnected");
spdlog::info("Stratum disconnected.");
}
void Connection::async_read_line()
Expand Down

0 comments on commit aa258d3

Please sign in to comment.