rippled
ShardVerificationScheduler.h
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 #ifndef RIPPLE_RPC_SHARDVERIFICATIONSCHEDULER_H_INCLUDED
21 #define RIPPLE_RPC_SHARDVERIFICATIONSCHEDULER_H_INCLUDED
22 
23 #include <ripple/app/main/Application.h>
24 #include <functional>
25 
26 namespace ripple {
27 namespace RPC {
28 
30 {
31 public:
32  // This is the signature of the function that the client
33  // wants to have invoked upon timer expiration. The function
34  // should check the error code 'ec' and abort the function
35  // if the timer was cancelled:
36  // (ec == boost::asio::error::operation_aborted).
37  // In the body of the function, the client should perform
38  // the necessary verification.
39  using retryFunction =
40  std::function<void(boost::system::error_code const& ec)>;
41 
42  ShardVerificationScheduler() = default;
43 
45  std::chrono::seconds retryInterval,
46  std::uint32_t maxAttempts);
47 
48  bool
49  retry(Application& app, bool shouldHaveHash, retryFunction f);
50 
51  void
52  reset();
53 
54 private:
55  using waitable_timer =
56  boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
57 
59  // NOTE: retryInterval_ and maxAttempts_ were chosen
60  // semi-arbitrarily and experimenting with other
61  // values might prove useful.
63 
65 
66  static constexpr std::uint32_t defaultmaxAttempts_{5};
67 
68  // The number of seconds to wait before retrying
69  // retrieval of a shard's last ledger hash
71 
72  // Maximum attempts to retrieve a shard's last ledger hash
74 
76 
77  // Number of attempts to retrieve a shard's last ledger hash
79 };
80 
81 } // namespace RPC
82 } // namespace ripple
83 
84 #endif // RIPPLE_RPC_SHARDVERIFICATIONSCHEDULER_H_INCLUDED
ripple::Application
Definition: Application.h:115
ripple::RPC::ShardVerificationScheduler::ShardVerificationScheduler
ShardVerificationScheduler()=default
ripple::RPC::ShardVerificationScheduler::defaultRetryInterval_
static constexpr std::chrono::seconds defaultRetryInterval_
Definition: ShardVerificationScheduler.h:64
functional
ripple::RPC::ShardVerificationScheduler::reset
void reset()
Definition: ShardVerificationScheduler.cpp:62
std::chrono::seconds
ripple::RPC::ShardVerificationScheduler::timer_
std::unique_ptr< waitable_timer > timer_
Definition: ShardVerificationScheduler.h:75
std::function
ripple::RPC::ShardVerificationScheduler::waitable_timer
boost::asio::basic_waitable_timer< std::chrono::steady_clock > waitable_timer
Definition: ShardVerificationScheduler.h:56
ripple::RPC::ShardVerificationScheduler::maxAttempts_
const std::uint32_t maxAttempts_
Definition: ShardVerificationScheduler.h:73
std::uint32_t
ripple::RPC::ShardVerificationScheduler::retry
bool retry(Application &app, bool shouldHaveHash, retryFunction f)
Definition: ShardVerificationScheduler.cpp:37
ripple::RPC::ShardVerificationScheduler
Definition: ShardVerificationScheduler.h:29
ripple::RPC::ShardVerificationScheduler::retryInterval_
const std::chrono::seconds retryInterval_
Definition: ShardVerificationScheduler.h:70
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RPC::ShardVerificationScheduler::defaultmaxAttempts_
static constexpr std::uint32_t defaultmaxAttempts_
Definition: ShardVerificationScheduler.h:66
std::unique_ptr< waitable_timer >
ripple::RPC::ShardVerificationScheduler::numAttempts_
std::uint32_t numAttempts_
Definition: ShardVerificationScheduler.h:78