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, jtx::envconfig(), nullptr, beast::severities::kDisabled)
587 , app(env.app())
588 , ledgerMaster(env.app().getLedgerMaster())
590 server.app.getLedgerMaster(),
592 inboundBhvr)
593 , serverMsgHandler(server.app, server.app.getLedgerReplayer())
595 , replayer(
596 env.app(),
598 std::make_unique<TestPeerSetBuilder>(
601 behavior,
602 peerFeature))
603 {
604 }
605
606 void
608 {
610 }
611
612 bool
613 haveLedgers(uint256 const& finishLedgerHash, int totalReplay)
614 {
615 uint256 hash = finishLedgerHash;
616 int i = 0;
617 for (; i < totalReplay; ++i)
618 {
619 auto const l = ledgerMaster.getLedgerByHash(hash);
620 if (!l)
621 return false;
622 hash = l->info().parentHash;
623 }
624 return true;
625 }
626
627 bool
628 waitForLedgers(uint256 const& finishLedgerHash, int totalReplay)
629 {
630 int totalRound = 100;
631 for (int i = 0; i < totalRound; ++i)
632 {
633 if (haveLedgers(finishLedgerHash, totalReplay))
634 return true;
635 if (i < totalRound - 1)
637 }
638 return false;
639 }
640
641 bool
643 {
644 int totalRound = 100;
645 for (int i = 0; i < totalRound; ++i)
646 {
647 bool allDone = true;
648 {
650 for (auto const& t : replayer.tasks_)
651 {
652 if (!t->finished())
653 {
654 allDone = false;
655 break;
656 }
657 }
658 }
659 if (allDone)
660 return true;
661 if (i < totalRound - 1)
663 }
664 return false;
665 }
666
669 {
671 return replayer.tasks_;
672 }
673
675 findTask(uint256 const& hash, int totalReplay)
676 {
678 auto i = std::find_if(
679 replayer.tasks_.begin(), replayer.tasks_.end(), [&](auto const& t) {
680 return t->parameter_.finishHash_ == hash &&
681 t->parameter_.totalLedgers_ == totalReplay;
682 });
683 if (i == replayer.tasks_.end())
684 return {};
685 return *i;
686 }
687
690 {
692 return replayer.deltas_.size();
693 }
694
697 {
699 return replayer.skipLists_.size();
700 }
701
702 bool
704 std::size_t tasks,
705 std::size_t skipLists,
706 std::size_t deltas)
707 {
709 return replayer.tasks_.size() == tasks &&
710 replayer.skipLists_.size() == skipLists &&
711 replayer.deltas_.size() == deltas;
712 }
713
716 {
718 auto i = replayer.skipLists_.find(hash);
719 if (i == replayer.skipLists_.end())
720 return {};
721 return i->second.lock();
722 }
723
726 {
728 auto i = replayer.deltas_.find(hash);
729 if (i == replayer.deltas_.end())
730 return {};
731 return i->second.lock();
732 }
733
734 template <typename T>
737 {
738 if (t->failed_)
739 return TaskStatus::Failed;
740 if (t->complete_)
742 return TaskStatus::NotDone;
743 }
744
745 bool
748 TaskStatus taskExpect,
749 TaskStatus skiplistExpect,
750 std::vector<TaskStatus> const& deltaExpects)
751 {
752 if (taskStatus(task) == taskExpect)
753 {
754 if (taskStatus(task->skipListAcquirer_) == skiplistExpect)
755 {
756 if (task->deltas_.size() == deltaExpects.size())
757 {
758 for (int i = 0; i < deltaExpects.size(); ++i)
759 {
760 if (taskStatus(task->deltas_[i]) != deltaExpects[i])
761 return false;
762 }
763 return true;
764 }
765 }
766 }
767 return false;
768 }
769
770 bool
772 uint256 const& hash,
773 int totalReplay,
774 TaskStatus taskExpect,
775 TaskStatus skiplistExpect,
776 std::vector<TaskStatus> const& deltaExpects)
777 {
778 auto t = findTask(hash, totalReplay);
779 if (!t)
780 {
781 if (taskExpect == TaskStatus::NotExist)
782 return true;
783 return false;
784 }
785
786 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
787 }
788
789 bool
791 uint256 const& hash,
792 int totalReplay,
793 TaskStatus taskExpect,
794 TaskStatus skiplistExpect,
795 std::vector<TaskStatus> const& deltaExpects)
796 {
797 auto t = findTask(hash, totalReplay);
798 if (!t)
799 {
800 if (taskExpect == TaskStatus::NotExist)
801 return true;
802 return false;
803 }
804
805 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
806 }
807
808 bool
810 uint256 const& hash,
811 int totalReplay,
812 TaskStatus taskExpect,
813 TaskStatus skiplistExpect,
814 std::vector<TaskStatus> const& deltaExpects)
815 {
816 if (!waitForDone())
817 return false;
818
819 return checkStatus(
820 hash, totalReplay, taskExpect, skiplistExpect, deltaExpects);
821 }
822
830};
831
832using namespace beast::severities;
833void
835 LedgerServer& server,
836 LedgerReplayClient& client,
837 beast::severities::Severity level = Severity::kTrace)
838{
839 server.app.logs().threshold(level);
840 client.app.logs().threshold(level);
841}
842// logAll(net.server, net.client);
843
844/*
845 * Create a LedgerServer and a LedgerReplayClient
846 */
848{
851 LedgerServer::Parameter const& param,
855 : server(suite, param)
856 , client(suite, server, behavior, inboundBhvr, peerFeature)
857 {
858 // logAll(server, client);
859 }
862};
863
890{
891 void
893 {
894 testcase("ProofPath");
895 LedgerServer server(*this, {1});
896 auto const l = server.ledgerMaster.getClosedLedger();
897
898 {
899 // request, missing key
900 auto request = std::make_shared<protocol::TMProofPathRequest>();
901 request->set_ledgerhash(
902 l->info().hash.data(), l->info().hash.size());
903 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
904 auto reply = std::make_shared<protocol::TMProofPathResponse>(
905 server.msgHandler.processProofPathRequest(request));
906 BEAST_EXPECT(reply->has_error());
907 BEAST_EXPECT(!server.msgHandler.processProofPathResponse(reply));
908 }
909 {
910 // request, wrong hash
911 auto request = std::make_shared<protocol::TMProofPathRequest>();
912 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
913 request->set_key(
914 keylet::skip().key.data(), keylet::skip().key.size());
915 uint256 hash(1234567);
916 request->set_ledgerhash(hash.data(), hash.size());
917 auto reply = std::make_shared<protocol::TMProofPathResponse>(
918 server.msgHandler.processProofPathRequest(request));
919 BEAST_EXPECT(reply->has_error());
920 }
921
922 {
923 // good request
924 auto request = std::make_shared<protocol::TMProofPathRequest>();
925 request->set_ledgerhash(
926 l->info().hash.data(), l->info().hash.size());
927 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
928 request->set_key(
929 keylet::skip().key.data(), keylet::skip().key.size());
930 // generate response
931 auto reply = std::make_shared<protocol::TMProofPathResponse>(
932 server.msgHandler.processProofPathRequest(request));
933 BEAST_EXPECT(!reply->has_error());
934 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
935
936 {
937 // bad reply
938 // bad header
939 std::string r(reply->ledgerheader());
940 r.back()--;
941 reply->set_ledgerheader(r);
942 BEAST_EXPECT(
943 !server.msgHandler.processProofPathResponse(reply));
944 r.back()++;
945 reply->set_ledgerheader(r);
946 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
947 // bad proof path
948 reply->mutable_path()->RemoveLast();
949 BEAST_EXPECT(
950 !server.msgHandler.processProofPathResponse(reply));
951 }
952 }
953 }
954
955 void
957 {
958 testcase("ReplayDelta");
959 LedgerServer server(*this, {1});
960 auto const l = server.ledgerMaster.getClosedLedger();
961
962 {
963 // request, missing hash
964 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
965 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
966 server.msgHandler.processReplayDeltaRequest(request));
967 BEAST_EXPECT(reply->has_error());
968 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
969 // request, wrong hash
970 uint256 hash(1234567);
971 request->set_ledgerhash(hash.data(), hash.size());
972 reply = std::make_shared<protocol::TMReplayDeltaResponse>(
973 server.msgHandler.processReplayDeltaRequest(request));
974 BEAST_EXPECT(reply->has_error());
975 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
976 }
977
978 {
979 // good request
980 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
981 request->set_ledgerhash(
982 l->info().hash.data(), l->info().hash.size());
983 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
984 server.msgHandler.processReplayDeltaRequest(request));
985 BEAST_EXPECT(!reply->has_error());
986 BEAST_EXPECT(server.msgHandler.processReplayDeltaResponse(reply));
987
988 {
989 // bad reply
990 // bad header
991 std::string r(reply->ledgerheader());
992 r.back()--;
993 reply->set_ledgerheader(r);
994 BEAST_EXPECT(
995 !server.msgHandler.processReplayDeltaResponse(reply));
996 r.back()++;
997 reply->set_ledgerheader(r);
998 BEAST_EXPECT(
999 server.msgHandler.processReplayDeltaResponse(reply));
1000 // bad txns
1001 reply->mutable_transaction()->RemoveLast();
1002 BEAST_EXPECT(
1003 !server.msgHandler.processReplayDeltaResponse(reply));
1004 }
1005 }
1006 }
1007
1008 void
1010 {
1011 testcase("TaskParameter");
1012
1013 auto makeSkipList = [](int count) -> std::vector<uint256> const {
1015 for (int i = 0; i < count; ++i)
1016 sList.emplace_back(i);
1017 return sList;
1018 };
1019
1022 BEAST_EXPECT(!tp10.update(uint256(777), 5, makeSkipList(10)));
1023 BEAST_EXPECT(!tp10.update(uint256(10), 5, makeSkipList(8)));
1024 BEAST_EXPECT(tp10.update(uint256(10), 10, makeSkipList(10)));
1025
1026 // can merge to self
1027 BEAST_EXPECT(tp10.canMergeInto(tp10));
1028
1029 // smaller task
1032
1033 BEAST_EXPECT(tp9.canMergeInto(tp10));
1034 BEAST_EXPECT(!tp10.canMergeInto(tp9));
1035
1036 tp9.totalLedgers_++;
1037 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1038 tp9.totalLedgers_--;
1039 BEAST_EXPECT(tp9.canMergeInto(tp10));
1040
1042 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1044 BEAST_EXPECT(tp9.canMergeInto(tp10));
1045
1046 tp9.finishHash_ = uint256(1234);
1047 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1048 tp9.finishHash_ = uint256(9);
1049 BEAST_EXPECT(tp9.canMergeInto(tp10));
1050
1051 // larger task
1054 BEAST_EXPECT(tp20.update(uint256(20), 20, makeSkipList(20)));
1055 BEAST_EXPECT(tp10.canMergeInto(tp20));
1056 BEAST_EXPECT(tp9.canMergeInto(tp20));
1057 BEAST_EXPECT(!tp20.canMergeInto(tp10));
1058 BEAST_EXPECT(!tp20.canMergeInto(tp9));
1059 }
1060
1061 void
1063 {
1064 testcase("config test");
1065 {
1066 Config c;
1067 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1068 }
1069
1070 {
1071 Config c;
1072 std::string toLoad(R"rippleConfig(
1073[ledger_replay]
10741
1075)rippleConfig");
1076 c.loadFromString(toLoad);
1077 BEAST_EXPECT(c.LEDGER_REPLAY == true);
1078 }
1079
1080 {
1081 Config c;
1082 std::string toLoad = (R"rippleConfig(
1083[ledger_replay]
10840
1085)rippleConfig");
1086 c.loadFromString(toLoad);
1087 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1088 }
1089 }
1090
1091 void
1093 {
1094 testcase("handshake test");
1095 auto handshake = [&](bool client, bool server, bool expecting) -> bool {
1096 auto request =
1097 ripple::makeRequest(true, false, client, false, false);
1098 http_request_type http_request;
1099 http_request.version(request.version());
1100 http_request.base() = request.base();
1101 bool serverResult =
1102 peerFeatureEnabled(http_request, FEATURE_LEDGER_REPLAY, server);
1103 if (serverResult != expecting)
1104 return false;
1105
1106 beast::IP::Address addr =
1107 boost::asio::ip::address::from_string("172.1.1.100");
1108 jtx::Env serverEnv(*this);
1109 serverEnv.app().config().LEDGER_REPLAY = server;
1110 auto http_resp = ripple::makeResponse(
1111 true,
1112 http_request,
1113 addr,
1114 addr,
1115 uint256{1},
1116 1,
1117 {1, 0},
1118 serverEnv.app());
1119 auto const clientResult =
1120 peerFeatureEnabled(http_resp, FEATURE_LEDGER_REPLAY, client);
1121 if (clientResult != expecting)
1122 return false;
1123
1124 return true;
1125 };
1126
1127 BEAST_EXPECT(handshake(false, false, false));
1128 BEAST_EXPECT(handshake(false, true, false));
1129 BEAST_EXPECT(handshake(true, false, false));
1130 BEAST_EXPECT(handshake(true, true, true));
1131 }
1132
1133 void
1134 testAllLocal(int totalReplay)
1135 {
1136 testcase("local node has all the ledgers");
1137 auto psBhvr = PeerSetBehavior::DropAll;
1138 auto ilBhvr = InboundLedgersBehavior::DropAll;
1139 auto peerFeature = PeerFeature::None;
1140
1141 NetworkOfTwo net(*this, {totalReplay + 1}, psBhvr, ilBhvr, peerFeature);
1142
1143 auto l = net.server.ledgerMaster.getClosedLedger();
1144 uint256 finalHash = l->info().hash;
1145 for (int i = 0; i < totalReplay; ++i)
1146 {
1147 BEAST_EXPECT(l);
1148 if (l)
1149 {
1150 net.client.ledgerMaster.storeLedger(l);
1151 l = net.server.ledgerMaster.getLedgerByHash(
1152 l->info().parentHash);
1153 }
1154 else
1155 break;
1156 }
1157
1158 net.client.replayer.replay(
1159 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1160
1161 std::vector<TaskStatus> deltaStatuses(
1162 totalReplay - 1, TaskStatus::Completed);
1163 BEAST_EXPECT(net.client.waitAndCheckStatus(
1164 finalHash,
1165 totalReplay,
1168 deltaStatuses));
1169
1170 // sweep
1171 net.client.replayer.sweep();
1172 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1173 }
1174
1175 void
1176 testAllInboundLedgers(int totalReplay)
1177 {
1178 testcase("all the ledgers from InboundLedgers");
1179 NetworkOfTwo net(
1180 *this,
1181 {totalReplay + 1},
1185
1186 auto l = net.server.ledgerMaster.getClosedLedger();
1187 uint256 finalHash = l->info().hash;
1188 net.client.replayer.replay(
1189 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1190
1191 std::vector<TaskStatus> deltaStatuses(
1192 totalReplay - 1, TaskStatus::Completed);
1193 BEAST_EXPECT(net.client.waitAndCheckStatus(
1194 finalHash,
1195 totalReplay,
1198 deltaStatuses));
1199
1200 // sweep
1201 net.client.replayer.sweep();
1202 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1203 }
1204
1205 void
1206 testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay = 4)
1207 {
1208 switch (peerSetBehavior)
1209 {
1211 testcase("good network");
1212 break;
1214 testcase("network drops 50% messages");
1215 break;
1217 testcase("network repeats all messages");
1218 break;
1219 default:
1220 return;
1221 }
1222
1223 NetworkOfTwo net(
1224 *this,
1225 {totalReplay + 1},
1226 peerSetBehavior,
1229
1230 // feed client with start ledger since InboundLedgers drops all
1231 auto l = net.server.ledgerMaster.getClosedLedger();
1232 uint256 finalHash = l->info().hash;
1233 for (int i = 0; i < totalReplay - 1; ++i)
1234 {
1235 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1236 }
1237 net.client.ledgerMaster.storeLedger(l);
1238
1239 net.client.replayer.replay(
1240 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1241
1242 std::vector<TaskStatus> deltaStatuses(
1243 totalReplay - 1, TaskStatus::Completed);
1244 BEAST_EXPECT(net.client.waitAndCheckStatus(
1245 finalHash,
1246 totalReplay,
1249 deltaStatuses));
1250 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1251
1252 // sweep
1253 net.client.replayer.sweep();
1254 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1255 }
1256
1257 void
1259 {
1260 testcase("stop before timeout");
1261 int totalReplay = 3;
1262 NetworkOfTwo net(
1263 *this,
1264 {totalReplay + 1},
1268
1269 auto l = net.server.ledgerMaster.getClosedLedger();
1270 uint256 finalHash = l->info().hash;
1271 net.client.replayer.replay(
1272 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1273
1274 std::vector<TaskStatus> deltaStatuses;
1275 BEAST_EXPECT(net.client.checkStatus(
1276 finalHash,
1277 totalReplay,
1280 deltaStatuses));
1281
1282 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1283 net.client.replayer.stop();
1284 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1285 }
1286
1287 void
1289 {
1290 testcase("SkipListAcquire bad reply");
1291 int totalReplay = 3;
1292 NetworkOfTwo net(
1293 *this,
1294 {totalReplay + 1 + 1},
1298
1299 auto l = net.server.ledgerMaster.getClosedLedger();
1300 uint256 finalHash = l->info().hash;
1301 net.client.replayer.replay(
1302 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1303
1304 auto skipList = net.client.findSkipListAcquire(finalHash);
1305
1306 std::uint8_t payload[55] = {
1307 0x6A, 0x09, 0xE6, 0x67, 0xF3, 0xBC, 0xC9, 0x08, 0xB2};
1308 auto item =
1309 make_shamapitem(uint256(12345), Slice(payload, sizeof(payload)));
1310 skipList->processData(l->seq(), item);
1311
1312 std::vector<TaskStatus> deltaStatuses;
1313 BEAST_EXPECT(net.client.waitAndCheckStatus(
1314 finalHash,
1315 totalReplay,
1318 deltaStatuses));
1319
1320 // add another task
1321 net.client.replayer.replay(
1322 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1323 BEAST_EXPECT(net.client.waitAndCheckStatus(
1324 finalHash,
1325 totalReplay,
1328 deltaStatuses));
1329 BEAST_EXPECT(net.client.countsAsExpected(2, 1, 0));
1330 }
1331
1332 void
1334 {
1335 testcase("LedgerDeltaAcquire bad reply");
1336 int totalReplay = 3;
1337 NetworkOfTwo net(
1338 *this,
1339 {totalReplay + 1},
1343
1344 auto l = net.server.ledgerMaster.getClosedLedger();
1345 uint256 finalHash = l->info().hash;
1346 net.client.ledgerMaster.storeLedger(l);
1347 net.client.replayer.replay(
1348 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1349
1350 auto delta = net.client.findLedgerDeltaAcquire(l->info().parentHash);
1351 delta->processData(
1352 l->info(), // wrong ledger info
1354 BEAST_EXPECT(net.client.taskStatus(delta) == TaskStatus::Failed);
1355 BEAST_EXPECT(
1356 net.client.taskStatus(net.client.findTask(
1357 finalHash, totalReplay)) == TaskStatus::Failed);
1358
1359 // add another task
1360 net.client.replayer.replay(
1361 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1362 BEAST_EXPECT(
1363 net.client.taskStatus(net.client.findTask(
1364 finalHash, totalReplay + 1)) == TaskStatus::Failed);
1365 }
1366
1367 void
1369 {
1370 testcase("Overlap tasks");
1371 int totalReplay = 5;
1372 NetworkOfTwo net(
1373 *this,
1374 {totalReplay * 3 + 1},
1378 auto l = net.server.ledgerMaster.getClosedLedger();
1379 uint256 finalHash = l->info().hash;
1380 net.client.replayer.replay(
1381 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1382 std::vector<TaskStatus> deltaStatuses(
1383 totalReplay - 1, TaskStatus::Completed);
1384 BEAST_EXPECT(net.client.waitAndCheckStatus(
1385 finalHash,
1386 totalReplay,
1389 deltaStatuses));
1390 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1391
1392 // same range, same reason
1393 net.client.replayer.replay(
1394 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1395 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1396 // same range, different reason
1397 net.client.replayer.replay(
1398 InboundLedger::Reason::CONSENSUS, finalHash, totalReplay);
1399 BEAST_EXPECT(net.client.countsAsExpected(2, 1, totalReplay - 1));
1400
1401 // no overlap
1402 for (int i = 0; i < totalReplay + 2; ++i)
1403 {
1404 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1405 }
1406 auto finalHash_early = l->info().hash;
1407 net.client.replayer.replay(
1408 InboundLedger::Reason::GENERIC, finalHash_early, totalReplay);
1409 BEAST_EXPECT(net.client.waitAndCheckStatus(
1410 finalHash_early,
1411 totalReplay,
1414 deltaStatuses)); // deltaStatuses no change
1415 BEAST_EXPECT(net.client.waitForLedgers(finalHash_early, totalReplay));
1416 BEAST_EXPECT(net.client.countsAsExpected(3, 2, 2 * (totalReplay - 1)));
1417
1418 // partial overlap
1419 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1420 auto finalHash_moreEarly = l->info().parentHash;
1421 net.client.replayer.replay(
1422 InboundLedger::Reason::GENERIC, finalHash_moreEarly, totalReplay);
1423 BEAST_EXPECT(net.client.waitAndCheckStatus(
1424 finalHash_moreEarly,
1425 totalReplay,
1428 deltaStatuses)); // deltaStatuses no change
1429 BEAST_EXPECT(
1430 net.client.waitForLedgers(finalHash_moreEarly, totalReplay));
1431 BEAST_EXPECT(
1432 net.client.countsAsExpected(4, 3, 2 * (totalReplay - 1) + 2));
1433
1434 // cover
1435 net.client.replayer.replay(
1436 InboundLedger::Reason::GENERIC, finalHash, totalReplay * 3);
1437 deltaStatuses =
1438 std::vector<TaskStatus>(totalReplay * 3 - 1, TaskStatus::Completed);
1439 BEAST_EXPECT(net.client.waitAndCheckStatus(
1440 finalHash,
1441 totalReplay * 3,
1444 deltaStatuses)); // deltaStatuses changed
1445 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay * 3));
1446 BEAST_EXPECT(net.client.countsAsExpected(5, 3, totalReplay * 3 - 1));
1447
1448 // sweep
1449 net.client.replayer.sweep();
1450 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1451 }
1452
1453 void
1454 run() override
1455 {
1456 testProofPath();
1459 testConfig();
1460 testHandshake();
1461 testAllLocal(1);
1462 testAllLocal(3);
1469 testStop();
1473 }
1474};
1475
1477{
1478 void
1480 {
1481 testcase("SkipListAcquire timeout");
1482 int totalReplay = 3;
1483 NetworkOfTwo net(
1484 *this,
1485 {totalReplay + 1},
1489
1490 auto l = net.server.ledgerMaster.getClosedLedger();
1491 uint256 finalHash = l->info().hash;
1492 net.client.replayer.replay(
1493 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1494
1495 std::vector<TaskStatus> deltaStatuses;
1496 BEAST_EXPECT(net.client.waitAndCheckStatus(
1497 finalHash,
1498 totalReplay,
1501 deltaStatuses));
1502
1503 // sweep
1504 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1505 net.client.replayer.sweep();
1506 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1507 }
1508
1509 void
1511 {
1512 testcase("LedgerDeltaAcquire timeout");
1513 int totalReplay = 3;
1514 NetworkOfTwo net(
1515 *this,
1516 {totalReplay + 1},
1520
1521 auto l = net.server.ledgerMaster.getClosedLedger();
1522 uint256 finalHash = l->info().hash;
1523 net.client.ledgerMaster.storeLedger(l);
1524 net.client.replayer.replay(
1525 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1526
1527 std::vector<TaskStatus> deltaStatuses(
1528 totalReplay - 1, TaskStatus::Failed);
1529 deltaStatuses.back() = TaskStatus::Completed; // in client ledgerMaster
1530 BEAST_EXPECT(net.client.waitAndCheckStatus(
1531 finalHash,
1532 totalReplay,
1535 deltaStatuses));
1536
1537 // sweep
1538 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1539 net.client.replayer.sweep();
1540 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1541 }
1542
1543 void
1544 run() override
1545 {
1548 }
1549};
1550
1552{
1553 void
1554 run() override
1555 {
1556 testcase("Acquire 1000 ledgers");
1557 int totalReplay = 250;
1558 int rounds = 4;
1559 NetworkOfTwo net(
1560 *this,
1561 {totalReplay * rounds + 1},
1565
1566 std::vector<uint256> finishHashes;
1567 auto l = net.server.ledgerMaster.getClosedLedger();
1568 for (int i = 0; i < rounds; ++i)
1569 {
1570 finishHashes.push_back(l->info().hash);
1571 for (int j = 0; j < totalReplay; ++j)
1572 {
1573 l = net.server.ledgerMaster.getLedgerByHash(
1574 l->info().parentHash);
1575 }
1576 }
1577 BEAST_EXPECT(finishHashes.size() == rounds);
1578
1579 for (int i = 0; i < rounds; ++i)
1580 {
1581 net.client.replayer.replay(
1582 InboundLedger::Reason::GENERIC, finishHashes[i], totalReplay);
1583 }
1584
1585 std::vector<TaskStatus> deltaStatuses(
1586 totalReplay - 1, TaskStatus::Completed);
1587 for (int i = 0; i < rounds; ++i)
1588 {
1589 BEAST_EXPECT(net.client.waitAndCheckStatus(
1590 finishHashes[i],
1591 totalReplay,
1594 deltaStatuses));
1595 }
1596
1597 BEAST_EXPECT(
1598 net.client.waitForLedgers(finishHashes[0], totalReplay * rounds));
1599 BEAST_EXPECT(net.client.countsAsExpected(
1600 rounds, rounds, rounds * (totalReplay - 1)));
1601
1602 // sweep
1603 net.client.replayer.sweep();
1604 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1605 }
1606};
1607
1608BEAST_DEFINE_TESTSUITE(LedgerReplay, app, ripple);
1609BEAST_DEFINE_TESTSUITE_PRIO(LedgerReplayer, app, ripple, 1);
1610BEAST_DEFINE_TESTSUITE(LedgerReplayerTimeout, app, ripple);
1611BEAST_DEFINE_TESTSUITE_MANUAL(LedgerReplayerLong, app, ripple);
1612
1613} // namespace test
1614} // 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
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: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)