Browse Source

WIP: merged mining.

cn_merge
Jianping Wu 6 years ago
parent
commit
1aa390ff47
  1. 8
      src/primitives/block.cpp
  2. 28
      src/primitives/block.h
  3. 7
      src/rpc/mining.cpp

8
src/primitives/block.cpp

@ -46,7 +46,7 @@ uint256 CBlockHeader::GetPoWHash() const @@ -46,7 +46,7 @@ uint256 CBlockHeader::GetPoWHash() const
// Merged mining.
cryptonote::tx_extra_keva_blockhash keva_blockhash;
if (!cryptonote::get_keva_blockhash_from_extra(cnHeader.aux_pow->miner_tx.extra, keva_blockhash)) {
if (!cryptonote::get_keva_blockhash_from_extra(cnHeader.aux_pow_ptr->miner_tx.extra, keva_blockhash)) {
return DIFFICULTY_1;
}
uint256 actualHash = GetHash();
@ -55,14 +55,14 @@ uint256 CBlockHeader::GetPoWHash() const @@ -55,14 +55,14 @@ uint256 CBlockHeader::GetPoWHash() const
}
crypto::hash miner_tx_hash;
if (!cryptonote::get_transaction_hash(cnHeader.aux_pow->miner_tx, miner_tx_hash)) {
if (!cryptonote::get_transaction_hash(cnHeader.aux_pow_ptr->miner_tx, miner_tx_hash)) {
return DIFFICULTY_1;
}
crypto::hash aux_blocks_merkle_root;
crypto::tree_hash_from_branch(
reinterpret_cast<const char (*)[32]>(cnHeader.aux_pow->merkle_branch.data()),
cnHeader.aux_pow->merkle_branch.size(),
reinterpret_cast<const char (*)[32]>(cnHeader.aux_pow_ptr->merkle_branch.data()),
cnHeader.aux_pow_ptr->merkle_branch.size(),
reinterpret_cast<char*>(&miner_tx_hash), 0,
reinterpret_cast<char*>(&aux_blocks_merkle_root));

28
src/primitives/block.h

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
#include <primitives/transaction.h>
#include <serialize.h>
#include <uint256.h>
#include <utilstrencodings.h>
#include <cryptonote_basic/cryptonote_format_utils.h>
@ -22,27 +23,6 @@ public: @@ -22,27 +23,6 @@ public:
// merkel tree whose root is merkle_root.
std::vector<crypto::hash> merkle_branch;
uint256 CheckMerkleBranch (uint256 hash,
const std::vector<uint256>& vMerkleBranch,
int nIndex)
{
if (nIndex == -1) {
return uint256();
}
#if 0
for (std::vector<uint256>::const_iterator it(vMerkleBranch.begin());
it != vMerkleBranch.end(); ++it) {
if (nIndex & 1) {
hash = Hash(BEGIN(*it), END(*it), BEGIN(hash), END(hash));
} else {
hash = Hash(BEGIN(hash), END(hash), BEGIN(*it), END(*it));
}
nIndex >>= 1;
}
return hash;
#endif
}
// load
template <template <bool> class Archive>
bool do_serialize(Archive<false>& ar)
@ -82,7 +62,7 @@ private: @@ -82,7 +62,7 @@ private:
bool is_aux_block;
public:
std::unique_ptr<CAuxPow> aux_pow; // It is used only is_aux_block is true.
std::shared_ptr<CAuxPow> aux_pow_ptr; // It is used only is_aux_block is true.
CryptoNoteHeader() : is_aux_block(false)
{
@ -131,7 +111,7 @@ public: @@ -131,7 +111,7 @@ public:
memcpy(merkle_root.begin(), &merkle_hash, merkle_root.size());
VARINT_FIELD(nTxes)
if (is_aux_block) {
aux_pow_ptr = std::make_unique<CAuxPow>();
aux_pow_ptr = std::shared_ptr<CAuxPow>(new CAuxPow());
FIELD(*aux_pow_ptr)
}
return true;
@ -153,7 +133,7 @@ public: @@ -153,7 +133,7 @@ public:
FIELD(merkle_hash)
VARINT_FIELD(nTxes)
if (is_aux_block) {
FIELD(*aux_pow)
FIELD(*aux_pow_ptr)
}
return true;
}

7
src/rpc/mining.cpp

@ -621,7 +621,7 @@ static uint256 CryptoHashToUint256(const crypto::hash& hash) @@ -621,7 +621,7 @@ static uint256 CryptoHashToUint256(const crypto::hash& hash)
// Cryptonote RPC call, only one parameter allowed.
UniValue submitblock(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() < 2) {
if (request.fHelp || request.params.size() > 2 || request.params.size() < 1) {
throw std::runtime_error(
"submitblock \"hexdata\"\n"
"\nAttempts to submit new block to network.\n"
@ -637,7 +637,7 @@ UniValue submitblock(const JSONRPCRequest& request) @@ -637,7 +637,7 @@ UniValue submitblock(const JSONRPCRequest& request)
);
}
std::unique_ptr<CAuxPow> auxPow = std::make_unique<CAuxPow>();
std::shared_ptr<CAuxPow> auxPow;
bool isAuxPow = false;
if (request.params.size() == 2) {
if (request.params[1].getType() != UniValue::VSTR) {
@ -647,6 +647,7 @@ UniValue submitblock(const JSONRPCRequest& request) @@ -647,6 +647,7 @@ UniValue submitblock(const JSONRPCRequest& request)
ss << request.params[1].get_str();
// load
binary_archive<false> ba(ss);
auxPow = std::shared_ptr<CAuxPow>(new CAuxPow());
isAuxPow = ::serialization::serialize(ba, *auxPow);
}
@ -698,7 +699,7 @@ UniValue submitblock(const JSONRPCRequest& request) @@ -698,7 +699,7 @@ UniValue submitblock(const JSONRPCRequest& request)
block.cnHeader.SetAuxBlock(isAuxPow);
if (isAuxPow) {
block.cnHeader.aux_pow = std::move(auxPow);
block.cnHeader.aux_pow_ptr = auxPow;
}
// TODO: fix the return message.

Loading…
Cancel
Save