mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -17,33 +17,33 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/app/misc/Manifest.h>
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/app/misc/Manifest.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/beast/utility/Journal.h>
|
||||
#include <ripple/core/TimeKeeper.h>
|
||||
#include <ripple/overlay/Compression.h>
|
||||
#include <ripple/overlay/impl/ZeroCopyStream.h>
|
||||
#include <ripple/overlay/impl/ProtocolMessage.h>
|
||||
#include <ripple/overlay/Message.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
#include <ripple/overlay/impl/ProtocolMessage.h>
|
||||
#include <ripple/overlay/impl/ZeroCopyStream.h>
|
||||
#include <ripple/protocol/HashPrefix.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/protocol/PublicKey.h>
|
||||
#include <ripple/protocol/SecretKey.h>
|
||||
#include <ripple/protocol/Sign.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/shamap/SHAMapNodeID.h>
|
||||
#include <ripple.pb.h>
|
||||
#include <boost/asio/ip/address_v4.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <test/jtx/Account.h>
|
||||
#include <test/jtx/amount.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/pay.h>
|
||||
#include <test/jtx/WSClient.h>
|
||||
#include <algorithm>
|
||||
#include <ripple.pb.h>
|
||||
#include <test/jtx/Account.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/WSClient.h>
|
||||
#include <test/jtx/amount.h>
|
||||
#include <test/jtx/pay.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -52,14 +52,13 @@ namespace test {
|
||||
using namespace ripple::test;
|
||||
using namespace ripple::test::jtx;
|
||||
|
||||
static
|
||||
uint256
|
||||
ledgerHash (LedgerInfo const& info)
|
||||
static uint256
|
||||
ledgerHash(LedgerInfo const& info)
|
||||
{
|
||||
return ripple::sha512Half(
|
||||
return ripple::sha512Half(
|
||||
HashPrefix::ledgerMaster,
|
||||
std::uint32_t(info.seq),
|
||||
std::uint64_t(info.drops.drops ()),
|
||||
std::uint64_t(info.drops.drops()),
|
||||
info.parentHash,
|
||||
info.txHash,
|
||||
info.accountHash,
|
||||
@@ -69,48 +68,66 @@ return ripple::sha512Half(
|
||||
std::uint8_t(info.closeFlags));
|
||||
}
|
||||
|
||||
class compression_test : public beast::unit_test::suite {
|
||||
class compression_test : public beast::unit_test::suite
|
||||
{
|
||||
using Compressed = compression::Compressed;
|
||||
using Algorithm = compression::Algorithm;
|
||||
|
||||
public:
|
||||
compression_test() {}
|
||||
compression_test()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
void
|
||||
doTest(std::shared_ptr<T> proto, protocol::MessageType mt, uint16_t nbuffers, const char *msg,
|
||||
bool log = false) {
|
||||
|
||||
doTest(
|
||||
std::shared_ptr<T> proto,
|
||||
protocol::MessageType mt,
|
||||
uint16_t nbuffers,
|
||||
const char* msg,
|
||||
bool log = false)
|
||||
{
|
||||
if (log)
|
||||
printf("=== compress/decompress %s ===\n", msg);
|
||||
Message m(*proto, mt);
|
||||
|
||||
auto &buffer = m.getBuffer(Compressed::On);
|
||||
auto& buffer = m.getBuffer(Compressed::On);
|
||||
|
||||
if (log)
|
||||
printf("==> compressed, original %d bytes, compressed %d bytes\n",
|
||||
(int)m.getBuffer(Compressed::Off).size(),
|
||||
(int)m.getBuffer(Compressed::On).size());
|
||||
printf(
|
||||
"==> compressed, original %d bytes, compressed %d bytes\n",
|
||||
(int)m.getBuffer(Compressed::Off).size(),
|
||||
(int)m.getBuffer(Compressed::On).size());
|
||||
|
||||
boost::beast::multi_buffer buffers;
|
||||
|
||||
|
||||
// simulate multi-buffer
|
||||
auto sz = buffer.size() / nbuffers;
|
||||
for (int i = 0; i < nbuffers; i++) {
|
||||
for (int i = 0; i < nbuffers; i++)
|
||||
{
|
||||
auto start = buffer.begin() + sz * i;
|
||||
auto end = i < nbuffers - 1 ? (buffer.begin() + sz * (i + 1)) : buffer.end();
|
||||
auto end = i < nbuffers - 1 ? (buffer.begin() + sz * (i + 1))
|
||||
: buffer.end();
|
||||
std::vector<std::uint8_t> slice(start, end);
|
||||
buffers.commit(
|
||||
boost::asio::buffer_copy(buffers.prepare(slice.size()), boost::asio::buffer(slice)));
|
||||
buffers.commit(boost::asio::buffer_copy(
|
||||
buffers.prepare(slice.size()), boost::asio::buffer(slice)));
|
||||
}
|
||||
auto header = ripple::detail::parseMessageHeader(buffers.data(), buffer.size());
|
||||
auto header =
|
||||
ripple::detail::parseMessageHeader(buffers.data(), buffer.size());
|
||||
|
||||
if (log)
|
||||
printf("==> parsed header: buffers size %d, compressed %d, algorithm %d, header size %d, payload size %d, buffer size %d\n",
|
||||
(int)buffers.size(), header->algorithm != Algorithm::None, (int)header->algorithm,
|
||||
(int)header->header_size, (int)header->payload_wire_size, (int)buffer.size());
|
||||
printf(
|
||||
"==> parsed header: buffers size %d, compressed %d, algorithm "
|
||||
"%d, header size %d, payload size %d, buffer size %d\n",
|
||||
(int)buffers.size(),
|
||||
header->algorithm != Algorithm::None,
|
||||
(int)header->algorithm,
|
||||
(int)header->header_size,
|
||||
(int)header->payload_wire_size,
|
||||
(int)buffer.size());
|
||||
|
||||
if (header->algorithm == Algorithm::None) {
|
||||
if (header->algorithm == Algorithm::None)
|
||||
{
|
||||
if (log)
|
||||
printf("==> NOT COMPRESSED\n");
|
||||
return;
|
||||
@@ -119,57 +136,78 @@ public:
|
||||
std::vector<std::uint8_t> decompressed;
|
||||
decompressed.resize(header->uncompressed_size);
|
||||
|
||||
BEAST_EXPECT(header->payload_wire_size == buffer.size() - header->header_size);
|
||||
BEAST_EXPECT(
|
||||
header->payload_wire_size == buffer.size() - header->header_size);
|
||||
|
||||
ZeroCopyInputStream stream(buffers.data());
|
||||
stream.Skip(header->header_size);
|
||||
|
||||
auto decompressedSize = ripple::compression::decompress(stream, header->payload_wire_size,
|
||||
decompressed.data(), header->uncompressed_size);
|
||||
auto decompressedSize = ripple::compression::decompress(
|
||||
stream,
|
||||
header->payload_wire_size,
|
||||
decompressed.data(),
|
||||
header->uncompressed_size);
|
||||
BEAST_EXPECT(decompressedSize == header->uncompressed_size);
|
||||
auto const proto1 = std::make_shared<T>();
|
||||
|
||||
BEAST_EXPECT(proto1->ParseFromArray(decompressed.data(), decompressedSize));
|
||||
BEAST_EXPECT(
|
||||
proto1->ParseFromArray(decompressed.data(), decompressedSize));
|
||||
auto uncompressed = m.getBuffer(Compressed::Off);
|
||||
BEAST_EXPECT(std::equal(uncompressed.begin() + ripple::compression::headerBytes,
|
||||
uncompressed.end(),
|
||||
decompressed.begin()));
|
||||
BEAST_EXPECT(std::equal(
|
||||
uncompressed.begin() + ripple::compression::headerBytes,
|
||||
uncompressed.end(),
|
||||
decompressed.begin()));
|
||||
if (log)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
std::shared_ptr<protocol::TMManifests>
|
||||
buildManifests(int n) {
|
||||
buildManifests(int n)
|
||||
{
|
||||
auto manifests = std::make_shared<protocol::TMManifests>();
|
||||
manifests->mutable_list()->Reserve(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
auto master = randomKeyPair(KeyType::ed25519);
|
||||
auto signing = randomKeyPair(KeyType::ed25519);
|
||||
STObject st(sfGeneric);
|
||||
st[sfSequence] = i;
|
||||
st[sfPublicKey] = std::get<0>(master);
|
||||
st[sfSigningPubKey] = std::get<0>(signing);
|
||||
st[sfDomain] = makeSlice(std::string("example") + std::to_string(i) + std::string(".com"));
|
||||
sign(st, HashPrefix::manifest, KeyType::ed25519, std::get<1>(master), sfMasterSignature);
|
||||
sign(st, HashPrefix::manifest, KeyType::ed25519, std::get<1>(signing));
|
||||
st[sfDomain] = makeSlice(
|
||||
std::string("example") + std::to_string(i) +
|
||||
std::string(".com"));
|
||||
sign(
|
||||
st,
|
||||
HashPrefix::manifest,
|
||||
KeyType::ed25519,
|
||||
std::get<1>(master),
|
||||
sfMasterSignature);
|
||||
sign(
|
||||
st,
|
||||
HashPrefix::manifest,
|
||||
KeyType::ed25519,
|
||||
std::get<1>(signing));
|
||||
Serializer s;
|
||||
st.add(s);
|
||||
auto *manifest = manifests->add_list();
|
||||
auto* manifest = manifests->add_list();
|
||||
manifest->set_stobject(s.data(), s.size());
|
||||
}
|
||||
return manifests;
|
||||
}
|
||||
|
||||
std::shared_ptr<protocol::TMEndpoints>
|
||||
buildEndpoints(int n) {
|
||||
buildEndpoints(int n)
|
||||
{
|
||||
auto endpoints = std::make_shared<protocol::TMEndpoints>();
|
||||
endpoints->mutable_endpoints()->Reserve(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
auto *endpoint = endpoints->add_endpoints();
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
auto* endpoint = endpoints->add_endpoints();
|
||||
endpoint->set_hops(i);
|
||||
std::string addr = std::string("10.0.1.") + std::to_string(i);
|
||||
endpoint->mutable_ipv4()->set_ipv4(
|
||||
boost::endian::native_to_big(boost::asio::ip::address_v4::from_string(addr).to_uint()));
|
||||
endpoint->mutable_ipv4()->set_ipv4(boost::endian::native_to_big(
|
||||
boost::asio::ip::address_v4::from_string(addr).to_uint()));
|
||||
endpoint->mutable_ipv4()->set_ipv4port(i);
|
||||
}
|
||||
endpoints->set_version(2);
|
||||
@@ -178,7 +216,8 @@ public:
|
||||
}
|
||||
|
||||
std::shared_ptr<protocol::TMTransaction>
|
||||
buildTransaction(Logs &logs) {
|
||||
buildTransaction(Logs& logs)
|
||||
{
|
||||
Env env(*this, envconfig());
|
||||
int fund = 10000;
|
||||
auto const alice = Account("alice");
|
||||
@@ -187,9 +226,10 @@ public:
|
||||
env.trust(bob["USD"](fund), alice);
|
||||
env.close();
|
||||
|
||||
auto toBinary = [](std::string const &text) {
|
||||
auto toBinary = [](std::string const& text) {
|
||||
std::string binary;
|
||||
for (size_t i = 0; i < text.size(); ++i) {
|
||||
for (size_t i = 0; i < text.size(); ++i)
|
||||
{
|
||||
unsigned int c = charUnHex(text[i]);
|
||||
c = c << 4;
|
||||
++i;
|
||||
@@ -206,11 +246,11 @@ public:
|
||||
Json::Value jrequestUsd;
|
||||
jrequestUsd[jss::secret] = toBase58(generateSeed("bob"));
|
||||
jrequestUsd[jss::tx_json] =
|
||||
pay("bob", "alice", bob["USD"](fund / 2));
|
||||
pay("bob", "alice", bob["USD"](fund / 2));
|
||||
Json::Value jreply_usd = wsc->invoke("sign", jrequestUsd);
|
||||
|
||||
usdTxBlob =
|
||||
toBinary(jreply_usd[jss::result][jss::tx_blob].asString());
|
||||
toBinary(jreply_usd[jss::result][jss::tx_blob].asString());
|
||||
}
|
||||
|
||||
auto transaction = std::make_shared<protocol::TMTransaction>();
|
||||
@@ -224,7 +264,8 @@ public:
|
||||
}
|
||||
|
||||
std::shared_ptr<protocol::TMGetLedger>
|
||||
buildGetLedger() {
|
||||
buildGetLedger()
|
||||
{
|
||||
auto getLedger = std::make_shared<protocol::TMGetLedger>();
|
||||
getLedger->set_itype(protocol::liTS_CANDIDATE);
|
||||
getLedger->set_ltype(protocol::TMLedgerType::ltACCEPTED);
|
||||
@@ -240,7 +281,8 @@ public:
|
||||
}
|
||||
|
||||
std::shared_ptr<protocol::TMLedgerData>
|
||||
buildLedgerData(uint32_t n, Logs &logs) {
|
||||
buildLedgerData(uint32_t n, Logs& logs)
|
||||
{
|
||||
auto ledgerData = std::make_shared<protocol::TMLedgerData>();
|
||||
uint256 const hash(ripple::sha512Half(12356789));
|
||||
ledgerData->set_ledgerhash(hash.data(), hash.size());
|
||||
@@ -250,7 +292,8 @@ public:
|
||||
ledgerData->set_error(protocol::TMReplyError::reNO_LEDGER);
|
||||
ledgerData->mutable_nodes()->Reserve(n);
|
||||
uint256 parentHash(0);
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
LedgerInfo info;
|
||||
auto tk = make_TimeKeeper(logs.journal("TimeKeeper"));
|
||||
info.seq = i;
|
||||
@@ -265,23 +308,27 @@ public:
|
||||
parentHash = ledgerHash(info);
|
||||
Serializer nData;
|
||||
ripple::addRaw(info, nData);
|
||||
ledgerData->add_nodes()->set_nodedata(nData.getDataPtr(), nData.getLength());
|
||||
ledgerData->add_nodes()->set_nodedata(
|
||||
nData.getDataPtr(), nData.getLength());
|
||||
}
|
||||
|
||||
return ledgerData;
|
||||
}
|
||||
|
||||
std::shared_ptr<protocol::TMGetObjectByHash>
|
||||
buildGetObjectByHash() {
|
||||
buildGetObjectByHash()
|
||||
{
|
||||
auto getObject = std::make_shared<protocol::TMGetObjectByHash>();
|
||||
|
||||
getObject->set_type(protocol::TMGetObjectByHash_ObjectType::TMGetObjectByHash_ObjectType_otTRANSACTION);
|
||||
getObject->set_type(protocol::TMGetObjectByHash_ObjectType::
|
||||
TMGetObjectByHash_ObjectType_otTRANSACTION);
|
||||
getObject->set_query(true);
|
||||
getObject->set_seq(123456789);
|
||||
uint256 hash(ripple::sha512Half(123456789));
|
||||
getObject->set_ledgerhash(hash.data(), hash.size());
|
||||
getObject->set_fat(true);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
uint256 hash(ripple::sha512Half(i));
|
||||
auto object = getObject->add_objects();
|
||||
object->set_hash(hash.data(), hash.size());
|
||||
@@ -306,14 +353,20 @@ public:
|
||||
st[sfPublicKey] = std::get<0>(master);
|
||||
st[sfSigningPubKey] = std::get<0>(signing);
|
||||
st[sfDomain] = makeSlice(std::string("example.com"));
|
||||
sign(st, HashPrefix::manifest, KeyType::ed25519, std::get<1>(master), sfMasterSignature);
|
||||
sign(
|
||||
st,
|
||||
HashPrefix::manifest,
|
||||
KeyType::ed25519,
|
||||
std::get<1>(master),
|
||||
sfMasterSignature);
|
||||
sign(st, HashPrefix::manifest, KeyType::ed25519, std::get<1>(signing));
|
||||
Serializer s;
|
||||
st.add(s);
|
||||
list->set_manifest(s.data(), s.size());
|
||||
list->set_version(3);
|
||||
STObject signature(sfSignature);
|
||||
ripple::sign(st, HashPrefix::manifest,KeyType::ed25519, std::get<1>(signing));
|
||||
ripple::sign(
|
||||
st, HashPrefix::manifest, KeyType::ed25519, std::get<1>(signing));
|
||||
Serializer s1;
|
||||
st.add(s1);
|
||||
list->set_signature(s1.data(), s1.size());
|
||||
@@ -322,7 +375,8 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
testProtocol() {
|
||||
testProtocol()
|
||||
{
|
||||
testcase("Message Compression");
|
||||
|
||||
auto thresh = beast::severities::Severity::kInfo;
|
||||
@@ -345,32 +399,65 @@ public:
|
||||
// 1.3KB
|
||||
doTest(buildEndpoints(100), protocol::mtENDPOINTS, 4, "TMEndpoints100");
|
||||
// 242B
|
||||
doTest(buildTransaction(*logs), protocol::mtTRANSACTION, 1, "TMTransaction");
|
||||
doTest(
|
||||
buildTransaction(*logs),
|
||||
protocol::mtTRANSACTION,
|
||||
1,
|
||||
"TMTransaction");
|
||||
// 87B
|
||||
doTest(buildGetLedger(), protocol::mtGET_LEDGER, 1, "TMGetLedger");
|
||||
// 61KB
|
||||
doTest(buildLedgerData(500, *logs), protocol::mtLEDGER_DATA, 10, "TMLedgerData500");
|
||||
doTest(
|
||||
buildLedgerData(500, *logs),
|
||||
protocol::mtLEDGER_DATA,
|
||||
10,
|
||||
"TMLedgerData500");
|
||||
// 122 KB
|
||||
doTest(buildLedgerData(1000, *logs), protocol::mtLEDGER_DATA, 20, "TMLedgerData1000");
|
||||
doTest(
|
||||
buildLedgerData(1000, *logs),
|
||||
protocol::mtLEDGER_DATA,
|
||||
20,
|
||||
"TMLedgerData1000");
|
||||
// 1.2MB
|
||||
doTest(buildLedgerData(10000, *logs), protocol::mtLEDGER_DATA, 50, "TMLedgerData10000");
|
||||
doTest(
|
||||
buildLedgerData(10000, *logs),
|
||||
protocol::mtLEDGER_DATA,
|
||||
50,
|
||||
"TMLedgerData10000");
|
||||
// 12MB
|
||||
doTest(buildLedgerData(100000, *logs), protocol::mtLEDGER_DATA, 100, "TMLedgerData100000");
|
||||
doTest(
|
||||
buildLedgerData(100000, *logs),
|
||||
protocol::mtLEDGER_DATA,
|
||||
100,
|
||||
"TMLedgerData100000");
|
||||
// 61MB
|
||||
doTest(buildLedgerData(500000, *logs), protocol::mtLEDGER_DATA, 100, "TMLedgerData500000");
|
||||
doTest(
|
||||
buildLedgerData(500000, *logs),
|
||||
protocol::mtLEDGER_DATA,
|
||||
100,
|
||||
"TMLedgerData500000");
|
||||
// 7.7KB
|
||||
doTest(buildGetObjectByHash(), protocol::mtGET_OBJECTS, 4, "TMGetObjectByHash");
|
||||
doTest(
|
||||
buildGetObjectByHash(),
|
||||
protocol::mtGET_OBJECTS,
|
||||
4,
|
||||
"TMGetObjectByHash");
|
||||
// 895B
|
||||
doTest(buildValidatorList(), protocol::mtVALIDATORLIST, 4, "TMValidatorList");
|
||||
doTest(
|
||||
buildValidatorList(),
|
||||
protocol::mtVALIDATORLIST,
|
||||
4,
|
||||
"TMValidatorList");
|
||||
}
|
||||
|
||||
void run() override {
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testProtocol();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(compression, ripple_data, ripple, 20);
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
Reference in New Issue
Block a user