mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-10 21:04:37 +00:00
commit
755fe28bc3
7 changed files with 83 additions and 20 deletions
|
@ -96,7 +96,7 @@ bool xmrig::DaemonClient::isTLS() const
|
|||
|
||||
int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
||||
{
|
||||
if (result.jobId != (m_blocktemplateStr.data() + m_blocktemplateStr.size() - 32)) {
|
||||
if (result.jobId != m_currentJobId) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,10 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
|||
memcpy(data + m_blocktemplate.eph_public_key_index * 2, result.sig_data + 32 * 2, 32 * 2);
|
||||
}
|
||||
|
||||
if (result.extra_nonce >= 0) {
|
||||
Cvt::toHex(data + m_blocktemplate.tx_extra_nonce_index * 2, 8, reinterpret_cast<const uint8_t*>(&result.extra_nonce), 4);
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
Cvt::toHex(data + m_job.nonceOffset() * 2, 8, reinterpret_cast<const uint8_t*>(&result.nonce), 4);
|
||||
|
@ -277,6 +281,19 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
return false;
|
||||
}
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
const size_t k = m_blocktemplate.miner_tx_prefix_begin_index;
|
||||
job.setMinerTx(
|
||||
m_blocktemplate.raw_blob.data() + k,
|
||||
m_blocktemplate.raw_blob.data() + m_blocktemplate.miner_tx_prefix_end_index,
|
||||
m_blocktemplate.eph_public_key_index - k,
|
||||
m_blocktemplate.tx_pubkey_index - k,
|
||||
m_blocktemplate.tx_extra_nonce_index - k,
|
||||
m_blocktemplate.tx_extra_nonce_size,
|
||||
m_blocktemplate.miner_tx_merkle_tree_branch
|
||||
);
|
||||
# endif
|
||||
|
||||
m_blockhashingblob = Json::getString(params, "blockhashing_blob");
|
||||
|
||||
if (m_blocktemplate.has_miner_signature) {
|
||||
|
@ -308,13 +325,6 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
job.setSpendSecretKey(secret_spendkey);
|
||||
job.setMinerTx(
|
||||
m_blocktemplate.raw_blob.data() + m_blocktemplate.miner_tx_prefix_begin_index,
|
||||
m_blocktemplate.raw_blob.data() + m_blocktemplate.miner_tx_prefix_end_index,
|
||||
m_blocktemplate.eph_public_key_index - m_blocktemplate.miner_tx_prefix_begin_index,
|
||||
m_blocktemplate.tx_pubkey_index - m_blocktemplate.miner_tx_prefix_begin_index,
|
||||
m_blocktemplate.miner_tx_merkle_tree_branch
|
||||
);
|
||||
# else
|
||||
uint8_t secret_viewkey[32];
|
||||
derive_view_secret_key(secret_spendkey, secret_viewkey);
|
||||
|
@ -377,7 +387,8 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
job.setHeight(Json::getUint64(params, kHeight));
|
||||
job.setDiff(Json::getUint64(params, "difficulty"));
|
||||
|
||||
job.setId(blocktemplate.data() + blocktemplate.size() - 32);
|
||||
m_currentJobId = Cvt::toHex(Cvt::randomBytes(4));
|
||||
job.setId(m_currentJobId);
|
||||
|
||||
m_job = std::move(job);
|
||||
m_blocktemplateStr = std::move(blocktemplate);
|
||||
|
|
|
@ -84,6 +84,7 @@ private:
|
|||
} m_apiVersion = API_MONERO;
|
||||
|
||||
std::shared_ptr<IHttpListener> m_httpListener;
|
||||
String m_currentJobId;
|
||||
String m_blocktemplateStr;
|
||||
String m_blockhashingblob;
|
||||
String m_prevHash;
|
||||
|
|
|
@ -201,6 +201,8 @@ void xmrig::Job::copy(const Job &other)
|
|||
m_minerTxPrefix = other.m_minerTxPrefix;
|
||||
m_minerTxEphPubKeyOffset = other.m_minerTxEphPubKeyOffset;
|
||||
m_minerTxPubKeyOffset = other.m_minerTxPubKeyOffset;
|
||||
m_minerTxExtraNonceOffset = other.m_minerTxExtraNonceOffset;
|
||||
m_minerTxExtraNonceSize = other.m_minerTxExtraNonceSize;
|
||||
m_minerTxMerkleTreeBranch = other.m_minerTxMerkleTreeBranch;
|
||||
# else
|
||||
memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey));
|
||||
|
@ -254,6 +256,8 @@ void xmrig::Job::move(Job &&other)
|
|||
m_minerTxPrefix = std::move(other.m_minerTxPrefix);
|
||||
m_minerTxEphPubKeyOffset = other.m_minerTxEphPubKeyOffset;
|
||||
m_minerTxPubKeyOffset = other.m_minerTxPubKeyOffset;
|
||||
m_minerTxExtraNonceOffset = other.m_minerTxExtraNonceOffset;
|
||||
m_minerTxExtraNonceSize = other.m_minerTxExtraNonceSize;
|
||||
m_minerTxMerkleTreeBranch = std::move(other.m_minerTxMerkleTreeBranch);
|
||||
# else
|
||||
memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey));
|
||||
|
@ -278,16 +282,24 @@ void xmrig::Job::setSpendSecretKey(const uint8_t *key)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Job::setMinerTx(const uint8_t *begin, const uint8_t *end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, const Buffer &minerTxMerkleTreeBranch)
|
||||
void xmrig::Job::setMinerTx(const uint8_t *begin, const uint8_t *end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer &minerTxMerkleTreeBranch)
|
||||
{
|
||||
m_minerTxPrefix.assign(begin, end);
|
||||
m_minerTxEphPubKeyOffset = minerTxEphPubKeyOffset;
|
||||
m_minerTxPubKeyOffset = minerTxPubKeyOffset;
|
||||
m_minerTxExtraNonceOffset = minerTxExtraNonceOffset;
|
||||
m_minerTxExtraNonceSize = minerTxExtraNonceSize;
|
||||
m_minerTxMerkleTreeBranch = minerTxMerkleTreeBranch;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Job::generateHashingBlob(String &signatureData)
|
||||
void xmrig::Job::setExtraNonceInMinerTx(uint32_t extra_nonce)
|
||||
{
|
||||
memcpy(m_minerTxPrefix.data() + m_minerTxExtraNonceOffset, &extra_nonce, std::min(m_minerTxExtraNonceSize, sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Job::generateSignatureData(String &signatureData) const
|
||||
{
|
||||
uint8_t* eph_public_key = m_minerTxPrefix.data() + m_minerTxEphPubKeyOffset;
|
||||
uint8_t* txkey_pub = m_minerTxPrefix.data() + m_minerTxPubKeyOffset;
|
||||
|
@ -309,13 +321,22 @@ void xmrig::Job::generateHashingBlob(String &signatureData)
|
|||
derive_secret_key(derivation, 0, m_spendSecretKey, buf + 64);
|
||||
|
||||
signatureData = Cvt::toHex(buf, sizeof(buf));
|
||||
}
|
||||
|
||||
void xmrig::Job::generateHashingBlob(String &blob) const
|
||||
{
|
||||
uint8_t root_hash[32];
|
||||
const uint8_t* p = m_minerTxPrefix.data();
|
||||
BlockTemplate::CalculateRootHash(p, p + m_minerTxPrefix.size(), m_minerTxMerkleTreeBranch, root_hash);
|
||||
|
||||
const uint64_t offset = nonceOffset() + nonceSize() + BlockTemplate::SIGNATURE_SIZE + 2 /* vote */;
|
||||
Cvt::toHex(m_rawBlob + offset * 2, 64, root_hash, 32);
|
||||
uint64_t root_hash_offset = nonceOffset() + nonceSize();
|
||||
|
||||
if (m_hasMinerSignature) {
|
||||
root_hash_offset += BlockTemplate::SIGNATURE_SIZE + 2 /* vote */;
|
||||
}
|
||||
|
||||
blob = rawBlob();
|
||||
Cvt::toHex(blob.data() + root_hash_offset * 2, 64, root_hash, BlockTemplate::HASH_SIZE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -119,9 +119,11 @@ public:
|
|||
# endif
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
void setSpendSecretKey(const uint8_t *key);
|
||||
void setMinerTx(const uint8_t *begin, const uint8_t *end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, const Buffer &minerTxMerkleTreeBranch);
|
||||
void generateHashingBlob(String &signatureData);
|
||||
void setSpendSecretKey(const uint8_t* key);
|
||||
void setMinerTx(const uint8_t* begin, const uint8_t* end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer& minerTxMerkleTreeBranch);
|
||||
void setExtraNonceInMinerTx(uint32_t extra_nonce);
|
||||
void generateSignatureData(String& signatureData) const;
|
||||
void generateHashingBlob(String& blob) const;
|
||||
# else
|
||||
inline const uint8_t* ephSecretKey() const { return m_hasMinerSignature ? m_ephSecretKey : nullptr; }
|
||||
|
||||
|
@ -170,6 +172,8 @@ private:
|
|||
mutable Buffer m_minerTxPrefix;
|
||||
size_t m_minerTxEphPubKeyOffset = 0;
|
||||
size_t m_minerTxPubKeyOffset = 0;
|
||||
size_t m_minerTxExtraNonceOffset = 0;
|
||||
size_t m_minerTxExtraNonceSize = 0;
|
||||
Buffer m_minerTxMerkleTreeBranch;
|
||||
# else
|
||||
// Miner signatures
|
||||
|
|
|
@ -61,6 +61,8 @@ public:
|
|||
|
||||
inline size_t index() const { return m_index; }
|
||||
|
||||
inline void skip(size_t N) { m_index += N; }
|
||||
|
||||
private:
|
||||
inline bool getByte(uint8_t& data)
|
||||
{
|
||||
|
|
|
@ -86,13 +86,35 @@ bool BlockTemplate::Init(const String& blockTemplate, Coin coin)
|
|||
ar(eph_public_key);
|
||||
ar(extra_size);
|
||||
|
||||
tx_pubkey_index = ar.index() + 1;
|
||||
const uint64_t tx_extra_index = ar.index();
|
||||
|
||||
ar.readItems(extra, extra_size);
|
||||
|
||||
// First thing in tx_extra must be TX_EXTRA_TAG_PUBKEY
|
||||
if (extra[0] != 0x01)
|
||||
return false;
|
||||
CBlobReader ar_extra(extra.data(), extra_size);
|
||||
|
||||
tx_extra_nonce_size = 0;
|
||||
tx_extra_nonce_index = 0;
|
||||
|
||||
while (ar_extra.index() < extra_size) {
|
||||
uint64_t extra_tag;
|
||||
ar_extra(extra_tag);
|
||||
|
||||
switch (extra_tag) {
|
||||
case 0x01: // TX_EXTRA_TAG_PUBKEY
|
||||
tx_pubkey_index = tx_extra_index + ar_extra.index();
|
||||
ar_extra.skip(KEY_SIZE);
|
||||
break;
|
||||
|
||||
case 0x02: // TX_EXTRA_NONCE
|
||||
ar_extra(tx_extra_nonce_size);
|
||||
tx_extra_nonce_index = tx_extra_index + ar_extra.index();
|
||||
ar_extra.skip(tx_extra_nonce_size);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false; // TODO: handle other tags
|
||||
}
|
||||
}
|
||||
|
||||
miner_tx_prefix_end_index = ar.index();
|
||||
// Prefix end
|
||||
|
|
|
@ -42,6 +42,8 @@ struct BlockTemplate
|
|||
Buffer raw_blob;
|
||||
size_t eph_public_key_index;
|
||||
size_t tx_pubkey_index;
|
||||
uint64_t tx_extra_nonce_size;
|
||||
size_t tx_extra_nonce_index;
|
||||
size_t miner_tx_prefix_begin_index;
|
||||
size_t miner_tx_prefix_end_index;
|
||||
|
||||
|
|
Loading…
Reference in a new issue