Skip to content

Commit 008a542

Browse files
committed
Backport signet block serialization
1 parent 98ff65a commit 008a542

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/primitives/bitcoin/block.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "utilstrencodings.h"
1313
#include "crypto/common.h"
1414

15+
bool g_solution_blocks = false;
16+
size_t g_solution_block_len = 0;
17+
std::map<uint256,std::vector<uint8_t>> g_blockheader_payload_map;
18+
1519
namespace Sidechain {
1620
namespace Bitcoin {
1721

src/primitives/bitcoin/block.h

+25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
#include "serialize.h"
1313
#include "uint256.h"
1414

15+
/**
16+
* If true, block headers contain a payload equal to a Bitcoin Script solution
17+
* to a signet challenge as defined in the chain params.
18+
*/
19+
extern bool g_solution_blocks;
20+
/**
21+
* If non-zero, defines an enforced size requirement for block header payloads.
22+
* It requires that all blocks are of size 80 + (this value) bytes.
23+
*/
24+
extern size_t g_solution_block_len;
25+
/**
26+
* Contains a mapping of hash to signature data for each block header
27+
* in signet networks.
28+
*/
29+
extern std::map<uint256,std::vector<uint8_t>> g_blockheader_payload_map;
30+
1531
namespace Sidechain {
1632
namespace Bitcoin {
1733

@@ -48,6 +64,15 @@ class CBlockHeader
4864
READWRITE(nTime);
4965
READWRITE(nBits);
5066
READWRITE(nNonce);
67+
if (g_solution_blocks && !(s.GetType() & SER_GETHASH)) {
68+
READWRITE(g_blockheader_payload_map[GetHash()]);
69+
size_t len = GetSizeOfCompactSize(g_blockheader_payload_map[GetHash()].size()) + g_blockheader_payload_map[GetHash()].size();
70+
while (len < g_solution_block_len) {
71+
uint8_t padding = 0;
72+
READWRITE(padding);
73+
len++;
74+
}
75+
}
5176
}
5277

5378
void SetNull()

0 commit comments

Comments
 (0)