Skip to content

Commit

Permalink
Define block signatures, active IFF g_signed_blocks active
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Dec 19, 2018
1 parent f7c5cf7 commit 60f7062
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/primitives/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
bool g_con_blockheightinheader = false;
bool g_signed_blocks = false;

std::string CProof::ToString() const
{
return strprintf("CProof(challenge=%s, solution=%s)",
HexStr(challenge), HexStr(solution));
}

uint256 CBlockHeader::GetHash() const
{
return SerializeHash(*this);
Expand All @@ -21,12 +27,12 @@ uint256 CBlockHeader::GetHash() const
std::string CBlock::ToString() const
{
std::stringstream s;
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, proof=%u, vtx=%u)\n",
GetHash().ToString(),
nVersion,
hashPrevBlock.ToString(),
hashMerkleRoot.ToString(),
nTime, nBits, nNonce,
nTime, nBits, nNonce, proof.ToString(),
vtx.size());
for (const auto& tx : vtx) {
s << " " << tx->ToString() << "\n";
Expand Down
55 changes: 52 additions & 3 deletions src/primitives/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,48 @@
#define BITCOIN_PRIMITIVES_BLOCK_H

#include <primitives/transaction.h>
#include <script/script.h>
#include <serialize.h>
#include <uint256.h>

extern bool g_con_blockheightinheader;
extern bool g_signed_blocks;

class CProof
{
public:
CScript challenge;
CScript solution;

CProof()
{
SetNull();
}
CProof(CScript challengeIn, CScript solutionIn) : challenge(challengeIn), solution(solutionIn) {}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(*(CScriptBase*)(&challenge));
if (!(s.GetType() & SER_GETHASH))
READWRITE(*(CScriptBase*)(&solution));
}

void SetNull()
{
challenge.clear();
solution.clear();
}

bool IsNull() const
{
return challenge.empty();
}

std::string ToString() const;
};

/** 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
Expand All @@ -32,6 +70,7 @@ class CBlockHeader
uint32_t block_height;
uint32_t nBits;
uint32_t nNonce;
CProof proof;

CBlockHeader()
{
Expand All @@ -49,8 +88,12 @@ class CBlockHeader
if (g_con_blockheightinheader) {
READWRITE(block_height);
}
READWRITE(nBits);
READWRITE(nNonce);
if (g_signed_blocks) {
READWRITE(proof);
} else {
READWRITE(nBits);
READWRITE(nNonce);
}
}

void SetNull()
Expand All @@ -62,11 +105,16 @@ class CBlockHeader
block_height = 0;
nBits = 0;
nNonce = 0;
proof.SetNull();
}

bool IsNull() const
{
return (nBits == 0);
if (g_signed_blocks) {
return proof.IsNull();
} else {
return (nBits == 0);
}
}

uint256 GetHash() const;
Expand Down Expand Up @@ -123,6 +171,7 @@ class CBlock : public CBlockHeader
block.block_height = block_height;
block.nBits = nBits;
block.nNonce = nNonce;
block.proof = proof;
return block;
}

Expand Down

0 comments on commit 60f7062

Please sign in to comment.