LCOV - code coverage report
Current view: top level - irohad/consensus/yac/storage/impl - yac_vote_storage.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 26 27 96.3 %
Date: 2018-12-05 17:11:35 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
       3             :  * http://soramitsu.co.jp
       4             :  *
       5             :  * Licensed under the Apache License, Version 2.0 (the "License");
       6             :  * you may not use this file except in compliance with the License.
       7             :  * You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  * Unless required by applicable law or agreed to in writing, software
      12             :  * distributed under the License is distributed on an "AS IS" BASIS,
      13             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  * See the License for the specific language governing permissions and
      15             :  * limitations under the License.
      16             :  */
      17             : 
      18             : #include "consensus/yac/storage/yac_vote_storage.hpp"
      19             : 
      20             : #include <algorithm>
      21             : #include <utility>
      22             : 
      23             : #include "consensus/yac/storage/yac_proposal_storage.hpp"
      24             : 
      25             : namespace iroha {
      26             :   namespace consensus {
      27             :     namespace yac {
      28             : 
      29             :       // --------| private api |--------
      30             : 
      31             :       auto YacVoteStorage::getProposalStorage(const Round &round) {
      32        2201 :         return std::find_if(proposal_storages_.begin(),
      33        2201 :                             proposal_storages_.end(),
      34             :                             [&round](const auto &storage) {
      35        4090 :                               return storage.getStorageKey() == round;
      36             :                             });
      37             :       }
      38             : 
      39             :       auto YacVoteStorage::findProposalStorage(const VoteMessage &msg,
      40             :                                                PeersNumberType peers_in_round) {
      41        1465 :         auto val = getProposalStorage(msg.hash.vote_round);
      42        1465 :         if (val != proposal_storages_.end()) {
      43         742 :           return val;
      44             :         }
      45         723 :         return proposal_storages_.emplace(
      46         723 :             proposal_storages_.end(),
      47         723 :             msg.hash.vote_round,
      48             :             peers_in_round,
      49         723 :             std::make_shared<SupermajorityCheckerImpl>());
      50        1465 :       }
      51             : 
      52             :       // --------| public api |--------
      53             : 
      54             :       boost::optional<Answer> YacVoteStorage::store(
      55             :           std::vector<VoteMessage> state, PeersNumberType peers_in_round) {
      56        1465 :         auto storage = findProposalStorage(state.at(0), peers_in_round);
      57        1465 :         return storage->insert(state);
      58           0 :       }
      59             : 
      60             :       bool YacVoteStorage::isCommitted(const Round &round) {
      61         736 :         auto iter = getProposalStorage(round);
      62         736 :         if (iter == proposal_storages_.end()) {
      63         735 :           return false;
      64             :         }
      65           1 :         return bool(iter->getState());
      66         736 :       }
      67             : 
      68             :       ProposalState YacVoteStorage::getProcessingState(const Round &round) {
      69        1448 :         return processing_state_[round];
      70             :       }
      71             : 
      72             :       void YacVoteStorage::nextProcessingState(const Round &round) {
      73        2876 :         auto &val = processing_state_[round];
      74        2876 :         switch (val) {
      75             :           case ProposalState::kNotSentNotProcessed:
      76         720 :             val = ProposalState::kSentNotProcessed;
      77         720 :             break;
      78             :           case ProposalState::kSentNotProcessed:
      79         718 :             val = ProposalState::kSentProcessed;
      80         718 :             break;
      81             :           case ProposalState::kSentProcessed:
      82             :             break;
      83             :         }
      84        1438 :       }
      85             : 
      86             :     }  // namespace yac
      87             :   }    // namespace consensus
      88             : }  // namespace iroha

Generated by: LCOV version 1.13