Skip to content

Commit 0402da6

Browse files
committed
Add dynamic federation blockheader fields to chaindb serialization
1 parent ab6e3e3 commit 0402da6

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/chain.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ class CBlockIndex
221221
uint32_t nBits;
222222
uint32_t nNonce;
223223
CProof proof;
224+
// Dynamic federation fields
225+
DynaFedParams d_params;
226+
CScriptWitness m_signblock_witness;
224227

225228
//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
226229
int32_t nSequenceId;
@@ -250,6 +253,8 @@ class CBlockIndex
250253
nBits = 0;
251254
nNonce = 0;
252255
proof.SetNull();
256+
d_params.SetNull();
257+
m_signblock_witness.SetNull();
253258
}
254259

255260
CBlockIndex()
@@ -267,6 +272,8 @@ class CBlockIndex
267272
nBits = block.nBits;
268273
nNonce = block.nNonce;
269274
proof = block.proof;
275+
d_params = block.m_dyna_params;
276+
m_signblock_witness = block.m_signblock_witness;
270277
}
271278

272279
CDiskBlockPos GetBlockPos() const {
@@ -301,6 +308,8 @@ class CBlockIndex
301308
block.nBits = nBits;
302309
block.nNonce = nNonce;
303310
block.proof = proof;
311+
block.m_dyna_params = d_params;
312+
block.m_signblock_witness = m_signblock_witness;
304313
return block;
305314
}
306315

@@ -423,13 +432,35 @@ class CDiskBlockIndex : public CBlockIndex
423432
READWRITE(VARINT(nUndoPos));
424433

425434
// block header
426-
READWRITE(this->nVersion);
435+
436+
// Detect dynamic federation block serialization using "HF bit",
437+
// or the signed bit which is invalid in Bitcoin
438+
bool is_dyna = false;
439+
int32_t nVersion;
440+
if (ser_action.ForRead()) {
441+
READWRITE(nVersion);
442+
is_dyna = nVersion < 0;
443+
this->nVersion = ~CBlockHeader::HF_MASK & nVersion;
444+
} else {
445+
nVersion = this->nVersion;
446+
if (!d_params.IsNull()) {
447+
nVersion |= CBlockHeader::HF_MASK;
448+
is_dyna = true;
449+
}
450+
READWRITE(nVersion);
451+
}
452+
427453
READWRITE(hashPrev);
428454
READWRITE(hashMerkleRoot);
429455
READWRITE(nTime);
430456
// For compatibility with elements 0.14 based chains
431457
if (g_signed_blocks) {
432-
READWRITE(proof);
458+
if (is_dyna) {
459+
READWRITE(d_params);
460+
READWRITE(m_signblock_witness.stack);
461+
} else {
462+
READWRITE(proof);
463+
}
433464
} else {
434465
READWRITE(nBits);
435466
READWRITE(nNonce);
@@ -449,6 +480,7 @@ class CDiskBlockIndex : public CBlockIndex
449480
block.nBits = nBits;
450481
block.nNonce = nNonce;
451482
block.proof = proof;
483+
block.m_dyna_params = d_params;
452484
return block.GetHash();
453485
}
454486

0 commit comments

Comments
 (0)