Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864506
D11514.id33665.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D11514.id33665.diff
View Options
diff --git a/src/avalanche/proof.h b/src/avalanche/proof.h
--- a/src/avalanche/proof.h
+++ b/src/avalanche/proof.h
@@ -140,6 +140,13 @@
limitedProofId(std::move(other.limitedProofId)),
proofid(std::move(other.proofid)), score(other.score) {}
+ /**
+ * Deserialization constructor.
+ */
+ template <typename Stream> Proof(deserialize_type, Stream &s) {
+ Unserialize(s);
+ }
+
SERIALIZE_METHODS(Proof, obj) {
READWRITE(obj.sequence, obj.expirationTime, obj.master, obj.stakes);
if (!useLegacy()) {
diff --git a/src/serialize.h b/src/serialize.h
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -8,6 +8,7 @@
#include <compat/endian.h>
#include <prevector.h>
+#include <rcu.h>
#include <span.h>
#include <algorithm>
@@ -838,6 +839,14 @@
template <typename Stream, typename T>
void Unserialize(Stream &os, std::unique_ptr<const T> &p);
+/**
+ * RCUPtr
+ */
+template <typename Stream, typename T>
+void Serialize(Stream &os, const RCUPtr<const T> &p);
+template <typename Stream, typename T>
+void Unserialize(Stream &os, RCUPtr<const T> &p);
+
/**
* If none of the specialized versions above matched, default to calling member
* function.
@@ -1077,6 +1086,19 @@
p = std::make_shared<const T>(deserialize, is);
}
+/**
+ * RCUPtr
+ */
+template <typename Stream, typename T>
+void Serialize(Stream &os, const RCUPtr<const T> &p) {
+ Serialize(os, *p);
+}
+
+template <typename Stream, typename T>
+void Unserialize(Stream &is, RCUPtr<const T> &p) {
+ p = RCUPtr<const T>::make(deserialize, is);
+}
+
/**
* Support for SERIALIZE_METHODS and READWRITE macro.
*/
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp
--- a/src/test/serialize_tests.cpp
+++ b/src/test/serialize_tests.cpp
@@ -4,6 +4,8 @@
#include <serialize.h>
+#include <avalanche/proof.h>
+#include <avalanche/proofbuilder.h>
#include <hash.h>
#include <streams.h>
#include <util/strencodings.h>
@@ -24,15 +26,18 @@
std::string stringval;
char charstrval[16];
CTransactionRef txval;
+ avalanche::ProofRef proofval;
public:
CSerializeMethodsTestSingle() = default;
CSerializeMethodsTestSingle(int intvalin, bool boolvalin,
std::string stringvalin,
const char *charstrvalin,
- const CTransactionRef &txvalin)
+ const CTransactionRef &txvalin,
+ const avalanche::ProofRef &proofvalin)
: intval(intvalin), boolval(boolvalin),
- stringval(std::move(stringvalin)), txval(txvalin) {
+ stringval(std::move(stringvalin)), txval(txvalin),
+ proofval(proofvalin) {
memcpy(charstrval, charstrvalin, sizeof(charstrval));
}
@@ -42,12 +47,15 @@
READWRITE(obj.stringval);
READWRITE(obj.charstrval);
READWRITE(obj.txval);
+ READWRITE(obj.proofval);
}
bool operator==(const CSerializeMethodsTestSingle &rhs) {
return intval == rhs.intval && boolval == rhs.boolval &&
stringval == rhs.stringval &&
- strcmp(charstrval, rhs.charstrval) == 0 && *txval == *rhs.txval;
+ strcmp(charstrval, rhs.charstrval) == 0 &&
+ *txval == *rhs.txval &&
+ proofval->getId() == rhs.proofval->getId();
}
};
@@ -57,7 +65,7 @@
SERIALIZE_METHODS(CSerializeMethodsTestMany, obj) {
READWRITE(obj.intval, obj.boolval, obj.stringval, obj.charstrval,
- obj.txval);
+ obj.txval, obj.proofval);
}
};
@@ -420,10 +428,12 @@
const char charstrval[16] = "testing charstr";
CMutableTransaction txval;
CTransactionRef tx_ref{MakeTransactionRef(txval)};
+ avalanche::ProofBuilder pb(0, 0, CKey::MakeCompressedKey());
+ avalanche::ProofRef proofval = pb.build();
CSerializeMethodsTestSingle methodtest1(intval, boolval, stringval,
- charstrval, tx_ref);
+ charstrval, tx_ref, proofval);
CSerializeMethodsTestMany methodtest2(intval, boolval, stringval,
- charstrval, tx_ref);
+ charstrval, tx_ref, proofval);
CSerializeMethodsTestSingle methodtest3;
CSerializeMethodsTestMany methodtest4;
CDataStream ss(SER_DISK, PROTOCOL_VERSION);
@@ -437,7 +447,7 @@
BOOST_CHECK(methodtest3 == methodtest4);
CDataStream ss2(SER_DISK, PROTOCOL_VERSION, intval, boolval, stringval,
- charstrval, txval);
+ charstrval, txval, proofval);
ss2 >> methodtest3;
BOOST_CHECK(methodtest3 == methodtest4);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 20:12 (4 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5864548
Default Alt Text
D11514.id33665.diff (4 KB)
Attached To
D11514: [RCU] Make it possible to serialize/deserialize a RCUPtr
Event Timeline
Log In to Comment