mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-16 15:57:39 +00:00
StratumServer: Use short target format (4 bytes) for diff <= ~2 million
This commit is contained in:
parent
4175f4c8bc
commit
ff4d89868b
2 changed files with 19 additions and 3 deletions
|
@ -277,7 +277,7 @@ struct hex_buf
|
|||
|
||||
template<> struct log::Stream::Entry<hex_buf>
|
||||
{
|
||||
static FORCEINLINE void put(hex_buf&& value, Stream* wrapper)
|
||||
static FORCEINLINE void put(const hex_buf& value, Stream* wrapper)
|
||||
{
|
||||
for (size_t i = 0; i < value.m_size; ++i) {
|
||||
char buf[2];
|
||||
|
|
|
@ -196,12 +196,20 @@ bool StratumServer::on_login(StratumClient* client, uint32_t id, const char* log
|
|||
client->m_rpcId = static_cast<uint32_t>(static_cast<StratumServer*>(client->m_owner)->get_random64());
|
||||
} while (!client->m_rpcId);
|
||||
|
||||
log::hex_buf target_hex(reinterpret_cast<const uint8_t*>(&target), sizeof(uint64_t));
|
||||
|
||||
// Use short target format (4 bytes) for diff <= ~2 million
|
||||
if ((target >> 32) >= 2147) {
|
||||
target_hex.m_data += sizeof(uint32_t);
|
||||
target_hex.m_size -= sizeof(uint32_t);
|
||||
}
|
||||
|
||||
log::Stream s(reinterpret_cast<char*>(buf));
|
||||
s << "{\"id\":" << id << ",\"jsonrpc\":\"2.0\",\"result\":{\"id\":\"";
|
||||
s << log::Hex(client->m_rpcId) << "\",\"job\":{\"blob\":\"";
|
||||
s << log::hex_buf(hashing_blob, blob_size) << "\",\"job_id\":\"";
|
||||
s << log::Hex(job_id) << "\",\"target\":\"";
|
||||
s << log::hex_buf(reinterpret_cast<const uint8_t*>(&target), sizeof(target)) << "\",\"algo\":\"rx/0\",\"height\":";
|
||||
s << target_hex << "\",\"algo\":\"rx/0\",\"height\":";
|
||||
s << height << ",\"seed_hash\":\"";
|
||||
s << seed_hash << "\"},\"extensions\":[\"algo\"],\"status\":\"OK\"}}\n";
|
||||
return s.m_pos;
|
||||
|
@ -382,11 +390,19 @@ void StratumServer::on_blobs_ready()
|
|||
const bool result = send(client,
|
||||
[data, target, client, hashing_blob, &job_id](void* buf)
|
||||
{
|
||||
log::hex_buf target_hex(reinterpret_cast<const uint8_t*>(&target), sizeof(uint64_t));
|
||||
|
||||
// Use short target format (4 bytes) for diff <= ~2 million
|
||||
if ((target >> 32) >= 2147) {
|
||||
target_hex.m_data += sizeof(uint32_t);
|
||||
target_hex.m_size -= sizeof(uint32_t);
|
||||
}
|
||||
|
||||
log::Stream s(reinterpret_cast<char*>(buf));
|
||||
s << "{\"jsonrpc\":\"2.0\",\"method\":\"job\",\"params\":{\"blob\":\"";
|
||||
s << log::hex_buf(hashing_blob, data->m_blobSize) << "\",\"job_id\":\"";
|
||||
s << log::Hex(job_id) << "\",\"target\":\"";
|
||||
s << log::hex_buf(reinterpret_cast<const uint8_t*>(&target), sizeof(target)) << "\",\"algo\":\"rx/0\",\"height\":";
|
||||
s << target_hex << "\",\"algo\":\"rx/0\",\"height\":";
|
||||
s << data->m_height << ",\"seed_hash\":\"";
|
||||
s << data->m_seedHash << "\"}}\n";
|
||||
return s.m_pos;
|
||||
|
|
Loading…
Reference in a new issue