hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
synchronizer_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SYNCHRONIZER_IMPL_HPP
7 #define IROHA_SYNCHRONIZER_IMPL_HPP
8 
10 
13 #include "logger/logger_fwd.hpp"
14 #include "network/block_loader.hpp"
17 
18 namespace iroha {
19 
20  namespace ametsuchi {
21  class BlockQueryFactory;
22  }
23 
24  namespace synchronizer {
25 
26  class SynchronizerImpl : public Synchronizer {
27  public:
29  std::shared_ptr<network::ConsensusGate> consensus_gate,
30  std::shared_ptr<validation::ChainValidator> validator,
31  std::shared_ptr<ametsuchi::MutableFactory> mutable_factory,
32  std::shared_ptr<ametsuchi::BlockQueryFactory> block_query_factory,
33  std::shared_ptr<network::BlockLoader> block_loader,
34  logger::LoggerPtr log);
35 
36  ~SynchronizerImpl() override;
37 
38  void processOutcome(consensus::GateObject object) override;
39  rxcpp::observable<SynchronizationEvent> on_commit_chain() override;
40 
41  private:
42  using PublicKeysRange =
44  boost::forward_traversal_tag,
45  const shared_model::interface::types::PubkeyType &>;
53  boost::optional<std::unique_ptr<LedgerState>> downloadMissingBlocks(
56  const PublicKeysRange &public_keys);
57 
58  void processNext(const consensus::PairValid &msg);
59 
66  void processDifferent(const consensus::Synchronizable &msg,
67  SynchronizationOutcomeType alternative_outcome);
68 
69  boost::optional<shared_model::interface::types::HeightType>
70  getTopBlockHeight() const;
71 
72  boost::optional<std::unique_ptr<ametsuchi::MutableStorage>> getStorage();
73 
74  std::shared_ptr<validation::ChainValidator> validator_;
75  std::shared_ptr<ametsuchi::MutableFactory> mutable_factory_;
76  std::shared_ptr<ametsuchi::BlockQueryFactory> block_query_factory_;
77  std::shared_ptr<network::BlockLoader> block_loader_;
78 
79  // internal
80  rxcpp::composite_subscription notifier_lifetime_;
81  rxcpp::subjects::subject<SynchronizationEvent> notifier_;
82  rxcpp::composite_subscription subscription_;
83 
84  logger::LoggerPtr log_;
85  };
86 
87  } // namespace synchronizer
88 } // namespace iroha
89 
90 #endif // IROHA_SYNCHRONIZER_IMPL_HPP
Current pair is valid.
Definition: gate_object.hpp:35
SynchronizationOutcomeType
Definition: synchronizer_common.hpp:24
uint64_t HeightType
Type of height (for Block, Proposal etc)
Definition: types.hpp:41
Definition: synchronizer_impl.hpp:26
Definition: synchronizer.hpp:19
Definition: gate_object.hpp:45
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: block_query.hpp:14
crypto::PublicKey PubkeyType
Type of public key.
Definition: types.hpp:45
boost::variant< PairValid, VoteOther, ProposalReject, BlockReject, AgreementOnNone > GateObject
Definition: gate_object.hpp:90