Tari: use `GetNewBlockTemplateWithCoinbases` API

merge-mining
SChernykh 1 month ago
parent 313a099a4b
commit 2085bb454b

@ -2,6 +2,7 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 0) #pragma warning(push, 0)
#pragma warning(disable : 4866)
#endif #endif
#include "proto/gRPC/base_node.pb.h" #include "proto/gRPC/base_node.pb.h"

@ -149,47 +149,60 @@ void MergeMiningClientTari::run()
LOGINFO(6, "Getting new block template from Tari node"); LOGINFO(6, "Getting new block template from Tari node");
grpc::Status status; GetNewBlockTemplateWithCoinbasesRequest request;
NewBlockTemplateRequest request;
PowAlgo* algo = new PowAlgo(); PowAlgo* algo = new PowAlgo();
algo->set_pow_algo(PowAlgo_PowAlgos_POW_ALGOS_RANDOMX); algo->set_pow_algo(PowAlgo_PowAlgos_POW_ALGOS_RANDOMX);
request.clear_algo(); request.clear_algo();
request.set_allocated_algo(algo); request.set_allocated_algo(algo);
request.set_max_weight(1); request.set_max_weight(1);
grpc::ClientContext ctx; NewBlockCoinbase* coinbase = request.add_coinbases();
NewBlockTemplateResponse response; coinbase->set_address(m_auxWallet);
status = m_TariNode->GetNewBlockTemplate(&ctx, request, &response);
grpc::ClientContext ctx2; // TODO this should be equal to the total weight of shares in the PPLNS window for each wallet
GetNewBlockResult response2; coinbase->set_value(1);
status = m_TariNode->GetNewBlock(&ctx2, response.new_block_template(), &response2);
bool aux_id_empty; coinbase->set_stealth_payment(false);
{ coinbase->set_revealed_value_proof(true);
ReadLock lock2(m_chainParamsLock); coinbase->clear_coinbase_extra();
aux_id_empty = m_chainParams.aux_id.empty();
}
if (aux_id_empty) { grpc::ClientContext ctx;
const std::string& id = response2.tari_unique_id(); GetNewBlockResult response;
LOGINFO(1, m_hostStr << " uses chain_id " << log::LightCyan() << log::hex_buf(id.data(), id.size()));
if (id.size() == HASH_SIZE) { const grpc::Status status = m_TariNode->GetNewBlockTemplateWithCoinbases(&ctx, request, &response);
WriteLock lock2(m_chainParamsLock);
std::copy(id.begin(), id.end(), m_chainParams.aux_id.h); if (!status.ok()) {
} LOGWARN(5, "GetNewBlockTemplateWithCoinbases failed: " << status.error_message());
else { if (!status.error_details().empty()) {
LOGERR(1, "Tari unique_id has invalid size (" << id.size() << ')'); LOGWARN(5, "GetNewBlockTemplateWithCoinbases failed: " << status.error_details());
} }
} }
else {
bool aux_id_empty;
{
ReadLock lock2(m_chainParamsLock);
aux_id_empty = m_chainParams.aux_id.empty();
}
LOGINFO(6, "Tari block template: height = " << response.new_block_template().header().height() if (aux_id_empty) {
<< ", diff = " << response.miner_data().target_difficulty() const std::string& id = response.tari_unique_id();
<< ", reward = " << response.miner_data().reward() LOGINFO(1, m_hostStr << " uses chain_id " << log::LightCyan() << log::hex_buf(id.data(), id.size()));
<< ", fees = " << response.miner_data().total_fees()
); if (id.size() == HASH_SIZE) {
WriteLock lock2(m_chainParamsLock);
std::copy(id.begin(), id.end(), m_chainParams.aux_id.h);
}
else {
LOGERR(1, "Tari unique_id has invalid size (" << id.size() << ')');
}
}
LOGINFO(6, "Tari block template: height = " << response.block().header().height()
<< ", diff = " << response.miner_data().target_difficulty()
<< ", reward = " << response.miner_data().reward()
<< ", fees = " << response.miner_data().total_fees()
);
}
const int64_t timeout = std::max<int64_t>(500'000'000 - duration_cast<nanoseconds>(high_resolution_clock::now() - t1).count(), 1'000'000); const int64_t timeout = std::max<int64_t>(500'000'000 - duration_cast<nanoseconds>(high_resolution_clock::now() - t1).count(), 1'000'000);

Loading…
Cancel
Save