rippled
Loading...
Searching...
No Matches
LedgerReplay_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2020 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx.h>
21#include <test/jtx/envconfig.h>
22#include <xrpld/app/ledger/BuildLedger.h>
23#include <xrpld/app/ledger/LedgerMaster.h>
24#include <xrpld/app/ledger/LedgerReplay.h>
25#include <xrpld/app/ledger/LedgerReplayTask.h>
26#include <xrpld/app/ledger/LedgerReplayer.h>
27#include <xrpld/app/ledger/detail/LedgerDeltaAcquire.h>
28#include <xrpld/app/ledger/detail/LedgerReplayMsgHandler.h>
29#include <xrpld/app/ledger/detail/SkipListAcquire.h>
30#include <xrpld/overlay/PeerSet.h>
31#include <xrpld/overlay/detail/PeerImp.h>
32#include <xrpl/basics/Slice.h>
33
34#include <chrono>
35#include <thread>
36
37namespace ripple {
38namespace test {
39
41{
42 void
43 run() override
44 {
45 testcase("Replay ledger");
46
47 using namespace jtx;
48
49 // Build a ledger normally
50 auto const alice = Account("alice");
51 auto const bob = Account("bob");
52
53 Env env(*this);
54 env.fund(XRP(100000), alice, bob);
55 env.close();
56
58 auto const lastClosed = ledgerMaster.getClosedLedger();
59 auto const lastClosedParent =
60 ledgerMaster.getLedgerByHash(lastClosed->info().parentHash);
61
62 auto const replayed = buildLedger(
63 LedgerReplay(lastClosedParent, lastClosed),
64 tapNONE,
65 env.app(),
66 env.journal);
67
68 BEAST_EXPECT(replayed->info().hash == lastClosed->info().hash);
69 }
70};
71
73 Good,
74 DropAll,
75};
76
83{
84public:
90 {
91 }
92 virtual ~MagicInboundLedgers() = default;
93
96 override
97 {
99 return {};
100 if (auto l = ledgerSource.getLedgerByHash(hash); l)
101 {
103 return l;
104 }
105
106 return {};
107 }
108
109 virtual void
111 uint256 const& hash,
113 InboundLedger::Reason reason) override
114 {
115 }
116
118 find(LedgerHash const& hash) override
119 {
120 return {};
121 }
122
123 virtual bool
125 LedgerHash const& ledgerHash,
128 {
129 return false;
130 }
131
132 virtual void
134 {
135 }
136
137 virtual void
139 {
140 }
141
142 virtual bool
143 isFailure(uint256 const& h) override
144 {
145 return false;
146 }
147
148 virtual void
149 clearFailures() override
150 {
151 }
152
153 virtual Json::Value
154 getInfo() override
155 {
156 return {};
157 }
158
159 virtual std::size_t
160 fetchRate() override
161 {
162 return 0;
163 }
164
165 virtual void
167 {
168 }
169
170 virtual void
171 gotFetchPack() override
172 {
173 }
174 virtual void
175 sweep() override
176 {
177 }
178
179 virtual void
180 stop() override
181 {
182 }
183
184 virtual size_t
185 cacheSize() override
186 {
187 return 0;
188 }
189
193};
194
195enum class PeerFeature {
197 None,
198};
199
205class TestPeer : public Peer
206{
207public:
208 TestPeer(bool enableLedgerReplay)
209 : ledgerReplayEnabled_(enableLedgerReplay)
211 {
212 }
213
214 void
216 {
217 }
219 getRemoteAddress() const override
220 {
221 return {};
222 }
223 void
224 charge(Resource::Charge const& fee, std::string const& context = {})
225 override
226 {
227 }
228 id_t
229 id() const override
230 {
231 return 1234;
232 }
233 bool
234 cluster() const override
235 {
236 return false;
237 }
238 bool
239 isHighLatency() const override
240 {
241 return false;
242 }
243 int
244 getScore(bool) const override
245 {
246 return 0;
247 }
248 PublicKey const&
249 getNodePublic() const override
250 {
251 return nodePublicKey_;
252 }
254 json() override
255 {
256 return {};
257 }
258 bool
260 {
262 return true;
263 return false;
264 }
266 publisherListSequence(PublicKey const&) const override
267 {
268 return {};
269 }
270 void
272 {
273 }
274 uint256 const&
275 getClosedLedgerHash() const override
276 {
277 static uint256 hash{};
278 return hash;
279 }
280 bool
281 hasLedger(uint256 const& hash, std::uint32_t seq) const override
282 {
283 return true;
284 }
285 void
286 ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override
287 {
288 }
289 bool
290 hasTxSet(uint256 const& hash) const override
291 {
292 return false;
293 }
294 void
295 cycleStatus() override
296 {
297 }
298 bool
300 {
301 return false;
302 }
303 bool
304 compressionEnabled() const override
305 {
306 return false;
307 }
308 void
309 sendTxQueue() override
310 {
311 }
312 void
313 addTxQueue(const uint256&) override
314 {
315 }
316 void
317 removeTxQueue(const uint256&) override
318 {
319 }
320 bool
321 txReduceRelayEnabled() const override
322 {
323 return false;
324 }
325
328};
329
330enum class PeerSetBehavior {
331 Good,
332 Drop50,
333 DropAll,
336 Repeat,
337};
338
345struct TestPeerSet : public PeerSet
346{
350 PeerSetBehavior bhvr,
351 bool enableLedgerReplay)
352 : local(me)
353 , remote(other)
354 , dummyPeer(std::make_shared<TestPeer>(enableLedgerReplay))
355 , behavior(bhvr)
356 {
357 }
358
359 void
361 std::size_t limit,
362 std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
363 std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) override
364 {
365 hasItem(dummyPeer);
366 onPeerAdded(dummyPeer);
367 }
368
369 void
371 ::google::protobuf::Message const& msg,
372 protocol::MessageType type,
373 std::shared_ptr<Peer> const& peer) override
374 {
375 int dropRate = 0;
377 dropRate = 50;
379 dropRate = 100;
380
381 if ((rand() % 100 + 1) <= dropRate)
382 return;
383
384 switch (type)
385 {
386 case protocol::mtPROOF_PATH_REQ: {
388 return;
389 auto request = std::make_shared<protocol::TMProofPathRequest>(
390 dynamic_cast<protocol::TMProofPathRequest const&>(msg));
391 auto reply = std::make_shared<protocol::TMProofPathResponse>(
396 break;
397 }
398 case protocol::mtREPLAY_DELTA_REQ: {
400 return;
401 auto request = std::make_shared<protocol::TMReplayDeltaRequest>(
402 dynamic_cast<protocol::TMReplayDeltaRequest const&>(msg));
403 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
408 break;
409 }
410 default:
411 return;
412 }
413 }
414
416 getPeerIds() const override
417 {
418 static std::set<Peer::id_t> emptyPeers;
419 return emptyPeers;
420 }
421
426};
427
432{
433public:
437 PeerSetBehavior bhvr,
438 PeerFeature peerFeature)
439 : local(me)
440 , remote(other)
441 , behavior(bhvr)
443 {
444 }
445
447 build() override
448 {
449 return std::make_unique<TestPeerSet>(
451 }
452
453private:
458};
459
465{
467 {
469 int initAccounts = 10;
470 int initAmount = 1'000'000;
472 int txAmount = 10;
473 };
474
476 : env(suite)
477 , app(env.app())
478 , ledgerMaster(env.app().getLedgerMaster())
479 , msgHandler(env.app(), env.app().getLedgerReplayer())
480 , param(p)
481 {
482 assert(param.initLedgers > 0);
486 }
487
491 void
492 createAccounts(int newAccounts)
493 {
494 auto fundedAccounts = accounts.size();
495 for (int i = 0; i < newAccounts; ++i)
496 {
497 accounts.emplace_back(
498 "alice_" + std::to_string(fundedAccounts + i));
500 }
501 env.close();
502 }
503
507 void
508 sendPayments(int newTxes)
509 {
510 int fundedAccounts = accounts.size();
511 assert(fundedAccounts >= newTxes);
513
514 // somewhat random but reproducible
515 int r = ledgerMaster.getClosedLedger()->seq() * 7;
516 int fromIdx = 0;
517 int toIdx = 0;
518 auto updateIdx = [&]() {
519 assert(fundedAccounts > senders.size());
520 fromIdx = (fromIdx + r) % fundedAccounts;
521 while (senders.count(fromIdx) != 0)
522 fromIdx = (fromIdx + 1) % fundedAccounts;
523 senders.insert(fromIdx);
524 toIdx = (toIdx + r * 2) % fundedAccounts;
525 if (toIdx == fromIdx)
526 toIdx = (toIdx + 1) % fundedAccounts;
527 };
528
529 for (int i = 0; i < newTxes; ++i)
530 {
531 updateIdx();
532 env.apply(
533 pay(accounts[fromIdx],
534 accounts[toIdx],
535 jtx::drops(ledgerMaster.getClosedLedger()->fees().base) +
540 }
541 env.close();
542 }
543
547 void
549 {
550 for (int i = 0; i < param.initLedgers - 1; ++i)
551 {
553 }
554 }
555
562};
563
564enum class TaskStatus {
565 Failed,
566 Completed,
567 NotDone,
568 NotExist,
569};
570
579{
580public:
583 LedgerServer& server,
587 : env(suite, jtx::envconfig(), nullptr, beast::severities::kDisabled)
588 , app(env.app())
589 , ledgerMaster(env.app().getLedgerMaster())
591 server.app.getLedgerMaster(),
593 inboundBhvr)
594 , serverMsgHandler(server.app, server.app.getLedgerReplayer())
596 , replayer(
597 env.app(),
599 std::make_unique<TestPeerSetBuilder>(
602 behavior,
603 peerFeature))
604 {
605 }
606
607 void
609 {
611 }
612
613 bool
614 haveLedgers(uint256 const& finishLedgerHash, int totalReplay)
615 {
616 uint256 hash = finishLedgerHash;
617 int i = 0;
618 for (; i < totalReplay; ++i)
619 {
620 auto const l = ledgerMaster.getLedgerByHash(hash);
621 if (!l)
622 return false;
623 hash = l->info().parentHash;
624 }
625 return true;
626 }
627
628 bool
629 waitForLedgers(uint256 const& finishLedgerHash, int totalReplay)
630 {
631 int totalRound = 100;
632 for (int i = 0; i < totalRound; ++i)
633 {
634 if (haveLedgers(finishLedgerHash, totalReplay))
635 return true;
636 if (i < totalRound - 1)
638 }
639 return false;
640 }
641
642 bool
644 {
645 int totalRound = 100;
646 for (int i = 0; i < totalRound; ++i)
647 {
648 bool allDone = true;
649 {
651 for (auto const& t : replayer.tasks_)
652 {
653 if (!t->finished())
654 {
655 allDone = false;
656 break;
657 }
658 }
659 }
660 if (allDone)
661 return true;
662 if (i < totalRound - 1)
664 }
665 return false;
666 }
667
670 {
672 return replayer.tasks_;
673 }
674
676 findTask(uint256 const& hash, int totalReplay)
677 {
679 auto i = std::find_if(
680 replayer.tasks_.begin(), replayer.tasks_.end(), [&](auto const& t) {
681 return t->parameter_.finishHash_ == hash &&
682 t->parameter_.totalLedgers_ == totalReplay;
683 });
684 if (i == replayer.tasks_.end())
685 return {};
686 return *i;
687 }
688
691 {
693 return replayer.deltas_.size();
694 }
695
698 {
700 return replayer.skipLists_.size();
701 }
702
703 bool
705 std::size_t tasks,
706 std::size_t skipLists,
707 std::size_t deltas)
708 {
710 return replayer.tasks_.size() == tasks &&
711 replayer.skipLists_.size() == skipLists &&
712 replayer.deltas_.size() == deltas;
713 }
714
717 {
719 auto i = replayer.skipLists_.find(hash);
720 if (i == replayer.skipLists_.end())
721 return {};
722 return i->second.lock();
723 }
724
727 {
729 auto i = replayer.deltas_.find(hash);
730 if (i == replayer.deltas_.end())
731 return {};
732 return i->second.lock();
733 }
734
735 template <typename T>
738 {
739 if (t->failed_)
740 return TaskStatus::Failed;
741 if (t->complete_)
743 return TaskStatus::NotDone;
744 }
745
746 bool
749 TaskStatus taskExpect,
750 TaskStatus skiplistExpect,
751 std::vector<TaskStatus> const& deltaExpects)
752 {
753 if (taskStatus(task) == taskExpect)
754 {
755 if (taskStatus(task->skipListAcquirer_) == skiplistExpect)
756 {
757 if (task->deltas_.size() == deltaExpects.size())
758 {
759 for (int i = 0; i < deltaExpects.size(); ++i)
760 {
761 if (taskStatus(task->deltas_[i]) != deltaExpects[i])
762 return false;
763 }
764 return true;
765 }
766 }
767 }
768 return false;
769 }
770
771 bool
773 uint256 const& hash,
774 int totalReplay,
775 TaskStatus taskExpect,
776 TaskStatus skiplistExpect,
777 std::vector<TaskStatus> const& deltaExpects)
778 {
779 auto t = findTask(hash, totalReplay);
780 if (!t)
781 {
782 if (taskExpect == TaskStatus::NotExist)
783 return true;
784 return false;
785 }
786
787 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
788 }
789
790 bool
792 uint256 const& hash,
793 int totalReplay,
794 TaskStatus taskExpect,
795 TaskStatus skiplistExpect,
796 std::vector<TaskStatus> const& deltaExpects)
797 {
798 auto t = findTask(hash, totalReplay);
799 if (!t)
800 {
801 if (taskExpect == TaskStatus::NotExist)
802 return true;
803 return false;
804 }
805
806 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
807 }
808
809 bool
811 uint256 const& hash,
812 int totalReplay,
813 TaskStatus taskExpect,
814 TaskStatus skiplistExpect,
815 std::vector<TaskStatus> const& deltaExpects)
816 {
817 if (!waitForDone())
818 return false;
819
820 return checkStatus(
821 hash, totalReplay, taskExpect, skiplistExpect, deltaExpects);
822 }
823
831};
832
833using namespace beast::severities;
834void
836 LedgerServer& server,
837 LedgerReplayClient& client,
838 beast::severities::Severity level = Severity::kTrace)
839{
840 server.app.logs().threshold(level);
841 client.app.logs().threshold(level);
842}
843// logAll(net.server, net.client);
844
845/*
846 * Create a LedgerServer and a LedgerReplayClient
847 */
849{
852 LedgerServer::Parameter const& param,
856 : server(suite, param)
857 , client(suite, server, behavior, inboundBhvr, peerFeature)
858 {
859 // logAll(server, client);
860 }
863};
864
891{
892 void
894 {
895 testcase("ProofPath");
896 LedgerServer server(*this, {1});
897 auto const l = server.ledgerMaster.getClosedLedger();
898
899 {
900 // request, missing key
901 auto request = std::make_shared<protocol::TMProofPathRequest>();
902 request->set_ledgerhash(
903 l->info().hash.data(), l->info().hash.size());
904 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
905 auto reply = std::make_shared<protocol::TMProofPathResponse>(
906 server.msgHandler.processProofPathRequest(request));
907 BEAST_EXPECT(reply->has_error());
908 BEAST_EXPECT(!server.msgHandler.processProofPathResponse(reply));
909 }
910 {
911 // request, wrong hash
912 auto request = std::make_shared<protocol::TMProofPathRequest>();
913 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
914 request->set_key(
915 keylet::skip().key.data(), keylet::skip().key.size());
916 uint256 hash(1234567);
917 request->set_ledgerhash(hash.data(), hash.size());
918 auto reply = std::make_shared<protocol::TMProofPathResponse>(
919 server.msgHandler.processProofPathRequest(request));
920 BEAST_EXPECT(reply->has_error());
921 }
922
923 {
924 // good request
925 auto request = std::make_shared<protocol::TMProofPathRequest>();
926 request->set_ledgerhash(
927 l->info().hash.data(), l->info().hash.size());
928 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
929 request->set_key(
930 keylet::skip().key.data(), keylet::skip().key.size());
931 // generate response
932 auto reply = std::make_shared<protocol::TMProofPathResponse>(
933 server.msgHandler.processProofPathRequest(request));
934 BEAST_EXPECT(!reply->has_error());
935 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
936
937 {
938 // bad reply
939 // bad header
940 std::string r(reply->ledgerheader());
941 r.back()--;
942 reply->set_ledgerheader(r);
943 BEAST_EXPECT(
944 !server.msgHandler.processProofPathResponse(reply));
945 r.back()++;
946 reply->set_ledgerheader(r);
947 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
948 // bad proof path
949 reply->mutable_path()->RemoveLast();
950 BEAST_EXPECT(
951 !server.msgHandler.processProofPathResponse(reply));
952 }
953 }
954 }
955
956 void
958 {
959 testcase("ReplayDelta");
960 LedgerServer server(*this, {1});
961 auto const l = server.ledgerMaster.getClosedLedger();
962
963 {
964 // request, missing hash
965 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
966 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
967 server.msgHandler.processReplayDeltaRequest(request));
968 BEAST_EXPECT(reply->has_error());
969 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
970 // request, wrong hash
971 uint256 hash(1234567);
972 request->set_ledgerhash(hash.data(), hash.size());
973 reply = std::make_shared<protocol::TMReplayDeltaResponse>(
974 server.msgHandler.processReplayDeltaRequest(request));
975 BEAST_EXPECT(reply->has_error());
976 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
977 }
978
979 {
980 // good request
981 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
982 request->set_ledgerhash(
983 l->info().hash.data(), l->info().hash.size());
984 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
985 server.msgHandler.processReplayDeltaRequest(request));
986 BEAST_EXPECT(!reply->has_error());
987 BEAST_EXPECT(server.msgHandler.processReplayDeltaResponse(reply));
988
989 {
990 // bad reply
991 // bad header
992 std::string r(reply->ledgerheader());
993 r.back()--;
994 reply->set_ledgerheader(r);
995 BEAST_EXPECT(
996 !server.msgHandler.processReplayDeltaResponse(reply));
997 r.back()++;
998 reply->set_ledgerheader(r);
999 BEAST_EXPECT(
1000 server.msgHandler.processReplayDeltaResponse(reply));
1001 // bad txns
1002 reply->mutable_transaction()->RemoveLast();
1003 BEAST_EXPECT(
1004 !server.msgHandler.processReplayDeltaResponse(reply));
1005 }
1006 }
1007 }
1008
1009 void
1011 {
1012 testcase("TaskParameter");
1013
1014 auto makeSkipList = [](int count) -> std::vector<uint256> const {
1016 for (int i = 0; i < count; ++i)
1017 sList.emplace_back(i);
1018 return sList;
1019 };
1020
1023 BEAST_EXPECT(!tp10.update(uint256(777), 5, makeSkipList(10)));
1024 BEAST_EXPECT(!tp10.update(uint256(10), 5, makeSkipList(8)));
1025 BEAST_EXPECT(tp10.update(uint256(10), 10, makeSkipList(10)));
1026
1027 // can merge to self
1028 BEAST_EXPECT(tp10.canMergeInto(tp10));
1029
1030 // smaller task
1033
1034 BEAST_EXPECT(tp9.canMergeInto(tp10));
1035 BEAST_EXPECT(!tp10.canMergeInto(tp9));
1036
1037 tp9.totalLedgers_++;
1038 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1039 tp9.totalLedgers_--;
1040 BEAST_EXPECT(tp9.canMergeInto(tp10));
1041
1043 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1045 BEAST_EXPECT(tp9.canMergeInto(tp10));
1046
1047 tp9.finishHash_ = uint256(1234);
1048 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1049 tp9.finishHash_ = uint256(9);
1050 BEAST_EXPECT(tp9.canMergeInto(tp10));
1051
1052 // larger task
1055 BEAST_EXPECT(tp20.update(uint256(20), 20, makeSkipList(20)));
1056 BEAST_EXPECT(tp10.canMergeInto(tp20));
1057 BEAST_EXPECT(tp9.canMergeInto(tp20));
1058 BEAST_EXPECT(!tp20.canMergeInto(tp10));
1059 BEAST_EXPECT(!tp20.canMergeInto(tp9));
1060 }
1061
1062 void
1064 {
1065 testcase("config test");
1066 {
1067 Config c;
1068 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1069 }
1070
1071 {
1072 Config c;
1073 std::string toLoad(R"rippleConfig(
1074[ledger_replay]
10751
1076)rippleConfig");
1077 c.loadFromString(toLoad);
1078 BEAST_EXPECT(c.LEDGER_REPLAY == true);
1079 }
1080
1081 {
1082 Config c;
1083 std::string toLoad = (R"rippleConfig(
1084[ledger_replay]
10850
1086)rippleConfig");
1087 c.loadFromString(toLoad);
1088 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1089 }
1090 }
1091
1092 void
1094 {
1095 testcase("handshake test");
1096 auto handshake = [&](bool client, bool server, bool expecting) -> bool {
1097 auto request =
1098 ripple::makeRequest(true, false, client, false, false);
1099 http_request_type http_request;
1100 http_request.version(request.version());
1101 http_request.base() = request.base();
1102 bool serverResult =
1103 peerFeatureEnabled(http_request, FEATURE_LEDGER_REPLAY, server);
1104 if (serverResult != expecting)
1105 return false;
1106
1107 beast::IP::Address addr =
1108 boost::asio::ip::address::from_string("172.1.1.100");
1109 jtx::Env serverEnv(*this);
1110 serverEnv.app().config().LEDGER_REPLAY = server;
1111 auto http_resp = ripple::makeResponse(
1112 true,
1113 http_request,
1114 addr,
1115 addr,
1116 uint256{1},
1117 1,
1118 {1, 0},
1119 serverEnv.app());
1120 auto const clientResult =
1121 peerFeatureEnabled(http_resp, FEATURE_LEDGER_REPLAY, client);
1122 if (clientResult != expecting)
1123 return false;
1124
1125 return true;
1126 };
1127
1128 BEAST_EXPECT(handshake(false, false, false));
1129 BEAST_EXPECT(handshake(false, true, false));
1130 BEAST_EXPECT(handshake(true, false, false));
1131 BEAST_EXPECT(handshake(true, true, true));
1132 }
1133
1134 void
1135 testAllLocal(int totalReplay)
1136 {
1137 testcase("local node has all the ledgers");
1138 auto psBhvr = PeerSetBehavior::DropAll;
1139 auto ilBhvr = InboundLedgersBehavior::DropAll;
1140 auto peerFeature = PeerFeature::None;
1141
1142 NetworkOfTwo net(*this, {totalReplay + 1}, psBhvr, ilBhvr, peerFeature);
1143
1144 auto l = net.server.ledgerMaster.getClosedLedger();
1145 uint256 finalHash = l->info().hash;
1146 for (int i = 0; i < totalReplay; ++i)
1147 {
1148 BEAST_EXPECT(l);
1149 if (l)
1150 {
1151 net.client.ledgerMaster.storeLedger(l);
1152 l = net.server.ledgerMaster.getLedgerByHash(
1153 l->info().parentHash);
1154 }
1155 else
1156 break;
1157 }
1158
1159 net.client.replayer.replay(
1160 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1161
1162 std::vector<TaskStatus> deltaStatuses(
1163 totalReplay - 1, TaskStatus::Completed);
1164 BEAST_EXPECT(net.client.waitAndCheckStatus(
1165 finalHash,
1166 totalReplay,
1169 deltaStatuses));
1170
1171 // sweep
1172 net.client.replayer.sweep();
1173 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1174 }
1175
1176 void
1177 testAllInboundLedgers(int totalReplay)
1178 {
1179 testcase("all the ledgers from InboundLedgers");
1180 NetworkOfTwo net(
1181 *this,
1182 {totalReplay + 1},
1186
1187 auto l = net.server.ledgerMaster.getClosedLedger();
1188 uint256 finalHash = l->info().hash;
1189 net.client.replayer.replay(
1190 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1191
1192 std::vector<TaskStatus> deltaStatuses(
1193 totalReplay - 1, TaskStatus::Completed);
1194 BEAST_EXPECT(net.client.waitAndCheckStatus(
1195 finalHash,
1196 totalReplay,
1199 deltaStatuses));
1200
1201 // sweep
1202 net.client.replayer.sweep();
1203 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1204 }
1205
1206 void
1207 testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay = 4)
1208 {
1209 switch (peerSetBehavior)
1210 {
1212 testcase("good network");
1213 break;
1215 testcase("network drops 50% messages");
1216 break;
1218 testcase("network repeats all messages");
1219 break;
1220 default:
1221 return;
1222 }
1223
1224 NetworkOfTwo net(
1225 *this,
1226 {totalReplay + 1},
1227 peerSetBehavior,
1230
1231 // feed client with start ledger since InboundLedgers drops all
1232 auto l = net.server.ledgerMaster.getClosedLedger();
1233 uint256 finalHash = l->info().hash;
1234 for (int i = 0; i < totalReplay - 1; ++i)
1235 {
1236 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1237 }
1238 net.client.ledgerMaster.storeLedger(l);
1239
1240 net.client.replayer.replay(
1241 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1242
1243 std::vector<TaskStatus> deltaStatuses(
1244 totalReplay - 1, TaskStatus::Completed);
1245 BEAST_EXPECT(net.client.waitAndCheckStatus(
1246 finalHash,
1247 totalReplay,
1250 deltaStatuses));
1251 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1252
1253 // sweep
1254 net.client.replayer.sweep();
1255 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1256 }
1257
1258 void
1260 {
1261 testcase("stop before timeout");
1262 int totalReplay = 3;
1263 NetworkOfTwo net(
1264 *this,
1265 {totalReplay + 1},
1269
1270 auto l = net.server.ledgerMaster.getClosedLedger();
1271 uint256 finalHash = l->info().hash;
1272 net.client.replayer.replay(
1273 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1274
1275 std::vector<TaskStatus> deltaStatuses;
1276 BEAST_EXPECT(net.client.checkStatus(
1277 finalHash,
1278 totalReplay,
1281 deltaStatuses));
1282
1283 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1284 net.client.replayer.stop();
1285 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1286 }
1287
1288 void
1290 {
1291 testcase("SkipListAcquire bad reply");
1292 int totalReplay = 3;
1293 NetworkOfTwo net(
1294 *this,
1295 {totalReplay + 1 + 1},
1299
1300 auto l = net.server.ledgerMaster.getClosedLedger();
1301 uint256 finalHash = l->info().hash;
1302 net.client.replayer.replay(
1303 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1304
1305 auto skipList = net.client.findSkipListAcquire(finalHash);
1306
1307 std::uint8_t payload[55] = {
1308 0x6A, 0x09, 0xE6, 0x67, 0xF3, 0xBC, 0xC9, 0x08, 0xB2};
1309 auto item =
1310 make_shamapitem(uint256(12345), Slice(payload, sizeof(payload)));
1311 skipList->processData(l->seq(), item);
1312
1313 std::vector<TaskStatus> deltaStatuses;
1314 BEAST_EXPECT(net.client.waitAndCheckStatus(
1315 finalHash,
1316 totalReplay,
1319 deltaStatuses));
1320
1321 // add another task
1322 net.client.replayer.replay(
1323 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1324 BEAST_EXPECT(net.client.waitAndCheckStatus(
1325 finalHash,
1326 totalReplay,
1329 deltaStatuses));
1330 BEAST_EXPECT(net.client.countsAsExpected(2, 1, 0));
1331 }
1332
1333 void
1335 {
1336 testcase("LedgerDeltaAcquire bad reply");
1337 int totalReplay = 3;
1338 NetworkOfTwo net(
1339 *this,
1340 {totalReplay + 1},
1344
1345 auto l = net.server.ledgerMaster.getClosedLedger();
1346 uint256 finalHash = l->info().hash;
1347 net.client.ledgerMaster.storeLedger(l);
1348 net.client.replayer.replay(
1349 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1350
1351 auto delta = net.client.findLedgerDeltaAcquire(l->info().parentHash);
1352 delta->processData(
1353 l->info(), // wrong ledger info
1355 BEAST_EXPECT(net.client.taskStatus(delta) == TaskStatus::Failed);
1356 BEAST_EXPECT(
1357 net.client.taskStatus(net.client.findTask(
1358 finalHash, totalReplay)) == TaskStatus::Failed);
1359
1360 // add another task
1361 net.client.replayer.replay(
1362 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1363 BEAST_EXPECT(
1364 net.client.taskStatus(net.client.findTask(
1365 finalHash, totalReplay + 1)) == TaskStatus::Failed);
1366 }
1367
1368 void
1370 {
1371 testcase("Overlap tasks");
1372 int totalReplay = 5;
1373 NetworkOfTwo net(
1374 *this,
1375 {totalReplay * 3 + 1},
1379 auto l = net.server.ledgerMaster.getClosedLedger();
1380 uint256 finalHash = l->info().hash;
1381 net.client.replayer.replay(
1382 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1383 std::vector<TaskStatus> deltaStatuses(
1384 totalReplay - 1, TaskStatus::Completed);
1385 BEAST_EXPECT(net.client.waitAndCheckStatus(
1386 finalHash,
1387 totalReplay,
1390 deltaStatuses));
1391 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1392
1393 // same range, same reason
1394 net.client.replayer.replay(
1395 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1396 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1397 // same range, different reason
1398 net.client.replayer.replay(
1399 InboundLedger::Reason::CONSENSUS, finalHash, totalReplay);
1400 BEAST_EXPECT(net.client.countsAsExpected(2, 1, totalReplay - 1));
1401
1402 // no overlap
1403 for (int i = 0; i < totalReplay + 2; ++i)
1404 {
1405 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1406 }
1407 auto finalHash_early = l->info().hash;
1408 net.client.replayer.replay(
1409 InboundLedger::Reason::GENERIC, finalHash_early, totalReplay);
1410 BEAST_EXPECT(net.client.waitAndCheckStatus(
1411 finalHash_early,
1412 totalReplay,
1415 deltaStatuses)); // deltaStatuses no change
1416 BEAST_EXPECT(net.client.waitForLedgers(finalHash_early, totalReplay));
1417 BEAST_EXPECT(net.client.countsAsExpected(3, 2, 2 * (totalReplay - 1)));
1418
1419 // partial overlap
1420 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1421 auto finalHash_moreEarly = l->info().parentHash;
1422 net.client.replayer.replay(
1423 InboundLedger::Reason::GENERIC, finalHash_moreEarly, totalReplay);
1424 BEAST_EXPECT(net.client.waitAndCheckStatus(
1425 finalHash_moreEarly,
1426 totalReplay,
1429 deltaStatuses)); // deltaStatuses no change
1430 BEAST_EXPECT(
1431 net.client.waitForLedgers(finalHash_moreEarly, totalReplay));
1432 BEAST_EXPECT(
1433 net.client.countsAsExpected(4, 3, 2 * (totalReplay - 1) + 2));
1434
1435 // cover
1436 net.client.replayer.replay(
1437 InboundLedger::Reason::GENERIC, finalHash, totalReplay * 3);
1438 deltaStatuses =
1439 std::vector<TaskStatus>(totalReplay * 3 - 1, TaskStatus::Completed);
1440 BEAST_EXPECT(net.client.waitAndCheckStatus(
1441 finalHash,
1442 totalReplay * 3,
1445 deltaStatuses)); // deltaStatuses changed
1446 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay * 3));
1447 BEAST_EXPECT(net.client.countsAsExpected(5, 3, totalReplay * 3 - 1));
1448
1449 // sweep
1450 net.client.replayer.sweep();
1451 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1452 }
1453
1454 void
1455 run() override
1456 {
1457 testProofPath();
1460 testConfig();
1461 testHandshake();
1462 testAllLocal(1);
1463 testAllLocal(3);
1470 testStop();
1474 }
1475};
1476
1478{
1479 void
1481 {
1482 testcase("SkipListAcquire timeout");
1483 int totalReplay = 3;
1484 NetworkOfTwo net(
1485 *this,
1486 {totalReplay + 1},
1490
1491 auto l = net.server.ledgerMaster.getClosedLedger();
1492 uint256 finalHash = l->info().hash;
1493 net.client.replayer.replay(
1494 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1495
1496 std::vector<TaskStatus> deltaStatuses;
1497 BEAST_EXPECT(net.client.waitAndCheckStatus(
1498 finalHash,
1499 totalReplay,
1502 deltaStatuses));
1503
1504 // sweep
1505 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1506 net.client.replayer.sweep();
1507 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1508 }
1509
1510 void
1512 {
1513 testcase("LedgerDeltaAcquire timeout");
1514 int totalReplay = 3;
1515 NetworkOfTwo net(
1516 *this,
1517 {totalReplay + 1},
1521
1522 auto l = net.server.ledgerMaster.getClosedLedger();
1523 uint256 finalHash = l->info().hash;
1524 net.client.ledgerMaster.storeLedger(l);
1525 net.client.replayer.replay(
1526 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1527
1528 std::vector<TaskStatus> deltaStatuses(
1529 totalReplay - 1, TaskStatus::Failed);
1530 deltaStatuses.back() = TaskStatus::Completed; // in client ledgerMaster
1531 BEAST_EXPECT(net.client.waitAndCheckStatus(
1532 finalHash,
1533 totalReplay,
1536 deltaStatuses));
1537
1538 // sweep
1539 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1540 net.client.replayer.sweep();
1541 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1542 }
1543
1544 void
1545 run() override
1546 {
1549 }
1550};
1551
1553{
1554 void
1555 run() override
1556 {
1557 testcase("Acquire 1000 ledgers");
1558 int totalReplay = 250;
1559 int rounds = 4;
1560 NetworkOfTwo net(
1561 *this,
1562 {totalReplay * rounds + 1},
1566
1567 std::vector<uint256> finishHashes;
1568 auto l = net.server.ledgerMaster.getClosedLedger();
1569 for (int i = 0; i < rounds; ++i)
1570 {
1571 finishHashes.push_back(l->info().hash);
1572 for (int j = 0; j < totalReplay; ++j)
1573 {
1574 l = net.server.ledgerMaster.getLedgerByHash(
1575 l->info().parentHash);
1576 }
1577 }
1578 BEAST_EXPECT(finishHashes.size() == rounds);
1579
1580 for (int i = 0; i < rounds; ++i)
1581 {
1582 net.client.replayer.replay(
1583 InboundLedger::Reason::GENERIC, finishHashes[i], totalReplay);
1584 }
1585
1586 std::vector<TaskStatus> deltaStatuses(
1587 totalReplay - 1, TaskStatus::Completed);
1588 for (int i = 0; i < rounds; ++i)
1589 {
1590 BEAST_EXPECT(net.client.waitAndCheckStatus(
1591 finishHashes[i],
1592 totalReplay,
1595 deltaStatuses));
1596 }
1597
1598 BEAST_EXPECT(
1599 net.client.waitForLedgers(finishHashes[0], totalReplay * rounds));
1600 BEAST_EXPECT(net.client.countsAsExpected(
1601 rounds, rounds, rounds * (totalReplay - 1)));
1602
1603 // sweep
1604 net.client.replayer.sweep();
1605 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1606 }
1607};
1608
1609BEAST_DEFINE_TESTSUITE(LedgerReplay, app, ripple);
1610BEAST_DEFINE_TESTSUITE_PRIO(LedgerReplayer, app, ripple, 1);
1611BEAST_DEFINE_TESTSUITE(LedgerReplayerTimeout, app, ripple);
1612BEAST_DEFINE_TESTSUITE_MANUAL(LedgerReplayerLong, app, ripple);
1613
1614} // namespace test
1615} // namespace ripple
T back(T... args)
Represents a JSON value.
Definition: json_value.h:147
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
A testsuite class.
Definition: suite.h:53
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:153
virtual Config & config()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual Logs & logs()=0
bool LEDGER_REPLAY
Definition: Config.h:230
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
Definition: Config.cpp:476
Manages the lifetime of inbound ledgers.
std::shared_ptr< Ledger const > getClosedLedger()
Definition: LedgerMaster.h:80
bool storeLedger(std::shared_ptr< Ledger const > ledger)
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
protocol::TMReplayDeltaResponse processReplayDeltaRequest(std::shared_ptr< protocol::TMReplayDeltaRequest > const &msg)
Process TMReplayDeltaRequest and return TMReplayDeltaResponse.
bool processProofPathResponse(std::shared_ptr< protocol::TMProofPathResponse > const &msg)
Process TMProofPathResponse.
bool processReplayDeltaResponse(std::shared_ptr< protocol::TMReplayDeltaResponse > const &msg)
Process TMReplayDeltaResponse.
protocol::TMProofPathResponse processProofPathRequest(std::shared_ptr< protocol::TMProofPathRequest > const &msg)
Process TMProofPathRequest and return TMProofPathResponse.
bool update(uint256 const &hash, std::uint32_t seq, std::vector< uint256 > const &sList)
fill all the fields that was not filled during construction
bool canMergeInto(TaskParameter const &existingTask) const
check if this task can be merged into an existing task
Manages the lifetime of ledger replay tasks.
std::vector< std::shared_ptr< LedgerReplayTask > > tasks_
hash_map< uint256, std::weak_ptr< SkipListAcquire > > skipLists_
hash_map< uint256, std::weak_ptr< LedgerDeltaAcquire > > deltas_
beast::severities::Severity threshold() const
Definition: Log.cpp:150
Supports data retrieval by managing a set of peers.
Definition: PeerSet.h:45
Represents a peer connection in the overlay.
std::uint32_t id_t
Uniquely identifies a peer.
A public key.
Definition: PublicKey.h:62
A consumption charge.
Definition: Charge.h:31
An immutable linear range of bytes.
Definition: Slice.h:45
pointer data()
Definition: base_uint.h:124
static constexpr std::size_t size()
Definition: base_uint.h:525
Ledger replay client side.
bool waitForLedgers(uint256 const &finishLedgerHash, int totalReplay)
bool asExpected(uint256 const &hash, int totalReplay, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
bool waitAndCheckStatus(uint256 const &hash, int totalReplay, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
LedgerReplayMsgHandler clientMsgHandler
std::shared_ptr< LedgerReplayTask > findTask(uint256 const &hash, int totalReplay)
LedgerReplayMsgHandler serverMsgHandler
bool countsAsExpected(std::size_t tasks, std::size_t skipLists, std::size_t deltas)
bool asExpected(std::shared_ptr< LedgerReplayTask > const &task, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
std::vector< std::shared_ptr< LedgerReplayTask > > getTasks()
std::shared_ptr< LedgerDeltaAcquire > findLedgerDeltaAcquire(uint256 const &hash)
bool haveLedgers(uint256 const &finishLedgerHash, int totalReplay)
LedgerReplayClient(beast::unit_test::suite &suite, LedgerServer &server, PeerSetBehavior behavior=PeerSetBehavior::Good, InboundLedgersBehavior inboundBhvr=InboundLedgersBehavior::Good, PeerFeature peerFeature=PeerFeature::LedgerReplayEnabled)
bool checkStatus(uint256 const &hash, int totalReplay, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
TaskStatus taskStatus(std::shared_ptr< T > const &t)
void addLedger(std::shared_ptr< Ledger const > const &l)
std::shared_ptr< SkipListAcquire > findSkipListAcquire(uint256 const &hash)
Simulate a network InboundLedgers.
virtual void acquireAsync(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason reason) override
virtual void onLedgerFetched() override
Called when a complete ledger is obtained.
virtual void clearFailures() override
virtual bool gotLedgerData(LedgerHash const &ledgerHash, std::shared_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData >) override
virtual std::shared_ptr< InboundLedger > find(LedgerHash const &hash) override
virtual ~MagicInboundLedgers()=default
virtual Json::Value getInfo() override
virtual size_t cacheSize() override
virtual void logFailure(uint256 const &h, std::uint32_t seq) override
MagicInboundLedgers(LedgerMaster &ledgerSource, LedgerMaster &ledgerSink, InboundLedgersBehavior bhvr)
virtual bool isFailure(uint256 const &h) override
virtual void gotStaleData(std::shared_ptr< protocol::TMLedgerData > packet) override
virtual std::size_t fetchRate() override
Returns the rate of historical ledger fetches per minute.
virtual void gotFetchPack() override
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason) override
std::unique_ptr< PeerSet > build() override
TestPeerSetBuilder(LedgerReplayMsgHandler &me, LedgerReplayMsgHandler &other, PeerSetBehavior bhvr, PeerFeature peerFeature)
Simulate a network peer.
bool hasLedger(uint256 const &hash, std::uint32_t seq) const override
void setPublisherListSequence(PublicKey const &, std::size_t const) override
bool cluster() const override
Returns true if this connection is a member of the cluster.
std::optional< std::size_t > publisherListSequence(PublicKey const &) const override
beast::IP::Endpoint getRemoteAddress() const override
void removeTxQueue(const uint256 &) override
Remove hash from the transactions' hashes queue.
TestPeer(bool enableLedgerReplay)
int getScore(bool) const override
PublicKey const & getNodePublic() const override
void charge(Resource::Charge const &fee, std::string const &context={}) override
Adjust this peer's load balance based on the type of load imposed.
Json::Value json() override
void send(std::shared_ptr< Message > const &m) override
void ledgerRange(std::uint32_t &minSeq, std::uint32_t &maxSeq) const override
id_t id() const override
bool txReduceRelayEnabled() const override
bool isHighLatency() const override
bool hasTxSet(uint256 const &hash) const override
void addTxQueue(const uint256 &) override
Aggregate transaction's hash.
uint256 const & getClosedLedgerHash() const override
bool compressionEnabled() const override
bool hasRange(std::uint32_t uMin, std::uint32_t uMax) override
bool supportsFeature(ProtocolFeature f) const override
void sendTxQueue() override
Send aggregated transactions' hashes.
Immutable cryptographic account descriptor.
Definition: Account.h:38
A transaction testing environment.
Definition: Env.h:117
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition: Env.cpp:121
Application & app()
Definition: Env.h:255
beast::Journal const journal
Definition: Env.h:158
Env & apply(JsonValue &&jv, FN const &... fN)
Apply funclets and submit.
Definition: Env.h:564
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:237
Set the fee on a JTx.
Definition: fee.h:36
Set the regular signature on a JTx.
Definition: sig.h:35
T count(T... args)
T emplace_back(T... args)
T find_if(T... args)
T insert(T... args)
boost::asio::ip::address Address
Definition: IPAddress.h:41
A namespace for easy access to logging severity values.
Definition: Journal.h:29
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:31
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:172
static autofill_t const autofill
Definition: tags.h:42
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:29
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:54
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:104
static uint256 ledgerHash(LedgerInfo const &info)
void logAll(LedgerServer &server, LedgerReplayClient &client, beast::severities::Severity level=Severity::kTrace)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::shared_ptr< Ledger > buildLedger(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, const bool closeTimeCorrect, NetClock::duration closeResolution, Application &app, CanonicalTXSet &txns, std::set< TxID > &failedTxs, beast::Journal j)
Build a new ledger by applying consensus transactions.
base_uint< 256 > uint256
Definition: base_uint.h:557
http_response_type makeResponse(bool crawlPublic, http_request_type const &req, beast::IP::Address public_ip, beast::IP::Address remote_ip, uint256 const &sharedValue, std::optional< std::uint32_t > networkID, ProtocolVersion protocol, Application &app)
Make http response.
Definition: Handshake.cpp:389
static constexpr char FEATURE_LEDGER_REPLAY[]
Definition: Handshake.h:148
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
Definition: SecretKey.cpp:313
SecretKey randomSecretKey()
Create a secret key using secure random numbers.
Definition: SecretKey.cpp:281
KeyType
Definition: KeyType.h:28
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handoff.h:31
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition: SHAMapItem.h:160
bool peerFeatureEnabled(headers const &request, std::string const &feature, std::string value, bool config)
Check if a feature should be enabled for a peer.
Definition: Handshake.h:199
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
Definition: Handshake.cpp:362
@ tapNONE
Definition: ApplyView.h:31
@ ledgerMaster
ledger master data for signing
STL namespace.
T push_back(T... args)
T size(T... args)
T sleep_for(T... args)
uint256 key
Definition: Keylet.h:40
void run() override
Runs the suite.
void run() override
Runs the suite.
Test cases: LedgerReplayer_test: – process TMProofPathRequest and TMProofPathResponse – process TMRep...
void run() override
Runs the suite.
void testAllInboundLedgers(int totalReplay)
void testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay=4)
Utility class for (1) creating ledgers with txns and (2) providing the ledgers via the ledgerMaster.
void createAccounts(int newAccounts)
LedgerReplayMsgHandler msgHandler
std::vector< jtx::Account > accounts
void createLedgerHistory()
create ledger history
LedgerServer(beast::unit_test::suite &suite, Parameter const &p)
NetworkOfTwo(beast::unit_test::suite &suite, LedgerServer::Parameter const &param, PeerSetBehavior behavior=PeerSetBehavior::Good, InboundLedgersBehavior inboundBhvr=InboundLedgersBehavior::Good, PeerFeature peerFeature=PeerFeature::LedgerReplayEnabled)
Simulate a peerSet that supplies peers to ledger replay subtasks.
void addPeers(std::size_t limit, std::function< bool(std::shared_ptr< Peer > const &)> hasItem, std::function< void(std::shared_ptr< Peer > const &)> onPeerAdded) override
Try add more peers.
LedgerReplayMsgHandler & remote
TestPeerSet(LedgerReplayMsgHandler &me, LedgerReplayMsgHandler &other, PeerSetBehavior bhvr, bool enableLedgerReplay)
void sendRequest(::google::protobuf::Message const &msg, protocol::MessageType type, std::shared_ptr< Peer > const &peer) override
LedgerReplayMsgHandler & local
std::shared_ptr< TestPeer > dummyPeer
const std::set< Peer::id_t > & getPeerIds() const override
get the set of ids of previously added peers
Set the sequence number on a JTx.
Definition: seq.h:34
T to_string(T... args)