Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8fef544
Add Slice: a (pointer, size) array view that acts like a container
sipa Apr 4, 2018
1ef2d90
Support serializing Span<unsigned char> and use that instead of FLATDATA
sipa Apr 4, 2018
fb3c646
Migrate last FLATDATA calls to use Span.
furszy May 31, 2021
5c36b3d
Introduce BigEndian wrapper and use it for netaddress ports
sipa Apr 8, 2018
f05e692
Drop unused GetType() from CSizeComputer
furszy May 31, 2021
ace7d14
Drop minor GetSerializeSize template
Empact Jun 15, 2018
6bb135e
Introduce new serialization macros without casts
sipa Jul 7, 2017
ace3895
Convert addrdb/addrman to new serialization
sipa Jul 7, 2017
39c58a1
Add a generic approach for (de)serialization of objects using code in…
sipa Jan 8, 2020
bbfc55c
Convert VARINT to the formatter/Using approach
sipa Jan 8, 2020
7376a95
Convert chain to new serialization
sipa Jul 8, 2017
3e38199
Move compressor utility functions out of class
sipa Jul 8, 2017
aa35991
Add FORMATTER_METHODS, similar to SERIALIZE_METHODS, but for formatters
sipa Jan 18, 2020
c2fdeaf
Convert compression.h to new serialization framework
sipa Jan 18, 2020
df4e1ba
Add a constant for the maximum vector allocation (5 Mbyte)
sipa Sep 6, 2017
1dfddce
Add custom vector-element formatter
sipa Jan 18, 2020
a926ba3
Make std::vector and prevector reuse the VectorFormatter logic
sipa Jan 29, 2020
e107a0c
Convert undo.h to new serialization framework
sipa Jan 29, 2020
bb99030
Get rid of VARINT default argument
sipa Feb 7, 2020
4e2afad
Convert CCompactSize to proper formatter
sipa Feb 4, 2020
fd29a50
Make VectorFormatter support stateful formatters
ryanofsky Feb 16, 2020
d6380c4
Add CustomUintFormatter
sipa Feb 16, 2020
806213a
Fix a violation of C++ standard rules that unions cannot be switched.
TheQuantumPhysicist Feb 17, 2020
3765d6c
Add static_asserts to ser_X_to_Y() methods
TheQuantumPhysicist Feb 19, 2020
c4d6228
Merge BigEndian functionality into CustomUintFormatter
sipa Mar 11, 2020
7344c1a
Extend CustomUintFormatter to support enums
ryanofsky Mar 30, 2020
13577fb
Add SER_READ and SER_WRITE for read/write-dependent statements
ryanofsky Mar 30, 2020
3d3ee64
Convert merkleblock to new serialization
sipa Mar 11, 2020
0f15784
Convert everything except wallet/qt to new serialization (step 1)
sipa Mar 11, 2020
eccd473
Convert to new serialization (step 2). Focused on object's serializat…
furszy Jun 1, 2021
3f7826e
Add comments to CustomUintFormatter
sipa May 19, 2020
35fca11
Convert Qt to new serialization
sipa May 20, 2020
dc0fc95
Remove old MESS_VER_STRMESS message version try-catch.
furszy Jun 1, 2021
cf06950
Convert to new serialization (step 3)
furszy Jun 1, 2021
221bf49
Convert wallet to new serialization
furszy Jun 1, 2021
1ee0cb2
Convert CDiskBlockIndex to new serialization.
furszy Jun 2, 2021
f021897
Fix CDiskBlockIndex serialization of dummy fields for old DB versions
random-zebra Jun 18, 2021
8c74c09
Convert LimitedString to formatter
sipa May 20, 2020
060d62b
Convert the last, non-trivial, serialization functions to the new form
furszy Jun 2, 2021
bd4b846
Remove old serialization primitives
sipa May 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ BITCOIN_CORE_H = \
script/standard.h \
script/script_error.h \
serialize.h \
span.h \
spork.h \
sporkdb.h \
sporkid.h \
Expand Down
2 changes: 1 addition & 1 deletion src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
unsigned char pchMsgTmp[4];
verifier >> pchMsgTmp;
// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)) != 0)
return error("%s: Invalid network magic number", __func__);

// de-serialize data
Expand Down
10 changes: 1 addition & 9 deletions src/addrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ class CBanEntry
nCreateTime = nCreateTimeIn;
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(nVersion);
READWRITE(nCreateTime);
READWRITE(nBanUntil);
READWRITE(banReason);
}
SERIALIZE_METHODS(CBanEntry, obj) { READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, obj.banReason); }

