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) override
225 {
226 }
227 id_t
228 id() const override
229 {
230 return 1234;
231 }
232 bool
233 cluster() const override
234 {
235 return false;
236 }
237 bool
238 isHighLatency() const override
239 {
240 return false;
241 }
242 int
243 getScore(bool) const override
244 {
245 return 0;
246 }
247 PublicKey const&
248 getNodePublic() const override
249 {
250 return nodePublicKey_;
251 }
253 json() override
254 {
255 return {};
256 }
257 bool
259 {
261 return true;
262 return false;
263 }
265 publisherListSequence(PublicKey const&) const override
266 {
267 return {};
268 }
269 void
271 {
272 }
273 uint256 const&
274 getClosedLedgerHash() const override
275 {
276 static uint256 hash{};
277 return hash;
278 }
279 bool
280 hasLedger(uint256 const& hash, std::uint32_t seq) const override
281 {
282 return true;
283 }
284 void
285 ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override
286 {
287 }
288 bool
289 hasTxSet(uint256 const& hash) const override
290 {
291 return false;
292 }
293 void
294 cycleStatus() override
295 {
296 }
297 bool
299 {
300 return false;
301 }
302 bool
303 compressionEnabled() const override
304 {
305 return false;
306 }
307 void
308 sendTxQueue() override
309 {
310 }
311 void
312 addTxQueue(const uint256&) override
313 {
314 }
315 void
316 removeTxQueue(const uint256&) override
317 {
318 }
319 bool
320 txReduceRelayEnabled() const override
321 {
322 return false;
323 }
324
327};
328
329enum class PeerSetBehavior {
330 Good,
331 Drop50,
332 DropAll,
335 Repeat,
336};
337
344struct TestPeerSet : public PeerSet
345{
349 PeerSetBehavior bhvr,
350 bool enableLedgerReplay)
351 : local(me)
352 , remote(other)
353 , dummyPeer(std::make_shared<TestPeer>(enableLedgerReplay))
354 , behavior(bhvr)
355 {
356 }
357
358 void
360 std::size_t limit,
361 std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
362 std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) override
363 {
364 hasItem(dummyPeer);
365 onPeerAdded(dummyPeer);
366 }
367
368 void
370 ::google::protobuf::Message const& msg,
371 protocol::MessageType type,
372 std::shared_ptr<Peer> const& peer) override
373 {
374 int dropRate = 0;
376 dropRate = 50;
378 dropRate = 100;
379
380 if ((rand() % 100 + 1) <= dropRate)
381 return;
382
383 switch (type)
384 {
385 case protocol::mtPROOF_PATH_REQ: {
387 return;
388 auto request = std::make_shared<protocol::TMProofPathRequest>(
389 dynamic_cast<protocol::TMProofPathRequest const&>(msg));
390 auto reply = std::make_shared<protocol::TMProofPathResponse>(
395 break;
396 }
397 case protocol::mtREPLAY_DELTA_REQ: {
399 return;
400 auto request = std::make_shared<protocol::TMReplayDeltaRequest>(
401 dynamic_cast<protocol::TMReplayDeltaRequest const&>(msg));
402 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
407 break;
408 }
409 default:
410 return;
411 }
412 }
413
415 getPeerIds() const override
416 {
417 static std::set<Peer::id_t> emptyPeers;
418 return emptyPeers;
419 }
420
425};
426
431{
432public:
436 PeerSetBehavior bhvr,
437 PeerFeature peerFeature)
438 : local(me)
439 , remote(other)
440 , behavior(bhvr)
442 {
443 }
444
446 build() override
447 {
448 return std::make_unique<TestPeerSet>(
450 }
451
452private:
457};
458
464{
466 {
468 int initAccounts = 10;
469 int initAmount = 1'000'000;
471 int txAmount = 10;
472 };
473
475 : env(suite)
476 , app(env.app())
477 , ledgerMaster(env.app().getLedgerMaster())
478 , msgHandler(env.app(), env.app().getLedgerReplayer())
479 , param(p)
480 {
481 assert(param.initLedgers > 0);
485 }
486
490 void
491 createAccounts(int newAccounts)
492 {
493 auto fundedAccounts = accounts.size();
494 for (int i = 0; i < newAccounts; ++i)
495 {
496 accounts.emplace_back(
497 "alice_" + std::to_string(fundedAccounts + i));
499 }
500 env.close();
501 }
502
506 void
507 sendPayments(int newTxes)
508 {
509 int fundedAccounts = accounts.size();
510 assert(fundedAccounts >= newTxes);
512
513 // somewhat random but reproducible
514 int r = ledgerMaster.getClosedLedger()->seq() * 7;
515 int fromIdx = 0;
516 int toIdx = 0;
517 auto updateIdx = [&]() {
518 assert(fundedAccounts > senders.size());
519 fromIdx = (fromIdx + r) % fundedAccounts;
520 while (senders.count(fromIdx) != 0)
521 fromIdx = (fromIdx + 1) % fundedAccounts;
522 senders.insert(fromIdx);
523 toIdx = (toIdx + r * 2) % fundedAccounts;
524 if (toIdx == fromIdx)
525 toIdx = (toIdx + 1) % fundedAccounts;
526 };
527
528 for (int i = 0; i < newTxes; ++i)
529 {
530 updateIdx();
531 env.apply(
532 pay(accounts[fromIdx],
533 accounts[toIdx],
534 jtx::drops(ledgerMaster.getClosedLedger()->fees().base) +
539 }
540 env.close();
541 }
542
546 void
548 {
549 for (int i = 0; i < param.initLedgers - 1; ++i)
550 {
552 }
553 }
554
561};
562
563enum class TaskStatus {
564 Failed,
565 Completed,
566 NotDone,
567 NotExist,
568};
569
578{
579public:
582 LedgerServer& server,
586 : env(suite,
587 jtx::envconfig(jtx::port_increment, 3),
588 nullptr,
589 beast::severities::kDisabled)
590 , app(env.app())
591 , ledgerMaster(env.app().getLedgerMaster())
593 server.app.getLedgerMaster(),
595 inboundBhvr)
596 , serverMsgHandler(server.app, server.app.getLedgerReplayer())
598 , replayer(
599 env.app(),
601 std::make_unique<TestPeerSetBuilder>(
604 behavior,
605 peerFeature))
606 {
607 }
608
609 void
611 {
613 }
614
615 bool
616 haveLedgers(uint256 const& finishLedgerHash, int totalReplay)
617 {
618 uint256 hash = finishLedgerHash;
619 int i = 0;
620 for (; i < totalReplay; ++i)
621 {
622 auto const l = ledgerMaster.getLedgerByHash(hash);
623 if (!l)
624 return false;
625 hash = l->info().parentHash;
626 }
627 return true;
628 }
629
630 bool
631 waitForLedgers(uint256 const& finishLedgerHash, int totalReplay)
632 {
633 int totalRound = 100;
634 for (int i = 0; i < totalRound; ++i)
635 {
636 if (haveLedgers(finishLedgerHash, totalReplay))
637 return true;
638 if (i < totalRound - 1)
640 }
641 return false;
642 }
643
644 bool
646 {
647 int totalRound = 100;
648 for (int i = 0; i < totalRound; ++i)
649 {
650 bool allDone = true;
651 {
653 for (auto const& t : replayer.tasks_)
654 {
655 if (!t->finished())
656 {
657 allDone = false;
658 break;
659 }
660 }
661 }
662 if (allDone)
663 return true;
664 if (i < totalRound - 1)
666 }
667 return false;
668 }
669
672 {
674 return replayer.tasks_;
675 }
676
678 findTask(uint256 const& hash, int totalReplay)
679 {
681 auto i = std::find_if(
682 replayer.tasks_.begin(), replayer.tasks_.end(), [&](auto const& t) {
683 return t->parameter_.finishHash_ == hash &&
684 t->parameter_.totalLedgers_ == totalReplay;
685 });
686 if (i == replayer.tasks_.end())
687 return {};
688 return *i;
689 }
690
693 {
695 return replayer.deltas_.size();
696 }
697
700 {
702 return replayer.skipLists_.size();
703 }
704
705 bool
707 std::size_t tasks,
708 std::size_t skipLists,
709 std::size_t deltas)
710 {
712 return replayer.tasks_.size() == tasks &&
713 replayer.skipLists_.size() == skipLists &&
714 replayer.deltas_.size() == deltas;
715 }
716
719 {
721 auto i = replayer.skipLists_.find(hash);
722 if (i == replayer.skipLists_.end())
723 return {};
724 return i->second.lock();
725 }
726
729 {
731 auto i = replayer.deltas_.find(hash);
732 if (i == replayer.deltas_.end())
733 return {};
734 return i->second.lock();
735 }
736
737 template <typename T>
740 {
741 if (t->failed_)
742 return TaskStatus::Failed;
743 if (t->complete_)
745 return TaskStatus::NotDone;
746 }
747
748 bool
751 TaskStatus taskExpect,
752 TaskStatus skiplistExpect,
753 std::vector<TaskStatus> const& deltaExpects)
754 {
755 if (taskStatus(task) == taskExpect)
756 {
757 if (taskStatus(task->skipListAcquirer_) == skiplistExpect)
758 {
759 if (task->deltas_.size() == deltaExpects.size())
760 {
761 for (int i = 0; i < deltaExpects.size(); ++i)
762 {
763 if (taskStatus(task->deltas_[i]) != deltaExpects[i])
764 return false;
765 }
766 return true;
767 }
768 }
769 }
770 return false;
771 }
772
773 bool
775 uint256 const& hash,
776 int totalReplay,
777 TaskStatus taskExpect,
778 TaskStatus skiplistExpect,
779 std::vector<TaskStatus> const& deltaExpects)
780 {
781 auto t = findTask(hash, totalReplay);
782 if (!t)
783 {
784 if (taskExpect == TaskStatus::NotExist)
785 return true;
786 return false;
787 }
788
789 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
790 }
791
792 bool
794 uint256 const& hash,
795 int totalReplay,
796 TaskStatus taskExpect,
797 TaskStatus skiplistExpect,
798 std::vector<TaskStatus> const& deltaExpects)
799 {
800 auto t = findTask(hash, totalReplay);
801 if (!t)
802 {
803 if (taskExpect == TaskStatus::NotExist)
804 return true;
805 return false;
806 }
807
808 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
809 }
810
811 bool
813 uint256 const& hash,
814 int totalReplay,
815 TaskStatus taskExpect,
816 TaskStatus skiplistExpect,
817 std::vector<TaskStatus> const& deltaExpects)
818 {
819 if (!waitForDone())
820 return false;
821
822 return checkStatus(
823 hash, totalReplay, taskExpect, skiplistExpect, deltaExpects);
824 }
825
833};
834
835using namespace beast::severities;
836void
838 LedgerServer& server,
839 LedgerReplayClient& client,
840 beast::severities::Severity level = Severity::kTrace)
841{
842 server.app.logs().threshold(level);
843 client.app.logs().threshold(level);
844}
845// logAll(net.server, net.client);
846
847/*
848 * Create a LedgerServer and a LedgerReplayClient
849 */
851{
854 LedgerServer::Parameter const& param,
858 : server(suite, param)
859 , client(suite, server, behavior, inboundBhvr, peerFeature)
860 {
861 // logAll(server, client);
862 }
865};
866
893{
894 void
896 {
897 testcase("ProofPath");
898 LedgerServer server(*this, {1});
899 auto const l = server.ledgerMaster.getClosedLedger();
900
901 {
902 // request, missing key
903 auto request = std::make_shared<protocol::TMProofPathRequest>();
904 request->set_ledgerhash(
905 l->info().hash.data(), l->info().hash.size());
906 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
907 auto reply = std::make_shared<protocol::TMProofPathResponse>(
908 server.msgHandler.processProofPathRequest(request));
909 BEAST_EXPECT(reply->has_error());
910 BEAST_EXPECT(!server.msgHandler.processProofPathResponse(reply));
911 }
912 {
913 // request, wrong hash
914 auto request = std::make_shared<protocol::TMProofPathRequest>();
915 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
916 request->set_key(
917 keylet::skip().key.data(), keylet::skip().key.size());
918 uint256 hash(1234567);
919 request->set_ledgerhash(hash.data(), hash.size());
920 auto reply = std::make_shared<protocol::TMProofPathResponse>(
921 server.msgHandler.processProofPathRequest(request));
922 BEAST_EXPECT(reply->has_error());
923 }
924
925 {
926 // good request
927 auto request = std::make_shared<protocol::TMProofPathRequest>();
928 request->set_ledgerhash(
929 l->info().hash.data(), l->info().hash.size());
930 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
931 request->set_key(
932 keylet::skip().key.data(), keylet::skip().key.size());
933 // generate response
934 auto reply = std::make_shared<protocol::TMProofPathResponse>(
935 server.msgHandler.processProofPathRequest(request));
936 BEAST_EXPECT(!reply->has_error());
937 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
938
939 {
940 // bad reply
941 // bad header
942 std::string r(reply->ledgerheader());
943 r.back()--;
944 reply->set_ledgerheader(r);
945 BEAST_EXPECT(
946 !server.msgHandler.processProofPathResponse(reply));
947 r.back()++;
948 reply->set_ledgerheader(r);
949 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
950 // bad proof path
951 reply->mutable_path()->RemoveLast();
952 BEAST_EXPECT(
953 !server.msgHandler.processProofPathResponse(reply));
954 }
955 }
956 }
957
958 void
960 {
961 testcase("ReplayDelta");
962 LedgerServer server(*this, {1});
963 auto const l = server.ledgerMaster.getClosedLedger();
964
965 {
966 // request, missing hash
967 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
968 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
969 server.msgHandler.processReplayDeltaRequest(request));
970 BEAST_EXPECT(reply->has_error());
971 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
972 // request, wrong hash
973 uint256 hash(1234567);
974 request->set_ledgerhash(hash.data(), hash.size());
975 reply = std::make_shared<protocol::TMReplayDeltaResponse>(
976 server.msgHandler.processReplayDeltaRequest(request));
977 BEAST_EXPECT(reply->has_error());
978 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
979 }
980
981 {
982 // good request
983 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
984 request->set_ledgerhash(
985 l->info().hash.data(), l->info().hash.size());
986 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
987 server.msgHandler.processReplayDeltaRequest(request));
988 BEAST_EXPECT(!reply->has_error());
989 BEAST_EXPECT(server.msgHandler.processReplayDeltaResponse(reply));
990
991 {
992 // bad reply
993 // bad header
994 std::string r(reply->ledgerheader());
995 r.back()--;
996 reply->set_ledgerheader(r);
997 BEAST_EXPECT(
998 !server.msgHandler.processReplayDeltaResponse(reply));
999 r.back()++;
1000 reply->set_ledgerheader(r);
1001 BEAST_EXPECT(
1002 server.msgHandler.processReplayDeltaResponse(reply));
1003 // bad txns
1004 reply->mutable_transaction()->RemoveLast();
1005 BEAST_EXPECT(
1006 !server.msgHandler.processReplayDeltaResponse(reply));
1007 }
1008 }
1009 }
1010
1011 void
1013 {
1014 testcase("TaskParameter");
1015
1016 auto makeSkipList = [](int count) -> std::vector<uint256> const {
1018 for (int i = 0; i < count; ++i)
1019 sList.emplace_back(i);
1020 return sList;
1021 };
1022
1025 BEAST_EXPECT(!tp10.update(uint256(777), 5, makeSkipList(10)));
1026 BEAST_EXPECT(!tp10.update(uint256(10), 5, makeSkipList(8)));
1027 BEAST_EXPECT(tp10.update(uint256(10), 10, makeSkipList(10)));
1028
1029 // can merge to self
1030 BEAST_EXPECT(tp10.canMergeInto(tp10));
1031
1032 // smaller task
1035
1036 BEAST_EXPECT(tp9.canMergeInto(tp10));
1037 BEAST_EXPECT(!tp10.canMergeInto(tp9));
1038
1039 tp9.totalLedgers_++;
1040 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1041 tp9.totalLedgers_--;
1042 BEAST_EXPECT(tp9.canMergeInto(tp10));
1043
1045 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1047 BEAST_EXPECT(tp9.canMergeInto(tp10));
1048
1049 tp9.finishHash_ = uint256(1234);
1050 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1051 tp9.finishHash_ = uint256(9);
1052 BEAST_EXPECT(tp9.canMergeInto(tp10));
1053
1054 // larger task
1057 BEAST_EXPECT(tp20.update(uint256(20), 20, makeSkipList(20)));
1058 BEAST_EXPECT(tp10.canMergeInto(tp20));
1059 BEAST_EXPECT(tp9.canMergeInto(tp20));
1060 BEAST_EXPECT(!tp20.canMergeInto(tp10));
1061 BEAST_EXPECT(!tp20.canMergeInto(tp9));
1062 }
1063
1064 void
1066 {
1067 testcase("config test");
1068 {
1069 Config c;
1070 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1071 }
1072
1073 {
1074 Config c;
1075 std::string toLoad(R"rippleConfig(
1076[ledger_replay]
10771
1078)rippleConfig");
1079 c.loadFromString(toLoad);
1080 BEAST_EXPECT(c.LEDGER_REPLAY == true);
1081 }
1082
1083 {
1084 Config c;
1085 std::string toLoad = (R"rippleConfig(
1086[ledger_replay]
10870
1088)rippleConfig");
1089 c.loadFromString(toLoad);
1090 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1091 }
1092 }
1093
1094 void
1096 {
1097 testcase("handshake test");
1098 auto handshake = [&](bool client, bool server, bool expecting) -> bool {
1099 auto request =
1100 ripple::makeRequest(true, false, client, false, false);
1101 http_request_type http_request;
1102 http_request.version(request.version());
1103 http_request.base() = request.base();
1104 bool serverResult =
1105 peerFeatureEnabled(http_request, FEATURE_LEDGER_REPLAY, server);
1106 if (serverResult != expecting)
1107 return false;
1108
1109 beast::IP::Address addr =
1110 boost::asio::ip::address::from_string("172.1.1.100");
1111 jtx::Env serverEnv(*this);
1112 serverEnv.app().config().LEDGER_REPLAY = server;
1113 auto http_resp = ripple::makeResponse(
1114 true,
1115 http_request,
1116 addr,
1117 addr,
1118 uint256{1},
1119 1,
1120 {1, 0},
1121 serverEnv.app());
1122 auto const clientResult =
1123 peerFeatureEnabled(http_resp, FEATURE_LEDGER_REPLAY, client);
1124 if (clientResult != expecting)
1125 return false;
1126
1127 return true;
1128 };
1129
1130 BEAST_EXPECT(handshake(false, false, false));
1131 BEAST_EXPECT(handshake(false, true, false));
1132 BEAST_EXPECT(handshake(true, false, false));
1133 BEAST_EXPECT(handshake(true, true, true));
1134 }
1135
1136 void
1137 testAllLocal(int totalReplay)
1138 {
1139 testcase("local node has all the ledgers");
1140 auto psBhvr = PeerSetBehavior::DropAll;
1141 auto ilBhvr = InboundLedgersBehavior::DropAll;
1142 auto peerFeature = PeerFeature::None;
1143
1144 NetworkOfTwo net(*this, {totalReplay + 1}, psBhvr, ilBhvr, peerFeature);
1145
1146 auto l = net.server.ledgerMaster.getClosedLedger();
1147 uint256 finalHash = l->info().hash;
1148 for (int i = 0; i < totalReplay; ++i)
1149 {
1150 BEAST_EXPECT(l);
1151 if (l)
1152 {
1153 net.client.ledgerMaster.storeLedger(l);
1154 l = net.server.ledgerMaster.getLedgerByHash(
1155 l->info().parentHash);
1156 }
1157 else
1158 break;
1159 }
1160
1161 net.client.replayer.replay(
1162 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1163
1164 std::vector<TaskStatus> deltaStatuses(
1165 totalReplay - 1, TaskStatus::Completed);
1166 BEAST_EXPECT(net.client.waitAndCheckStatus(
1167 finalHash,
1168 totalReplay,
1171 deltaStatuses));
1172
1173 // sweep
1174 net.client.replayer.sweep();
1175 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1176 }
1177
1178 void
1179 testAllInboundLedgers(int totalReplay)
1180 {
1181 testcase("all the ledgers from InboundLedgers");
1182 NetworkOfTwo net(
1183 *this,
1184 {totalReplay + 1},
1188
1189 auto l = net.server.ledgerMaster.getClosedLedger();
1190 uint256 finalHash = l->info().hash;
1191 net.client.replayer.replay(
1192 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1193
1194 std::vector<TaskStatus> deltaStatuses(
1195 totalReplay - 1, TaskStatus::Completed);
1196 BEAST_EXPECT(net.client.waitAndCheckStatus(
1197 finalHash,
1198 totalReplay,
1201 deltaStatuses));
1202
1203 // sweep
1204 net.client.replayer.sweep();
1205 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1206 }
1207
1208 void
1209 testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay = 4)
1210 {
1211 switch (peerSetBehavior)
1212 {
1214 testcase("good network");
1215 break;
1217 testcase("network drops 50% messages");
1218 break;
1220 testcase("network repeats all messages");
1221 break;
1222 default:
1223 return;
1224 }
1225
1226 NetworkOfTwo net(
1227 *this,
1228 {totalReplay + 1},
1229 peerSetBehavior,
1232
1233 // feed client with start ledger since InboundLedgers drops all
1234 auto l = net.server.ledgerMaster.getClosedLedger();
1235 uint256 finalHash = l->info().hash;
1236 for (int i = 0; i < totalReplay - 1; ++i)
1237 {
1238 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1239 }
1240 net.client.ledgerMaster.storeLedger(l);
1241
1242 net.client.replayer.replay(
1243 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1244
1245 std::vector<TaskStatus> deltaStatuses(
1246 totalReplay - 1, TaskStatus::Completed);
1247 BEAST_EXPECT(net.client.waitAndCheckStatus(
1248 finalHash,
1249 totalReplay,
1252 deltaStatuses));
1253 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1254
1255 // sweep
1256 net.client.replayer.sweep();
1257 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1258 }
1259
1260 void
1262 {
1263 testcase("stop before timeout");
1264 int totalReplay = 3;
1265 NetworkOfTwo net(
1266 *this,
1267 {totalReplay + 1},
1271
1272 auto l = net.server.ledgerMaster.getClosedLedger();
1273 uint256 finalHash = l->info().hash;
1274 net.client.replayer.replay(
1275 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1276
1277 std::vector<TaskStatus> deltaStatuses;
1278 BEAST_EXPECT(net.client.checkStatus(
1279 finalHash,
1280 totalReplay,
1283 deltaStatuses));
1284
1285 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1286 net.client.replayer.stop();
1287 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1288 }
1289
1290 void
1292 {
1293 testcase("SkipListAcquire bad reply");
1294 int totalReplay = 3;
1295 NetworkOfTwo net(
1296 *this,
1297 {totalReplay + 1 + 1},
1301
1302 auto l = net.server.ledgerMaster.getClosedLedger();
1303 uint256 finalHash = l->info().hash;
1304 net.client.replayer.replay(
1305 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1306
1307 auto skipList = net.client.findSkipListAcquire(finalHash);
1308
1309 std::uint8_t payload[55] = {
1310 0x6A, 0x09, 0xE6, 0x67, 0xF3, 0xBC, 0xC9, 0x08, 0xB2};
1311 auto item =
1312 make_shamapitem(uint256(12345), Slice(payload, sizeof(payload)));
1313 skipList->processData(l->seq(), item);
1314
1315 std::vector<TaskStatus> deltaStatuses;
1316 BEAST_EXPECT(net.client.waitAndCheckStatus(
1317 finalHash,
1318 totalReplay,
1321 deltaStatuses));
1322
1323 // add another task
1324 net.client.replayer.replay(
1325 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1326 BEAST_EXPECT(net.client.waitAndCheckStatus(
1327 finalHash,
1328 totalReplay,
1331 deltaStatuses));
1332 BEAST_EXPECT(net.client.countsAsExpected(2, 1, 0));
1333 }
1334
1335 void
1337 {
1338 testcase("LedgerDeltaAcquire bad reply");
1339 int totalReplay = 3;
1340 NetworkOfTwo net(
1341 *this,
1342 {totalReplay + 1},
1346
1347 auto l = net.server.ledgerMaster.getClosedLedger();
1348 uint256 finalHash = l->info().hash;
1349 net.client.ledgerMaster.storeLedger(l);
1350 net.client.replayer.replay(
1351 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1352
1353 auto delta = net.client.findLedgerDeltaAcquire(l->info().parentHash);
1354 delta->processData(
1355 l->info(), // wrong ledger info
1357 BEAST_EXPECT(net.client.taskStatus(delta) == TaskStatus::Failed);
1358 BEAST_EXPECT(
1359 net.client.taskStatus(net.client.findTask(
1360 finalHash, totalReplay)) == TaskStatus::Failed);
1361
1362 // add another task
1363 net.client.replayer.replay(
1364 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1365 BEAST_EXPECT(
1366 net.client.taskStatus(net.client.findTask(
1367 finalHash, totalReplay + 1)) == TaskStatus::Failed);
1368 }
1369
1370 void
1372 {
1373 testcase("Overlap tasks");
1374 int totalReplay = 5;
1375 NetworkOfTwo net(
1376 *this,
1377 {totalReplay * 3 + 1},
1381 auto l = net.server.ledgerMaster.getClosedLedger();
1382 uint256 finalHash = l->info().hash;
1383 net.client.replayer.replay(
1384 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1385 std::vector<TaskStatus> deltaStatuses(
1386 totalReplay - 1, TaskStatus::Completed);
1387 BEAST_EXPECT(net.client.waitAndCheckStatus(
1388 finalHash,
1389 totalReplay,
1392 deltaStatuses));
1393 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1394
1395 // same range, same reason
1396 net.client.replayer.replay(
1397 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1398 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1399 // same range, different reason
1400 net.client.replayer.replay(
1401 InboundLedger::Reason::CONSENSUS, finalHash, totalReplay);
1402 BEAST_EXPECT(net.client.countsAsExpected(2, 1, totalReplay - 1));
1403
1404 // no overlap
1405 for (int i = 0; i < totalReplay + 2; ++i)
1406 {
1407 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1408 }
1409 auto finalHash_early = l->info().hash;
1410 net.client.replayer.replay(
1411 InboundLedger::Reason::GENERIC, finalHash_early, totalReplay);
1412 BEAST_EXPECT(net.client.waitAndCheckStatus(
1413 finalHash_early,
1414 totalReplay,
1417 deltaStatuses)); // deltaStatuses no change
1418 BEAST_EXPECT(net.client.waitForLedgers(finalHash_early, totalReplay));
1419 BEAST_EXPECT(net.client.countsAsExpected(3, 2, 2 * (totalReplay - 1)));
1420
1421 // partial overlap
1422 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1423 auto finalHash_moreEarly = l->info().parentHash;
1424 net.client.replayer.replay(
1425 InboundLedger::Reason::GENERIC, finalHash_moreEarly, totalReplay);
1426 BEAST_EXPECT(net.client.waitAndCheckStatus(
1427 finalHash_moreEarly,
1428 totalReplay,
1431 deltaStatuses)); // deltaStatuses no change
1432 BEAST_EXPECT(
1433 net.client.waitForLedgers(finalHash_moreEarly, totalReplay));
1434 BEAST_EXPECT(
1435 net.client.countsAsExpected(4, 3, 2 * (totalReplay - 1) + 2));
1436
1437 // cover
1438 net.client.replayer.replay(
1439 InboundLedger::Reason::GENERIC, finalHash, totalReplay * 3);
1440 deltaStatuses =
1441 std::vector<TaskStatus>(totalReplay * 3 - 1, TaskStatus::Completed);
1442 BEAST_EXPECT(net.client.waitAndCheckStatus(
1443 finalHash,
1444 totalReplay * 3,
1447 deltaStatuses)); // deltaStatuses changed
1448 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay * 3));
1449 BEAST_EXPECT(net.client.countsAsExpected(5, 3, totalReplay * 3 - 1));
1450
1451 // sweep
1452 net.client.replayer.sweep();
1453 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1454 }
1455
1456 void
1457 run() override
1458 {
1459 testProofPath();
1462 testConfig();
1463 testHandshake();
1464 testAllLocal(1);
1465 testAllLocal(3);
1472 testStop();
1476 }
1477};
1478
1480{
1481 void
1483 {
1484 testcase("SkipListAcquire timeout");
1485 int totalReplay = 3;
1486 NetworkOfTwo net(
1487 *this,
1488 {totalReplay + 1},
1492
1493 auto l = net.server.ledgerMaster.getClosedLedger();
1494 uint256 finalHash = l->info().hash;
1495 net.client.replayer.replay(
1496 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1497
1498 std::vector<TaskStatus> deltaStatuses;
1499 BEAST_EXPECT(net.client.waitAndCheckStatus(
1500 finalHash,
1501 totalReplay,
1504 deltaStatuses));
1505
1506 // sweep
1507 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1508 net.client.replayer.sweep();
1509 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1510 }
1511
1512 void
1514 {
1515 testcase("LedgerDeltaAcquire timeout");
1516 int totalReplay = 3;
1517 NetworkOfTwo net(
1518 *this,
1519 {totalReplay + 1},
1523
1524 auto l = net.server.ledgerMaster.getClosedLedger();
1525 uint256 finalHash = l->info().hash;
1526 net.client.ledgerMaster.storeLedger(l);
1527 net.client.replayer.replay(
1528 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1529
1530 std::vector<TaskStatus> deltaStatuses(
1531 totalReplay - 1, TaskStatus::Failed);
1532 deltaStatuses.back() = TaskStatus::Completed; // in client ledgerMaster
1533 BEAST_EXPECT(net.client.waitAndCheckStatus(
1534 finalHash,
1535 totalReplay,
1538 deltaStatuses));
1539
1540 // sweep
1541 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1542 net.client.replayer.sweep();
1543 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1544 }
1545
1546 void
1547 run() override
1548 {
1551 }
1552};
1553
1555{
1556 void
1557 run() override
1558 {
1559 testcase("Acquire 1000 ledgers");
1560 int totalReplay = 250;
1561 int rounds = 4;
1562 NetworkOfTwo net(
1563 *this,
1564 {totalReplay * rounds + 1},
1568
1569 std::vector<uint256> finishHashes;
1570 auto l = net.server.ledgerMaster.getClosedLedger();
1571 for (int i = 0; i < rounds; ++i)
1572 {
1573 finishHashes.push_back(l->info().hash);
1574 for (int j = 0; j < totalReplay; ++j)
1575 {
1576 l = net.server.ledgerMaster.getLedgerByHash(
1577 l->info().parentHash);
1578 }
1579 }
1580 BEAST_EXPECT(finishHashes.size() == rounds);
1581
1582 for (int i = 0; i < rounds; ++i)
1583 {
1584 net.client.replayer.replay(
1585 InboundLedger::Reason::GENERIC, finishHashes[i], totalReplay);
1586 }
1587
1588 std::vector<TaskStatus> deltaStatuses(
1589 totalReplay - 1, TaskStatus::Completed);
1590 for (int i = 0; i < rounds; ++i)
1591 {
1592 BEAST_EXPECT(net.client.waitAndCheckStatus(
1593 finishHashes[i],
1594 totalReplay,
1597 deltaStatuses));
1598 }
1599
1600 BEAST_EXPECT(
1601 net.client.waitForLedgers(finishHashes[0], totalReplay * rounds));
1602 BEAST_EXPECT(net.client.countsAsExpected(
1603 rounds, rounds, rounds * (totalReplay - 1)));
1604
1605 // sweep
1606 net.client.replayer.sweep();
1607 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1608 }
1609};
1610
1611BEAST_DEFINE_TESTSUITE(LedgerReplay, app, ripple);
1612BEAST_DEFINE_TESTSUITE_PRIO(LedgerReplayer, app, ripple, 1);
1613BEAST_DEFINE_TESTSUITE(LedgerReplayerTimeout, app, ripple);
1614BEAST_DEFINE_TESTSUITE_MANUAL(LedgerReplayerLong, app, ripple);
1615
1616} // namespace test
1617} // 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:446
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
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
void charge(Resource::Charge const &fee) override
Adjust this peer's load balance based on the type of load imposed.
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:550
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.
std::unique_ptr< Config > port_increment(std::unique_ptr< Config >, int)
adjust the default configured server ports by a specified value
Definition: envconfig.cpp:127
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)