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 }
326 releaseRequestCookies(uint256 const& requestHash) override
327 {
328 return {};
329 }
330
333};
334
335enum class PeerSetBehavior {
336 Good,
337 Drop50,
338 DropAll,
341 Repeat,
342};
343
350struct TestPeerSet : public PeerSet
351{
355 PeerSetBehavior bhvr,
356 bool enableLedgerReplay)
357 : local(me)
358 , remote(other)
359 , dummyPeer(std::make_shared<TestPeer>(enableLedgerReplay))
360 , behavior(bhvr)
361 {
362 }
363
364 void
366 std::size_t limit,
367 std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
368 std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) override
369 {
370 hasItem(dummyPeer);
371 onPeerAdded(dummyPeer);
372 }
373
374 void
376 ::google::protobuf::Message const& msg,
377 protocol::MessageType type,
378 std::shared_ptr<Peer> const& peer) override
379 {
380 int dropRate = 0;
382 dropRate = 50;
384 dropRate = 100;
385
386 if ((rand() % 100 + 1) <= dropRate)
387 return;
388
389 switch (type)
390 {
391 case protocol::mtPROOF_PATH_REQ: {
393 return;
394 auto request = std::make_shared<protocol::TMProofPathRequest>(
395 dynamic_cast<protocol::TMProofPathRequest const&>(msg));
396 auto reply = std::make_shared<protocol::TMProofPathResponse>(
401 break;
402 }
403 case protocol::mtREPLAY_DELTA_REQ: {
405 return;
406 auto request = std::make_shared<protocol::TMReplayDeltaRequest>(
407 dynamic_cast<protocol::TMReplayDeltaRequest const&>(msg));
408 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
413 break;
414 }
415 default:
416 return;
417 }
418 }
419
421 getPeerIds() const override
422 {
423 static std::set<Peer::id_t> emptyPeers;
424 return emptyPeers;
425 }
426
431};
432
437{
438public:
442 PeerSetBehavior bhvr,
443 PeerFeature peerFeature)
444 : local(me)
445 , remote(other)
446 , behavior(bhvr)
448 {
449 }
450
452 build() override
453 {
454 return std::make_unique<TestPeerSet>(
456 }
457
458private:
463};
464
470{
472 {
474 int initAccounts = 10;
475 int initAmount = 1'000'000;
477 int txAmount = 10;
478 };
479
481 : env(suite)
482 , app(env.app())
483 , ledgerMaster(env.app().getLedgerMaster())
484 , msgHandler(env.app(), env.app().getLedgerReplayer())
485 , param(p)
486 {
487 assert(param.initLedgers > 0);
491 }
492
496 void
497 createAccounts(int newAccounts)
498 {
499 auto fundedAccounts = accounts.size();
500 for (int i = 0; i < newAccounts; ++i)
501 {
502 accounts.emplace_back(
503 "alice_" + std::to_string(fundedAccounts + i));
505 }
506 env.close();
507 }
508
512 void
513 sendPayments(int newTxes)
514 {
515 int fundedAccounts = accounts.size();
516 assert(fundedAccounts >= newTxes);
518
519 // somewhat random but reproducible
520 int r = ledgerMaster.getClosedLedger()->seq() * 7;
521 int fromIdx = 0;
522 int toIdx = 0;
523 auto updateIdx = [&]() {
524 assert(fundedAccounts > senders.size());
525 fromIdx = (fromIdx + r) % fundedAccounts;
526 while (senders.count(fromIdx) != 0)
527 fromIdx = (fromIdx + 1) % fundedAccounts;
528 senders.insert(fromIdx);
529 toIdx = (toIdx + r * 2) % fundedAccounts;
530 if (toIdx == fromIdx)
531 toIdx = (toIdx + 1) % fundedAccounts;
532 };
533
534 for (int i = 0; i < newTxes; ++i)
535 {
536 updateIdx();
537 env.apply(
538 pay(accounts[fromIdx],
539 accounts[toIdx],
540 jtx::drops(ledgerMaster.getClosedLedger()->fees().base) +
545 }
546 env.close();
547 }
548
552 void
554 {
555 for (int i = 0; i < param.initLedgers - 1; ++i)
556 {
558 }
559 }
560
567};
568
569enum class TaskStatus {
570 Failed,
571 Completed,
572 NotDone,
573 NotExist,
574};
575
584{
585public:
588 LedgerServer& server,
592 : env(suite, jtx::envconfig(), nullptr, beast::severities::kDisabled)
593 , app(env.app())
594 , ledgerMaster(env.app().getLedgerMaster())
596 server.app.getLedgerMaster(),
598 inboundBhvr)
599 , serverMsgHandler(server.app, server.app.getLedgerReplayer())
601 , replayer(
602 env.app(),
604 std::make_unique<TestPeerSetBuilder>(
607 behavior,
608 peerFeature))
609 {
610 }
611
612 void
614 {
616 }
617
618 bool
619 haveLedgers(uint256 const& finishLedgerHash, int totalReplay)
620 {
621 uint256 hash = finishLedgerHash;
622 int i = 0;
623 for (; i < totalReplay; ++i)
624 {
625 auto const l = ledgerMaster.getLedgerByHash(hash);
626 if (!l)
627 return false;
628 hash = l->info().parentHash;
629 }
630 return true;
631 }
632
633 bool
634 waitForLedgers(uint256 const& finishLedgerHash, int totalReplay)
635 {
636 int totalRound = 100;
637 for (int i = 0; i < totalRound; ++i)
638 {
639 if (haveLedgers(finishLedgerHash, totalReplay))
640 return true;
641 if (i < totalRound - 1)
643 }
644 return false;
645 }
646
647 bool
649 {
650 int totalRound = 100;
651 for (int i = 0; i < totalRound; ++i)
652 {
653 bool allDone = true;
654 {
656 for (auto const& t : replayer.tasks_)
657 {
658 if (!t->finished())
659 {
660 allDone = false;
661 break;
662 }
663 }
664 }
665 if (allDone)
666 return true;
667 if (i < totalRound - 1)
669 }
670 return false;
671 }
672
675 {
677 return replayer.tasks_;
678 }
679
681 findTask(uint256 const& hash, int totalReplay)
682 {
684 auto i = std::find_if(
685 replayer.tasks_.begin(), replayer.tasks_.end(), [&](auto const& t) {
686 return t->parameter_.finishHash_ == hash &&
687 t->parameter_.totalLedgers_ == totalReplay;
688 });
689 if (i == replayer.tasks_.end())
690 return {};
691 return *i;
692 }
693
696 {
698 return replayer.deltas_.size();
699 }
700
703 {
705 return replayer.skipLists_.size();
706 }
707
708 bool
710 std::size_t tasks,
711 std::size_t skipLists,
712 std::size_t deltas)
713 {
715 return replayer.tasks_.size() == tasks &&
716 replayer.skipLists_.size() == skipLists &&
717 replayer.deltas_.size() == deltas;
718 }
719
722 {
724 auto i = replayer.skipLists_.find(hash);
725 if (i == replayer.skipLists_.end())
726 return {};
727 return i->second.lock();
728 }
729
732 {
734 auto i = replayer.deltas_.find(hash);
735 if (i == replayer.deltas_.end())
736 return {};
737 return i->second.lock();
738 }
739
740 template <typename T>
743 {
744 if (t->failed_)
745 return TaskStatus::Failed;
746 if (t->complete_)
748 return TaskStatus::NotDone;
749 }
750
751 bool
754 TaskStatus taskExpect,
755 TaskStatus skiplistExpect,
756 std::vector<TaskStatus> const& deltaExpects)
757 {
758 if (taskStatus(task) == taskExpect)
759 {
760 if (taskStatus(task->skipListAcquirer_) == skiplistExpect)
761 {
762 if (task->deltas_.size() == deltaExpects.size())
763 {
764 for (int i = 0; i < deltaExpects.size(); ++i)
765 {
766 if (taskStatus(task->deltas_[i]) != deltaExpects[i])
767 return false;
768 }
769 return true;
770 }
771 }
772 }
773 return false;
774 }
775
776 bool
778 uint256 const& hash,
779 int totalReplay,
780 TaskStatus taskExpect,
781 TaskStatus skiplistExpect,
782 std::vector<TaskStatus> const& deltaExpects)
783 {
784 auto t = findTask(hash, totalReplay);
785 if (!t)
786 {
787 if (taskExpect == TaskStatus::NotExist)
788 return true;
789 return false;
790 }
791
792 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
793 }
794
795 bool
797 uint256 const& hash,
798 int totalReplay,
799 TaskStatus taskExpect,
800 TaskStatus skiplistExpect,
801 std::vector<TaskStatus> const& deltaExpects)
802 {
803 auto t = findTask(hash, totalReplay);
804 if (!t)
805 {
806 if (taskExpect == TaskStatus::NotExist)
807 return true;
808 return false;
809 }
810
811 return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
812 }
813
814 bool
816 uint256 const& hash,
817 int totalReplay,
818 TaskStatus taskExpect,
819 TaskStatus skiplistExpect,
820 std::vector<TaskStatus> const& deltaExpects)
821 {
822 if (!waitForDone())
823 return false;
824
825 return checkStatus(
826 hash, totalReplay, taskExpect, skiplistExpect, deltaExpects);
827 }
828
836};
837
838using namespace beast::severities;
839void
841 LedgerServer& server,
842 LedgerReplayClient& client,
843 beast::severities::Severity level = Severity::kTrace)
844{
845 server.app.logs().threshold(level);
846 client.app.logs().threshold(level);
847}
848// logAll(net.server, net.client);
849
850/*
851 * Create a LedgerServer and a LedgerReplayClient
852 */
854{
857 LedgerServer::Parameter const& param,
861 : server(suite, param)
862 , client(suite, server, behavior, inboundBhvr, peerFeature)
863 {
864 // logAll(server, client);
865 }
868};
869
896{
897 void
899 {
900 testcase("ProofPath");
901 LedgerServer server(*this, {1});
902 auto const l = server.ledgerMaster.getClosedLedger();
903
904 {
905 // request, missing key
906 auto request = std::make_shared<protocol::TMProofPathRequest>();
907 request->set_ledgerhash(
908 l->info().hash.data(), l->info().hash.size());
909 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
910 auto reply = std::make_shared<protocol::TMProofPathResponse>(
911 server.msgHandler.processProofPathRequest(request));
912 BEAST_EXPECT(reply->has_error());
913 BEAST_EXPECT(!server.msgHandler.processProofPathResponse(reply));
914 }
915 {
916 // request, wrong hash
917 auto request = std::make_shared<protocol::TMProofPathRequest>();
918 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
919 request->set_key(
920 keylet::skip().key.data(), keylet::skip().key.size());
921 uint256 hash(1234567);
922 request->set_ledgerhash(hash.data(), hash.size());
923 auto reply = std::make_shared<protocol::TMProofPathResponse>(
924 server.msgHandler.processProofPathRequest(request));
925 BEAST_EXPECT(reply->has_error());
926 }
927
928 {
929 // good request
930 auto request = std::make_shared<protocol::TMProofPathRequest>();
931 request->set_ledgerhash(
932 l->info().hash.data(), l->info().hash.size());
933 request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
934 request->set_key(
935 keylet::skip().key.data(), keylet::skip().key.size());
936 // generate response
937 auto reply = std::make_shared<protocol::TMProofPathResponse>(
938 server.msgHandler.processProofPathRequest(request));
939 BEAST_EXPECT(!reply->has_error());
940 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
941
942 {
943 // bad reply
944 // bad header
945 std::string r(reply->ledgerheader());
946 r.back()--;
947 reply->set_ledgerheader(r);
948 BEAST_EXPECT(
949 !server.msgHandler.processProofPathResponse(reply));
950 r.back()++;
951 reply->set_ledgerheader(r);
952 BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
953 // bad proof path
954 reply->mutable_path()->RemoveLast();
955 BEAST_EXPECT(
956 !server.msgHandler.processProofPathResponse(reply));
957 }
958 }
959 }
960
961 void
963 {
964 testcase("ReplayDelta");
965 LedgerServer server(*this, {1});
966 auto const l = server.ledgerMaster.getClosedLedger();
967
968 {
969 // request, missing hash
970 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
971 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
972 server.msgHandler.processReplayDeltaRequest(request));
973 BEAST_EXPECT(reply->has_error());
974 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
975 // request, wrong hash
976 uint256 hash(1234567);
977 request->set_ledgerhash(hash.data(), hash.size());
978 reply = std::make_shared<protocol::TMReplayDeltaResponse>(
979 server.msgHandler.processReplayDeltaRequest(request));
980 BEAST_EXPECT(reply->has_error());
981 BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
982 }
983
984 {
985 // good request
986 auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
987 request->set_ledgerhash(
988 l->info().hash.data(), l->info().hash.size());
989 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
990 server.msgHandler.processReplayDeltaRequest(request));
991 BEAST_EXPECT(!reply->has_error());
992 BEAST_EXPECT(server.msgHandler.processReplayDeltaResponse(reply));
993
994 {
995 // bad reply
996 // bad header
997 std::string r(reply->ledgerheader());
998 r.back()--;
999 reply->set_ledgerheader(r);
1000 BEAST_EXPECT(
1001 !server.msgHandler.processReplayDeltaResponse(reply));
1002 r.back()++;
1003 reply->set_ledgerheader(r);
1004 BEAST_EXPECT(
1005 server.msgHandler.processReplayDeltaResponse(reply));
1006 // bad txns
1007 reply->mutable_transaction()->RemoveLast();
1008 BEAST_EXPECT(
1009 !server.msgHandler.processReplayDeltaResponse(reply));
1010 }
1011 }
1012 }
1013
1014 void
1016 {
1017 testcase("TaskParameter");
1018
1019 auto makeSkipList = [](int count) -> std::vector<uint256> const {
1021 for (int i = 0; i < count; ++i)
1022 sList.emplace_back(i);
1023 return sList;
1024 };
1025
1028 BEAST_EXPECT(!tp10.update(uint256(777), 5, makeSkipList(10)));
1029 BEAST_EXPECT(!tp10.update(uint256(10), 5, makeSkipList(8)));
1030 BEAST_EXPECT(tp10.update(uint256(10), 10, makeSkipList(10)));
1031
1032 // can merge to self
1033 BEAST_EXPECT(tp10.canMergeInto(tp10));
1034
1035 // smaller task
1038
1039 BEAST_EXPECT(tp9.canMergeInto(tp10));
1040 BEAST_EXPECT(!tp10.canMergeInto(tp9));
1041
1042 tp9.totalLedgers_++;
1043 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1044 tp9.totalLedgers_--;
1045 BEAST_EXPECT(tp9.canMergeInto(tp10));
1046
1048 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1050 BEAST_EXPECT(tp9.canMergeInto(tp10));
1051
1052 tp9.finishHash_ = uint256(1234);
1053 BEAST_EXPECT(!tp9.canMergeInto(tp10));
1054 tp9.finishHash_ = uint256(9);
1055 BEAST_EXPECT(tp9.canMergeInto(tp10));
1056
1057 // larger task
1060 BEAST_EXPECT(tp20.update(uint256(20), 20, makeSkipList(20)));
1061 BEAST_EXPECT(tp10.canMergeInto(tp20));
1062 BEAST_EXPECT(tp9.canMergeInto(tp20));
1063 BEAST_EXPECT(!tp20.canMergeInto(tp10));
1064 BEAST_EXPECT(!tp20.canMergeInto(tp9));
1065 }
1066
1067 void
1069 {
1070 testcase("config test");
1071 {
1072 Config c;
1073 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1074 }
1075
1076 {
1077 Config c;
1078 std::string toLoad(R"rippleConfig(
1079[ledger_replay]
10801
1081)rippleConfig");
1082 c.loadFromString(toLoad);
1083 BEAST_EXPECT(c.LEDGER_REPLAY == true);
1084 }
1085
1086 {
1087 Config c;
1088 std::string toLoad = (R"rippleConfig(
1089[ledger_replay]
10900
1091)rippleConfig");
1092 c.loadFromString(toLoad);
1093 BEAST_EXPECT(c.LEDGER_REPLAY == false);
1094 }
1095 }
1096
1097 void
1099 {
1100 testcase("handshake test");
1101 auto handshake = [&](bool client, bool server, bool expecting) -> bool {
1102 auto request =
1103 ripple::makeRequest(true, false, client, false, false);
1104 http_request_type http_request;
1105 http_request.version(request.version());
1106 http_request.base() = request.base();
1107 bool serverResult =
1108 peerFeatureEnabled(http_request, FEATURE_LEDGER_REPLAY, server);
1109 if (serverResult != expecting)
1110 return false;
1111
1112 beast::IP::Address addr =
1113 boost::asio::ip::address::from_string("172.1.1.100");
1114 jtx::Env serverEnv(*this);
1115 serverEnv.app().config().LEDGER_REPLAY = server;
1116 auto http_resp = ripple::makeResponse(
1117 true,
1118 http_request,
1119 addr,
1120 addr,
1121 uint256{1},
1122 1,
1123 {1, 0},
1124 serverEnv.app());
1125 auto const clientResult =
1126 peerFeatureEnabled(http_resp, FEATURE_LEDGER_REPLAY, client);
1127 if (clientResult != expecting)
1128 return false;
1129
1130 return true;
1131 };
1132
1133 BEAST_EXPECT(handshake(false, false, false));
1134 BEAST_EXPECT(handshake(false, true, false));
1135 BEAST_EXPECT(handshake(true, false, false));
1136 BEAST_EXPECT(handshake(true, true, true));
1137 }
1138
1139 void
1140 testAllLocal(int totalReplay)
1141 {
1142 testcase("local node has all the ledgers");
1143 auto psBhvr = PeerSetBehavior::DropAll;
1144 auto ilBhvr = InboundLedgersBehavior::DropAll;
1145 auto peerFeature = PeerFeature::None;
1146
1147 NetworkOfTwo net(*this, {totalReplay + 1}, psBhvr, ilBhvr, peerFeature);
1148
1149 auto l = net.server.ledgerMaster.getClosedLedger();
1150 uint256 finalHash = l->info().hash;
1151 for (int i = 0; i < totalReplay; ++i)
1152 {
1153 BEAST_EXPECT(l);
1154 if (l)
1155 {
1156 net.client.ledgerMaster.storeLedger(l);
1157 l = net.server.ledgerMaster.getLedgerByHash(
1158 l->info().parentHash);
1159 }
1160 else
1161 break;
1162 }
1163
1164 net.client.replayer.replay(
1165 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1166
1167 std::vector<TaskStatus> deltaStatuses(
1168 totalReplay - 1, TaskStatus::Completed);
1169 BEAST_EXPECT(net.client.waitAndCheckStatus(
1170 finalHash,
1171 totalReplay,
1174 deltaStatuses));
1175
1176 // sweep
1177 net.client.replayer.sweep();
1178 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1179 }
1180
1181 void
1182 testAllInboundLedgers(int totalReplay)
1183 {
1184 testcase("all the ledgers from InboundLedgers");
1185 NetworkOfTwo net(
1186 *this,
1187 {totalReplay + 1},
1191
1192 auto l = net.server.ledgerMaster.getClosedLedger();
1193 uint256 finalHash = l->info().hash;
1194 net.client.replayer.replay(
1195 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1196
1197 std::vector<TaskStatus> deltaStatuses(
1198 totalReplay - 1, TaskStatus::Completed);
1199 BEAST_EXPECT(net.client.waitAndCheckStatus(
1200 finalHash,
1201 totalReplay,
1204 deltaStatuses));
1205
1206 // sweep
1207 net.client.replayer.sweep();
1208 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1209 }
1210
1211 void
1212 testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay = 4)
1213 {
1214 switch (peerSetBehavior)
1215 {
1217 testcase("good network");
1218 break;
1220 testcase("network drops 50% messages");
1221 break;
1223 testcase("network repeats all messages");
1224 break;
1225 default:
1226 return;
1227 }
1228
1229 NetworkOfTwo net(
1230 *this,
1231 {totalReplay + 1},
1232 peerSetBehavior,
1235
1236 // feed client with start ledger since InboundLedgers drops all
1237 auto l = net.server.ledgerMaster.getClosedLedger();
1238 uint256 finalHash = l->info().hash;
1239 for (int i = 0; i < totalReplay - 1; ++i)
1240 {
1241 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1242 }
1243 net.client.ledgerMaster.storeLedger(l);
1244
1245 net.client.replayer.replay(
1246 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1247
1248 std::vector<TaskStatus> deltaStatuses(
1249 totalReplay - 1, TaskStatus::Completed);
1250 BEAST_EXPECT(net.client.waitAndCheckStatus(
1251 finalHash,
1252 totalReplay,
1255 deltaStatuses));
1256 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1257
1258 // sweep
1259 net.client.replayer.sweep();
1260 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1261 }
1262
1263 void
1265 {
1266 testcase("stop before timeout");
1267 int totalReplay = 3;
1268 NetworkOfTwo net(
1269 *this,
1270 {totalReplay + 1},
1274
1275 auto l = net.server.ledgerMaster.getClosedLedger();
1276 uint256 finalHash = l->info().hash;
1277 net.client.replayer.replay(
1278 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1279
1280 std::vector<TaskStatus> deltaStatuses;
1281 BEAST_EXPECT(net.client.checkStatus(
1282 finalHash,
1283 totalReplay,
1286 deltaStatuses));
1287
1288 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1289 net.client.replayer.stop();
1290 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1291 }
1292
1293 void
1295 {
1296 testcase("SkipListAcquire bad reply");
1297 int totalReplay = 3;
1298 NetworkOfTwo net(
1299 *this,
1300 {totalReplay + 1 + 1},
1304
1305 auto l = net.server.ledgerMaster.getClosedLedger();
1306 uint256 finalHash = l->info().hash;
1307 net.client.replayer.replay(
1308 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1309
1310 auto skipList = net.client.findSkipListAcquire(finalHash);
1311
1312 std::uint8_t payload[55] = {
1313 0x6A, 0x09, 0xE6, 0x67, 0xF3, 0xBC, 0xC9, 0x08, 0xB2};
1314 auto item =
1315 make_shamapitem(uint256(12345), Slice(payload, sizeof(payload)));
1316 skipList->processData(l->seq(), item);
1317
1318 std::vector<TaskStatus> deltaStatuses;
1319 BEAST_EXPECT(net.client.waitAndCheckStatus(
1320 finalHash,
1321 totalReplay,
1324 deltaStatuses));
1325
1326 // add another task
1327 net.client.replayer.replay(
1328 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1329 BEAST_EXPECT(net.client.waitAndCheckStatus(
1330 finalHash,
1331 totalReplay,
1334 deltaStatuses));
1335 BEAST_EXPECT(net.client.countsAsExpected(2, 1, 0));
1336 }
1337
1338 void
1340 {
1341 testcase("LedgerDeltaAcquire bad reply");
1342 int totalReplay = 3;
1343 NetworkOfTwo net(
1344 *this,
1345 {totalReplay + 1},
1349
1350 auto l = net.server.ledgerMaster.getClosedLedger();
1351 uint256 finalHash = l->info().hash;
1352 net.client.ledgerMaster.storeLedger(l);
1353 net.client.replayer.replay(
1354 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1355
1356 auto delta = net.client.findLedgerDeltaAcquire(l->info().parentHash);
1357 delta->processData(
1358 l->info(), // wrong ledger info
1360 BEAST_EXPECT(net.client.taskStatus(delta) == TaskStatus::Failed);
1361 BEAST_EXPECT(
1362 net.client.taskStatus(net.client.findTask(
1363 finalHash, totalReplay)) == TaskStatus::Failed);
1364
1365 // add another task
1366 net.client.replayer.replay(
1367 InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1368 BEAST_EXPECT(
1369 net.client.taskStatus(net.client.findTask(
1370 finalHash, totalReplay + 1)) == TaskStatus::Failed);
1371 }
1372
1373 void
1375 {
1376 testcase("Overlap tasks");
1377 int totalReplay = 5;
1378 NetworkOfTwo net(
1379 *this,
1380 {totalReplay * 3 + 1},
1384 auto l = net.server.ledgerMaster.getClosedLedger();
1385 uint256 finalHash = l->info().hash;
1386 net.client.replayer.replay(
1387 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1388 std::vector<TaskStatus> deltaStatuses(
1389 totalReplay - 1, TaskStatus::Completed);
1390 BEAST_EXPECT(net.client.waitAndCheckStatus(
1391 finalHash,
1392 totalReplay,
1395 deltaStatuses));
1396 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1397
1398 // same range, same reason
1399 net.client.replayer.replay(
1400 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1401 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1402 // same range, different reason
1403 net.client.replayer.replay(
1404 InboundLedger::Reason::CONSENSUS, finalHash, totalReplay);
1405 BEAST_EXPECT(net.client.countsAsExpected(2, 1, totalReplay - 1));
1406
1407 // no overlap
1408 for (int i = 0; i < totalReplay + 2; ++i)
1409 {
1410 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1411 }
1412 auto finalHash_early = l->info().hash;
1413 net.client.replayer.replay(
1414 InboundLedger::Reason::GENERIC, finalHash_early, totalReplay);
1415 BEAST_EXPECT(net.client.waitAndCheckStatus(
1416 finalHash_early,
1417 totalReplay,
1420 deltaStatuses)); // deltaStatuses no change
1421 BEAST_EXPECT(net.client.waitForLedgers(finalHash_early, totalReplay));
1422 BEAST_EXPECT(net.client.countsAsExpected(3, 2, 2 * (totalReplay - 1)));
1423
1424 // partial overlap
1425 l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1426 auto finalHash_moreEarly = l->info().parentHash;
1427 net.client.replayer.replay(
1428 InboundLedger::Reason::GENERIC, finalHash_moreEarly, totalReplay);
1429 BEAST_EXPECT(net.client.waitAndCheckStatus(
1430 finalHash_moreEarly,
1431 totalReplay,
1434 deltaStatuses)); // deltaStatuses no change
1435 BEAST_EXPECT(
1436 net.client.waitForLedgers(finalHash_moreEarly, totalReplay));
1437 BEAST_EXPECT(
1438 net.client.countsAsExpected(4, 3, 2 * (totalReplay - 1) + 2));
1439
1440 // cover
1441 net.client.replayer.replay(
1442 InboundLedger::Reason::GENERIC, finalHash, totalReplay * 3);
1443 deltaStatuses =
1444 std::vector<TaskStatus>(totalReplay * 3 - 1, TaskStatus::Completed);
1445 BEAST_EXPECT(net.client.waitAndCheckStatus(
1446 finalHash,
1447 totalReplay * 3,
1450 deltaStatuses)); // deltaStatuses changed
1451 BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay * 3));
1452 BEAST_EXPECT(net.client.countsAsExpected(5, 3, totalReplay * 3 - 1));
1453
1454 // sweep
1455 net.client.replayer.sweep();
1456 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1457 }
1458
1459 void
1460 run() override
1461 {
1462 testProofPath();
1465 testConfig();
1466 testHandshake();
1467 testAllLocal(1);
1468 testAllLocal(3);
1475 testStop();
1479 }
1480};
1481
1483{
1484 void
1486 {
1487 testcase("SkipListAcquire timeout");
1488 int totalReplay = 3;
1489 NetworkOfTwo net(
1490 *this,
1491 {totalReplay + 1},
1495
1496 auto l = net.server.ledgerMaster.getClosedLedger();
1497 uint256 finalHash = l->info().hash;
1498 net.client.replayer.replay(
1499 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1500
1501 std::vector<TaskStatus> deltaStatuses;
1502 BEAST_EXPECT(net.client.waitAndCheckStatus(
1503 finalHash,
1504 totalReplay,
1507 deltaStatuses));
1508
1509 // sweep
1510 BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1511 net.client.replayer.sweep();
1512 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1513 }
1514
1515 void
1517 {
1518 testcase("LedgerDeltaAcquire timeout");
1519 int totalReplay = 3;
1520 NetworkOfTwo net(
1521 *this,
1522 {totalReplay + 1},
1526
1527 auto l = net.server.ledgerMaster.getClosedLedger();
1528 uint256 finalHash = l->info().hash;
1529 net.client.ledgerMaster.storeLedger(l);
1530 net.client.replayer.replay(
1531 InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1532
1533 std::vector<TaskStatus> deltaStatuses(
1534 totalReplay - 1, TaskStatus::Failed);
1535 deltaStatuses.back() = TaskStatus::Completed; // in client ledgerMaster
1536 BEAST_EXPECT(net.client.waitAndCheckStatus(
1537 finalHash,
1538 totalReplay,
1541 deltaStatuses));
1542
1543 // sweep
1544 BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1545 net.client.replayer.sweep();
1546 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1547 }
1548
1549 void
1550 run() override
1551 {
1554 }
1555};
1556
1558{
1559 void
1560 run() override
1561 {
1562 testcase("Acquire 1000 ledgers");
1563 int totalReplay = 250;
1564 int rounds = 4;
1565 NetworkOfTwo net(
1566 *this,
1567 {totalReplay * rounds + 1},
1571
1572 std::vector<uint256> finishHashes;
1573 auto l = net.server.ledgerMaster.getClosedLedger();
1574 for (int i = 0; i < rounds; ++i)
1575 {
1576 finishHashes.push_back(l->info().hash);
1577 for (int j = 0; j < totalReplay; ++j)
1578 {
1579 l = net.server.ledgerMaster.getLedgerByHash(
1580 l->info().parentHash);
1581 }
1582 }
1583 BEAST_EXPECT(finishHashes.size() == rounds);
1584
1585 for (int i = 0; i < rounds; ++i)
1586 {
1587 net.client.replayer.replay(
1588 InboundLedger::Reason::GENERIC, finishHashes[i], totalReplay);
1589 }
1590
1591 std::vector<TaskStatus> deltaStatuses(
1592 totalReplay - 1, TaskStatus::Completed);
1593 for (int i = 0; i < rounds; ++i)
1594 {
1595 BEAST_EXPECT(net.client.waitAndCheckStatus(
1596 finishHashes[i],
1597 totalReplay,
1600 deltaStatuses));
1601 }
1602
1603 BEAST_EXPECT(
1604 net.client.waitForLedgers(finishHashes[0], totalReplay * rounds));
1605 BEAST_EXPECT(net.client.countsAsExpected(
1606 rounds, rounds, rounds * (totalReplay - 1)));
1607
1608 // sweep
1609 net.client.replayer.sweep();
1610 BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1611 }
1612};
1613
1614BEAST_DEFINE_TESTSUITE(LedgerReplay, app, ripple);
1615BEAST_DEFINE_TESTSUITE_PRIO(LedgerReplayer, app, ripple, 1);
1616BEAST_DEFINE_TESTSUITE(LedgerReplayerTimeout, app, ripple);
1617BEAST_DEFINE_TESTSUITE_MANUAL(LedgerReplayerLong, app, ripple);
1618
1619} // namespace test
1620} // 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
std::set< std::optional< uint64_t > > releaseRequestCookies(uint256 const &requestHash) 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)