void SetNull()
{
Expand Down
12 changes: 4 additions & 8 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@ class CAddrInfo : public CAddress
friend class CAddrMan;

public:
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CAddrInfo, obj)
{
READWRITEAS(CAddress, *this);
READWRITE(source);
READWRITE(nLastSuccess);
READWRITE(nAttempts);
READWRITEAS(CAddress, obj);
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
}

void Init()
Expand Down Expand Up @@ -310,7 +306,7 @@ class CAddrMan
* This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
* changes to the ADDRMAN_ parameters without breaking the on-disk structure.
*
* We don't use ADD_SERIALIZE_METHODS since the serialization and deserialization code has
* We don't use SERIALIZE_METHODS since the serialization and deserialization code has
* very little in common.
*/
template <typename Stream>
Expand Down
1 change: 1 addition & 0 deletions src/bench/prevector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
struct nontrivial_t {
int x;
nontrivial_t() :x(-1) {}
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
};
static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value,
"expected nontrivial_t to not be trivially constructible");
Expand Down
17 changes: 4 additions & 13 deletions src/bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ enum bloomflags {
/**
* BloomFilter is a probabilistic filter which SPV clients provide
* so that we can filter the transactions we sends them.
*
*
* This allows for significantly more efficient transaction and block downloads.
*
*
* Because bloom filters are probabilistic, an SPV node can increase the false-
* positive rate, making us send them transactions which aren't actually theirs,
* positive rate, making us send them transactions which aren't actually theirs,
* allowing clients to trade more bandwidth for more privacy by obfuscating which
* keys are owned by them.
*/
Expand Down Expand Up @@ -66,16 +66,7 @@ class CBloomFilter
CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak, unsigned char nFlagsIn);
CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vData);
READWRITE(nHashFuncs);
READWRITE(nTweak);
READWRITE(nFlags);
}
SERIALIZE_METHODS(CBloomFilter, obj) { READWRITE(obj.vData, obj.nHashFuncs, obj.nTweak, obj.nFlags); }

void insert(const std::vector<unsigned char>& vKey);
void insert(const COutPoint& outpoint);
Expand Down
7 changes: 3 additions & 4 deletions src/budget/budgetdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ CBudgetDB::ReadResult CBudgetDB::Read(CBudgetManager& objToLoad, bool fDryRun)
}

int version;
unsigned char pchMsgTmp[4];
std::string strMagicMessageTmp;
try {
// de-serialize file header
Expand All @@ -106,12 +105,12 @@ CBudgetDB::ReadResult CBudgetDB::Read(CBudgetManager& objToLoad, bool fDryRun)
return IncorrectMagicMessage;
}


// de-serialize file header (network specific magic number) and ..
ssObj >> FLATDATA(pchMsgTmp);
std::vector<unsigned char> pchMsgTmp(4);
ssObj >> MakeSpan(pchMsgTmp);

// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) {
if (memcmp(pchMsgTmp.data(), Params().MessageStart(), pchMsgTmp.size()) != 0) {
error("%s : Invalid network magic number", __func__);
return IncorrectMagicNumber;
}
Expand Down
25 changes: 9 additions & 16 deletions src/budget/budgetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,23 @@ class CBudgetManager
// Remove proposal/budget by FeeTx (called when a block is disconnected)
void RemoveByFeeTxId(const uint256& feeTxId);

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CBudgetManager, obj)
{
{
LOCK(cs_proposals);
READWRITE(mapProposals);
READWRITE(mapFeeTxToProposal);
LOCK(obj.cs_proposals);
READWRITE(obj.mapProposals, obj.mapFeeTxToProposal);
}
{
LOCK(cs_votes);
READWRITE(mapSeenProposalVotes);
READWRITE(mapOrphanProposalVotes);
LOCK(obj.cs_votes);
READWRITE(obj.mapSeenProposalVotes, obj.mapOrphanProposalVotes);
}
{
LOCK(cs_budgets);
READWRITE(mapFinalizedBudgets);
READWRITE(mapFeeTxToBudget);
READWRITE(mapUnconfirmedFeeTx);
LOCK(obj.cs_budgets);
READWRITE(obj.mapFinalizedBudgets, obj.mapFeeTxToBudget, obj.mapUnconfirmedFeeTx);
}
{
LOCK(cs_finalizedvotes);
READWRITE(mapSeenFinalizedBudgetVotes);
READWRITE(mapOrphanFinalizedBudgetVotes);
LOCK(obj.cs_finalizedvotes);
READWRITE(obj.mapSeenFinalizedBudgetVotes, obj.mapOrphanFinalizedBudgetVotes);
}
}
};
Expand Down
22 changes: 10 additions & 12 deletions src/budget/budgetproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,17 @@ class CBudgetProposal
}

