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 
14 #include "logger/logger_fwd.hpp"
15 #include "network/block_loader.hpp"
18 
19 namespace iroha {
20 
21  namespace ametsuchi {
22  class BlockQueryFactory;
23  class CommandExecutor;
24  } // namespace ametsuchi
25 
26  namespace synchronizer {
27 
28  class SynchronizerImpl : public Synchronizer {
29  public:
31  std::unique_ptr<iroha::ametsuchi::CommandExecutor> command_executor,
32  std::shared_ptr<network::ConsensusGate> consensus_gate,
33  std::shared_ptr<validation::ChainValidator> validator,
34  std::shared_ptr<ametsuchi::MutableFactory> mutable_factory,
35  std::shared_ptr<ametsuchi::BlockQueryFactory> block_query_factory,
36  std::shared_ptr<network::BlockLoader> block_loader,
37  logger::LoggerPtr log);
38 
39  ~SynchronizerImpl() override;
40 
41  void processOutcome(consensus::GateObject object) override;
42  rxcpp::observable<SynchronizationEvent> on_commit_chain() override;
43 
44  private:
45  using PublicKeysRange =
47  boost::forward_traversal_tag,
48  const shared_model::interface::types::PubkeyType &>;
57  ametsuchi::CommitResult downloadAndCommitMissingBlocks(
60  const PublicKeysRange &public_keys);
61 
62  void processNext(const consensus::PairValid &msg);
63 
70  void processDifferent(const consensus::Synchronizable &msg,
71  SynchronizationOutcomeType alternative_outcome);
72 
73  boost::optional<shared_model::interface::types::HeightType>
74  getTopBlockHeight() const;
75 
76  std::unique_ptr<ametsuchi::MutableStorage> getStorage();
77 
78  std::shared_ptr<iroha::ametsuchi::CommandExecutor> command_executor_;
79 
80  std::shared_ptr<validation::ChainValidator> validator_;
81  std::shared_ptr<ametsuchi::MutableFactory> mutable_factory_;
82  std::shared_ptr<ametsuchi::BlockQueryFactory> block_query_factory_;
83  std::shared_ptr<network::BlockLoader> block_loader_;
84 
85  // internal
86  rxcpp::composite_subscription notifier_lifetime_;
87  rxcpp::subjects::subject<SynchronizationEvent> notifier_;
88  rxcpp::composite_subscription subscription_;
89 
90  logger::LoggerPtr log_;
91  };
92 
93  } // namespace synchronizer
94 } // namespace iroha
95 
96 #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:43
Definition: synchronizer_impl.hpp:28
Definition: synchronizer.hpp:19
iroha::expected::Result< std::shared_ptr< const iroha::LedgerState >, std::string > CommitResult
Definition: commit_result.hpp:20
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:47
boost::variant< PairValid, VoteOther, ProposalReject, BlockReject, AgreementOnNone > GateObject
Definition: gate_object.hpp:90