Skip to content

Commit

Permalink
Convert CDiskBlockIndex to new serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Jul 3, 2021
1 parent 221bf49 commit 1ee0cb2
Showing 1 changed file with 55 additions and 65 deletions.
120 changes: 55 additions & 65 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,103 +276,93 @@ class CDiskBlockIndex : public CBlockIndex
hashPrev = (pprev ? pprev->GetBlockHash() : UINT256_ZERO);
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CDiskBlockIndex, obj)
{
int nSerVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH))
READWRITE(VARINT_MODE(nSerVersion, VarIntMode::NONNEGATIVE_SIGNED));

READWRITE(VARINT_MODE(nHeight, VarIntMode::NONNEGATIVE_SIGNED));
READWRITE(VARINT(nStatus));
READWRITE(VARINT(nTx));
if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO))
READWRITE(VARINT_MODE(nFile, VarIntMode::NONNEGATIVE_SIGNED));
if (nStatus & BLOCK_HAVE_DATA)
READWRITE(VARINT(nDataPos));
if (nStatus & BLOCK_HAVE_UNDO)
READWRITE(VARINT(nUndoPos));
if (!(s.GetType() & SER_GETHASH)) READWRITE(VARINT_MODE(nSerVersion, VarIntMode::NONNEGATIVE_SIGNED));

READWRITE(VARINT_MODE(obj.nHeight, VarIntMode::NONNEGATIVE_SIGNED));
READWRITE(VARINT(obj.nStatus));
READWRITE(VARINT(obj.nTx));
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 (nSerVersion >= DBI_SER_VERSION_NO_ZC) {
// Serialization with CLIENT_VERSION = 4009902+
READWRITE(nFlags);
READWRITE(this->nVersion);
READWRITE(vStakeModifier);
READWRITE(hashPrev);
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
if(this->nVersion > 3 && this->nVersion < 7)
READWRITE(nAccumulatorCheckpoint);
READWRITE(obj.nFlags);
READWRITE(obj.nVersion);
READWRITE(obj.vStakeModifier);
READWRITE(obj.hashPrev);
READWRITE(obj.hashMerkleRoot);
READWRITE(obj.nTime);
READWRITE(obj.nBits);
READWRITE(obj.nNonce);
if(obj.nVersion > 3 && obj.nVersion < 7)
READWRITE(obj.nAccumulatorCheckpoint);

// Sapling blocks
if (this->nVersion >= 8) {
READWRITE(hashFinalSaplingRoot);
READWRITE(nSaplingValue);
if (obj.nVersion >= 8) {
READWRITE(obj.hashFinalSaplingRoot);
READWRITE(obj.nSaplingValue);
}

} else if (nSerVersion > DBI_OLD_SER_VERSION && ser_action.ForRead()) {
// Serialization with CLIENT_VERSION = 4009901
std::map<libzerocoin::CoinDenomination, int64_t> mapZerocoinSupply;
int64_t nMoneySupply = 0;
READWRITE(nMoneySupply);
READWRITE(nFlags);
READWRITE(this->nVersion);
READWRITE(vStakeModifier);
READWRITE(hashPrev);
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
if(this->nVersion > 3) {
READWRITE(mapZerocoinSupply);
if(this->nVersion < 7) READWRITE(nAccumulatorCheckpoint);
SER_READ(obj, nMoneySupply);
READWRITE(obj.nFlags);
READWRITE(obj.nVersion);
READWRITE(obj.vStakeModifier);
READWRITE(obj.hashPrev);
READWRITE(obj.hashMerkleRoot);
READWRITE(obj.nTime);
READWRITE(obj.nBits);
READWRITE(obj.nNonce);
if (obj.nVersion > 3) {
SER_READ(obj, mapZerocoinSupply);
if (obj.nVersion < 7) READWRITE(obj.nAccumulatorCheckpoint);
}

} else if (ser_action.ForRead()) {
// Serialization with CLIENT_VERSION = 4009900-
int64_t nMint = 0;
uint256 hashNext{};
int64_t nMoneySupply = 0;
READWRITE(nMint);
READWRITE(nMoneySupply);
READWRITE(nFlags);
if (!Params().GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_4)) {
SER_READ(obj, nMint);
SER_READ(obj, nMoneySupply);
READWRITE(obj.nFlags);
if (!Params().GetConsensus().NetworkUpgradeActive(obj.nHeight, Consensus::UPGRADE_V3_4)) {
uint64_t nStakeModifier = 0;
READWRITE(nStakeModifier);
this->SetStakeModifier(nStakeModifier, this->GeneratedStakeModifier());
SER_READ(obj, obj.SetStakeModifier(nStakeModifier, obj.GeneratedStakeModifier()));
} else {
uint256 nStakeModifierV2;
READWRITE(nStakeModifierV2);
this->SetStakeModifier(nStakeModifierV2);
SER_READ(obj, nStakeModifierV2);
SER_READ(obj, obj.SetStakeModifier(nStakeModifierV2));
}
if (IsProofOfStake()) {
if (obj.IsProofOfStake()) {
COutPoint prevoutStake;
unsigned int nStakeTime = 0;
READWRITE(prevoutStake);
READWRITE(nStakeTime);
SER_READ(obj, prevoutStake);
SER_READ(obj, nStakeTime);
}
READWRITE(this->nVersion);
READWRITE(hashPrev);
READWRITE(hashNext);
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
if(this->nVersion > 3) {
READWRITE(obj.nVersion);
READWRITE(obj.hashPrev);
SER_READ(obj, hashNext);
READWRITE(obj.hashMerkleRoot);
READWRITE(obj.nTime);
READWRITE(obj.nBits);
READWRITE(obj.nNonce);
if (obj.nVersion > 3) {
std::map<libzerocoin::CoinDenomination, int64_t> mapZerocoinSupply;
std::vector<libzerocoin::CoinDenomination> vMintDenominationsInBlock;
READWRITE(nAccumulatorCheckpoint);
READWRITE(mapZerocoinSupply);
READWRITE(vMintDenominationsInBlock);
READWRITE(obj.nAccumulatorCheckpoint);
SER_READ(obj, mapZerocoinSupply);
SER_READ(obj, vMintDenominationsInBlock);
}
}
}


uint256 GetBlockHash() const
{
CBlockHeader block;
Expand Down

0 comments on commit 1ee0cb2

Please sign in to comment.