Skip to content

Commit

Permalink
Use non-header-only fmt library; refactor std::accumulate usages
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
  • Loading branch information
lebdron committed Sep 27, 2019
1 parent d7c4d65 commit 5863d41
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 224 deletions.
62 changes: 0 additions & 62 deletions cmake/Modules/Findfmt.cmake

This file was deleted.

6 changes: 5 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ endif()
###################################
# fmt #
###################################
find_package(fmt 5.3.0 REQUIRED)
find_package(fmt 5.3.0 REQUIRED CONFIG)
add_library(fmt INTERFACE IMPORTED)
target_link_libraries(fmt INTERFACE
fmt::fmt
)

if (USE_LIBIROHA)
find_package(libiroha)
Expand Down
12 changes: 6 additions & 6 deletions irohad/ametsuchi/impl/postgres_specific_query_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ametsuchi/impl/postgres_specific_query_executor.hpp"

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/format.hpp>
#include <boost/range/adaptor/filtered.hpp>
Expand Down Expand Up @@ -668,12 +669,11 @@ namespace iroha {
const shared_model::interface::GetTransactions &q,
const shared_model::interface::types::AccountIdType &creator_id,
const shared_model::interface::types::HashType &query_hash) {
auto escape = [](auto &hash) { return "'" + hash.hex() + "'"; };
std::string hash_str = std::accumulate(
std::next(q.transactionHashes().begin()),
q.transactionHashes().end(),
escape(q.transactionHashes().front()),
[&escape](auto &acc, auto &val) { return acc + "," + escape(val); });
std::string hash_str = boost::algorithm::join(
q.transactionHashes()
| boost::adaptors::transformed(
[](const auto &h) { return "'" + h.hex() + "'"; }),
", ");

using QueryTuple =
QueryType<shared_model::interface::types::HeightType, std::string>;
Expand Down
7 changes: 2 additions & 5 deletions irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "ametsuchi/impl/temporary_wsv_impl.hpp"

#include <boost/algorithm/string/join.hpp>
#include <boost/format.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include "ametsuchi/impl/postgres_command_executor.hpp"
Expand Down Expand Up @@ -35,11 +36,7 @@ namespace iroha {
auto keys_range = transaction.signatures()
| boost::adaptors::transformed(
[](const auto &s) { return s.publicKey().hex(); });
auto keys = std::accumulate(
std::next(std::begin(keys_range)),
std::end(keys_range),
keys_range.front(),
[](auto acc, const auto &val) { return acc + "'), ('" + val; });
auto keys = boost::algorithm::join(keys_range, "'), ('");
// not using bool since it is not supported by SOCI
boost::optional<uint8_t> signatories_valid;

Expand Down
33 changes: 14 additions & 19 deletions irohad/consensus/yac/impl/yac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <utility>

#include <boost/algorithm/string/join.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include "common/bind.hpp"
#include "common/visitor.hpp"
Expand All @@ -29,21 +30,6 @@ namespace iroha {
namespace consensus {
namespace yac {

template <typename T>
static std::string cryptoError(const T &votes) {
std::string result =
"Crypto verification failed for message.\n Votes: ";
result += logger::to_string(votes, [](const auto &vote) {
std::string result = "(Public key: ";
result += vote.signature->publicKey().hex();
result += ", Signature: ";
result += vote.signature->signedData().hex();
result += ")\n";
return result;
});
return result;
}

std::shared_ptr<Yac> Yac::create(
YacVoteStorage vote_storage,
std::shared_ptr<YacNetwork> network,
Expand Down Expand Up @@ -90,9 +76,12 @@ namespace iroha {
void Yac::vote(YacHash hash,
ClusterOrdering order,
boost::optional<ClusterOrdering> alternative_order) {
log_->info("Order for voting: {}",
logger::to_string(order.getPeers(),
[](auto val) { return val->address(); }));
log_->info("Order for voting: [{}]",
boost::algorithm::join(
order.getPeers()
| boost::adaptors::transformed(
[](const auto &p) { return p->address(); }),
", "));

std::unique_lock<std::mutex> lock(mutex_);
cluster_order_ = order;
Expand Down Expand Up @@ -180,7 +169,13 @@ namespace iroha {

applyState(state, guard);
} else {
log_->warn("{}", cryptoError(state));
log_->warn(
"Crypto verification failed for message. Votes: [{}]",
boost::algorithm::join(
state | boost::adaptors::transformed([](const auto &v) {
return v.signature->toString();
}),
", "));
}
}

Expand Down
5 changes: 3 additions & 2 deletions irohad/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ target_link_libraries(iroha_conf_loader
)

add_library(iroha_conf_literals iroha_conf_literals.cpp)
add_dependencies(iroha_conf_literals logger)
target_include_directories(iroha_conf_literals PUBLIC ${fmt_INCLUDE_DIR})
target_link_libraries(iroha_conf_literals
logger
)

add_install_step_for_bin(irohad)
2 changes: 1 addition & 1 deletion irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ Irohad::RunResult Irohad::initOrderingGate() {
delay,
log_manager_->getChild("Ordering"));
log_->info("[Init] => init ordering gate - [{}]",
logger::logBool(ordering_gate));
logger::boolRepr(bool(ordering_gate)));
return {};
}

Expand Down
2 changes: 2 additions & 0 deletions irohad/main/impl/on_demand_ordering_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "main/impl/on_demand_ordering_init.hpp"

#include <numeric>

#include <rxcpp/operators/rx-filter.hpp>
#include <rxcpp/operators/rx-map.hpp>
#include <rxcpp/operators/rx-skip.hpp>
Expand Down
1 change: 1 addition & 0 deletions irohad/multi_sig_transactions/state/impl/mst_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "multi_sig_transactions/state/mst_state.hpp"

#include <numeric>
#include <utility>
#include <vector>

Expand Down
20 changes: 8 additions & 12 deletions irohad/ordering/impl/on_demand_os_server_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,14 @@ grpc::Status OnDemandOsServerGrpc::SendBatches(

auto batch_candidates = batch_parser_->parseBatches(std::move(transactions));

auto batches = std::accumulate(
std::begin(batch_candidates),
std::end(batch_candidates),
OdOsNotification::CollectionType{},
[this](auto &acc, const auto &cand) {
batch_factory_->createTransactionBatch(cand).match(
[&](auto &&value) { acc.push_back(std::move(value).value); },
[&](const auto &error) {
log_->warn("Batch deserialization failed: {}", error.error);
});
return acc;
});
OdOsNotification::CollectionType batches;
for (auto &cand : batch_candidates) {
batch_factory_->createTransactionBatch(cand).match(
[&](auto &&value) { batches.push_back(std::move(value).value); },
[&](const auto &error) {
log_->warn("Batch deserialization failed: {}", error.error);
});
}

ordering_service_->onBatches(std::move(batches));

Expand Down
13 changes: 6 additions & 7 deletions irohad/torii/impl/command_service_transport_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <condition_variable>
#include <iterator>

#include <boost/algorithm/string/join.hpp>
#include <boost/format.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
Expand Down Expand Up @@ -80,13 +81,11 @@ namespace iroha {
.str();
}

std::string folded_hashes =
std::accumulate(std::next(tx_hashes.begin()),
tx_hashes.end(),
tx_hashes[0].hex(),
[](auto &&acc, const auto &h) -> std::string {
return acc + ", " + h.hex();
});
std::string folded_hashes = boost::algorithm::join(
tx_hashes | boost::adaptors::transformed([](const auto &h) {
return h.hex();
}),
", ");

return (boost::format(
"Stateless invalid tx in transaction sequence, error: %s\n"
Expand Down
23 changes: 11 additions & 12 deletions irohad/validation/impl/chain_validator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "validation/impl/chain_validator_impl.hpp"

#include <boost/algorithm/string/join.hpp>
#include <rxcpp/rx-lite.hpp>
#include "ametsuchi/ledger_state.hpp"
#include "ametsuchi/mutable_storage.hpp"
Expand Down Expand Up @@ -81,18 +82,16 @@ namespace iroha {
"Block does not contain signatures of supermajority of "
"peers. Block signatures public keys: [{}], ledger peers "
"public keys: [{}]",
std::accumulate(std::next(std::begin(signatures)),
std::end(signatures),
signatures.front().publicKey().hex(),
[](auto acc, auto &sig) {
return acc + ", " + sig.publicKey().hex();
}),
std::accumulate(std::next(std::begin(peers)),
std::end(peers),
peers.front()->pubkey().hex(),
[](auto acc, auto &peer) {
return acc + ", " + peer->pubkey().hex();
}));
boost::algorithm::join(
signatures | boost::adaptors::transformed([](const auto &s) {
return s.publicKey().toString();
}),
", "),
boost::algorithm::join(
peers | boost::adaptors::transformed([](const auto &p) {
return p->pubkey().toString();
}),
", "));
}

return has_supermajority;
Expand Down

0 comments on commit 5863d41

Please sign in to comment.