API: added merge mining data
This commit is contained in:
@@ -50,6 +50,7 @@ public:
|
||||
virtual void submit_solution(const std::vector<uint8_t>& coinbase_merkle_proof, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof, uint32_t merkle_proof_path) = 0;
|
||||
|
||||
virtual void print_status() const = 0;
|
||||
virtual void api_status(log::Stream&) const = 0;
|
||||
};
|
||||
|
||||
} // namespace p2pool
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace p2pool {
|
||||
MergeMiningClientJSON_RPC::MergeMiningClientJSON_RPC(p2pool* pool, const std::string& host, const std::string& wallet)
|
||||
: m_host(host)
|
||||
, m_port(80)
|
||||
, m_chainParamsTimestamp(0)
|
||||
, m_auxWallet(wallet)
|
||||
, m_ping(0.0)
|
||||
, m_pool(pool)
|
||||
@@ -283,6 +284,8 @@ bool MergeMiningClientJSON_RPC::parse_merge_mining_get_aux_block(const char* dat
|
||||
m_chainParams.aux_diff.hi = 0;
|
||||
m_chainParams.last_updated = seconds_since_epoch();
|
||||
|
||||
m_chainParamsTimestamp = time(nullptr);
|
||||
|
||||
changed = true;
|
||||
|
||||
return true;
|
||||
@@ -333,6 +336,19 @@ void MergeMiningClientJSON_RPC::print_status() const
|
||||
);
|
||||
}
|
||||
|
||||
void MergeMiningClientJSON_RPC::api_status(log::Stream& s) const
|
||||
{
|
||||
ReadLock lock(m_lock);
|
||||
|
||||
s << '{'
|
||||
<< "\"api\":\"JSON RPC\","
|
||||
<< "\"host\":\"" << m_host << ':' << m_port << "\","
|
||||
<< "\"wallet\":\"" << m_auxWallet << "\","
|
||||
<< "\"difficulty\":" << m_chainParams.aux_diff << ","
|
||||
<< "\"timestamp\":" << m_chainParamsTimestamp
|
||||
<< '}';
|
||||
}
|
||||
|
||||
bool MergeMiningClientJSON_RPC::get_params(ChainParameters& out_params) const
|
||||
{
|
||||
const uint64_t t = seconds_since_epoch();
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
void submit_solution(const std::vector<uint8_t>& coinbase_merkle_proof, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof, uint32_t merkle_proof_path) override;
|
||||
|
||||
void print_status() const override;
|
||||
void api_status(log::Stream&) const override;
|
||||
|
||||
private:
|
||||
static void loop(void* data);
|
||||
@@ -56,6 +57,8 @@ private:
|
||||
mutable uv_rwlock_t m_lock;
|
||||
ChainParameters m_chainParams;
|
||||
|
||||
uint64_t m_chainParamsTimestamp;
|
||||
|
||||
std::string m_auxWallet;
|
||||
|
||||
double m_ping;
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace p2pool {
|
||||
|
||||
MergeMiningClientTari::MergeMiningClientTari(p2pool* pool, std::string host, const std::string& wallet)
|
||||
: m_chainParams{}
|
||||
, m_chainParamsTimestamp(0)
|
||||
, m_previousAuxHashes{}
|
||||
, m_previousAuxHashesIndex(0)
|
||||
, m_auxWallet(wallet)
|
||||
@@ -540,6 +541,22 @@ void MergeMiningClientTari::print_status() const
|
||||
);
|
||||
}
|
||||
|
||||
void MergeMiningClientTari::api_status(log::Stream& s) const
|
||||
{
|
||||
ReadLock lock(m_chainParamsLock);
|
||||
|
||||
s << '{'
|
||||
<< "\"api\":\"Tari gRPC\","
|
||||
<< "\"host\":\"" << m_hostStr << "\","
|
||||
<< "\"wallet\":\"" << m_auxWallet << "\","
|
||||
<< "\"height\":" << m_tariJobParams.height << ","
|
||||
<< "\"difficulty\":" << m_tariJobParams.diff << ","
|
||||
<< "\"reward\":" << m_tariJobParams.reward << ","
|
||||
<< "\"fees\":" << m_tariJobParams.fees << ","
|
||||
<< "\"timestamp\":" << m_chainParamsTimestamp
|
||||
<< '}';
|
||||
}
|
||||
|
||||
void MergeMiningClientTari::run_wrapper(void* arg)
|
||||
{
|
||||
reinterpret_cast<MergeMiningClientTari*>(arg)->run();
|
||||
@@ -668,6 +685,8 @@ void MergeMiningClientTari::run()
|
||||
m_chainParams.aux_diff = static_cast<difficulty_type>(response.miner_data().target_difficulty());
|
||||
m_chainParams.last_updated = seconds_since_epoch();
|
||||
|
||||
m_chainParamsTimestamp = time(nullptr);
|
||||
|
||||
m_tariBlock = response.block();
|
||||
|
||||
LOGINFO(4, "Tari aux block template: height = " << job_params.height
|
||||
|
||||
@@ -38,11 +38,14 @@ public:
|
||||
void submit_solution(const std::vector<uint8_t>& coinbase_merkle_proof, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof, uint32_t merkle_proof_path) override;
|
||||
|
||||
void print_status() const override;
|
||||
void api_status(log::Stream&) const override;
|
||||
|
||||
private:
|
||||
mutable uv_rwlock_t m_chainParamsLock;
|
||||
ChainParameters m_chainParams;
|
||||
|
||||
uint64_t m_chainParamsTimestamp;
|
||||
|
||||
enum {
|
||||
NUM_PREVIOUS_HASHES = 8,
|
||||
};
|
||||
|
||||
@@ -716,6 +716,8 @@ void p2pool::update_aux_data(const hash& chain_id)
|
||||
#if defined(WITH_MERGE_MINING_DONATION) && defined(WITH_TLS)
|
||||
send_aux_job_donation();
|
||||
#endif
|
||||
|
||||
api_update_aux_data();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2024,6 +2026,30 @@ void p2pool::on_external_block(const PoolBlock& block)
|
||||
}
|
||||
}
|
||||
|
||||
void p2pool::api_update_aux_data()
|
||||
{
|
||||
if (!m_api || m_stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_api->set(p2pool_api::Category::LOCAL, "merge_mining",
|
||||
[this](log::Stream& s)
|
||||
{
|
||||
s << "{\"chains\":[";
|
||||
{
|
||||
ReadLock lock(m_mergeMiningClientsLock);
|
||||
|
||||
for (size_t i = 0, n = m_mergeMiningClients.size(); i < n; ++i) {
|
||||
if (i > 0) {
|
||||
s << ',';
|
||||
}
|
||||
m_mergeMiningClients[i]->api_status(s);
|
||||
}
|
||||
}
|
||||
s << "]}";
|
||||
});
|
||||
}
|
||||
|
||||
bool p2pool::get_difficulty_at_height(uint64_t height, difficulty_type& diff)
|
||||
{
|
||||
ReadLock lock(m_mainchainLock);
|
||||
|
||||
@@ -123,6 +123,8 @@ public:
|
||||
void api_update_block_found(const ChainMain* data, const PoolBlock* block, bool update_stats_mod = true);
|
||||
void on_external_block(const PoolBlock& block);
|
||||
|
||||
void api_update_aux_data();
|
||||
|
||||
bool get_difficulty_at_height(uint64_t height, difficulty_type& diff);
|
||||
|
||||
#ifdef WITH_RANDOMX
|
||||
|
||||
Reference in New Issue
Block a user