Skip to content

Commit 60f7062

Browse files
committed
Define block signatures, active IFF g_signed_blocks active
1 parent f7c5cf7 commit 60f7062

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

src/primitives/block.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
bool g_con_blockheightinheader = false;
1414
bool g_signed_blocks = false;
1515

16+
std::string CProof::ToString() const
17+
{
18+
return strprintf("CProof(challenge=%s, solution=%s)",
19+
HexStr(challenge), HexStr(solution));
20+
}
21+
1622
uint256 CBlockHeader::GetHash() const
1723
{
1824
return SerializeHash(*this);
@@ -21,12 +27,12 @@ uint256 CBlockHeader::GetHash() const
2127
std::string CBlock::ToString() const
2228
{
2329
std::stringstream s;
24-
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
30+
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, proof=%u, vtx=%u)\n",
2531
GetHash().ToString(),
2632
nVersion,
2733
hashPrevBlock.ToString(),
2834
hashMerkleRoot.ToString(),
29-
nTime, nBits, nNonce,
35+
nTime, nBits, nNonce, proof.ToString(),
3036
vtx.size());
3137
for (const auto& tx : vtx) {
3238
s << " " << tx->ToString() << "\n";

src/primitives/block.h

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,48 @@
77
#define BITCOIN_PRIMITIVES_BLOCK_H
88

99
#include <primitives/transaction.h>
10+
#include <script/script.h>
1011
#include <serialize.h>
1112
#include <uint256.h>
1213

1314
extern bool g_con_blockheightinheader;
15+
extern bool g_signed_blocks;
16+
17+
class CProof
18+
{
19+
public:
20+
CScript challenge;
21+
CScript solution;
22+
23+
CProof()
24+
{
25+
SetNull();
26+
}
27+
CProof(CScript challengeIn, CScript solutionIn) : challenge(challengeIn), solution(solutionIn) {}
28+
29+
ADD_SERIALIZE_METHODS;
30+
31+
template <typename Stream, typename Operation>
32+
inline void SerializationOp(Stream& s, Operation ser_action)
33+
{
34+
READWRITE(*(CScriptBase*)(&challenge));
35+
if (!(s.GetType() & SER_GETHASH))
36+
READWRITE(*(CScriptBase*)(&solution));
37+
}
38+
39+
void SetNull()
40+
{
41+
challenge.clear();
42+
solution.clear();
43+
}
44+
45+
bool IsNull() const
46+
{
47+
return challenge.empty();
48+
}
49+
50+
std::string ToString() const;
51+
};
1452

1553
/** Nodes collect new transactions into a block, hash them into a hash tree,
1654
* and scan through nonce values to make the block's hash satisfy proof-of-work
@@ -32,6 +70,7 @@ class CBlockHeader
3270
uint32_t block_height;
3371
uint32_t nBits;
3472
uint32_t nNonce;
73+
CProof proof;
3574

3675
CBlockHeader()
3776
{
@@ -49,8 +88,12 @@ class CBlockHeader
4988
if (g_con_blockheightinheader) {
5089
READWRITE(block_height);
5190
}
52-
READWRITE(nBits);
53-
READWRITE(nNonce);
91+
if (g_signed_blocks) {
92+
READWRITE(proof);
93+
} else {
94+
READWRITE(nBits);
95+
READWRITE(nNonce);
96+
}
5497
}
5598

5699
void SetNull()
@@ -62,11 +105,16 @@ class CBlockHeader
62105
block_height = 0;
63106
nBits = 0;
64107
nNonce = 0;
108+
proof.SetNull();
65109
}
66110

67111
bool IsNull() const
68112
{
69-
return (nBits == 0);
113+
if (g_signed_blocks) {
114+
return proof.IsNull();
115+
} else {
116+
return (nBits == 0);
117+
}
70118
}
71119

72120
uint256 GetHash() const;
@@ -123,6 +171,7 @@ class CBlock : public CBlockHeader
123171
block.block_height = block_height;
124172
block.nBits = nBits;
125173
block.nNonce = nNonce;
174+
block.proof = proof;
126175
return block;
127176
}
128177

0 commit comments

Comments
 (0)