LCOV - code coverage report
Current view: top level - irohad/consensus/yac/impl - peer_orderer_impl.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 9 11 81.8 %
Date: 2019-03-07 14:46:43 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "consensus/yac/impl/peer_orderer_impl.hpp"
       7             : 
       8             : #include <random>
       9             : 
      10             : #include "common/bind.hpp"
      11             : #include "consensus/yac/cluster_order.hpp"
      12             : #include "consensus/yac/yac_hash_provider.hpp"
      13             : #include "interfaces/common_objects/peer.hpp"
      14             : 
      15             : namespace iroha {
      16             :   namespace consensus {
      17             :     namespace yac {
      18             :       PeerOrdererImpl::PeerOrdererImpl(
      19             :           std::shared_ptr<ametsuchi::PeerQueryFactory> peer_query_factory)
      20         257 :           : peer_query_factory_(peer_query_factory) {}
      21             : 
      22             :       boost::optional<ClusterOrdering> PeerOrdererImpl::getInitialOrdering() {
      23         249 :         return peer_query_factory_->createPeerQuery() |
      24             :             [](const auto &query) { return query->getLedgerPeers(); } |
      25             :             [](const auto &peers) { return ClusterOrdering::create(peers); };
      26           0 :       }
      27             : 
      28             :       boost::optional<ClusterOrdering> PeerOrdererImpl::getOrdering(
      29             :           const YacHash &hash) {
      30        4095 :         return peer_query_factory_->createPeerQuery() |
      31             :             [](const auto &query) { return query->getLedgerPeers(); } |
      32             :             [&hash](auto peers) {
      33        3853 :               std::seed_seq seed(hash.vote_hashes.block_hash.begin(),
      34        3853 :                                  hash.vote_hashes.block_hash.end());
      35        3853 :               std::default_random_engine gen(seed);
      36        3853 :               std::shuffle(peers.begin(), peers.end(), gen);
      37        3853 :               return ClusterOrdering::create(peers);
      38        3853 :             };
      39           0 :       }
      40             :     }  // namespace yac
      41             :   }    // namespace consensus
      42             : }  // namespace iroha

Generated by: LCOV version 1.13