// Serialization for local DB
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CBudgetProposal, obj)
{
READWRITE(LIMITED_STRING(strProposalName, 20));
READWRITE(LIMITED_STRING(strURL, 64));
READWRITE(nBlockStart);
READWRITE(nBlockEnd);
READWRITE(nAmount);
READWRITE(address);
READWRITE(nFeeTXHash);
READWRITE(nTime);
READWRITE(mapVotes);
READWRITE(LIMITED_STRING(obj.strProposalName, 20));
READWRITE(LIMITED_STRING(obj.strURL, 64));
READWRITE(obj.nBlockStart);
READWRITE(obj.nBlockEnd);
READWRITE(obj.nAmount);
READWRITE(obj.address);
READWRITE(obj.nFeeTXHash);
READWRITE(obj.nTime);
READWRITE(obj.mapVotes);
}

// Serialization for network messages.
Expand Down
22 changes: 2 additions & 20 deletions src/budget/budgetvote.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class CBudgetVote : public CSignedMessage
{
public:
enum VoteDirection {
enum VoteDirection : uint32_t {
VOTE_ABSTAIN = 0,
VOTE_YES = 1,
VOTE_NO = 2
Expand Down Expand Up @@ -64,25 +64,7 @@ class CBudgetVote : public CSignedMessage
void SetTime(const int64_t& _nTime) { nTime = _nTime; }
void SetValid(bool _fValid) { fValid = _fValid; }

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vin);
READWRITE(nProposalHash);
int nVoteInt = (int) nVote;
READWRITE(nVoteInt);
if (ser_action.ForRead())
nVote = (VoteDirection) nVoteInt;
READWRITE(nTime);
READWRITE(vchSig);
try
{
READWRITE(nMessVersion);
} catch (...) {
nMessVersion = MessageVersion::MESS_VER_STRMESS;
}
}
SERIALIZE_METHODS(CBudgetVote, obj) { READWRITE(obj.vin, obj.nProposalHash, Using<CustomUintFormatter<4>>(obj.nVote), obj.nTime, obj.vchSig, obj.nMessVersion); }
};

#endif // BUDGET_VOTE_H
30 changes: 10 additions & 20 deletions src/budget/finalizedbudget.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,16 @@ class CFinalizedBudget
}

// Serialization for local DB
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CFinalizedBudget, obj)
{
READWRITE(LIMITED_STRING(strBudgetName, 20));
READWRITE(nFeeTXHash);
READWRITE(nTime);
READWRITE(nBlockStart);
READWRITE(vecBudgetPayments);
READWRITE(fAutoChecked);
READWRITE(mapVotes);
READWRITE(strProposals);
READWRITE(LIMITED_STRING(obj.strBudgetName, 20));
READWRITE(obj.nFeeTXHash);
READWRITE(obj.nTime);
READWRITE(obj.nBlockStart);
READWRITE(obj.vecBudgetPayments);
READWRITE(obj.fAutoChecked);
READWRITE(obj.mapVotes);
READWRITE(obj.strProposals);
}

// Serialization for network messages.
Expand Down Expand Up @@ -155,16 +153,8 @@ class CTxBudgetPayment
nAmount(_nAmount)
{}

ADD_SERIALIZE_METHODS;

//for saving to the serialized db
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(payee);
READWRITE(nAmount);
READWRITE(nProposalHash);
}
SERIALIZE_METHODS(CTxBudgetPayment, obj) { READWRITE(obj.payee, obj.nAmount, obj.nProposalHash); }

// compare payments by proposal hash
inline bool operator>(const CTxBudgetPayment& other) const
Expand Down
16 changes: 1 addition & 15 deletions src/budget/finalizedbudgetvote.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,7 @@ class CFinalizedBudgetVote : public CSignedMessage
void SetTime(const int64_t& _nTime) { nTime = _nTime; }
void SetValid(bool _fValid) { fValid = _fValid; }

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vin);
READWRITE(nBudgetHash);
READWRITE(nTime);
READWRITE(vchSig);
try
{
READWRITE(nMessVersion);
} catch (...) {
nMessVersion = MessageVersion::MESS_VER_STRMESS;
}
}
SERIALIZE_METHODS(CFinalizedBudgetVote, obj) { READWRITE(obj.vin, obj.nBudgetHash, obj.nTime, obj.vchSig, obj.nMessVersion); }
};

#endif // FINALIZED_BUDGET_VOTE_H
Loading