Skip to content

Commit

Permalink
Merge pull request #1535 from cyrossignol/upgrade-serialization
Browse files Browse the repository at this point in the history
Backport newer serialization facilities from Bitcoin
  • Loading branch information
jamescowens committed Sep 25, 2019
2 parents d7ecc2c + 61b776b commit caaa0f5
Show file tree
Hide file tree
Showing 61 changed files with 3,435 additions and 1,871 deletions.
13 changes: 10 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ GRIDCOIN_CORE_H = \
addrdb.h \
addrman.h \
alert.h \
allocators.h \
attributes.h \
appcache.h \
attributes.h \
backup.h \
banman.h \
base58.h \
Expand Down Expand Up @@ -116,7 +115,13 @@ GRIDCOIN_CORE_H = \
script.h \
scrypt.h \
serialize.h \
span.h \
streams.h \
strlcpy.h \
support/allocators/secure.h \
support/allocators/zeroafterfree.h \
support/cleanse.h \
support/lockedpool.h \
sync.h \
tally.h \
threadsafety.h \
Expand All @@ -125,6 +130,7 @@ GRIDCOIN_CORE_H = \
txdb-leveldb.h \
ui_interface.h \
uint256.h \
util/memory.h \
util.h \
version.h \
walletdb.h \
Expand All @@ -133,7 +139,6 @@ GRIDCOIN_CORE_H = \
GRIDCOIN_CORE_CPP = addrdb.cpp \
addrman.cpp \
alert.cpp \
allocators.cpp \
appcache.cpp \
backup.cpp \
banman.cpp \
Expand Down Expand Up @@ -205,6 +210,8 @@ libgridcoin_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libgridcoin_util_a_SOURCES = $(GRIDCOIN_CORE_CPP) \
neuralnet/neuralnet_stub.cpp \
neuralnet/neuralnet.cpp \
support/cleanse.cpp \
support/lockedpool.cpp \
$(GRIDCOIN_CORE_H)

if TARGET_WINDOWS
Expand Down
4 changes: 2 additions & 2 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ bool SerializeDB(Stream& stream, const Data& data)
// Write and commit header, data
try {
CHashWriter hasher(SER_DISK, CLIENT_VERSION);
stream << FLATDATA(pchMessageStart) << data;
hasher << FLATDATA(pchMessageStart) << data;
stream << pchMessageStart << data;
hasher << pchMessageStart << data;
stream << hasher.GetHash();
} catch (const std::exception& e) {
return error("%s: Serialize or I/O error - %s", __func__, e.what());
Expand Down
8 changes: 4 additions & 4 deletions src/addrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class CBanEntry

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITEVARIADIC(this->nVersion);
READWRITEVARIADIC(nCreateTime);
READWRITEVARIADIC(nBanUntil);
READWRITEVARIADIC(banReason);
READWRITE(this->nVersion);
READWRITE(nCreateTime);
READWRITE(nBanUntil);
READWRITE(banReason);
}

void SetNull()
Expand Down
2 changes: 2 additions & 0 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "addrman.h"
#include "streams.h"

using namespace std;

int CAddrInfo::GetTriedBucket(const std::vector<unsigned char> &nKey) const
Expand Down
22 changes: 10 additions & 12 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ class CAddrInfo : public CAddress

public:

IMPLEMENT_SERIALIZE(
CAddress* pthis = (CAddress*)(this);
READWRITE(*pthis);
ADD_SERIALIZE_METHODS;

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

void Init()
{
Expand Down Expand Up @@ -265,10 +268,10 @@ 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 IMPLEMENT_SERIALIZE since the serialization and deserialization code has
// We don't use ADD_SERIALIZE_METHODS since the serialization and deserialization code has
// very little in common.
template<typename Stream>
void Serialize(Stream &s, int nType, int nVersionDummy) const
void Serialize(Stream &s) const
{
LOCK(cs);

Expand Down Expand Up @@ -312,7 +315,7 @@ class CAddrMan
}

template<typename Stream>
void Unserialize(Stream& s, int nType, int nVersionDummy)
void Unserialize(Stream& s)
{
LOCK(cs);

Expand Down Expand Up @@ -376,11 +379,6 @@ class CAddrMan
}
}

unsigned int GetSerializeSize(int nType, int nVersion) const
{
return (CSizeComputer(nType, nVersion) << *this).size();
}

CAddrMan() : vRandom(0), vvTried(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0)), vvNew(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>())
{
nKey.resize(32);
Expand Down
1 change: 1 addition & 0 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "alert.h"
#include "key.h"
#include "net.h"
#include "streams.h"
#include "sync.h"
#include "ui_interface.h"
#include "uint256.h"
Expand Down
23 changes: 15 additions & 8 deletions src/alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ class CUnsignedAlert
std::string strStatusBar;
std::string strReserved;

IMPLEMENT_SERIALIZE
(
READWRITE(this->nVersion);
nVersion = this->nVersion;
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(nVersion);
s.SetVersion(nVersion);

READWRITE(nRelayUntil);
READWRITE(nExpiration);
READWRITE(nID);
Expand All @@ -56,7 +60,7 @@ class CUnsignedAlert
READWRITE(strComment);
READWRITE(strStatusBar);
READWRITE(strReserved);
)
}

void SetNull();

Expand All @@ -76,11 +80,14 @@ class CAlert : public CUnsignedAlert
SetNull();
}

IMPLEMENT_SERIALIZE
(
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vchMsg);
READWRITE(vchSig);
)
}

void SetNull();
bool IsNull() const;
Expand Down
64 changes: 0 additions & 64 deletions src/allocators.cpp

This file was deleted.

Loading

0 comments on commit caaa0f5

Please sign in to comment.