From 80396a7a0f6a65377974c2b26e84a1ae33051591 Mon Sep 17 00:00:00 2001 From: Jianping Wu Date: Wed, 6 Mar 2019 13:12:55 -0800 Subject: [PATCH] WIP: added cn header to block header. --- src/primitives/block.cpp | 7 ++--- src/primitives/block.h | 67 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index e7d68003f..f2667ec02 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -9,11 +9,8 @@ #include #include #include -//#include -extern "C" -{ - #include -} + +extern "C" void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed); uint256 CBlockHeader::GetHash() const { diff --git a/src/primitives/block.h b/src/primitives/block.h index ce00716cf..9372e3182 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -10,6 +10,66 @@ #include #include +#include + +/** + * 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 + inline void SerializationOp(Stream& s, Operation ser_action) { + std::string blob = cryptonote::t_serializable_object_to_blob(*this); + blob.append(reinterpret_cast(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, * 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 @@ -28,6 +88,9 @@ public: uint32_t nBits; uint32_t nNonce; + // CryptoNote header for emulation or merged mining + CryptoNoteHeader cnHeader; + CBlockHeader() { SetNull(); @@ -43,6 +106,10 @@ public: READWRITE(nTime); READWRITE(nBits); READWRITE(nNonce); + // Genesis block does not have cnHeader. + if (!hashPrevBlock.IsNull()) { + READWRITE(cnHeader); + } } void SetNull()