rippled
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 <ripple/app/ledger/BuildLedger.h>
21 #include <ripple/app/ledger/LedgerMaster.h>
22 #include <ripple/app/ledger/LedgerReplay.h>
23 #include <ripple/app/ledger/LedgerReplayTask.h>
24 #include <ripple/app/ledger/LedgerReplayer.h>
25 #include <ripple/app/ledger/impl/LedgerDeltaAcquire.h>
26 #include <ripple/app/ledger/impl/LedgerReplayMsgHandler.h>
27 #include <ripple/app/ledger/impl/SkipListAcquire.h>
28 #include <ripple/basics/Slice.h>
29 #include <ripple/overlay/PeerSet.h>
30 #include <ripple/overlay/impl/PeerImp.h>
31 #include <test/jtx.h>
32 #include <test/jtx/envconfig.h>
33 
34 #include <chrono>
35 #include <thread>
36 
37 namespace ripple {
38 namespace test {
39 
40 struct LedgerReplay_test : public beast::unit_test::suite
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 {
84 public:
86  LedgerMaster& ledgerSource,
87  LedgerMaster& ledgerSink,
89  : ledgerSource(ledgerSource), ledgerSink(ledgerSink), bhvr(bhvr)
90  {
91  }
92  virtual ~MagicInboundLedgers() = default;
93 
96  override
97  {
99  return {};
100  if (auto l = ledgerSource.getLedgerByHash(hash); l)
101  {
102  ledgerSink.storeLedger(l);
103  return l;
104  }
105 
106  return {};
107  }
108 
110  find(LedgerHash const& hash) override
111  {
112  return {};
113  }
114 
115  virtual bool
117  LedgerHash const& ledgerHash,
120  {
121  return false;
122  }
123 
124  virtual void
126  {
127  }
128 
129  virtual void
130  logFailure(uint256 const& h, std::uint32_t seq) override
131  {
132  }
133 
134  virtual bool
135  isFailure(uint256 const& h) override
136  {
137  return false;
138  }
139 
140  virtual void
141  clearFailures() override
142  {
143  }
144 
145  virtual Json::Value
146  getInfo() override
147  {
148  return {};
149  }
150 
151  virtual std::size_t
152  fetchRate() override
153  {
154  return 0;
155  }
156 
157  virtual void
158  onLedgerFetched() override
159  {
160  }
161 
162  virtual void
163  gotFetchPack() override
164  {
165  }
166  virtual void
167  sweep() override
168  {
169  }
170 
171  virtual void
172  stop() override
173  {
174  }
175 
179 };
180 
181 enum class PeerFeature {
183  None,
184 };
185 
191 class TestPeer : public Peer
192 {
193 public:
194  TestPeer(bool enableLedgerReplay) : ledgerReplayEnabled_(enableLedgerReplay)
195  {
196  }
197 
198  void
199  send(std::shared_ptr<Message> const& m) override
200  {
201  }
203  getRemoteAddress() const override
204  {
205  return {};
206  }
207  void
208  charge(Resource::Charge const& fee) override
209  {
210  }
211  id_t
212  id() const override
213  {
214  return 1234;
215  }
216  bool
217  cluster() const override
218  {
219  return false;
220  }
221  bool
222  isHighLatency() const override
223  {
224  return false;
225  }
226  int
227  getScore(bool) const override
228  {
229  return 0;
230  }
231  PublicKey const&
232  getNodePublic() const override
233  {
234  static PublicKey key{};
235  return key;
236  }
238  json() override
239  {
240  return {};
241  }
242  bool
244  {
245  if (f == ProtocolFeature::LedgerReplay && ledgerReplayEnabled_)
246  return true;
247  return false;
248  }
250  publisherListSequence(PublicKey const&) const override
251  {
252  return {};
253  }
254  void
256  {
257  }
258  uint256 const&
259  getClosedLedgerHash() const override
260  {
261  static uint256 hash{};
262  return hash;
263  }
264  bool
265  hasLedger(uint256 const& hash, std::uint32_t seq) const override
266  {
267  return true;
268  }
269  void
270  ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override
271  {
272  }
273  bool
274  hasTxSet(uint256 const& hash) const override
275  {
276  return false;
277  }
278  void
279  cycleStatus() override
280  {
281  }
282  bool
283  hasRange(std::uint32_t uMin, std::uint32_t uMax) override
284  {
285  return false;
286  }
287  bool
288  compressionEnabled() const override
289  {
290  return false;
291  }
292 
294 };
295 
296 enum class PeerSetBehavior {
297  Good,
298  Drop50,
299  DropAll,
302  Repeat,
303 };
304 
311 struct TestPeerSet : public PeerSet
312 {
315  LedgerReplayMsgHandler& other,
316  PeerSetBehavior bhvr,
317  bool enableLedgerReplay)
318  : local(me)
319  , remote(other)
320  , dummyPeer(std::make_shared<TestPeer>(enableLedgerReplay))
321  , behavior(bhvr)
322  {
323  }
324 
325  void
327  std::size_t limit,
328  std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
329  std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) override
330  {
331  hasItem(dummyPeer);
332  onPeerAdded(dummyPeer);
333  }
334 
335  void
337  ::google::protobuf::Message const& msg,
338  protocol::MessageType type,
339  std::shared_ptr<Peer> const& peer) override
340  {
341  int dropRate = 0;
342  if (behavior == PeerSetBehavior::Drop50)
343  dropRate = 50;
344  else if (behavior == PeerSetBehavior::DropAll)
345  dropRate = 100;
346 
347  if ((rand() % 100 + 1) <= dropRate)
348  return;
349 
350  switch (type)
351  {
352  case protocol::mtPROOF_PATH_REQ: {
353  if (behavior == PeerSetBehavior::DropSkipListReply)
354  return;
355  auto request = std::make_shared<protocol::TMProofPathRequest>(
356  dynamic_cast<protocol::TMProofPathRequest const&>(msg));
357  auto reply = std::make_shared<protocol::TMProofPathResponse>(
358  remote.processProofPathRequest(request));
359  local.processProofPathResponse(reply);
360  if (behavior == PeerSetBehavior::Repeat)
361  local.processProofPathResponse(reply);
362  break;
363  }
364  case protocol::mtREPLAY_DELTA_REQ: {
366  return;
367  auto request = std::make_shared<protocol::TMReplayDeltaRequest>(
368  dynamic_cast<protocol::TMReplayDeltaRequest const&>(msg));
369  auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
370  remote.processReplayDeltaRequest(request));
371  local.processReplayDeltaResponse(reply);
372  if (behavior == PeerSetBehavior::Repeat)
373  local.processReplayDeltaResponse(reply);
374  break;
375  }
376  default:
377  return;
378  }
379  }
380 
381  const std::set<Peer::id_t>&
382  getPeerIds() const override
383  {
384  static std::set<Peer::id_t> emptyPeers;
385  return emptyPeers;
386  }
387 
392 };
393 
398 {
399 public:
402  LedgerReplayMsgHandler& other,
403  PeerSetBehavior bhvr,
404  PeerFeature peerFeature)
405  : local(me)
406  , remote(other)
407  , behavior(bhvr)
408  , enableLedgerReplay(peerFeature == PeerFeature::LedgerReplayEnabled)
409  {
410  }
411 
413  build() override
414  {
415  return std::make_unique<TestPeerSet>(
416  local, remote, behavior, enableLedgerReplay);
417  }
418 
419 private:
424 };
425 
431 {
432  struct Parameter
433  {
435  int initAccounts = 10;
436  int initAmount = 1'000'000;
437  int numTxPerLedger = 10;
438  int txAmount = 10;
439  };
440 
441  LedgerServer(beast::unit_test::suite& suite, Parameter const& p)
442  : env(suite)
443  , app(env.app())
444  , ledgerMaster(env.app().getLedgerMaster())
445  , msgHandler(env.app(), env.app().getLedgerReplayer())
446  , param(p)
447  {
448  assert(param.initLedgers > 0);
449  createAccounts(param.initAccounts);
450  createLedgerHistory();
451  app.logs().threshold(beast::severities::Severity::kWarning);
452  }
453 
457  void
458  createAccounts(int newAccounts)
459  {
460  auto fundedAccounts = accounts.size();
461  for (int i = 0; i < newAccounts; ++i)
462  {
463  accounts.emplace_back(
464  "alice_" + std::to_string(fundedAccounts + i));
465  env.fund(jtx::XRP(param.initAmount), accounts.back());
466  }
467  env.close();
468  }
469 
473  void
474  sendPayments(int newTxes)
475  {
476  int fundedAccounts = accounts.size();
477  assert(fundedAccounts >= newTxes);
478  std::unordered_set<int> senders;
479 
480  // somewhat random but reproducible
481  int r = ledgerMaster.getClosedLedger()->seq() * 7;
482  int fromIdx = 0;
483  int toIdx = 0;
484  auto updateIdx = [&]() {
485  assert(fundedAccounts > senders.size());
486  fromIdx = (fromIdx + r) % fundedAccounts;
487  while (senders.count(fromIdx) != 0)
488  fromIdx = (fromIdx + 1) % fundedAccounts;
489  senders.insert(fromIdx);
490  toIdx = (toIdx + r * 2) % fundedAccounts;
491  if (toIdx == fromIdx)
492  toIdx = (toIdx + 1) % fundedAccounts;
493  };
494 
495  for (int i = 0; i < newTxes; ++i)
496  {
497  updateIdx();
498  env.apply(
499  pay(accounts[fromIdx],
500  accounts[toIdx],
501  jtx::drops(ledgerMaster.getClosedLedger()->fees().base) +
502  jtx::XRP(param.txAmount)),
506  }
507  env.close();
508  }
509 
513  void
515  {
516  for (int i = 0; i < param.initLedgers - 1; ++i)
517  {
518  sendPayments(param.numTxPerLedger);
519  }
520  }
521 
528 };
529 
530 enum class TaskStatus {
531  Failed,
532  Completed,
533  NotDone,
534  NotExist,
535 };
536 
545 {
546 public:
548  beast::unit_test::suite& suite,
549  LedgerServer& server,
553  : env(suite, jtx::envconfig(jtx::port_increment, 3))
554  , app(env.app())
555  , ledgerMaster(env.app().getLedgerMaster())
556  , inboundLedgers(
557  server.app.getLedgerMaster(),
558  ledgerMaster,
559  inboundBhvr)
560  , serverMsgHandler(server.app, server.app.getLedgerReplayer())
561  , clientMsgHandler(env.app(), replayer)
562  , replayer(
563  env.app(),
564  inboundLedgers,
565  std::make_unique<TestPeerSetBuilder>(
566  clientMsgHandler,
567  serverMsgHandler,
568  behavior,
569  peerFeature))
570  {
571  }
572 
573  void
575  {
576  ledgerMaster.storeLedger(l);
577  }
578 
579  bool
580  haveLedgers(uint256 const& finishLedgerHash, int totalReplay)
581  {
582  uint256 hash = finishLedgerHash;
583  int i = 0;
584  for (; i < totalReplay; ++i)
585  {
586  auto const l = ledgerMaster.getLedgerByHash(hash);
587  if (!l)
588  return false;
589  hash = l->info().parentHash;
590  }
591  return true;
592  }
593 
594  bool
595  waitForLedgers(uint256 const& finishLedgerHash, int totalReplay)
596  {
597  int totalRound = 100;
598  for (int i = 0; i < totalRound; ++i)
599  {
600  if (haveLedgers(finishLedgerHash, totalReplay))
601  return true;
602  if (i < totalRound - 1)
604  }
605  return false;
606  }
607 
608  bool
610  {
611  int totalRound = 100;
612  for (int i = 0; i < totalRound; ++i)
613  {
614  bool allDone = true;
615  {
616  std::unique_lock<std::mutex> lock(replayer.mtx_);
617  for (auto const& t : replayer.tasks_)
618  {
619  if (!t->finished())
620  {
621  allDone = false;
622  break;
623  }
624  }
625  }
626  if (allDone)
627  return true;
628  if (i < totalRound - 1)
630  }
631  return false;
632  }
633 
636  {
637  std::unique_lock<std::mutex> lock(replayer.mtx_);
638  return replayer.tasks_;
639  }
640 
642  findTask(uint256 const& hash, int totalReplay)
643  {
644  std::unique_lock<std::mutex> lock(replayer.mtx_);
645  auto i = std::find_if(
646  replayer.tasks_.begin(), replayer.tasks_.end(), [&](auto const& t) {
647  return t->parameter_.finishHash_ == hash &&
648  t->parameter_.totalLedgers_ == totalReplay;
649  });
650  if (i == replayer.tasks_.end())
651  return {};
652  return *i;
653  }
654 
657  {
658  std::unique_lock<std::mutex> lock(replayer.mtx_);
659  return replayer.deltas_.size();
660  }
661 
664  {
665  std::unique_lock<std::mutex> lock(replayer.mtx_);
666  return replayer.skipLists_.size();
667  }
668 
669  bool
671  std::size_t tasks,
672  std::size_t skipLists,
673  std::size_t deltas)
674  {
675  std::unique_lock<std::mutex> lock(replayer.mtx_);
676  return replayer.tasks_.size() == tasks &&
677  replayer.skipLists_.size() == skipLists &&
678  replayer.deltas_.size() == deltas;
679  }
680 
683  {
684  std::unique_lock<std::mutex> lock(replayer.mtx_);
685  auto i = replayer.skipLists_.find(hash);
686  if (i == replayer.skipLists_.end())
687  return {};
688  return i->second.lock();
689  }
690 
693  {
694  std::unique_lock<std::mutex> lock(replayer.mtx_);
695  auto i = replayer.deltas_.find(hash);
696  if (i == replayer.deltas_.end())
697  return {};
698  return i->second.lock();
699  }
700 
701  template <typename T>
702  TaskStatus
704  {
705  if (t->failed_)
706  return TaskStatus::Failed;
707  if (t->complete_)
708  return TaskStatus::Completed;
709  return TaskStatus::NotDone;
710  }
711 
712  bool
715  TaskStatus taskExpect,
716  TaskStatus skiplistExpect,
717  std::vector<TaskStatus> const& deltaExpects)
718  {
719  if (taskStatus(task) == taskExpect)
720  {
721  if (taskStatus(task->skipListAcquirer_) == skiplistExpect)
722  {
723  if (task->deltas_.size() == deltaExpects.size())
724  {
725  for (int i = 0; i < deltaExpects.size(); ++i)
726  {
727  if (taskStatus(task->deltas_[i]) != deltaExpects[i])
728  return false;
729  }
730  return true;
731  }
732  }
733  }
734  return false;
735  }
736 
737  bool
739  uint256 const& hash,
740  int totalReplay,
741  TaskStatus taskExpect,
742  TaskStatus skiplistExpect,
743  std::vector<TaskStatus> const& deltaExpects)
744  {
745  auto t = findTask(hash, totalReplay);
746  if (!t)
747  {
748  if (taskExpect == TaskStatus::NotExist)
749  return true;
750  return false;
751  }
752 
753  return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
754  }
755 
756  bool
758  uint256 const& hash,
759  int totalReplay,
760  TaskStatus taskExpect,
761  TaskStatus skiplistExpect,
762  std::vector<TaskStatus> const& deltaExpects)
763  {
764  auto t = findTask(hash, totalReplay);
765  if (!t)
766  {
767  if (taskExpect == TaskStatus::NotExist)
768  return true;
769  return false;
770  }
771 
772  return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
773  }
774 
775  bool
777  uint256 const& hash,
778  int totalReplay,
779  TaskStatus taskExpect,
780  TaskStatus skiplistExpect,
781  std::vector<TaskStatus> const& deltaExpects)
782  {
783  if (!waitForDone())
784  return false;
785 
786  return checkStatus(
787  hash, totalReplay, taskExpect, skiplistExpect, deltaExpects);
788  }
789 
797 };
798 
799 using namespace beast::severities;
800 void
802  LedgerServer& server,
803  LedgerReplayClient& client,
804  beast::severities::Severity level = Severity::kTrace)
805 {
806  server.app.logs().threshold(level);
807  client.app.logs().threshold(level);
808 }
809 // logAll(net.server, net.client);
810 
811 /*
812  * Create a LedgerServer and a LedgerReplayClient
813  */
815 {
817  beast::unit_test::suite& suite,
818  LedgerServer::Parameter const& param,
822  : server(suite, param)
823  , client(suite, server, behavior, inboundBhvr, peerFeature)
824  {
825  // logAll(server, client);
826  }
829 };
830 
856 struct LedgerReplayer_test : public beast::unit_test::suite
857 {
858  void
860  {
861  testcase("ProofPath");
862  LedgerServer server(*this, {1});
863  auto const l = server.ledgerMaster.getClosedLedger();
864 
865  {
866  // request, missing key
867  auto request = std::make_shared<protocol::TMProofPathRequest>();
868  request->set_ledgerhash(
869  l->info().hash.data(), l->info().hash.size());
870  request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
871  auto reply = std::make_shared<protocol::TMProofPathResponse>(
872  server.msgHandler.processProofPathRequest(request));
873  BEAST_EXPECT(reply->has_error());
874  BEAST_EXPECT(!server.msgHandler.processProofPathResponse(reply));
875  }
876  {
877  // request, wrong hash
878  auto request = std::make_shared<protocol::TMProofPathRequest>();
879  request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
880  request->set_key(
881  keylet::skip().key.data(), keylet::skip().key.size());
882  uint256 hash(1234567);
883  request->set_ledgerhash(hash.data(), hash.size());
884  auto reply = std::make_shared<protocol::TMProofPathResponse>(
885  server.msgHandler.processProofPathRequest(request));
886  BEAST_EXPECT(reply->has_error());
887  }
888 
889  {
890  // good request
891  auto request = std::make_shared<protocol::TMProofPathRequest>();
892  request->set_ledgerhash(
893  l->info().hash.data(), l->info().hash.size());
894  request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
895  request->set_key(
896  keylet::skip().key.data(), keylet::skip().key.size());
897  // generate response
898  auto reply = std::make_shared<protocol::TMProofPathResponse>(
899  server.msgHandler.processProofPathRequest(request));
900  BEAST_EXPECT(!reply->has_error());
901  BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
902 
903  {
904  // bad reply
905  // bad header
906  std::string r(reply->ledgerheader());
907  r.back()--;
908  reply->set_ledgerheader(r);
909  BEAST_EXPECT(
910  !server.msgHandler.processProofPathResponse(reply));
911  r.back()++;
912  reply->set_ledgerheader(r);
913  BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
914  // bad proof path
915  reply->mutable_path()->RemoveLast();
916  BEAST_EXPECT(
917  !server.msgHandler.processProofPathResponse(reply));
918  }
919  }
920  }
921 
922  void
924  {
925  testcase("ReplayDelta");
926  LedgerServer server(*this, {1});
927  auto const l = server.ledgerMaster.getClosedLedger();
928 
929  {
930  // request, missing hash
931  auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
932  auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
933  server.msgHandler.processReplayDeltaRequest(request));
934  BEAST_EXPECT(reply->has_error());
935  BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
936  // request, wrong hash
937  uint256 hash(1234567);
938  request->set_ledgerhash(hash.data(), hash.size());
939  reply = std::make_shared<protocol::TMReplayDeltaResponse>(
940  server.msgHandler.processReplayDeltaRequest(request));
941  BEAST_EXPECT(reply->has_error());
942  BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
943  }
944 
945  {
946  // good request
947  auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
948  request->set_ledgerhash(
949  l->info().hash.data(), l->info().hash.size());
950  auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
951  server.msgHandler.processReplayDeltaRequest(request));
952  BEAST_EXPECT(!reply->has_error());
953  BEAST_EXPECT(server.msgHandler.processReplayDeltaResponse(reply));
954 
955  {
956  // bad reply
957  // bad header
958  std::string r(reply->ledgerheader());
959  r.back()--;
960  reply->set_ledgerheader(r);
961  BEAST_EXPECT(
962  !server.msgHandler.processReplayDeltaResponse(reply));
963  r.back()++;
964  reply->set_ledgerheader(r);
965  BEAST_EXPECT(
966  server.msgHandler.processReplayDeltaResponse(reply));
967  // bad txns
968  reply->mutable_transaction()->RemoveLast();
969  BEAST_EXPECT(
970  !server.msgHandler.processReplayDeltaResponse(reply));
971  }
972  }
973  }
974 
975  void
977  {
978  testcase("TaskParameter");
979 
980  auto makeSkipList = [](int count) -> std::vector<uint256> const {
981  std::vector<uint256> sList;
982  for (int i = 0; i < count; ++i)
983  sList.emplace_back(i);
984  return sList;
985  };
986 
989  BEAST_EXPECT(!tp10.update(uint256(777), 5, makeSkipList(10)));
990  BEAST_EXPECT(!tp10.update(uint256(10), 5, makeSkipList(8)));
991  BEAST_EXPECT(tp10.update(uint256(10), 10, makeSkipList(10)));
992 
993  // can merge to self
994  BEAST_EXPECT(tp10.canMergeInto(tp10));
995 
996  // smaller task
999 
1000  BEAST_EXPECT(tp9.canMergeInto(tp10));
1001  BEAST_EXPECT(!tp10.canMergeInto(tp9));
1002 
1003  tp9.totalLedgers_++;
1004  BEAST_EXPECT(!tp9.canMergeInto(tp10));
1005  tp9.totalLedgers_--;
1006  BEAST_EXPECT(tp9.canMergeInto(tp10));
1007 
1009  BEAST_EXPECT(!tp9.canMergeInto(tp10));
1011  BEAST_EXPECT(tp9.canMergeInto(tp10));
1012 
1013  tp9.finishHash_ = uint256(1234);
1014  BEAST_EXPECT(!tp9.canMergeInto(tp10));
1015  tp9.finishHash_ = uint256(9);
1016  BEAST_EXPECT(tp9.canMergeInto(tp10));
1017 
1018  // larger task
1021  BEAST_EXPECT(tp20.update(uint256(20), 20, makeSkipList(20)));
1022  BEAST_EXPECT(tp10.canMergeInto(tp20));
1023  BEAST_EXPECT(tp9.canMergeInto(tp20));
1024  BEAST_EXPECT(!tp20.canMergeInto(tp10));
1025  BEAST_EXPECT(!tp20.canMergeInto(tp9));
1026  }
1027 
1028  void
1030  {
1031  testcase("config test");
1032  {
1033  Config c;
1034  BEAST_EXPECT(c.LEDGER_REPLAY == false);
1035  }
1036 
1037  {
1038  Config c;
1039  std::string toLoad(R"rippleConfig(
1040 [ledger_replay]
1041 1
1042 )rippleConfig");
1043  c.loadFromString(toLoad);
1044  BEAST_EXPECT(c.LEDGER_REPLAY == true);
1045  }
1046 
1047  {
1048  Config c;
1049  std::string toLoad = (R"rippleConfig(
1050 [ledger_replay]
1051 0
1052 )rippleConfig");
1053  c.loadFromString(toLoad);
1054  BEAST_EXPECT(c.LEDGER_REPLAY == false);
1055  }
1056  }
1057 
1058  void
1060  {
1061  testcase("handshake test");
1062  auto handshake = [&](bool client, bool server, bool expecting) -> bool {
1063  auto request = ripple::makeRequest(true, false, false, client);
1064  http_request_type http_request;
1065  http_request.version(request.version());
1066  http_request.base() = request.base();
1067  bool serverResult =
1068  peerFeatureEnabled(http_request, FEATURE_LEDGER_REPLAY, server);
1069  if (serverResult != expecting)
1070  return false;
1071 
1072  beast::IP::Address addr =
1073  boost::asio::ip::address::from_string("172.1.1.100");
1074  jtx::Env serverEnv(*this);
1075  serverEnv.app().config().LEDGER_REPLAY = server;
1076  auto http_resp = ripple::makeResponse(
1077  true,
1078  http_request,
1079  addr,
1080  addr,
1081  uint256{1},
1082  1,
1083  {1, 0},
1084  serverEnv.app());
1085  auto const clientResult =
1086  peerFeatureEnabled(http_resp, FEATURE_LEDGER_REPLAY, client);
1087  if (clientResult != expecting)
1088  return false;
1089 
1090  return true;
1091  };
1092 
1093  BEAST_EXPECT(handshake(false, false, false));
1094  BEAST_EXPECT(handshake(false, true, false));
1095  BEAST_EXPECT(handshake(true, false, false));
1096  BEAST_EXPECT(handshake(true, true, true));
1097  }
1098 
1099  void
1100  testAllLocal(int totalReplay)
1101  {
1102  testcase("local node has all the ledgers");
1103  auto psBhvr = PeerSetBehavior::DropAll;
1104  auto ilBhvr = InboundLedgersBehavior::DropAll;
1105  auto peerFeature = PeerFeature::None;
1106 
1107  NetworkOfTwo net(*this, {totalReplay + 1}, psBhvr, ilBhvr, peerFeature);
1108 
1109  auto l = net.server.ledgerMaster.getClosedLedger();
1110  uint256 finalHash = l->info().hash;
1111  for (int i = 0; i < totalReplay; ++i)
1112  {
1113  BEAST_EXPECT(l);
1114  if (l)
1115  {
1116  net.client.ledgerMaster.storeLedger(l);
1117  l = net.server.ledgerMaster.getLedgerByHash(
1118  l->info().parentHash);
1119  }
1120  else
1121  break;
1122  }
1123 
1124  net.client.replayer.replay(
1125  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1126 
1127  std::vector<TaskStatus> deltaStatuses(
1128  totalReplay - 1, TaskStatus::Completed);
1129  BEAST_EXPECT(net.client.waitAndCheckStatus(
1130  finalHash,
1131  totalReplay,
1134  deltaStatuses));
1135 
1136  // sweep
1137  net.client.replayer.sweep();
1138  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1139  }
1140 
1141  void
1142  testAllInboundLedgers(int totalReplay)
1143  {
1144  testcase("all the ledgers from InboundLedgers");
1145  NetworkOfTwo net(
1146  *this,
1147  {totalReplay + 1},
1151 
1152  auto l = net.server.ledgerMaster.getClosedLedger();
1153  uint256 finalHash = l->info().hash;
1154  net.client.replayer.replay(
1155  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1156 
1157  std::vector<TaskStatus> deltaStatuses(
1158  totalReplay - 1, TaskStatus::Completed);
1159  BEAST_EXPECT(net.client.waitAndCheckStatus(
1160  finalHash,
1161  totalReplay,
1164  deltaStatuses));
1165 
1166  // sweep
1167  net.client.replayer.sweep();
1168  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1169  }
1170 
1171  void
1172  testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay = 4)
1173  {
1174  switch (peerSetBehavior)
1175  {
1176  case PeerSetBehavior::Good:
1177  testcase("good network");
1178  break;
1180  testcase("network drops 50% messages");
1181  break;
1183  testcase("network repeats all messages");
1184  break;
1185  default:
1186  return;
1187  }
1188 
1189  NetworkOfTwo net(
1190  *this,
1191  {totalReplay + 1},
1192  peerSetBehavior,
1195 
1196  // feed client with start ledger since InboundLedgers drops all
1197  auto l = net.server.ledgerMaster.getClosedLedger();
1198  uint256 finalHash = l->info().hash;
1199  for (int i = 0; i < totalReplay - 1; ++i)
1200  {
1201  l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1202  }
1203  net.client.ledgerMaster.storeLedger(l);
1204 
1205  net.client.replayer.replay(
1206  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1207 
1208  std::vector<TaskStatus> deltaStatuses(
1209  totalReplay - 1, TaskStatus::Completed);
1210  BEAST_EXPECT(net.client.waitAndCheckStatus(
1211  finalHash,
1212  totalReplay,
1215  deltaStatuses));
1216  BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1217 
1218  // sweep
1219  net.client.replayer.sweep();
1220  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1221  }
1222 
1223  void
1225  {
1226  testcase("stop before timeout");
1227  int totalReplay = 3;
1228  NetworkOfTwo net(
1229  *this,
1230  {totalReplay + 1},
1234 
1235  auto l = net.server.ledgerMaster.getClosedLedger();
1236  uint256 finalHash = l->info().hash;
1237  net.client.replayer.replay(
1238  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1239 
1240  std::vector<TaskStatus> deltaStatuses;
1241  BEAST_EXPECT(net.client.checkStatus(
1242  finalHash,
1243  totalReplay,
1246  deltaStatuses));
1247 
1248  BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1249  net.client.replayer.stop();
1250  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1251  }
1252 
1253  void
1255  {
1256  testcase("SkipListAcquire bad reply");
1257  int totalReplay = 3;
1258  NetworkOfTwo net(
1259  *this,
1260  {totalReplay + 1 + 1},
1264 
1265  auto l = net.server.ledgerMaster.getClosedLedger();
1266  uint256 finalHash = l->info().hash;
1267  net.client.replayer.replay(
1268  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1269 
1270  auto skipList = net.client.findSkipListAcquire(finalHash);
1271 
1272  std::uint8_t payload[55] = {
1273  0x6A, 0x09, 0xE6, 0x67, 0xF3, 0xBC, 0xC9, 0x08, 0xB2};
1274  auto item = std::make_shared<SHAMapItem>(
1275  uint256(12345), Slice(payload, sizeof(payload)));
1276  skipList->processData(l->seq(), item);
1277 
1278  std::vector<TaskStatus> deltaStatuses;
1279  BEAST_EXPECT(net.client.waitAndCheckStatus(
1280  finalHash,
1281  totalReplay,
1284  deltaStatuses));
1285 
1286  // add another task
1287  net.client.replayer.replay(
1288  InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1289  BEAST_EXPECT(net.client.waitAndCheckStatus(
1290  finalHash,
1291  totalReplay,
1294  deltaStatuses));
1295  BEAST_EXPECT(net.client.countsAsExpected(2, 1, 0));
1296  }
1297 
1298  void
1300  {
1301  testcase("LedgerDeltaAcquire bad reply");
1302  int totalReplay = 3;
1303  NetworkOfTwo net(
1304  *this,
1305  {totalReplay + 1},
1309 
1310  auto l = net.server.ledgerMaster.getClosedLedger();
1311  uint256 finalHash = l->info().hash;
1312  net.client.ledgerMaster.storeLedger(l);
1313  net.client.replayer.replay(
1314  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1315 
1316  auto delta = net.client.findLedgerDeltaAcquire(l->info().parentHash);
1317  delta->processData(
1318  l->info(), // wrong ledger info
1320  BEAST_EXPECT(net.client.taskStatus(delta) == TaskStatus::Failed);
1321  BEAST_EXPECT(
1322  net.client.taskStatus(net.client.findTask(
1323  finalHash, totalReplay)) == TaskStatus::Failed);
1324 
1325  // add another task
1326  net.client.replayer.replay(
1327  InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1328  BEAST_EXPECT(
1329  net.client.taskStatus(net.client.findTask(
1330  finalHash, totalReplay + 1)) == TaskStatus::Failed);
1331  }
1332 
1333  void
1335  {
1336  testcase("Overlap tasks");
1337  int totalReplay = 5;
1338  NetworkOfTwo net(
1339  *this,
1340  {totalReplay * 3 + 1},
1344  auto l = net.server.ledgerMaster.getClosedLedger();
1345  uint256 finalHash = l->info().hash;
1346  net.client.replayer.replay(
1347  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1348  std::vector<TaskStatus> deltaStatuses(
1349  totalReplay - 1, TaskStatus::Completed);
1350  BEAST_EXPECT(net.client.waitAndCheckStatus(
1351  finalHash,
1352  totalReplay,
1355  deltaStatuses));
1356  BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1357 
1358  // same range, same reason
1359  net.client.replayer.replay(
1360  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1361  BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1362  // same range, different reason
1363  net.client.replayer.replay(
1364  InboundLedger::Reason::CONSENSUS, finalHash, totalReplay);
1365  BEAST_EXPECT(net.client.countsAsExpected(2, 1, totalReplay - 1));
1366 
1367  // no overlap
1368  for (int i = 0; i < totalReplay + 2; ++i)
1369  {
1370  l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1371  }
1372  auto finalHash_early = l->info().hash;
1373  net.client.replayer.replay(
1374  InboundLedger::Reason::GENERIC, finalHash_early, totalReplay);
1375  BEAST_EXPECT(net.client.waitAndCheckStatus(
1376  finalHash_early,
1377  totalReplay,
1380  deltaStatuses)); // deltaStatuses no change
1381  BEAST_EXPECT(net.client.waitForLedgers(finalHash_early, totalReplay));
1382  BEAST_EXPECT(net.client.countsAsExpected(3, 2, 2 * (totalReplay - 1)));
1383 
1384  // partial overlap
1385  l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1386  auto finalHash_moreEarly = l->info().parentHash;
1387  net.client.replayer.replay(
1388  InboundLedger::Reason::GENERIC, finalHash_moreEarly, totalReplay);
1389  BEAST_EXPECT(net.client.waitAndCheckStatus(
1390  finalHash_moreEarly,
1391  totalReplay,
1394  deltaStatuses)); // deltaStatuses no change
1395  BEAST_EXPECT(
1396  net.client.waitForLedgers(finalHash_moreEarly, totalReplay));
1397  BEAST_EXPECT(
1398  net.client.countsAsExpected(4, 3, 2 * (totalReplay - 1) + 2));
1399 
1400  // cover
1401  net.client.replayer.replay(
1402  InboundLedger::Reason::GENERIC, finalHash, totalReplay * 3);
1403  deltaStatuses =
1404  std::vector<TaskStatus>(totalReplay * 3 - 1, TaskStatus::Completed);
1405  BEAST_EXPECT(net.client.waitAndCheckStatus(
1406  finalHash,
1407  totalReplay * 3,
1410  deltaStatuses)); // deltaStatuses changed
1411  BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay * 3));
1412  BEAST_EXPECT(net.client.countsAsExpected(5, 3, totalReplay * 3 - 1));
1413 
1414  // sweep
1415  net.client.replayer.sweep();
1416  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1417  }
1418 
1419  void
1420  run() override
1421  {
1422  testProofPath();
1423  testReplayDelta();
1424  testTaskParameter();
1425  testConfig();
1426  testHandshake();
1427  testAllLocal(1);
1428  testAllLocal(3);
1429  testAllInboundLedgers(1);
1430  testAllInboundLedgers(4);
1431  testPeerSetBehavior(PeerSetBehavior::Good, 1);
1432  testPeerSetBehavior(PeerSetBehavior::Good);
1433  testPeerSetBehavior(PeerSetBehavior::Drop50);
1434  testPeerSetBehavior(PeerSetBehavior::Repeat);
1435  testStop();
1436  testSkipListBadReply();
1437  testLedgerDeltaBadReply();
1438  testLedgerReplayOverlap();
1439  }
1440 };
1441 
1442 struct LedgerReplayerTimeout_test : public beast::unit_test::suite
1443 {
1444  void
1446  {
1447  testcase("SkipListAcquire timeout");
1448  int totalReplay = 3;
1449  NetworkOfTwo net(
1450  *this,
1451  {totalReplay + 1},
1455 
1456  auto l = net.server.ledgerMaster.getClosedLedger();
1457  uint256 finalHash = l->info().hash;
1458  net.client.replayer.replay(
1459  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1460 
1461  std::vector<TaskStatus> deltaStatuses;
1462  BEAST_EXPECT(net.client.waitAndCheckStatus(
1463  finalHash,
1464  totalReplay,
1467  deltaStatuses));
1468 
1469  // sweep
1470  BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1471  net.client.replayer.sweep();
1472  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1473  }
1474 
1475  void
1477  {
1478  testcase("LedgerDeltaAcquire timeout");
1479  int totalReplay = 3;
1480  NetworkOfTwo net(
1481  *this,
1482  {totalReplay + 1},
1486 
1487  auto l = net.server.ledgerMaster.getClosedLedger();
1488  uint256 finalHash = l->info().hash;
1489  net.client.ledgerMaster.storeLedger(l);
1490  net.client.replayer.replay(
1491  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1492 
1493  std::vector<TaskStatus> deltaStatuses(
1494  totalReplay - 1, TaskStatus::Failed);
1495  deltaStatuses.back() = TaskStatus::Completed; // in client ledgerMaster
1496  BEAST_EXPECT(net.client.waitAndCheckStatus(
1497  finalHash,
1498  totalReplay,
1501  deltaStatuses));
1502 
1503  // sweep
1504  BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1505  net.client.replayer.sweep();
1506  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1507  }
1508 
1509  void
1510  run() override
1511  {
1512  testSkipListTimeout();
1513  testLedgerDeltaTimeout();
1514  }
1515 };
1516 
1517 struct LedgerReplayerLong_test : public beast::unit_test::suite
1518 {
1519  void
1520  run() override
1521  {
1522  testcase("Acquire 1000 ledgers");
1523  int totalReplay = 250;
1524  int rounds = 4;
1525  NetworkOfTwo net(
1526  *this,
1527  {totalReplay * rounds + 1},
1531 
1532  std::vector<uint256> finishHashes;
1533  auto l = net.server.ledgerMaster.getClosedLedger();
1534  for (int i = 0; i < rounds; ++i)
1535  {
1536  finishHashes.push_back(l->info().hash);
1537  for (int j = 0; j < totalReplay; ++j)
1538  {
1539  l = net.server.ledgerMaster.getLedgerByHash(
1540  l->info().parentHash);
1541  }
1542  }
1543  BEAST_EXPECT(finishHashes.size() == rounds);
1544 
1545  for (int i = 0; i < rounds; ++i)
1546  {
1547  net.client.replayer.replay(
1548  InboundLedger::Reason::GENERIC, finishHashes[i], totalReplay);
1549  }
1550 
1551  std::vector<TaskStatus> deltaStatuses(
1552  totalReplay - 1, TaskStatus::Completed);
1553  for (int i = 0; i < rounds; ++i)
1554  {
1555  BEAST_EXPECT(net.client.waitAndCheckStatus(
1556  finishHashes[i],
1557  totalReplay,
1560  deltaStatuses));
1561  }
1562 
1563  BEAST_EXPECT(
1564  net.client.waitForLedgers(finishHashes[0], totalReplay * rounds));
1565  BEAST_EXPECT(net.client.countsAsExpected(
1566  rounds, rounds, rounds * (totalReplay - 1)));
1567 
1568  // sweep
1569  net.client.replayer.sweep();
1570  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1571  }
1572 };
1573 
1576 BEAST_DEFINE_TESTSUITE(LedgerReplayerTimeout, app, ripple);
1577 BEAST_DEFINE_TESTSUITE_MANUAL(LedgerReplayerLong, app, ripple);
1578 
1579 } // namespace test
1580 } // namespace ripple
ripple::test::LedgerReplayClient::waitAndCheckStatus
bool waitAndCheckStatus(uint256 const &hash, int totalReplay, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
Definition: LedgerReplay_test.cpp:776
ripple::test::LedgerServer::param
Parameter param
Definition: LedgerReplay_test.cpp:526
ripple::test::TestPeer::TestPeer
TestPeer(bool enableLedgerReplay)
Definition: LedgerReplay_test.cpp:194
ripple::test::LedgerServer::Parameter::initLedgers
int initLedgers
Definition: LedgerReplay_test.cpp:434
ripple::test::TestPeer::compressionEnabled
bool compressionEnabled() const override
Definition: LedgerReplay_test.cpp:288
ripple::Application
Definition: Application.h:103
ripple::test::LedgerReplayClient::replayer
LedgerReplayer replayer
Definition: LedgerReplay_test.cpp:796
ripple::test::LedgerReplayer_test::testLedgerReplayOverlap
void testLedgerReplayOverlap()
Definition: LedgerReplay_test.cpp:1334
ripple::test::ledgerHash
static uint256 ledgerHash(LedgerInfo const &info)
Definition: compression_test.cpp:57
ripple::HashPrefix::ledgerMaster
@ ledgerMaster
ledger master data for signing
ripple::test::LedgerReplayClient::countSkipLists
std::size_t countSkipLists()
Definition: LedgerReplay_test.cpp:663
std::this_thread::sleep_for
T sleep_for(T... args)
ripple::test::jtx::XRP
const XRP_t XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
ripple::test::TestPeer::supportsFeature
bool supportsFeature(ProtocolFeature f) const override
Definition: LedgerReplay_test.cpp:243
ripple::test::NetworkOfTwo::NetworkOfTwo
NetworkOfTwo(beast::unit_test::suite &suite, LedgerServer::Parameter const &param, PeerSetBehavior behavior=PeerSetBehavior::Good, InboundLedgersBehavior inboundBhvr=InboundLedgersBehavior::Good, PeerFeature peerFeature=PeerFeature::LedgerReplayEnabled)
Definition: LedgerReplay_test.cpp:816
ripple::test::LedgerReplayClient::countsAsExpected
bool countsAsExpected(std::size_t tasks, std::size_t skipLists, std::size_t deltas)
Definition: LedgerReplay_test.cpp:670
ripple::test::LedgerReplayer_test::testLedgerDeltaBadReply
void testLedgerDeltaBadReply()
Definition: LedgerReplay_test.cpp:1299
ripple::test::LedgerReplayerTimeout_test::testLedgerDeltaTimeout
void testLedgerDeltaTimeout()
Definition: LedgerReplay_test.cpp:1476
ripple::LedgerReplayTask::TaskParameter::reason_
InboundLedger::Reason reason_
Definition: LedgerReplayTask.h:50
ripple::InboundLedger::Reason::CONSENSUS
@ CONSENSUS
std::string
STL class.
std::shared_ptr
STL class.
ripple::test::NetworkOfTwo::client
LedgerReplayClient client
Definition: LedgerReplay_test.cpp:828
ripple::test::LedgerReplay_test::run
void run() override
Definition: LedgerReplay_test.cpp:43
ripple::test::TestPeer::send
void send(std::shared_ptr< Message > const &m) override
Definition: LedgerReplay_test.cpp:199
ripple::test::jtx::drops
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Definition: amount.h:241
ripple::test::LedgerReplayer_test::testConfig
void testConfig()
Definition: LedgerReplay_test.cpp:1029
ripple::test::TestPeerSetBuilder
Build the TestPeerSet.
Definition: LedgerReplay_test.cpp:397
ripple::test::TaskStatus::NotExist
@ NotExist
ripple::test::TestPeer::hasLedger
bool hasLedger(uint256 const &hash, std::uint32_t seq) const override
Definition: LedgerReplay_test.cpp:265
ripple::test::MagicInboundLedgers::gotStaleData
virtual void gotStaleData(std::shared_ptr< protocol::TMLedgerData > packet) override
Definition: LedgerReplay_test.cpp:125
ripple::test::PeerSetBehavior::Good
@ Good
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
std::unordered_set
STL class.
ripple::Config::LEDGER_REPLAY
bool LEDGER_REPLAY
Definition: Config.h:194
ripple::LedgerMaster
Definition: LedgerMaster.h:70
ripple::test::TestPeer::isHighLatency
bool isHighLatency() const override
Definition: LedgerReplay_test.cpp:222
ripple::InboundLedger::Reason::GENERIC
@ GENERIC
ripple::test::LedgerServer
Utility class for (1) creating ledgers with txns and (2) providing the ledgers via the ledgerMaster.
Definition: LedgerReplay_test.cpp:430
std::vector
STL class.
std::find_if
T find_if(T... args)
std::unordered_set::size
T size(T... args)
ripple::test::LedgerReplayerLong_test
Definition: LedgerReplay_test.cpp:1517
ripple::test::MagicInboundLedgers::ledgerSource
LedgerMaster & ledgerSource
Definition: LedgerReplay_test.cpp:176
ripple::test::TestPeerSet::addPeers
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.
Definition: LedgerReplay_test.cpp:326
ripple::test::TestPeer::json
Json::Value json() override
Definition: LedgerReplay_test.cpp:238
ripple::test::LedgerServer::sendPayments
void sendPayments(int newTxes)
Definition: LedgerReplay_test.cpp:474
ripple::FEATURE_LEDGER_REPLAY
static constexpr char FEATURE_LEDGER_REPLAY[]
Definition: Handshake.h:139
std::chrono::milliseconds
ripple::test::PeerSetBehavior::Drop50
@ Drop50
ripple::ProtocolFeature::LedgerReplay
@ LedgerReplay
ripple::test::TaskStatus::Failed
@ Failed
ripple::keylet::skip
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:142
ripple::test::jtx::port_increment
std::unique_ptr< Config > port_increment(std::unique_ptr< Config >, int)
adjust the default configured server ports by a specified value
Definition: envconfig.cpp:98
ripple::test::TestPeer::cluster
bool cluster() const override
Returns true if this connection is a member of the cluster.
Definition: LedgerReplay_test.cpp:217
ripple::test::LedgerServer::createLedgerHistory
void createLedgerHistory()
create ledger history
Definition: LedgerReplay_test.cpp:514
ripple::test::jtx::Env::journal
const beast::Journal journal
Definition: Env.h:143
ripple::test::TestPeer::id
id_t id() const override
Definition: LedgerReplay_test.cpp:212
ripple::test::TaskStatus
TaskStatus
Definition: LedgerReplay_test.cpp:530
beast::severities
A namespace for easy access to logging severity values.
Definition: Journal.h:29
ripple::test::TestPeer::charge
void charge(Resource::Charge const &fee) override
Adjust this peer's load balance based on the type of load imposed.
Definition: LedgerReplay_test.cpp:208
ripple::test::PeerFeature::None
@ None
ripple::test::LedgerReplayer_test::testSkipListBadReply
void testSkipListBadReply()
Definition: LedgerReplay_test.cpp:1254
ripple::test::MagicInboundLedgers::acquire
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason) override
Definition: LedgerReplay_test.cpp:95
ripple::test::InboundLedgersBehavior::Good
@ Good
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:240
std::string::back
T back(T... args)
std::function
ripple::test::LedgerReplayer_test::testAllInboundLedgers
void testAllInboundLedgers(int totalReplay)
Definition: LedgerReplay_test.cpp:1142
ripple::test::MagicInboundLedgers::ledgerSink
LedgerMaster & ledgerSink
Definition: LedgerReplay_test.cpp:177
ripple::test::TestPeerSet::behavior
PeerSetBehavior behavior
Definition: LedgerReplay_test.cpp:391
ripple::test::TestPeer::hasTxSet
bool hasTxSet(uint256 const &hash) const override
Definition: LedgerReplay_test.cpp:274
ripple::test::LedgerReplayClient::ledgerMaster
LedgerMaster & ledgerMaster
Definition: LedgerReplay_test.cpp:792
ripple::test::jtx::envconfig
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:49
ripple::ProtocolFeature
ProtocolFeature
Definition: ripple/overlay/Peer.h:38
ripple::test::LedgerReplayClient::haveLedgers
bool haveLedgers(uint256 const &finishLedgerHash, int totalReplay)
Definition: LedgerReplay_test.cpp:580
ripple::test::TestPeerSetBuilder::local
LedgerReplayMsgHandler & local
Definition: LedgerReplay_test.cpp:420
ripple::tapNONE
@ tapNONE
Definition: ApplyView.h:30
ripple::test::NetworkOfTwo::server
LedgerServer server
Definition: LedgerReplay_test.cpp:827
ripple::test::LedgerReplayer_test::testAllLocal
void testAllLocal(int totalReplay)
Definition: LedgerReplay_test.cpp:1100
ripple::test::TestPeer::getScore
int getScore(bool) const override
Definition: LedgerReplay_test.cpp:227
ripple::base_uint::data
pointer data()
Definition: base_uint.h:114
ripple::test::BEAST_DEFINE_TESTSUITE_PRIO
BEAST_DEFINE_TESTSUITE_PRIO(AccountDelete, app, ripple, 2)
ripple::test::jtx::autofill
static const autofill_t autofill
Definition: tags.h:42
ripple::test::LedgerReplayClient::waitForDone
bool waitForDone()
Definition: LedgerReplay_test.cpp:609
ripple::test::LedgerServer::LedgerServer
LedgerServer(beast::unit_test::suite &suite, Parameter const &p)
Definition: LedgerReplay_test.cpp:441
ripple::test::LedgerReplayerTimeout_test
Definition: LedgerReplay_test.cpp:1442
ripple::PeerSetBuilder
Definition: PeerSet.h:80
ripple::base_uint::size
constexpr static std::size_t size()
Definition: base_uint.h:495
ripple::LedgerReplayTask::TaskParameter::update
bool update(uint256 const &hash, std::uint32_t seq, std::vector< uint256 > const &sList)
fill all the fields that was not filled during construction
Definition: LedgerReplayTask.cpp:39
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:526
std::vector::push_back
T push_back(T... args)
ripple::test::MagicInboundLedgers::MagicInboundLedgers
MagicInboundLedgers(LedgerMaster &ledgerSource, LedgerMaster &ledgerSink, InboundLedgersBehavior bhvr)
Definition: LedgerReplay_test.cpp:85
ripple::test::TestPeerSet::local
LedgerReplayMsgHandler & local
Definition: LedgerReplay_test.cpp:388
ripple::Keylet::key
uint256 key
Definition: Keylet.h:41
ripple::base_uint< 256 >
ripple::test::TestPeer::ledgerReplayEnabled_
bool ledgerReplayEnabled_
Definition: LedgerReplay_test.cpp:293
ripple::test::LedgerServer::accounts
std::vector< jtx::Account > accounts
Definition: LedgerReplay_test.cpp:527
ripple::test::MagicInboundLedgers::isFailure
virtual bool isFailure(uint256 const &h) override
Definition: LedgerReplay_test.cpp:135
ripple::test::TestPeerSet::sendRequest
void sendRequest(::google::protobuf::Message const &msg, protocol::MessageType type, std::shared_ptr< Peer > const &peer) override
Definition: LedgerReplay_test.cpp:336
ripple::test::MagicInboundLedgers::gotLedgerData
virtual bool gotLedgerData(LedgerHash const &ledgerHash, std::shared_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData >) override
Definition: LedgerReplay_test.cpp:116
ripple::test::TestPeer::getClosedLedgerHash
uint256 const & getClosedLedgerHash() const override
Definition: LedgerReplay_test.cpp:259
ripple::test::MagicInboundLedgers::clearFailures
virtual void clearFailures() override
Definition: LedgerReplay_test.cpp:141
ripple::test::TestPeerSet::getPeerIds
const std::set< Peer::id_t > & getPeerIds() const override
get the set of ids of previously added peers
Definition: LedgerReplay_test.cpp:382
ripple::Config::loadFromString
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
Definition: Config.cpp:454
ripple::test::PeerSetBehavior::DropAll
@ DropAll
thread
beast::IP::Address
boost::asio::ip::address Address
Definition: IPAddress.h:41
ripple::test::LedgerReplayClient::asExpected
bool asExpected(uint256 const &hash, int totalReplay, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
Definition: LedgerReplay_test.cpp:738
ripple::test::InboundLedgersBehavior
InboundLedgersBehavior
Definition: LedgerReplay_test.cpp:72
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::test::LedgerReplayClient::findTask
std::shared_ptr< LedgerReplayTask > findTask(uint256 const &hash, int totalReplay)
Definition: LedgerReplay_test.cpp:642
ripple::test::LedgerServer::app
Application & app
Definition: LedgerReplay_test.cpp:523
ripple::Config
Definition: Config.h:68
chrono
ripple::Application::config
virtual Config & config()=0
ripple::test::LedgerReplayerTimeout_test::run
void run() override
Definition: LedgerReplay_test.cpp:1510
ripple::test::TestPeer::hasRange
bool hasRange(std::uint32_t uMin, std::uint32_t uMax) override
Definition: LedgerReplay_test.cpp:283
std::unique_lock
STL class.
std::to_string
T to_string(T... args)
ripple::test::LedgerServer::ledgerMaster
LedgerMaster & ledgerMaster
Definition: LedgerReplay_test.cpp:524
ripple::test::jtx::Env::close
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition: Env.cpp:121
ripple::test::LedgerServer::env
jtx::Env env
Definition: LedgerReplay_test.cpp:522
ripple::test::PeerSetBehavior::DropLedgerDeltaReply
@ DropLedgerDeltaReply
ripple::test::LedgerReplayClient::findLedgerDeltaAcquire
std::shared_ptr< LedgerDeltaAcquire > findLedgerDeltaAcquire(uint256 const &hash)
Definition: LedgerReplay_test.cpp:692
ripple::test::MagicInboundLedgers::getInfo
virtual Json::Value getInfo() override
Definition: LedgerReplay_test.cpp:146
ripple::Application::logs
virtual Logs & logs()=0
ripple::test::LedgerReplayClient::serverMsgHandler
LedgerReplayMsgHandler serverMsgHandler
Definition: LedgerReplay_test.cpp:794
ripple::peerFeatureEnabled
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:191
std::uint32_t
ripple::test::jtx::sig
Set the regular signature on a JTx.
Definition: sig.h:34
ripple::test::MagicInboundLedgers::logFailure
virtual void logFailure(uint256 const &h, std::uint32_t seq) override
Definition: LedgerReplay_test.cpp:130
ripple::test::LedgerReplayer_test::testHandshake
void testHandshake()
Definition: LedgerReplay_test.cpp:1059
ripple::test::TestPeerSetBuilder::remote
LedgerReplayMsgHandler & remote
Definition: LedgerReplay_test.cpp:421
std::map
STL class.
ripple::test::LedgerReplayer_test::testProofPath
void testProofPath()
Definition: LedgerReplay_test.cpp:859
ripple::test::InboundLedgersBehavior::DropAll
@ DropAll
ripple::test::LedgerReplayClient::LedgerReplayClient
LedgerReplayClient(beast::unit_test::suite &suite, LedgerServer &server, PeerSetBehavior behavior=PeerSetBehavior::Good, InboundLedgersBehavior inboundBhvr=InboundLedgersBehavior::Good, PeerFeature peerFeature=PeerFeature::LedgerReplayEnabled)
Definition: LedgerReplay_test.cpp:547
ripple::test::LedgerReplayClient
Ledger replay client side.
Definition: LedgerReplay_test.cpp:544
ripple::test::TaskStatus::NotDone
@ NotDone
ripple::makeRequest
auto makeRequest(bool crawlPublic, bool comprEnabled, bool vpReduceRelayEnabled, bool ledgerReplayEnabled) -> request_type
Make outbound http request.
Definition: Handshake.cpp:363
ripple::test::TestPeerSetBuilder::behavior
PeerSetBehavior behavior
Definition: LedgerReplay_test.cpp:422
ripple::InboundLedgers
Manages the lifetime of inbound ledgers.
Definition: InboundLedgers.h:33
ripple::test::jtx::fee
Set the fee on a JTx.
Definition: fee.h:35
ripple::LedgerReplayTask::TaskParameter
Definition: LedgerReplayTask.h:46
ripple::test::TestPeerSetBuilder::build
std::unique_ptr< PeerSet > build() override
Definition: LedgerReplay_test.cpp:413
ripple::test::jtx::None
Definition: amount.h:57
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:33
ripple::test::MagicInboundLedgers
Simulate a network InboundLedgers.
Definition: LedgerReplay_test.cpp:82
ripple::LedgerMaster::getClosedLedger
std::shared_ptr< Ledger const > getClosedLedger()
Definition: LedgerMaster.h:98
ripple::test::LedgerReplayClient::findSkipListAcquire
std::shared_ptr< SkipListAcquire > findSkipListAcquire(uint256 const &hash)
Definition: LedgerReplay_test.cpp:682
ripple::Logs::threshold
beast::severities::Severity threshold() const
Definition: Log.cpp:150
ripple::test::LedgerReplayer_test::testStop
void testStop()
Definition: LedgerReplay_test.cpp:1224
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::LedgerReplayClient::app
Application & app
Definition: LedgerReplay_test.cpp:791
ripple::LedgerReplayMsgHandler
Definition: LedgerReplayMsgHandler.h:30
ripple::test::MagicInboundLedgers::find
virtual std::shared_ptr< InboundLedger > find(LedgerHash const &hash) override
Definition: LedgerReplay_test.cpp:110
ripple::test::MagicInboundLedgers::fetchRate
virtual std::size_t fetchRate() override
Returns the rate of historical ledger fetches per minute.
Definition: LedgerReplay_test.cpp:152
ripple::test::LedgerReplayer_test
Test cases: LedgerReplayer_test: – process TMProofPathRequest and TMProofPathResponse – process TMRep...
Definition: LedgerReplay_test.cpp:856
ripple::test::logAll
void logAll(LedgerServer &server, LedgerReplayClient &client, beast::severities::Severity level=Severity::kTrace)
Definition: LedgerReplay_test.cpp:801
ripple::test::LedgerReplayClient::checkStatus
bool checkStatus(uint256 const &hash, int totalReplay, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
Definition: LedgerReplay_test.cpp:757
ripple::test::TestPeer::setPublisherListSequence
void setPublisherListSequence(PublicKey const &, std::size_t const) override
Definition: LedgerReplay_test.cpp:255
ripple::test::jtx::pay
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:29
ripple::test::LedgerReplayer_test::testPeerSetBehavior
void testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay=4)
Definition: LedgerReplay_test.cpp:1172
ripple::test::TestPeer::cycleStatus
void cycleStatus() override
Definition: LedgerReplay_test.cpp:279
ripple::test::TestPeer::publisherListSequence
std::optional< std::size_t > publisherListSequence(PublicKey const &) const override
Definition: LedgerReplay_test.cpp:250
ripple::test::MagicInboundLedgers::sweep
virtual void sweep() override
Definition: LedgerReplay_test.cpp:167
ripple::test::LedgerReplayClient::countDeltas
std::size_t countDeltas()
Definition: LedgerReplay_test.cpp:656
beast::severities::Severity
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:31
std
STL namespace.
ripple::test::MagicInboundLedgers::onLedgerFetched
virtual void onLedgerFetched() override
Called when a complete ledger is obtained.
Definition: LedgerReplay_test.cpp:158
std::unordered_set::insert
T insert(T... args)
ripple::test::jtx::Env::fund
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:225
ripple::test::LedgerServer::createAccounts
void createAccounts(int newAccounts)
Definition: LedgerReplay_test.cpp:458
ripple::PeerSet
Supports data retrieval by managing a set of peers.
Definition: PeerSet.h:44
ripple::test::LedgerReplayClient::clientMsgHandler
LedgerReplayMsgHandler clientMsgHandler
Definition: LedgerReplay_test.cpp:795
ripple::Resource::Charge
A consumption charge.
Definition: Charge.h:30
ripple::buildLedger
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.
Definition: BuildLedger.cpp:175
ripple::test::LedgerReplayClient::addLedger
void addLedger(std::shared_ptr< Ledger const > const &l)
Definition: LedgerReplay_test.cpp:574
std::unordered_set::count
T count(T... args)
ripple::test::NetworkOfTwo
Definition: LedgerReplay_test.cpp:814
ripple::test::LedgerReplayerLong_test::run
void run() override
Definition: LedgerReplay_test.cpp:1520
ripple::LedgerReplayer
Manages the lifetime of ledger replay tasks.
Definition: LedgerReplayer.h:72
ripple::test::LedgerReplayClient::getTasks
std::vector< std::shared_ptr< LedgerReplayTask > > getTasks()
Definition: LedgerReplay_test.cpp:635
ripple::test::LedgerReplayer_test::run
void run() override
Definition: LedgerReplay_test.cpp:1420
ripple::test::LedgerReplayer_test::testReplayDelta
void testReplayDelta()
Definition: LedgerReplay_test.cpp:923
ripple::test::TestPeerSet::dummyPeer
std::shared_ptr< TestPeer > dummyPeer
Definition: LedgerReplay_test.cpp:390
ripple::test::LedgerServer::msgHandler
LedgerReplayMsgHandler msgHandler
Definition: LedgerReplay_test.cpp:525
ripple::test::TestPeer::getRemoteAddress
beast::IP::Endpoint getRemoteAddress() const override
Definition: LedgerReplay_test.cpp:203
ripple::test::TestPeerSet
Simulate a peerSet that supplies peers to ledger replay subtasks.
Definition: LedgerReplay_test.cpp:311
std::optional< std::size_t >
ripple::LedgerReplayTask::TaskParameter::finishHash_
uint256 finishHash_
Definition: LedgerReplayTask.h:51
std::size_t
ripple::LedgerReplayTask::TaskParameter::totalLedgers_
std::uint32_t totalLedgers_
Definition: LedgerReplayTask.h:52
ripple::test::TestPeerSetBuilder::enableLedgerReplay
bool enableLedgerReplay
Definition: LedgerReplay_test.cpp:423
ripple::test::TestPeerSet::remote
LedgerReplayMsgHandler & remote
Definition: LedgerReplay_test.cpp:389
ripple::test::LedgerServer::Parameter
Definition: LedgerReplay_test.cpp:432
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::test::PeerSetBehavior::Repeat
@ Repeat
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
ripple::test::MagicInboundLedgers::stop
virtual void stop() override
Definition: LedgerReplay_test.cpp:172
ripple::InboundLedger::Reason
Reason
Definition: InboundLedger.h:46
ripple::test::LedgerReplayClient::env
jtx::Env env
Definition: LedgerReplay_test.cpp:790
ripple::test::LedgerReplayClient::taskStatus
TaskStatus taskStatus(std::shared_ptr< T > const &t)
Definition: LedgerReplay_test.cpp:703
ripple::test::LedgerReplay_test
Definition: LedgerReplay_test.cpp:40
ripple::test::LedgerReplayClient::waitForLedgers
bool waitForLedgers(uint256 const &finishLedgerHash, int totalReplay)
Definition: LedgerReplay_test.cpp:595
ripple::test::LedgerReplayerTimeout_test::testSkipListTimeout
void testSkipListTimeout()
Definition: LedgerReplay_test.cpp:1445
ripple::test::TestPeerSet::TestPeerSet
TestPeerSet(LedgerReplayMsgHandler &me, LedgerReplayMsgHandler &other, PeerSetBehavior bhvr, bool enableLedgerReplay)
Definition: LedgerReplay_test.cpp:313
ripple::test::PeerSetBehavior
PeerSetBehavior
Definition: LedgerReplay_test.cpp:296
ripple::test::PeerFeature
PeerFeature
Definition: LedgerReplay_test.cpp:181
ripple::makeResponse
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:386
ripple::test::PeerSetBehavior::DropSkipListReply
@ DropSkipListReply
ripple::test::LedgerReplayClient::inboundLedgers
MagicInboundLedgers inboundLedgers
Definition: LedgerReplay_test.cpp:793
ripple::http_request_type
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handshake.h:47
ripple::test::PeerFeature::LedgerReplayEnabled
@ LedgerReplayEnabled
std::unique_ptr
STL class.
ripple::test::MagicInboundLedgers::bhvr
InboundLedgersBehavior bhvr
Definition: LedgerReplay_test.cpp:178
ripple::test::TestPeer
Simulate a network peer.
Definition: LedgerReplay_test.cpp:191
ripple::test::TestPeerSetBuilder::TestPeerSetBuilder
TestPeerSetBuilder(LedgerReplayMsgHandler &me, LedgerReplayMsgHandler &other, PeerSetBehavior bhvr, PeerFeature peerFeature)
Definition: LedgerReplay_test.cpp:400
ripple::test::TaskStatus::Completed
@ Completed
ripple::test::LedgerReplayClient::asExpected
bool asExpected(std::shared_ptr< LedgerReplayTask > const &task, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
Definition: LedgerReplay_test.cpp:713
std::set
STL class.
ripple::test::TestPeer::ledgerRange
void ledgerRange(std::uint32_t &minSeq, std::uint32_t &maxSeq) const override
Definition: LedgerReplay_test.cpp:270
ripple::LedgerReplayTask::TaskParameter::canMergeInto
bool canMergeInto(TaskParameter const &existingTask) const
check if this task can be merged into an existing task
Definition: LedgerReplayTask.cpp:58
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:115
ripple::test::LedgerReplayer_test::testTaskParameter
void testTaskParameter()
Definition: LedgerReplay_test.cpp:976
ripple::test::BEAST_DEFINE_TESTSUITE_MANUAL
BEAST_DEFINE_TESTSUITE_MANUAL(LedgerReplayerLong, app, ripple)
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::test::TestPeer::getNodePublic
PublicKey const & getNodePublic() const override
Definition: LedgerReplay_test.cpp:232
ripple::Peer
Represents a peer connection in the overlay.
Definition: ripple/overlay/Peer.h:45
ripple::test::MagicInboundLedgers::gotFetchPack
virtual void gotFetchPack() override
Definition: LedgerReplay_test.cpp:163
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)
ripple::LedgerReplay
Definition: LedgerReplay.h:32