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  onStop() 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  hasShard(std::uint32_t shardIndex) const override
275  {
276  return false;
277  }
278  bool
279  hasTxSet(uint256 const& hash) const override
280  {
281  return false;
282  }
283  void
284  cycleStatus() override
285  {
286  }
287  bool
288  hasRange(std::uint32_t uMin, std::uint32_t uMax) override
289  {
290  return false;
291  }
292  bool
293  compressionEnabled() const override
294  {
295  return false;
296  }
297 
299 };
300 
301 enum class PeerSetBehavior {
302  Good,
303  Drop50,
304  DropAll,
307  Repeat,
308 };
309 
316 struct TestPeerSet : public PeerSet
317 {
320  LedgerReplayMsgHandler& other,
321  PeerSetBehavior bhvr,
322  bool enableLedgerReplay)
323  : local(me)
324  , remote(other)
325  , dummyPeer(std::make_shared<TestPeer>(enableLedgerReplay))
326  , behavior(bhvr)
327  {
328  }
329 
330  void
332  std::size_t limit,
333  std::function<bool(std::shared_ptr<Peer> const&)> hasItem,
334  std::function<void(std::shared_ptr<Peer> const&)> onPeerAdded) override
335  {
336  hasItem(dummyPeer);
337  onPeerAdded(dummyPeer);
338  }
339 
340  void
342  ::google::protobuf::Message const& msg,
343  protocol::MessageType type,
344  std::shared_ptr<Peer> const& peer) override
345  {
346  int dropRate = 0;
347  if (behavior == PeerSetBehavior::Drop50)
348  dropRate = 50;
349  else if (behavior == PeerSetBehavior::DropAll)
350  dropRate = 100;
351 
352  if ((rand() % 100 + 1) <= dropRate)
353  return;
354 
355  switch (type)
356  {
357  case protocol::mtPROOF_PATH_REQ: {
358  if (behavior == PeerSetBehavior::DropSkipListReply)
359  return;
360  auto request = std::make_shared<protocol::TMProofPathRequest>(
361  dynamic_cast<protocol::TMProofPathRequest const&>(msg));
362  auto reply = std::make_shared<protocol::TMProofPathResponse>(
363  remote.processProofPathRequest(request));
364  local.processProofPathResponse(reply);
365  if (behavior == PeerSetBehavior::Repeat)
366  local.processProofPathResponse(reply);
367  break;
368  }
369  case protocol::mtREPLAY_DELTA_REQ: {
371  return;
372  auto request = std::make_shared<protocol::TMReplayDeltaRequest>(
373  dynamic_cast<protocol::TMReplayDeltaRequest const&>(msg));
374  auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
375  remote.processReplayDeltaRequest(request));
376  local.processReplayDeltaResponse(reply);
377  if (behavior == PeerSetBehavior::Repeat)
378  local.processReplayDeltaResponse(reply);
379  break;
380  }
381  default:
382  return;
383  }
384  }
385 
386  const std::set<Peer::id_t>&
387  getPeerIds() const override
388  {
389  static std::set<Peer::id_t> emptyPeers;
390  return emptyPeers;
391  }
392 
397 };
398 
403 {
404 public:
407  LedgerReplayMsgHandler& other,
408  PeerSetBehavior bhvr,
409  PeerFeature peerFeature)
410  : local(me)
411  , remote(other)
412  , behavior(bhvr)
413  , enableLedgerReplay(peerFeature == PeerFeature::LedgerReplayEnabled)
414  {
415  }
416 
418  build() override
419  {
420  return std::make_unique<TestPeerSet>(
421  local, remote, behavior, enableLedgerReplay);
422  }
423 
424 private:
429 };
430 
436 {
437  struct Parameter
438  {
440  int initAccounts = 10;
441  int initAmount = 1'000'000;
442  int numTxPerLedger = 10;
443  int txAmount = 10;
444  };
445 
446  LedgerServer(beast::unit_test::suite& suite, Parameter const& p)
447  : env(suite)
448  , app(env.app())
449  , ledgerMaster(env.app().getLedgerMaster())
450  , msgHandler(env.app(), env.app().getLedgerReplayer())
451  , param(p)
452  {
453  assert(param.initLedgers > 0);
454  createAccounts(param.initAccounts);
455  createLedgerHistory();
456  app.logs().threshold(beast::severities::Severity::kWarning);
457  }
458 
462  void
463  createAccounts(int newAccounts)
464  {
465  auto fundedAccounts = accounts.size();
466  for (int i = 0; i < newAccounts; ++i)
467  {
468  accounts.emplace_back(
469  "alice_" + std::to_string(fundedAccounts + i));
470  env.fund(jtx::XRP(param.initAmount), accounts.back());
471  }
472  env.close();
473  }
474 
478  void
479  sendPayments(int newTxes)
480  {
481  int fundedAccounts = accounts.size();
482  assert(fundedAccounts >= newTxes);
483  std::unordered_set<int> senders;
484 
485  // somewhat random but reproducible
486  int r = ledgerMaster.getClosedLedger()->seq() * 7;
487  int fromIdx = 0;
488  int toIdx = 0;
489  auto updateIdx = [&]() {
490  assert(fundedAccounts > senders.size());
491  fromIdx = (fromIdx + r) % fundedAccounts;
492  while (senders.count(fromIdx) != 0)
493  fromIdx = (fromIdx + 1) % fundedAccounts;
494  senders.insert(fromIdx);
495  toIdx = (toIdx + r * 2) % fundedAccounts;
496  if (toIdx == fromIdx)
497  toIdx = (toIdx + 1) % fundedAccounts;
498  };
499 
500  for (int i = 0; i < newTxes; ++i)
501  {
502  updateIdx();
503  env.apply(
504  pay(accounts[fromIdx],
505  accounts[toIdx],
506  jtx::drops(ledgerMaster.getClosedLedger()->fees().base) +
507  jtx::XRP(param.txAmount)),
511  }
512  env.close();
513  }
514 
518  void
520  {
521  for (int i = 0; i < param.initLedgers - 1; ++i)
522  {
523  sendPayments(param.numTxPerLedger);
524  }
525  }
526 
533 };
534 
535 enum class TaskStatus {
536  Failed,
537  Completed,
538  NotDone,
539  NotExist,
540 };
541 
550 {
551 public:
553  beast::unit_test::suite& suite,
554  LedgerServer& server,
558  : env(suite, jtx::envconfig(jtx::port_increment, 3))
559  , app(env.app())
560  , ledgerMaster(env.app().getLedgerMaster())
561  , inboundLedgers(
562  server.app.getLedgerMaster(),
563  ledgerMaster,
564  inboundBhvr)
565  , serverMsgHandler(server.app, server.app.getLedgerReplayer())
566  , clientMsgHandler(env.app(), replayer)
567  , stopableParent("replayerStopParent")
568  , replayer(
569  env.app(),
570  inboundLedgers,
571  std::make_unique<TestPeerSetBuilder>(
572  clientMsgHandler,
573  serverMsgHandler,
574  behavior,
575  peerFeature),
576  stopableParent)
577  {
578  }
579 
580  void
582  {
583  ledgerMaster.storeLedger(l);
584  }
585 
586  bool
587  haveLedgers(uint256 const& finishLedgerHash, int totalReplay)
588  {
589  uint256 hash = finishLedgerHash;
590  int i = 0;
591  for (; i < totalReplay; ++i)
592  {
593  auto const l = ledgerMaster.getLedgerByHash(hash);
594  if (!l)
595  return false;
596  hash = l->info().parentHash;
597  }
598  return true;
599  }
600 
601  bool
602  waitForLedgers(uint256 const& finishLedgerHash, int totalReplay)
603  {
604  int totalRound = 100;
605  for (int i = 0; i < totalRound; ++i)
606  {
607  if (haveLedgers(finishLedgerHash, totalReplay))
608  return true;
609  if (i < totalRound - 1)
611  }
612  return false;
613  }
614 
615  bool
617  {
618  int totalRound = 100;
619  for (int i = 0; i < totalRound; ++i)
620  {
621  bool allDone = true;
622  {
623  std::unique_lock<std::mutex> lock(replayer.mtx_);
624  for (auto const& t : replayer.tasks_)
625  {
626  if (!t->finished())
627  {
628  allDone = false;
629  break;
630  }
631  }
632  }
633  if (allDone)
634  return true;
635  if (i < totalRound - 1)
637  }
638  return false;
639  }
640 
643  {
644  std::unique_lock<std::mutex> lock(replayer.mtx_);
645  return replayer.tasks_;
646  }
647 
649  findTask(uint256 const& hash, int totalReplay)
650  {
651  std::unique_lock<std::mutex> lock(replayer.mtx_);
652  auto i = std::find_if(
653  replayer.tasks_.begin(), replayer.tasks_.end(), [&](auto const& t) {
654  return t->parameter_.finishHash_ == hash &&
655  t->parameter_.totalLedgers_ == totalReplay;
656  });
657  if (i == replayer.tasks_.end())
658  return {};
659  return *i;
660  }
661 
664  {
665  std::unique_lock<std::mutex> lock(replayer.mtx_);
666  return replayer.deltas_.size();
667  }
668 
671  {
672  std::unique_lock<std::mutex> lock(replayer.mtx_);
673  return replayer.skipLists_.size();
674  }
675 
676  bool
678  std::size_t tasks,
679  std::size_t skipLists,
680  std::size_t deltas)
681  {
682  std::unique_lock<std::mutex> lock(replayer.mtx_);
683  return replayer.tasks_.size() == tasks &&
684  replayer.skipLists_.size() == skipLists &&
685  replayer.deltas_.size() == deltas;
686  }
687 
690  {
691  std::unique_lock<std::mutex> lock(replayer.mtx_);
692  auto i = replayer.skipLists_.find(hash);
693  if (i == replayer.skipLists_.end())
694  return {};
695  return i->second.lock();
696  }
697 
700  {
701  std::unique_lock<std::mutex> lock(replayer.mtx_);
702  auto i = replayer.deltas_.find(hash);
703  if (i == replayer.deltas_.end())
704  return {};
705  return i->second.lock();
706  }
707 
708  template <typename T>
709  TaskStatus
711  {
712  if (t->failed_)
713  return TaskStatus::Failed;
714  if (t->complete_)
715  return TaskStatus::Completed;
716  return TaskStatus::NotDone;
717  }
718 
719  bool
722  TaskStatus taskExpect,
723  TaskStatus skiplistExpect,
724  std::vector<TaskStatus> const& deltaExpects)
725  {
726  if (taskStatus(task) == taskExpect)
727  {
728  if (taskStatus(task->skipListAcquirer_) == skiplistExpect)
729  {
730  if (task->deltas_.size() == deltaExpects.size())
731  {
732  for (int i = 0; i < deltaExpects.size(); ++i)
733  {
734  if (taskStatus(task->deltas_[i]) != deltaExpects[i])
735  return false;
736  }
737  return true;
738  }
739  }
740  }
741  return false;
742  }
743 
744  bool
746  uint256 const& hash,
747  int totalReplay,
748  TaskStatus taskExpect,
749  TaskStatus skiplistExpect,
750  std::vector<TaskStatus> const& deltaExpects)
751  {
752  auto t = findTask(hash, totalReplay);
753  if (!t)
754  {
755  if (taskExpect == TaskStatus::NotExist)
756  return true;
757  return false;
758  }
759 
760  return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
761  }
762 
763  bool
765  uint256 const& hash,
766  int totalReplay,
767  TaskStatus taskExpect,
768  TaskStatus skiplistExpect,
769  std::vector<TaskStatus> const& deltaExpects)
770  {
771  auto t = findTask(hash, totalReplay);
772  if (!t)
773  {
774  if (taskExpect == TaskStatus::NotExist)
775  return true;
776  return false;
777  }
778 
779  return asExpected(t, taskExpect, skiplistExpect, deltaExpects);
780  }
781 
782  bool
784  uint256 const& hash,
785  int totalReplay,
786  TaskStatus taskExpect,
787  TaskStatus skiplistExpect,
788  std::vector<TaskStatus> const& deltaExpects)
789  {
790  if (!waitForDone())
791  return false;
792 
793  return checkStatus(
794  hash, totalReplay, taskExpect, skiplistExpect, deltaExpects);
795  }
796 
805 };
806 
807 using namespace beast::severities;
808 void
810  LedgerServer& server,
811  LedgerReplayClient& client,
812  beast::severities::Severity level = Severity::kTrace)
813 {
814  server.app.logs().threshold(level);
815  client.app.logs().threshold(level);
816 }
817 // logAll(net.server, net.client);
818 
819 /*
820  * Create a LedgerServer and a LedgerReplayClient
821  */
823 {
825  beast::unit_test::suite& suite,
826  LedgerServer::Parameter const& param,
830  : server(suite, param)
831  , client(suite, server, behavior, inboundBhvr, peerFeature)
832  {
833  // logAll(server, client);
834  }
837 };
838 
864 struct LedgerReplayer_test : public beast::unit_test::suite
865 {
866  void
868  {
869  testcase("ProofPath");
870  LedgerServer server(*this, {1});
871  auto const l = server.ledgerMaster.getClosedLedger();
872 
873  {
874  // request, missing key
875  auto request = std::make_shared<protocol::TMProofPathRequest>();
876  request->set_ledgerhash(
877  l->info().hash.data(), l->info().hash.size());
878  request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
879  auto reply = std::make_shared<protocol::TMProofPathResponse>(
880  server.msgHandler.processProofPathRequest(request));
881  BEAST_EXPECT(reply->has_error());
882  BEAST_EXPECT(!server.msgHandler.processProofPathResponse(reply));
883  }
884  {
885  // request, wrong hash
886  auto request = std::make_shared<protocol::TMProofPathRequest>();
887  request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
888  request->set_key(
889  keylet::skip().key.data(), keylet::skip().key.size());
890  uint256 hash(1234567);
891  request->set_ledgerhash(hash.data(), hash.size());
892  auto reply = std::make_shared<protocol::TMProofPathResponse>(
893  server.msgHandler.processProofPathRequest(request));
894  BEAST_EXPECT(reply->has_error());
895  }
896 
897  {
898  // good request
899  auto request = std::make_shared<protocol::TMProofPathRequest>();
900  request->set_ledgerhash(
901  l->info().hash.data(), l->info().hash.size());
902  request->set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
903  request->set_key(
904  keylet::skip().key.data(), keylet::skip().key.size());
905  // generate response
906  auto reply = std::make_shared<protocol::TMProofPathResponse>(
907  server.msgHandler.processProofPathRequest(request));
908  BEAST_EXPECT(!reply->has_error());
909  BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
910 
911  {
912  // bad reply
913  // bad header
914  std::string r(reply->ledgerheader());
915  r.back()--;
916  reply->set_ledgerheader(r);
917  BEAST_EXPECT(
918  !server.msgHandler.processProofPathResponse(reply));
919  r.back()++;
920  reply->set_ledgerheader(r);
921  BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply));
922  // bad proof path
923  reply->mutable_path()->RemoveLast();
924  BEAST_EXPECT(
925  !server.msgHandler.processProofPathResponse(reply));
926  }
927  }
928  }
929 
930  void
932  {
933  testcase("ReplayDelta");
934  LedgerServer server(*this, {1});
935  auto const l = server.ledgerMaster.getClosedLedger();
936 
937  {
938  // request, missing hash
939  auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
940  auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
941  server.msgHandler.processReplayDeltaRequest(request));
942  BEAST_EXPECT(reply->has_error());
943  BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
944  // request, wrong hash
945  uint256 hash(1234567);
946  request->set_ledgerhash(hash.data(), hash.size());
947  reply = std::make_shared<protocol::TMReplayDeltaResponse>(
948  server.msgHandler.processReplayDeltaRequest(request));
949  BEAST_EXPECT(reply->has_error());
950  BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(reply));
951  }
952 
953  {
954  // good request
955  auto request = std::make_shared<protocol::TMReplayDeltaRequest>();
956  request->set_ledgerhash(
957  l->info().hash.data(), l->info().hash.size());
958  auto reply = std::make_shared<protocol::TMReplayDeltaResponse>(
959  server.msgHandler.processReplayDeltaRequest(request));
960  BEAST_EXPECT(!reply->has_error());
961  BEAST_EXPECT(server.msgHandler.processReplayDeltaResponse(reply));
962 
963  {
964  // bad reply
965  // bad header
966  std::string r(reply->ledgerheader());
967  r.back()--;
968  reply->set_ledgerheader(r);
969  BEAST_EXPECT(
970  !server.msgHandler.processReplayDeltaResponse(reply));
971  r.back()++;
972  reply->set_ledgerheader(r);
973  BEAST_EXPECT(
974  server.msgHandler.processReplayDeltaResponse(reply));
975  // bad txns
976  reply->mutable_transaction()->RemoveLast();
977  BEAST_EXPECT(
978  !server.msgHandler.processReplayDeltaResponse(reply));
979  }
980  }
981  }
982 
983  void
985  {
986  testcase("TaskParameter");
987 
988  auto makeSkipList = [](int count) -> std::vector<uint256> const {
989  std::vector<uint256> sList;
990  for (int i = 0; i < count; ++i)
991  sList.emplace_back(i);
992  return sList;
993  };
994 
997  BEAST_EXPECT(!tp10.update(uint256(777), 5, makeSkipList(10)));
998  BEAST_EXPECT(!tp10.update(uint256(10), 5, makeSkipList(8)));
999  BEAST_EXPECT(tp10.update(uint256(10), 10, makeSkipList(10)));
1000 
1001  // can merge to self
1002  BEAST_EXPECT(tp10.canMergeInto(tp10));
1003 
1004  // smaller task
1007 
1008  BEAST_EXPECT(tp9.canMergeInto(tp10));
1009  BEAST_EXPECT(!tp10.canMergeInto(tp9));
1010 
1011  tp9.totalLedgers_++;
1012  BEAST_EXPECT(!tp9.canMergeInto(tp10));
1013  tp9.totalLedgers_--;
1014  BEAST_EXPECT(tp9.canMergeInto(tp10));
1015 
1017  BEAST_EXPECT(!tp9.canMergeInto(tp10));
1019  BEAST_EXPECT(tp9.canMergeInto(tp10));
1020 
1021  tp9.finishHash_ = uint256(1234);
1022  BEAST_EXPECT(!tp9.canMergeInto(tp10));
1023  tp9.finishHash_ = uint256(9);
1024  BEAST_EXPECT(tp9.canMergeInto(tp10));
1025 
1026  // larger task
1029  BEAST_EXPECT(tp20.update(uint256(20), 20, makeSkipList(20)));
1030  BEAST_EXPECT(tp10.canMergeInto(tp20));
1031  BEAST_EXPECT(tp9.canMergeInto(tp20));
1032  BEAST_EXPECT(!tp20.canMergeInto(tp10));
1033  BEAST_EXPECT(!tp20.canMergeInto(tp9));
1034  }
1035 
1036  void
1038  {
1039  testcase("config test");
1040  {
1041  Config c;
1042  BEAST_EXPECT(c.LEDGER_REPLAY == false);
1043  }
1044 
1045  {
1046  Config c;
1047  std::string toLoad(R"rippleConfig(
1048 [ledger_replay]
1049 1
1050 )rippleConfig");
1051  c.loadFromString(toLoad);
1052  BEAST_EXPECT(c.LEDGER_REPLAY == true);
1053  }
1054 
1055  {
1056  Config c;
1057  std::string toLoad = (R"rippleConfig(
1058 [ledger_replay]
1059 0
1060 )rippleConfig");
1061  c.loadFromString(toLoad);
1062  BEAST_EXPECT(c.LEDGER_REPLAY == false);
1063  }
1064  }
1065 
1066  void
1068  {
1069  testcase("handshake test");
1070  auto handshake = [&](bool client, bool server, bool expecting) -> bool {
1071  auto request = ripple::makeRequest(true, false, false, client);
1072  http_request_type http_request;
1073  http_request.version(request.version());
1074  http_request.base() = request.base();
1075  bool serverResult =
1076  peerFeatureEnabled(http_request, FEATURE_LEDGER_REPLAY, server);
1077  if (serverResult != expecting)
1078  return false;
1079 
1080  beast::IP::Address addr =
1081  boost::asio::ip::address::from_string("172.1.1.100");
1082  jtx::Env serverEnv(*this);
1083  serverEnv.app().config().LEDGER_REPLAY = server;
1084  auto http_resp = ripple::makeResponse(
1085  true,
1086  http_request,
1087  addr,
1088  addr,
1089  uint256{1},
1090  1,
1091  {1, 0},
1092  serverEnv.app());
1093  auto const clientResult =
1094  peerFeatureEnabled(http_resp, FEATURE_LEDGER_REPLAY, client);
1095  if (clientResult != expecting)
1096  return false;
1097 
1098  return true;
1099  };
1100 
1101  BEAST_EXPECT(handshake(false, false, false));
1102  BEAST_EXPECT(handshake(false, true, false));
1103  BEAST_EXPECT(handshake(true, false, false));
1104  BEAST_EXPECT(handshake(true, true, true));
1105  }
1106 
1107  void
1108  testAllLocal(int totalReplay)
1109  {
1110  testcase("local node has all the ledgers");
1111  auto psBhvr = PeerSetBehavior::DropAll;
1112  auto ilBhvr = InboundLedgersBehavior::DropAll;
1113  auto peerFeature = PeerFeature::None;
1114 
1115  NetworkOfTwo net(*this, {totalReplay + 1}, psBhvr, ilBhvr, peerFeature);
1116 
1117  auto l = net.server.ledgerMaster.getClosedLedger();
1118  uint256 finalHash = l->info().hash;
1119  for (int i = 0; i < totalReplay; ++i)
1120  {
1121  BEAST_EXPECT(l);
1122  if (l)
1123  {
1124  net.client.ledgerMaster.storeLedger(l);
1125  l = net.server.ledgerMaster.getLedgerByHash(
1126  l->info().parentHash);
1127  }
1128  else
1129  break;
1130  }
1131 
1132  net.client.replayer.replay(
1133  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1134 
1135  std::vector<TaskStatus> deltaStatuses(
1136  totalReplay - 1, TaskStatus::Completed);
1137  BEAST_EXPECT(net.client.waitAndCheckStatus(
1138  finalHash,
1139  totalReplay,
1142  deltaStatuses));
1143 
1144  // sweep
1145  net.client.replayer.sweep();
1146  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1147  }
1148 
1149  void
1150  testAllInboundLedgers(int totalReplay)
1151  {
1152  testcase("all the ledgers from InboundLedgers");
1153  NetworkOfTwo net(
1154  *this,
1155  {totalReplay + 1},
1159 
1160  auto l = net.server.ledgerMaster.getClosedLedger();
1161  uint256 finalHash = l->info().hash;
1162  net.client.replayer.replay(
1163  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1164 
1165  std::vector<TaskStatus> deltaStatuses(
1166  totalReplay - 1, TaskStatus::Completed);
1167  BEAST_EXPECT(net.client.waitAndCheckStatus(
1168  finalHash,
1169  totalReplay,
1172  deltaStatuses));
1173 
1174  // sweep
1175  net.client.replayer.sweep();
1176  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1177  }
1178 
1179  void
1180  testPeerSetBehavior(PeerSetBehavior peerSetBehavior, int totalReplay = 4)
1181  {
1182  switch (peerSetBehavior)
1183  {
1184  case PeerSetBehavior::Good:
1185  testcase("good network");
1186  break;
1188  testcase("network drops 50% messages");
1189  break;
1191  testcase("network repeats all messages");
1192  break;
1193  default:
1194  return;
1195  }
1196 
1197  NetworkOfTwo net(
1198  *this,
1199  {totalReplay + 1},
1200  peerSetBehavior,
1203 
1204  // feed client with start ledger since InboundLedgers drops all
1205  auto l = net.server.ledgerMaster.getClosedLedger();
1206  uint256 finalHash = l->info().hash;
1207  for (int i = 0; i < totalReplay - 1; ++i)
1208  {
1209  l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1210  }
1211  net.client.ledgerMaster.storeLedger(l);
1212 
1213  net.client.replayer.replay(
1214  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1215 
1216  std::vector<TaskStatus> deltaStatuses(
1217  totalReplay - 1, TaskStatus::Completed);
1218  BEAST_EXPECT(net.client.waitAndCheckStatus(
1219  finalHash,
1220  totalReplay,
1223  deltaStatuses));
1224  BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1225 
1226  // sweep
1227  net.client.replayer.sweep();
1228  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1229  }
1230 
1231  void
1233  {
1234  testcase("onStop before timeout");
1235  int totalReplay = 3;
1236  NetworkOfTwo net(
1237  *this,
1238  {totalReplay + 1},
1242 
1243  auto l = net.server.ledgerMaster.getClosedLedger();
1244  uint256 finalHash = l->info().hash;
1245  net.client.replayer.replay(
1246  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1247 
1248  std::vector<TaskStatus> deltaStatuses;
1249  BEAST_EXPECT(net.client.checkStatus(
1250  finalHash,
1251  totalReplay,
1254  deltaStatuses));
1255 
1256  // onStop
1257  BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1258  net.client.replayer.onStop();
1259  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1260  }
1261 
1262  void
1264  {
1265  testcase("SkipListAcquire bad reply");
1266  int totalReplay = 3;
1267  NetworkOfTwo net(
1268  *this,
1269  {totalReplay + 1 + 1},
1273 
1274  auto l = net.server.ledgerMaster.getClosedLedger();
1275  uint256 finalHash = l->info().hash;
1276  net.client.replayer.replay(
1277  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1278 
1279  auto skipList = net.client.findSkipListAcquire(finalHash);
1280 
1281  std::uint8_t payload[55] = {
1282  0x6A, 0x09, 0xE6, 0x67, 0xF3, 0xBC, 0xC9, 0x08, 0xB2};
1283  auto item = std::make_shared<SHAMapItem>(
1284  uint256(12345), Slice(payload, sizeof(payload)));
1285  skipList->processData(l->seq(), item);
1286 
1287  std::vector<TaskStatus> deltaStatuses;
1288  BEAST_EXPECT(net.client.waitAndCheckStatus(
1289  finalHash,
1290  totalReplay,
1293  deltaStatuses));
1294 
1295  // add another task
1296  net.client.replayer.replay(
1297  InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1298  BEAST_EXPECT(net.client.waitAndCheckStatus(
1299  finalHash,
1300  totalReplay,
1303  deltaStatuses));
1304  BEAST_EXPECT(net.client.countsAsExpected(2, 1, 0));
1305  }
1306 
1307  void
1309  {
1310  testcase("LedgerDeltaAcquire bad reply");
1311  int totalReplay = 3;
1312  NetworkOfTwo net(
1313  *this,
1314  {totalReplay + 1},
1318 
1319  auto l = net.server.ledgerMaster.getClosedLedger();
1320  uint256 finalHash = l->info().hash;
1321  net.client.ledgerMaster.storeLedger(l);
1322  net.client.replayer.replay(
1323  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1324 
1325  auto delta = net.client.findLedgerDeltaAcquire(l->info().parentHash);
1326  delta->processData(
1327  l->info(), // wrong ledger info
1329  BEAST_EXPECT(net.client.taskStatus(delta) == TaskStatus::Failed);
1330  BEAST_EXPECT(
1331  net.client.taskStatus(net.client.findTask(
1332  finalHash, totalReplay)) == TaskStatus::Failed);
1333 
1334  // add another task
1335  net.client.replayer.replay(
1336  InboundLedger::Reason::GENERIC, finalHash, totalReplay + 1);
1337  BEAST_EXPECT(
1338  net.client.taskStatus(net.client.findTask(
1339  finalHash, totalReplay + 1)) == TaskStatus::Failed);
1340  }
1341 
1342  void
1344  {
1345  testcase("Overlap tasks");
1346  int totalReplay = 5;
1347  NetworkOfTwo net(
1348  *this,
1349  {totalReplay * 3 + 1},
1353  auto l = net.server.ledgerMaster.getClosedLedger();
1354  uint256 finalHash = l->info().hash;
1355  net.client.replayer.replay(
1356  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1357  std::vector<TaskStatus> deltaStatuses(
1358  totalReplay - 1, TaskStatus::Completed);
1359  BEAST_EXPECT(net.client.waitAndCheckStatus(
1360  finalHash,
1361  totalReplay,
1364  deltaStatuses));
1365  BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay));
1366 
1367  // same range, same reason
1368  net.client.replayer.replay(
1369  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1370  BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1371  // same range, different reason
1372  net.client.replayer.replay(
1373  InboundLedger::Reason::CONSENSUS, finalHash, totalReplay);
1374  BEAST_EXPECT(net.client.countsAsExpected(2, 1, totalReplay - 1));
1375 
1376  // no overlap
1377  for (int i = 0; i < totalReplay + 2; ++i)
1378  {
1379  l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1380  }
1381  auto finalHash_early = l->info().hash;
1382  net.client.replayer.replay(
1383  InboundLedger::Reason::GENERIC, finalHash_early, totalReplay);
1384  BEAST_EXPECT(net.client.waitAndCheckStatus(
1385  finalHash_early,
1386  totalReplay,
1389  deltaStatuses)); // deltaStatuses no change
1390  BEAST_EXPECT(net.client.waitForLedgers(finalHash_early, totalReplay));
1391  BEAST_EXPECT(net.client.countsAsExpected(3, 2, 2 * (totalReplay - 1)));
1392 
1393  // partial overlap
1394  l = net.server.ledgerMaster.getLedgerByHash(l->info().parentHash);
1395  auto finalHash_moreEarly = l->info().parentHash;
1396  net.client.replayer.replay(
1397  InboundLedger::Reason::GENERIC, finalHash_moreEarly, totalReplay);
1398  BEAST_EXPECT(net.client.waitAndCheckStatus(
1399  finalHash_moreEarly,
1400  totalReplay,
1403  deltaStatuses)); // deltaStatuses no change
1404  BEAST_EXPECT(
1405  net.client.waitForLedgers(finalHash_moreEarly, totalReplay));
1406  BEAST_EXPECT(
1407  net.client.countsAsExpected(4, 3, 2 * (totalReplay - 1) + 2));
1408 
1409  // cover
1410  net.client.replayer.replay(
1411  InboundLedger::Reason::GENERIC, finalHash, totalReplay * 3);
1412  deltaStatuses =
1413  std::vector<TaskStatus>(totalReplay * 3 - 1, TaskStatus::Completed);
1414  BEAST_EXPECT(net.client.waitAndCheckStatus(
1415  finalHash,
1416  totalReplay * 3,
1419  deltaStatuses)); // deltaStatuses changed
1420  BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay * 3));
1421  BEAST_EXPECT(net.client.countsAsExpected(5, 3, totalReplay * 3 - 1));
1422 
1423  // sweep
1424  net.client.replayer.sweep();
1425  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1426  }
1427 
1428  void
1429  run() override
1430  {
1431  testProofPath();
1432  testReplayDelta();
1433  testTaskParameter();
1434  testConfig();
1435  testHandshake();
1436  testAllLocal(1);
1437  testAllLocal(3);
1438  testAllInboundLedgers(1);
1439  testAllInboundLedgers(4);
1440  testPeerSetBehavior(PeerSetBehavior::Good, 1);
1441  testPeerSetBehavior(PeerSetBehavior::Good);
1442  testPeerSetBehavior(PeerSetBehavior::Drop50);
1443  testPeerSetBehavior(PeerSetBehavior::Repeat);
1444  testOnStop();
1445  testSkipListBadReply();
1446  testLedgerDeltaBadReply();
1447  testLedgerReplayOverlap();
1448  }
1449 };
1450 
1451 struct LedgerReplayerTimeout_test : public beast::unit_test::suite
1452 {
1453  void
1455  {
1456  testcase("SkipListAcquire timeout");
1457  int totalReplay = 3;
1458  NetworkOfTwo net(
1459  *this,
1460  {totalReplay + 1},
1464 
1465  auto l = net.server.ledgerMaster.getClosedLedger();
1466  uint256 finalHash = l->info().hash;
1467  net.client.replayer.replay(
1468  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1469 
1470  std::vector<TaskStatus> deltaStatuses;
1471  BEAST_EXPECT(net.client.waitAndCheckStatus(
1472  finalHash,
1473  totalReplay,
1476  deltaStatuses));
1477 
1478  // sweep
1479  BEAST_EXPECT(net.client.countsAsExpected(1, 1, 0));
1480  net.client.replayer.sweep();
1481  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1482  }
1483 
1484  void
1486  {
1487  testcase("LedgerDeltaAcquire timeout");
1488  int totalReplay = 3;
1489  NetworkOfTwo net(
1490  *this,
1491  {totalReplay + 1},
1495 
1496  auto l = net.server.ledgerMaster.getClosedLedger();
1497  uint256 finalHash = l->info().hash;
1498  net.client.ledgerMaster.storeLedger(l);
1499  net.client.replayer.replay(
1500  InboundLedger::Reason::GENERIC, finalHash, totalReplay);
1501 
1502  std::vector<TaskStatus> deltaStatuses(
1503  totalReplay - 1, TaskStatus::Failed);
1504  deltaStatuses.back() = TaskStatus::Completed; // in client ledgerMaster
1505  BEAST_EXPECT(net.client.waitAndCheckStatus(
1506  finalHash,
1507  totalReplay,
1510  deltaStatuses));
1511 
1512  // sweep
1513  BEAST_EXPECT(net.client.countsAsExpected(1, 1, totalReplay - 1));
1514  net.client.replayer.sweep();
1515  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1516  }
1517 
1518  void
1519  run() override
1520  {
1521  testSkipListTimeout();
1522  testLedgerDeltaTimeout();
1523  }
1524 };
1525 
1526 struct LedgerReplayerLong_test : public beast::unit_test::suite
1527 {
1528  void
1529  run() override
1530  {
1531  testcase("Acquire 1000 ledgers");
1532  int totalReplay = 250;
1533  int rounds = 4;
1534  NetworkOfTwo net(
1535  *this,
1536  {totalReplay * rounds + 1},
1540 
1541  std::vector<uint256> finishHashes;
1542  auto l = net.server.ledgerMaster.getClosedLedger();
1543  for (int i = 0; i < rounds; ++i)
1544  {
1545  finishHashes.push_back(l->info().hash);
1546  for (int j = 0; j < totalReplay; ++j)
1547  {
1548  l = net.server.ledgerMaster.getLedgerByHash(
1549  l->info().parentHash);
1550  }
1551  }
1552  BEAST_EXPECT(finishHashes.size() == rounds);
1553 
1554  for (int i = 0; i < rounds; ++i)
1555  {
1556  net.client.replayer.replay(
1557  InboundLedger::Reason::GENERIC, finishHashes[i], totalReplay);
1558  }
1559 
1560  std::vector<TaskStatus> deltaStatuses(
1561  totalReplay - 1, TaskStatus::Completed);
1562  for (int i = 0; i < rounds; ++i)
1563  {
1564  BEAST_EXPECT(net.client.waitAndCheckStatus(
1565  finishHashes[i],
1566  totalReplay,
1569  deltaStatuses));
1570  }
1571 
1572  BEAST_EXPECT(
1573  net.client.waitForLedgers(finishHashes[0], totalReplay * rounds));
1574  BEAST_EXPECT(net.client.countsAsExpected(
1575  rounds, rounds, rounds * (totalReplay - 1)));
1576 
1577  // sweep
1578  net.client.replayer.sweep();
1579  BEAST_EXPECT(net.client.countsAsExpected(0, 0, 0));
1580  }
1581 };
1582 
1585 BEAST_DEFINE_TESTSUITE(LedgerReplayerTimeout, app, ripple);
1586 BEAST_DEFINE_TESTSUITE_MANUAL(LedgerReplayerLong, app, ripple);
1587 
1588 } // namespace test
1589 } // 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:783
ripple::test::LedgerServer::param
Parameter param
Definition: LedgerReplay_test.cpp:531
ripple::test::TestPeer::TestPeer
TestPeer(bool enableLedgerReplay)
Definition: LedgerReplay_test.cpp:194
ripple::test::LedgerServer::Parameter::initLedgers
int initLedgers
Definition: LedgerReplay_test.cpp:439
ripple::test::TestPeer::compressionEnabled
bool compressionEnabled() const override
Definition: LedgerReplay_test.cpp:293
ripple::Application
Definition: Application.h:102
ripple::test::LedgerReplayClient::replayer
LedgerReplayer replayer
Definition: LedgerReplay_test.cpp:804
ripple::test::LedgerReplayer_test::testLedgerReplayOverlap
void testLedgerReplayOverlap()
Definition: LedgerReplay_test.cpp:1343
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:670
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:824
ripple::test::LedgerReplayClient::countsAsExpected
bool countsAsExpected(std::size_t tasks, std::size_t skipLists, std::size_t deltas)
Definition: LedgerReplay_test.cpp:677
ripple::test::LedgerReplayer_test::testLedgerDeltaBadReply
void testLedgerDeltaBadReply()
Definition: LedgerReplay_test.cpp:1308
ripple::test::LedgerReplayerTimeout_test::testLedgerDeltaTimeout
void testLedgerDeltaTimeout()
Definition: LedgerReplay_test.cpp:1485
ripple::LedgerReplayTask::TaskParameter::reason_
InboundLedger::Reason reason_
Definition: LedgerReplayTask.h:50
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
ripple::InboundLedger::Reason::CONSENSUS
@ CONSENSUS
std::string
STL class.
std::shared_ptr
STL class.
ripple::test::NetworkOfTwo::client
LedgerReplayClient client
Definition: LedgerReplay_test.cpp:836
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:1037
ripple::test::TestPeerSetBuilder
Build the TestPeerSet.
Definition: LedgerReplay_test.cpp:402
ripple::test::TaskStatus::NotExist
@ NotExist
ripple::test::MagicInboundLedgers::onStop
virtual void onStop() override
Definition: LedgerReplay_test.cpp:172
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:189
ripple::LedgerMaster
Definition: LedgerMaster.h:72
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:435
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:1526
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:331
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:479
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:519
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:535
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:1263
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:1150
ripple::test::MagicInboundLedgers::ledgerSink
LedgerMaster & ledgerSink
Definition: LedgerReplay_test.cpp:177
ripple::test::TestPeerSet::behavior
PeerSetBehavior behavior
Definition: LedgerReplay_test.cpp:396
ripple::test::TestPeer::hasTxSet
bool hasTxSet(uint256 const &hash) const override
Definition: LedgerReplay_test.cpp:279
ripple::test::LedgerReplayClient::ledgerMaster
LedgerMaster & ledgerMaster
Definition: LedgerReplay_test.cpp:799
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:587
ripple::test::TestPeerSetBuilder::local
LedgerReplayMsgHandler & local
Definition: LedgerReplay_test.cpp:425
ripple::tapNONE
@ tapNONE
Definition: ApplyView.h:30
ripple::test::TestPeer::hasShard
bool hasShard(std::uint32_t shardIndex) const override
Definition: LedgerReplay_test.cpp:274
ripple::test::NetworkOfTwo::server
LedgerServer server
Definition: LedgerReplay_test.cpp:835
ripple::test::LedgerReplayer_test::testAllLocal
void testAllLocal(int totalReplay)
Definition: LedgerReplay_test.cpp:1108
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::jtx::autofill
static const autofill_t autofill
Definition: tags.h:42
ripple::test::LedgerReplayClient::waitForDone
bool waitForDone()
Definition: LedgerReplay_test.cpp:616
ripple::test::LedgerServer::LedgerServer
LedgerServer(beast::unit_test::suite &suite, Parameter const &p)
Definition: LedgerReplay_test.cpp:446
ripple::test::LedgerReplayerTimeout_test
Definition: LedgerReplay_test.cpp:1451
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:393
ripple::Keylet::key
uint256 key
Definition: Keylet.h:41
ripple::base_uint< 256 >
ripple::test::TestPeer::ledgerReplayEnabled_
bool ledgerReplayEnabled_
Definition: LedgerReplay_test.cpp:298
ripple::test::LedgerServer::accounts
std::vector< jtx::Account > accounts
Definition: LedgerReplay_test.cpp:532
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:341
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:387
ripple::Config::loadFromString
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
Definition: Config.cpp:346
ripple::test::PeerSetBehavior::DropAll
@ DropAll
ripple::RootStoppable
Definition: Stoppable.h:354
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:745
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:649
ripple::test::LedgerServer::app
Application & app
Definition: LedgerReplay_test.cpp:528
ripple::Config
Definition: Config.h:67
chrono
ripple::Application::config
virtual Config & config()=0
ripple::test::LedgerReplayerTimeout_test::run
void run() override
Definition: LedgerReplay_test.cpp:1519
ripple::test::TestPeer::hasRange
bool hasRange(std::uint32_t uMin, std::uint32_t uMax) override
Definition: LedgerReplay_test.cpp:288
std::unique_lock
STL class.
std::to_string
T to_string(T... args)
ripple::test::LedgerServer::ledgerMaster
LedgerMaster & ledgerMaster
Definition: LedgerReplay_test.cpp:529
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:527
ripple::test::PeerSetBehavior::DropLedgerDeltaReply
@ DropLedgerDeltaReply
ripple::test::LedgerReplayClient::findLedgerDeltaAcquire
std::shared_ptr< LedgerDeltaAcquire > findLedgerDeltaAcquire(uint256 const &hash)
Definition: LedgerReplay_test.cpp:699
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:801
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:1067
ripple::test::TestPeerSetBuilder::remote
LedgerReplayMsgHandler & remote
Definition: LedgerReplay_test.cpp:426
std::map
STL class.
ripple::test::LedgerReplayer_test::testOnStop
void testOnStop()
Definition: LedgerReplay_test.cpp:1232
ripple::test::LedgerReplayer_test::testProofPath
void testProofPath()
Definition: LedgerReplay_test.cpp:867
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:552
ripple::test::LedgerReplayClient
Ledger replay client side.
Definition: LedgerReplay_test.cpp:549
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:364
ripple::test::TestPeerSetBuilder::behavior
PeerSetBehavior behavior
Definition: LedgerReplay_test.cpp:427
ripple::InboundLedgers
Manages the lifetime of inbound ledgers.
Definition: InboundLedgers.h:34
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:418
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:105
ripple::test::LedgerReplayClient::findSkipListAcquire
std::shared_ptr< SkipListAcquire > findSkipListAcquire(uint256 const &hash)
Definition: LedgerReplay_test.cpp:689
ripple::Logs::threshold
beast::severities::Severity threshold() const
Definition: Log.cpp:150
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:798
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:864
ripple::test::LedgerReplayClient::stopableParent
RootStoppable stopableParent
Definition: LedgerReplay_test.cpp:803
ripple::test::logAll
void logAll(LedgerServer &server, LedgerReplayClient &client, beast::severities::Severity level=Severity::kTrace)
Definition: LedgerReplay_test.cpp:809
ripple::test::LedgerReplayClient::checkStatus
bool checkStatus(uint256 const &hash, int totalReplay, TaskStatus taskExpect, TaskStatus skiplistExpect, std::vector< TaskStatus > const &deltaExpects)
Definition: LedgerReplay_test.cpp:764
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:1180
ripple::test::TestPeer::cycleStatus
void cycleStatus() override
Definition: LedgerReplay_test.cpp:284
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:663
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:219
ripple::test::LedgerServer::createAccounts
void createAccounts(int newAccounts)
Definition: LedgerReplay_test.cpp:463
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:802
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:581
std::unordered_set::count
T count(T... args)
ripple::test::NetworkOfTwo
Definition: LedgerReplay_test.cpp:822
ripple::test::LedgerReplayerLong_test::run
void run() override
Definition: LedgerReplay_test.cpp:1529
ripple::LedgerReplayer
Manages the lifetime of ledger replay tasks.
Definition: LedgerReplayer.h:73
ripple::test::LedgerReplayClient::getTasks
std::vector< std::shared_ptr< LedgerReplayTask > > getTasks()
Definition: LedgerReplay_test.cpp:642
ripple::test::LedgerReplayer_test::run
void run() override
Definition: LedgerReplay_test.cpp:1429
ripple::test::LedgerReplayer_test::testReplayDelta
void testReplayDelta()
Definition: LedgerReplay_test.cpp:931
ripple::test::TestPeerSet::dummyPeer
std::shared_ptr< TestPeer > dummyPeer
Definition: LedgerReplay_test.cpp:395
ripple::test::LedgerServer::msgHandler
LedgerReplayMsgHandler msgHandler
Definition: LedgerReplay_test.cpp:530
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:316
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:428
ripple::test::TestPeerSet::remote
LedgerReplayMsgHandler & remote
Definition: LedgerReplay_test.cpp:394
ripple::test::LedgerServer::Parameter
Definition: LedgerReplay_test.cpp:437
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::InboundLedger::Reason
Reason
Definition: InboundLedger.h:46
ripple::test::LedgerReplayClient::env
jtx::Env env
Definition: LedgerReplay_test.cpp:797
ripple::test::LedgerReplayClient::taskStatus
TaskStatus taskStatus(std::shared_ptr< T > const &t)
Definition: LedgerReplay_test.cpp:710
ripple::test::LedgerReplay_test
Definition: LedgerReplay_test.cpp:40
ripple::test::LedgerReplayClient::waitForLedgers
bool waitForLedgers(uint256 const &finishLedgerHash, int totalReplay)
Definition: LedgerReplay_test.cpp:602
ripple::test::LedgerReplayerTimeout_test::testSkipListTimeout
void testSkipListTimeout()
Definition: LedgerReplay_test.cpp:1454
ripple::test::TestPeerSet::TestPeerSet
TestPeerSet(LedgerReplayMsgHandler &me, LedgerReplayMsgHandler &other, PeerSetBehavior bhvr, bool enableLedgerReplay)
Definition: LedgerReplay_test.cpp:318
ripple::test::PeerSetBehavior
PeerSetBehavior
Definition: LedgerReplay_test.cpp:301
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:387
ripple::test::PeerSetBehavior::DropSkipListReply
@ DropSkipListReply
ripple::test::LedgerReplayClient::inboundLedgers
MagicInboundLedgers inboundLedgers
Definition: LedgerReplay_test.cpp:800
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:405
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:720
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:984
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::LedgerReplay
Definition: LedgerReplay.h:32