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
23#include <xrpld/app/ledger/BuildLedger.h>
24#include <xrpld/app/ledger/LedgerMaster.h>
25#include <xrpld/app/ledger/LedgerReplay.h>
26#include <xrpld/app/ledger/LedgerReplayTask.h>
27#include <xrpld/app/ledger/LedgerReplayer.h>
28#include <xrpld/app/ledger/detail/LedgerDeltaAcquire.h>
29#include <xrpld/app/ledger/detail/LedgerReplayMsgHandler.h>
30#include <xrpld/app/ledger/detail/SkipListAcquire.h>
31#include <xrpld/overlay/PeerSet.h>
32#include <xrpld/overlay/detail/PeerImp.h>
33
34#include <xrpl/basics/Slice.h>
35
36#include <chrono>
37#include <thread>
38
39namespace ripple {
40namespace test {
41
43{
44 void
45 run() override
46 {
47 testcase("Replay ledger");
48
49 using namespace jtx;
50
51 // Build a ledger normally
52 auto const alice = Account("alice");
53 auto const bob = Account("bob");
54
55 Env env(*this);
56 env.fund(XRP(100000), alice, bob);
57 env.close();
58
60 auto const lastClosed = ledgerMaster.getClosedLedger();
61 auto const lastClosedParent =
62 ledgerMaster.getLedgerByHash(lastClosed->info().parentHash);
63
64 auto const replayed = buildLedger(
65 LedgerReplay(lastClosedParent, lastClosed),
66 tapNONE,
67 env.app(),
68 env.journal);
69
70 BEAST_EXPECT(replayed->info().hash == lastClosed->info().hash);
71 }
72};
73
75 Good,
76 DropAll,
77};
78
85{
86public:
92 {
93 }
94 virtual ~MagicInboundLedgers() = default;
95
98 override
99 {
101 return {};
102 if (auto l = ledgerSource.getLedgerByHash(hash); l)
103 {
105 return l;
106 }
107
108 return {};
109 }
110
111 virtual void
113 uint256 const& hash,
115 InboundLedger::Reason reason) override
116 {
117 }
118
120 find(LedgerHash const& hash) override
121 {
122 return {};
123 }
124
125 virtual bool
127 LedgerHash const& ledgerHash,
130 {
131 return false;
132 }
133
134 virtual void
136 {
137 }
138
139 virtual void
141 {
142 }
143
144 virtual bool
145 isFailure(uint256 const& h) override
146 {
147 return false;
148 }
149
150 virtual void
151 clearFailures() override
152 {
153 }
154
155 virtual Json::Value
156 getInfo() override
157 {
158 return {};
159 }
160
161 virtual std::size_t
162 fetchRate() override
163 {
164 return 0;
165 }
166
167 virtual void
169 {
170 }
171
172 virtual void
173 gotFetchPack() override
174 {
175 }
176 virtual void
177 sweep() override
178 {
179 }
180
181 virtual void
182 stop() override
183 {
184 }
185
186 virtual size_t
187 cacheSize() override
188 {
189 return 0;
190 }
191
195};
196
197enum class PeerFeature {
199 None,
200};
201
207class TestPeer : public Peer
208{
209public:
210 TestPeer(bool enableLedgerReplay)
211 : ledgerReplayEnabled_(enableLedgerReplay)
213 {
214 }
215
216 void
218 {
219 }
221 getRemoteAddress() const override
222 {
223 return {};
224 }
225 void
226 charge(Resource::Charge const& fee, std::string const& context = {})
227 override
228 {
229 }
230 id_t
231 id() const override
232 {
233 return 1234;
234 }
235 bool
236 cluster() const override
237 {
238 return false;
239 }
240 bool
241 isHighLatency() const override
242 {
243 return false;
244 }
245 int
246 getScore(bool) const override
247 {
248 return 0;
249 }
250 PublicKey const&
251 getNodePublic() const override
252 {
253 return nodePublicKey_;
254 }
256 json() override
257 {
258 return {};
259 }
260 bool
262 {
264 return true;
265 return false;
266 }
268 publisherListSequence(PublicKey const&) const override
269 {
270 return {};
271 }
272 void
274 {
275 }
276 uint256 const&
277 getClosedLedgerHash() const override
278 {
279 static uint256 hash{};
280 return hash;
281 }
282 bool
283 hasLedger(uint256 const& hash, std::uint32_t seq) const override
284 {
285 return true;
286 }
287 void
288 ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override
289 {
290 }
291 bool
292 hasTxSet(uint256 const& hash) const override
293 {
294 return false;
295 }
296 void
297 cycleStatus() override
298 {
299 }
300 bool
302 {
303 return false;
304 }
305 bool
306 compressionEnabled() const override
307 {
308 return false;
309 }
310 void
311 sendTxQueue() override
312 {
313 }
314 void
315 addTxQueue(uint256 const&) override
316 {
317 }
318 void
319 removeTxQueue(uint256 const&) override
320 {
321 }
322 bool
323 txReduceRelayEnabled() const override
324 {
325 return false;
326 }
327
330};
331
332enum class PeerSetBehavior {
333 Good,
334 Drop50,
335 DropAll,
338 Repeat,
339};
340
347struct TestPeerSet : public PeerSet
348{
352 PeerSetBehavior bhvr,
353 bool enableLedgerReplay)
354 : local(me)
355 , remote(other)
356 , dummyPeer(std::make_shared<TestPeer>(enableLedgerReplay))
357 , behavior(bhvr)
358 {
359 }
360
361 void
363 std::size_t limit,
364 std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
365 std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) override
366 {
367 hasItem(dummyPeer);
368 onPeerAdded(dummyPeer);
369 }
370
371 void
373 ::google::protobuf::Message const& msg,
374 protocol::MessageType type,
375 std::shared_ptr<Peer> const& peer) override
376 {
377 int dropRate = 0;
379 dropRate = 50;
381 dropRate = 100;
382
383 if ((rand() % 100 + 1) <= dropRate)
384 return;
385
386 switch (type)
387 {
388 case protocol::mtPROOF_PATH_REQ: {
390 return;
391 auto request = std::make_shared<protocol::TMProofPathRequest>(
392 dynamic_cast<protocol::TMProofPathRequest const&>(msg));
393 auto reply = std::make_shared<protocol::TMProofPathResponse>(
398 break;
399 }
400 case protocol::mtREPLAY_DELTA_REQ: {
402 return;
403 auto request = std::make_shared<protocol::TMReplayDeltaRequest>(
404 dynamic_cast<protocol::TMReplayDeltaRequest const&>(msg));
405 auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
410 break;
411 }
412 default:
413 return;
414 }
415 }
416
418 getPeerIds() const override
419 {
420 static std::set<Peer::id_t> emptyPeers;
421 return emptyPeers;
422 }
423
428};
429
434{
435public:
439 PeerSetBehavior bhvr,
440 PeerFeature peerFeature)
441 : local(me)
442 , remote(other)
443 , behavior(bhvr)
445 {
446 }
447
449 build() override
450 {
451 return std::make_unique<TestPeerSet>(
453 }
454
455private:
460};
461
467{
469 {
471 int initAccounts = 10;
472 int initAmount = 1'000'000;
474 int txAmount = 10;
475 };
476
478 : env(suite)
479 , app(env.app())
480 , ledgerMaster(env.app().getLedgerMaster())
481 , msgHandler(env.app(), env.app().getLedgerReplayer())
482 , param(p)
483 {
484 assert(param.initLedgers > 0);
488 }
489
493 void
494 createAccounts(int newAccounts)
495 {
496 auto fundedAccounts = accounts.size();
497 for (int i = 0; i < newAccounts; ++i)
498 {
499 accounts.emplace_back(
500 "alice_" + std::to_string(fundedAccounts + i));
502 }
503 env.close();
504 }
505
509 void
510 sendPayments(int newTxes)
511 {
512 int fundedAccounts = accounts.size();
513 assert(fundedAccounts >= newTxes);
515
516 // somewhat random but reproducible
517 int r = ledgerMaster.getClosedLedger()->seq() * 7;
518 int fromIdx = 0;
519 int toIdx = 0;
520 auto updateIdx = [&]() {
521 assert(fundedAccounts > senders.size());
522 fromIdx = (fromIdx + r) % fundedAccounts;
523 while (senders.count(fromIdx) != 0)
524 fromIdx = (fromIdx + 1) % fundedAccounts;
525 senders.insert(fromIdx);
526 toIdx = (toIdx + r * 2) % fundedAccounts;
527 if (toIdx == fromIdx)
528 toIdx = (toIdx + 1) % fundedAccounts;
529 };
530
531 for (int i = 0; i < newTxes; ++i)
532 {
533 updateIdx();
534 env.apply(
535 pay(accounts[fromIdx],
536 accounts[toIdx],
537 jtx::drops(ledgerMaster.getClosedLedger()->fees().base) +
542 }
543 env.close();
544 }
545
549 void
551 {
552 for (int i = 0; i < param.initLedgers - 1; ++i)
553 {
555 }
556 }
557
564};
565
566enum class TaskStatus {
567 Failed,
568 Completed,
569 NotDone,
570 NotExist,
571};
572
581{
582public:
585 LedgerServer& server,
589 : env(suite, jtx::envconfig(), nullptr, 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:150
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
A testsuite class.
Definition: suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:155
virtual Config & config()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual Logs & logs()=0
bool LEDGER_REPLAY
Definition: Config.h:223
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
Definition: Config.cpp:478
Manages the lifetime of inbound ledgers.
std::shared_ptr< Ledger const > getClosedLedger()
Definition: LedgerMaster.h:79
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:166
Supports data retrieval by managing a set of peers.
Definition: PeerSet.h:40
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:46
pointer data()
Definition: base_uint.h:125
static constexpr std::size_t size()
Definition: base_uint.h:526
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
void removeTxQueue(uint256 const &) override
Remove hash from the transactions' hashes queue.
beast::IP::Endpoint getRemoteAddress() const override
TestPeer(bool enableLedgerReplay)
int getScore(bool) const override
PublicKey const & getNodePublic() const override
void charge(Resource::Charge const &fee, std::string const &context={}) override
Adjust this peer's load balance based on the type of load imposed.
Json::Value json() override
void send(std::shared_ptr< Message > const &m) override
void ledgerRange(std::uint32_t &minSeq, std::uint32_t &maxSeq) const override
void addTxQueue(uint256 const &) override
Aggregate transaction's hash.
id_t id() const override
bool txReduceRelayEnabled() const override
bool isHighLatency() const override
bool hasTxSet(uint256 const &hash) const override
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:39
A transaction testing environment.
Definition: Env.h:121
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition: Env.cpp:117
Application & app()
Definition: Env.h:261
beast::Journal const journal
Definition: Env.h:162
Env & apply(JsonValue &&jv, FN const &... fN)
Apply funclets and submit.
Definition: Env.h:570
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:233
Set the fee on a JTx.
Definition: fee.h:37
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:43
A namespace for easy access to logging severity values.
Definition: Journal.h:30
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:32
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:189
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:30
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:105
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
base_uint< 256 > uint256
Definition: base_uint.h:558
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:392
static constexpr char FEATURE_LEDGER_REPLAY[]
Definition: Handshake.h:147
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
Definition: SecretKey.cpp:331
SecretKey randomSecretKey()
Create a secret key using secure random numbers.
Definition: SecretKey.cpp:299
KeyType
Definition: KeyType.h:28
std::shared_ptr< Ledger > buildLedger(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, bool const closeTimeCorrect, NetClock::duration closeResolution, Application &app, CanonicalTXSet &txns, std::set< TxID > &failedTxs, beast::Journal j)
Build a new ledger by applying consensus transactions.
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handoff.h:33
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition: SHAMapItem.h:161
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:198
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
Definition: Handshake.cpp:365
@ tapNONE
Definition: ApplyView.h:32
@ 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
std::set< Peer::id_t > const & getPeerIds() const override
get the set of ids of previously added peers
LedgerReplayMsgHandler & local
std::shared_ptr< TestPeer > dummyPeer
Set the sequence number on a JTx.
Definition: seq.h:34
T to_string(T... args)