Browse Source

WIP: added cn header to block header.

cn_merge
Jianping Wu 6 years ago
parent
commit
80396a7a0f
  1. 7
      src/primitives/block.cpp
  2. 67
      src/primitives/block.h

7
src/primitives/block.cpp

@ -9,11 +9,8 @@
#include <tinyformat.h> #include <tinyformat.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
#include <crypto/common.h> #include <crypto/common.h>
//#include <crypto/scrypt.h>
extern "C" extern "C" void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed);
{
#include <cryptonight/hash-ops.h>
}
uint256 CBlockHeader::GetHash() const uint256 CBlockHeader::GetHash() const
{ {

67
src/primitives/block.h

@ -10,6 +10,66 @@
#include <serialize.h> #include <serialize.h>
#include <uint256.h> #include <uint256.h>
#include <cryptonote_core/cryptonote_format_utils.h>
/**
* This header is to store the proof-of-work of cryptonote mining.
* Kevacoin uses Cryptonight PoW and uses its existing infrastructure
* (mining pools and miners)
*/
class CryptoNoteHeader
{
public:
uint8_t major_version;
uint8_t minor_version; // now used as a voting mechanism, rather than how this particular block is built
uint64_t timestamp;
uint256 prev_id;
uint32_t nonce;
uint256 merkle_root;
size_t nTxes; // Number of transactions.
CryptoNoteHeader()
{
SetNull();
}
void SetNull()
{
major_version = 0;
minor_version = 0;
prev_id.SetNull();
timestamp = 0;
nonce = 0;
merkle_root.SetNull();
nTxes = 0;
}
bool IsNull() const
{
return (timestamp == 0);
}
BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
VARINT_FIELD(minor_version)
VARINT_FIELD(timestamp)
crypto::hash prev_hash;
memcpy(&prev_hash, prev_id.begin(), prev_id.size());
FIELD(prev_hash)
FIELD(nonce)
END_SERIALIZE()
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
std::string blob = cryptonote::t_serializable_object_to_blob(*this);
blob.append(reinterpret_cast<const char*>(merkle_root.begin()), merkle_root.size());
blob.append(tools::get_varint_data(nTxes + 1));
READWRITE(blob);
}
};
/** Nodes collect new transactions into a block, hash them into a hash tree, /** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work * and scan through nonce values to make the block's hash satisfy proof-of-work
* requirements. When they solve the proof-of-work, they broadcast the block * requirements. When they solve the proof-of-work, they broadcast the block
@ -28,6 +88,9 @@ public:
uint32_t nBits; uint32_t nBits;
uint32_t nNonce; uint32_t nNonce;
// CryptoNote header for emulation or merged mining
CryptoNoteHeader cnHeader;
CBlockHeader() CBlockHeader()
{ {
SetNull(); SetNull();
@ -43,6 +106,10 @@ public:
READWRITE(nTime); READWRITE(nTime);
READWRITE(nBits); READWRITE(nBits);
READWRITE(nNonce); READWRITE(nNonce);
// Genesis block does not have cnHeader.
if (!hashPrevBlock.IsNull()) {
READWRITE(cnHeader);
}
} }
void SetNull() void SetNull()

Loading…
Cancel
Save