MWEB: Adding mweb_header, hogex_hash, and mweb_amount to CBlockIndex

pull/816/head
David Burkett 2 years ago committed by Loshan T
parent 012002a65f
commit d48c35a176

@ -127,6 +127,8 @@ enum BlockStatus: uint32_t {
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD,
BLOCK_OPT_WITNESS = 128, //!< block data in blk*.data was received with a witness-enforcing client
BLOCK_HAVE_MWEB = (1 << 28)
};
/** The block chain is a tree shaped structure starting with the
@ -180,6 +182,11 @@ public:
uint32_t nBits{0};
uint32_t nNonce{0};
//! MWEB data (only populated when BLOCK_HAVE_MWEB is set)
mw::Header::CPtr mweb_header{nullptr};
uint256 hogex_hash{};
CAmount mweb_amount{0};
//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
int32_t nSequenceId{0};
@ -346,6 +353,12 @@ public:
if (obj.nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED));
if (obj.nStatus & BLOCK_HAVE_DATA) READWRITE(VARINT(obj.nDataPos));
if (obj.nStatus & BLOCK_HAVE_UNDO) READWRITE(VARINT(obj.nUndoPos));
if (obj.nStatus & BLOCK_HAVE_MWEB) {
READWRITE(obj.mweb_header);
READWRITE(obj.hogex_hash);
READWRITE(VARINT_MODE(obj.mweb_amount, VarIntMode::NONNEGATIVE_SIGNED));
}
// block header
READWRITE(obj.nVersion);

@ -279,6 +279,9 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
pindexNew->nNonce = diskindex.nNonce;
pindexNew->nStatus = diskindex.nStatus;
pindexNew->nTx = diskindex.nTx;
pindexNew->mweb_header = diskindex.mweb_header;
pindexNew->hogex_hash = diskindex.hogex_hash;
pindexNew->mweb_amount = diskindex.mweb_amount;
// Litecoin: Disable PoW Sanity check while loading block index from disk.
// We use the sha256 hash for the block index for performance reasons, which is recorded for later use.
@ -323,7 +326,7 @@ public:
void Unserialize(Stream &s) {
unsigned int nCode = 0;
// version
unsigned int nVersionDummy;
unsigned int nVersionDummy = 0;
::Unserialize(s, VARINT(nVersionDummy));
// header code
::Unserialize(s, VARINT(nCode));

@ -2232,6 +2232,18 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
if (fJustCheck)
return true;
// MWEB: Update BlockIndex
if (!block.mweb_block.IsNull()) {
auto pHogEx = block.GetHogEx();
if ((pindex->nStatus & BLOCK_HAVE_MWEB) == 0) {
pindex->nStatus |= BLOCK_HAVE_MWEB;
pindex->mweb_header = block.mweb_block.GetMWEBHeader();
pindex->hogex_hash = pHogEx->GetHash();
pindex->mweb_amount = pHogEx->vout.front().nValue;
setDirtyBlockIndex.insert(pindex);
}
}
if (!WriteUndoDataForBlock(blockundo, state, pindex, chainparams))
return false;

Loading…
Cancel
Save