From 4e52f2c83cda9ffd2c44b9c29c8340a09adde562 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Fri, 31 May 2019 11:00:32 -0400 Subject: [PATCH] Add dynamic federation blockheader fields to chaindb serialization --- src/chain.h | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/chain.h b/src/chain.h index 21d6122909..ccb6fd3336 100644 --- a/src/chain.h +++ b/src/chain.h @@ -221,6 +221,9 @@ public: uint32_t nBits; uint32_t nNonce; CProof proof; + // Dynamic federation fields + DynaFedParams d_params; + CScriptWitness m_signblock_witness; //! (memory only) Sequential id assigned to distinguish order in which blocks are received. int32_t nSequenceId; @@ -250,6 +253,8 @@ public: nBits = 0; nNonce = 0; proof.SetNull(); + d_params.SetNull(); + m_signblock_witness.SetNull(); } CBlockIndex() @@ -267,6 +272,8 @@ public: nBits = block.nBits; nNonce = block.nNonce; proof = block.proof; + d_params = block.m_dyna_params; + m_signblock_witness = block.m_signblock_witness; } CDiskBlockPos GetBlockPos() const { @@ -301,6 +308,8 @@ public: block.nBits = nBits; block.nNonce = nNonce; block.proof = proof; + block.m_dyna_params = d_params; + block.m_signblock_witness = m_signblock_witness; return block; } @@ -423,13 +432,35 @@ public: READWRITE(VARINT(nUndoPos)); // block header - READWRITE(this->nVersion); + + // Detect dynamic federation block serialization using "HF bit", + // or the signed bit which is invalid in Bitcoin + bool is_dyna = false; + int32_t nVersion; + if (ser_action.ForRead()) { + READWRITE(nVersion); + is_dyna = nVersion < 0; + this->nVersion = ~CBlockHeader::HF_MASK & nVersion; + } else { + nVersion = this->nVersion; + if (!d_params.IsNull()) { + nVersion |= CBlockHeader::HF_MASK; + is_dyna = true; + } + READWRITE(nVersion); + } + READWRITE(hashPrev); READWRITE(hashMerkleRoot); READWRITE(nTime); // For compatibility with elements 0.14 based chains if (g_signed_blocks) { - READWRITE(proof); + if (is_dyna) { + READWRITE(d_params); + READWRITE(m_signblock_witness.stack); + } else { + READWRITE(proof); + } } else { READWRITE(nBits); READWRITE(nNonce); @@ -449,6 +480,7 @@ public: block.nBits = nBits; block.nNonce = nNonce; block.proof = proof; + block.m_dyna_params = d_params; return block.GetHash(); }