Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…#896 hyperledger#835

Integrate kOnBlock to storage_impl.cpp
Closes hyperledger#837 Add total number of blocks
Closes hyperledger#883 Number of domains
Closes hyperledger#919 Number of signatures in the last block
Closes hyperledger#896 Measure total number of transactions
Closes hyperledger#835 Total nodes/peers updated when kOnBlock
Should close hyperledger#835 no online/connected peers parameter in this commit.
Add CMake files to .clang-format-ignore
Disable prometheus-cpp logs
Extend WSV to countDomains(), countTransactions(), countPeers()
-fno-lto to link GCC-10 and clang with civetweb which was built with
GCC-9
Tests dependant on ametsuchi are linked against sync_subscription, not
async
Closes hyperledger#966 Disable prometheus-cpp self-metrics

Signed-off-by: Ivan 'kuvaldini' Kuvaldin <ivan@kuvaldini.pro>
  • Loading branch information
kuvaldini committed May 8, 2021
1 parent 4646e74 commit 803762c
Show file tree
Hide file tree
Showing 28 changed files with 575 additions and 136 deletions.
2 changes: 2 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CMakeLists.txt
*.cmake
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ if(CMAKE_BUILD_TYPE MATCHES "Release")
endif()
endif()

## FIXME revert this after change CI to GitHub actions.
## Temporal fix for 'bytecode stream version incompatible' between gcc-9 and gcc-10 and clang
## when dependancies were build via vcpkg with default GCC9 could not be linked with iroha built with GCC-10
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)

if(WIN32)
# We have to set _WIN32_WINNT for gRPC
if(${CMAKE_SYSTEM_VERSION} EQUAL 10) # Windows 10
Expand Down
27 changes: 27 additions & 0 deletions irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ametsuchi/impl/postgres_wsv_query.hpp"

#include <soci/boost-tuple.h>

#include "ametsuchi/impl/soci_std_optional.hpp"
#include "ametsuchi/impl/soci_utils.hpp"
#include "ametsuchi/ledger_state.hpp"
Expand Down Expand Up @@ -79,6 +80,32 @@ namespace iroha {
return getPeersFromSociRowSet(result);
}

iroha::expected::Result<size_t, std::string> PostgresWsvQuery::count(
std::string_view what) try {
int count;
sql_ << "SELECT count(*) FROM " << what, soci::into(count);
return count;
} catch (const std::exception &e) {
auto msg = fmt::format("Failed to count {}, query: {}", what, e.what());
log_->error(msg);
return iroha::expected::makeError(msg);
}

iroha::expected::Result<size_t, std::string>
PostgresWsvQuery::countPeers() {
return count("peer");
}

iroha::expected::Result<size_t, std::string>
PostgresWsvQuery::countDomains() {
return count("domain");
}

iroha::expected::Result<size_t, std::string>
PostgresWsvQuery::countTransactions() {
return count("tx_positions");
}

boost::optional<std::shared_ptr<shared_model::interface::Peer>>
PostgresWsvQuery::getPeerByPublicKey(
shared_model::interface::types::PublicKeyHexStringView public_key) {
Expand Down
10 changes: 8 additions & 2 deletions irohad/ametsuchi/impl/postgres_wsv_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#ifndef IROHA_POSTGRES_WSV_QUERY_HPP
#define IROHA_POSTGRES_WSV_QUERY_HPP

#include "ametsuchi/wsv_query.hpp"

#include <soci/soci.h>

#include "ametsuchi/wsv_query.hpp"
#include "logger/logger_fwd.hpp"

namespace iroha {
Expand All @@ -28,6 +28,10 @@ namespace iroha {
std::vector<std::shared_ptr<shared_model::interface::Peer>>>
getPeers() override;

iroha::expected::Result<size_t, std::string> countPeers() override;
iroha::expected::Result<size_t, std::string> countDomains() override;
iroha::expected::Result<size_t, std::string> countTransactions() override;

boost::optional<std::shared_ptr<shared_model::interface::Peer>>
getPeerByPublicKey(shared_model::interface::types::PublicKeyHexStringView
public_key) override;
Expand All @@ -43,6 +47,8 @@ namespace iroha {
template <typename T, typename F>
auto execute(F &&f) -> boost::optional<soci::rowset<T>>;

iroha::expected::Result<size_t, std::string> count(std::string_view);

// TODO andrei 24.09.2018: IR-1718 Consistent soci::session fields in
// storage classes
std::unique_ptr<soci::session> psql_;
Expand Down
17 changes: 14 additions & 3 deletions irohad/ametsuchi/impl/storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

#include "ametsuchi/impl/storage_impl.hpp"

#include <utility>

#include <soci/callbacks.h>
#include <soci/postgresql/soci-postgresql.h>

#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include <boost/range/algorithm/replace_if.hpp>
#include <boost/tuple/tuple.hpp>

#include "ametsuchi/impl/mutable_storage_impl.hpp"
#include "ametsuchi/impl/peer_query_wsv.hpp"
#include "ametsuchi/impl/postgres_block_index.hpp"
Expand All @@ -36,6 +36,7 @@
#include "logger/logger.hpp"
#include "logger/logger_manager.hpp"
#include "main/impl/pg_connection_init.hpp"
#include "main/subscription.hpp"

namespace iroha {
namespace ametsuchi {
Expand Down Expand Up @@ -307,7 +308,11 @@ namespace iroha {
if (not maybe_block) {
return fmt::format("Failed to fetch block {}", height);
}
notifier_.get_subscriber().on_next(*std::move(maybe_block));

std::shared_ptr<const shared_model::interface::Block> block_ptr =
std::move(maybe_block.get());
notifier_.get_subscriber().on_next(block_ptr);
getSubscription()->notify(EventTypes::kOnBlock, block_ptr);
}
return expected::makeValue(std::move(commit_result.ledger_state));
};
Expand Down Expand Up @@ -357,6 +362,9 @@ namespace iroha {
}

notifier_.get_subscriber().on_next(block);
getSubscription()->notify(
EventTypes::kOnBlock,
std::shared_ptr<const shared_model::interface::Block>(block));

decltype(std::declval<PostgresWsvQuery>().getPeers()) opt_ledger_peers;
{
Expand Down Expand Up @@ -455,6 +463,9 @@ namespace iroha {
std::shared_ptr<const shared_model::interface::Block> block) {
if (block_store_->insert(block)) {
notifier_.get_subscriber().on_next(block);
getSubscription()->notify(
EventTypes::kOnBlock,
std::shared_ptr<const shared_model::interface::Block>(block));
return {};
}
return expected::makeError("Block insertion to storage failed");
Expand Down
31 changes: 30 additions & 1 deletion irohad/ametsuchi/wsv_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#ifndef IROHA_WSV_QUERY_HPP
#define IROHA_WSV_QUERY_HPP

#include <boost/optional.hpp>
#include <vector>

#include <boost/optional.hpp>
#include "common/result.hpp"
#include "interfaces/common_objects/peer.hpp"
#include "interfaces/common_objects/string_view_types.hpp"
Expand Down Expand Up @@ -40,6 +40,35 @@ namespace iroha {
std::vector<std::shared_ptr<shared_model::interface::Peer>>>
getPeers() = 0;

// ToDo?(kuvaldini,iceseer) #997
// /**
// * @brief Fetch domains stored in ledger
// * @return list of domains in insertion to ledger order
// */
// virtual iroha::expected::Result<
// std::vector<std::shared_ptr<shared_model::interface::Domain>>,
// std::string>
// getDomains() = 0;

/**
* @brief Fetch number of domains in ledger
* @return number of domains in ledger
*/
virtual iroha::expected::Result<size_t, std::string> countPeers() = 0;

/**
* @brief Fetch number of domains in ledger
* @return number of domains in ledger
*/
virtual iroha::expected::Result<size_t, std::string> countDomains() = 0;

/**
* @brief Fetch number of valid transactions in ledger
* @return number of transactions in ledger
*/
virtual iroha::expected::Result<size_t, std::string>
countTransactions() = 0;

/**
* Fetch peer with given public key from ledger
* @return the peer if found, none otherwise
Expand Down
10 changes: 8 additions & 2 deletions irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "main/impl/pg_connection_init.hpp"
#include "main/impl/storage_init.hpp"
#include "main/server_runner.hpp"
#include "main/subscription.hpp"
#include "multi_sig_transactions/gossip_propagation_strategy.hpp"
#include "multi_sig_transactions/mst_processor_impl.hpp"
#include "multi_sig_transactions/mst_propagation_strategy_stub.hpp"
Expand Down Expand Up @@ -114,7 +115,8 @@ Irohad::Irohad(
const boost::optional<GossipPropagationStrategyParams>
&opt_mst_gossip_params,
boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config)
: config_(config),
: se_(getSubscription()),
config_(config),
listen_ip_(listen_ip),
keypair_(keypair),
startup_wsv_sync_policy_(startup_wsv_sync_policy),
Expand Down Expand Up @@ -154,6 +156,7 @@ Irohad::~Irohad() {
}
consensus_gate_objects_lifetime.unsubscribe();
consensus_gate_events_subscription.unsubscribe();
se_->dispose();
}

/**
Expand Down Expand Up @@ -1011,7 +1014,10 @@ Irohad::RunResult Irohad::run() {
storage->on_commit().subscribe(
ordering_init.commit_notifier.get_subscriber());

ordering_init.commit_notifier.get_subscriber().on_next(std::move(block));
std::shared_ptr<const shared_model::interface::Block> sh_block{
std::move(block)};
ordering_init.commit_notifier.get_subscriber().on_next(sh_block);
getSubscription()->notify(EventTypes::kOnInitialBlock, sh_block);

ordering_init.sync_event_notifier.get_subscriber().on_next(
synchronizer::SynchronizationEvent{
Expand Down
2 changes: 2 additions & 0 deletions irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "main/iroha_conf_loader.hpp"
#include "main/server_runner.hpp"
#include "main/startup_params.hpp"
#include "main/subscription.hpp"
#include "multi_sig_transactions/gossip_propagation_strategy_params.hpp"
#include "torii/tls_params.hpp"

Expand Down Expand Up @@ -215,6 +216,7 @@ class Irohad {
virtual RunResult initWsvRestorer();

// constructor dependencies
std::shared_ptr<iroha::Subscription> se_;
IrohadConfig config_;
const std::string listen_ip_;
boost::optional<shared_model::crypto::Keypair> keypair_;
Expand Down
65 changes: 44 additions & 21 deletions irohad/main/irohad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,6 @@ int main(int argc, char *argv[]) {
log_manager);
}

if (FLAGS_metrics_port.size()) {
maintenance_metrics_init(FLAGS_metrics_addr + ":" + FLAGS_metrics_port);
} else if (config.metrics_addr_port.size()) {
maintenance_metrics_init(config.metrics_addr_port);
}

daemon_status_notifier->notify(
::iroha::utility_service::Status::kInitialization);

Expand Down Expand Up @@ -374,10 +368,18 @@ int main(int argc, char *argv[]) {

// clear previous storage if any
irohad->dropStorage();
// Check if iroha daemon storage was successfully re-initialized
if (not irohad->storage) {
// Abort execution if not
log->error("Failed to re-initialize storage");
daemon_status_notifier->notify(
::iroha::utility_service::Status::kFailed);
return EXIT_FAILURE;
}

const auto txs_num = block->transactions().size();
if (auto e = iroha::expected::resultToOptionalError(
irohad->storage->insertBlock(std::move(block)))) {
auto inserted = irohad->storage->insertBlock(std::move(block));
if (auto e = iroha::expected::resultToOptionalError(inserted)) {
log->critical("Could not apply genesis block: {}", e.value());
return EXIT_FAILURE;
}
Expand All @@ -391,19 +393,17 @@ int main(int argc, char *argv[]) {
"genesis block is provided. Please pecify new genesis block using "
"--genesis_block parameter.");
return EXIT_FAILURE;
} else {
if (overwrite) {
// no genesis, blockstore present, overwrite specified -> new block
// store, world state should be reset
irohad->resetWsv();
if (not FLAGS_reuse_state) {
log->warn(
"No new genesis block is specified - blockstore will not be "
"overwritten. If you want overwrite ledger state, please "
"specify new genesis block using --genesis_block parameter. "
"If you want to reuse existing state data (WSV), consider the "
"--reuse_state flag.");
}
} else if (overwrite) {
// no genesis, blockstore present, overwrite specified -> new block
// store, world state should be reset
irohad->resetWsv();
if (not FLAGS_reuse_state) {
log->warn(
"No new genesis block is specified - blockstore will not be "
"overwritten. If you want overwrite ledger state, please "
"specify new genesis block using --genesis_block parameter. "
"If you want to reuse existing state data (WSV), consider the "
"--reuse_state flag.");
}
}
}
Expand Down Expand Up @@ -446,6 +446,29 @@ int main(int argc, char *argv[]) {
std::signal(SIGQUIT, handler);
#endif

// start metrics
std::shared_ptr<Metrics> metrics; // Must be a pointer because 'this' is
// captured to lambdas in constructor.
std::string metrics_addr;
if (FLAGS_metrics_port.size()) {
metrics_addr = FLAGS_metrics_addr + ":" + FLAGS_metrics_port;
} else if (config.metrics_addr_port.size()) {
metrics_addr = config.metrics_addr_port;
}
if (metrics_addr.empty()) {
log->info("Skiping Metrics initialization.");
} else {
try {
metrics =
Metrics::create(metrics_addr,
irohad->storage,
log_manager->getChild("Metrics")->getLogger());
log->info("Metrics listens on {}", metrics->getListenAddress());
} catch (std::exception const &ex) {
log->warn("Failed to initialize Metrics: {}", ex.what());
}
}

// runs iroha
log->info("Running iroha");
auto run_result = irohad->run();
Expand Down
1 change: 1 addition & 0 deletions irohad/main/subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace iroha {
kYac = 0,
kRequestProposal,
kVoteProcess,
kMetrics,
//---------------
kTotalCount
};
Expand Down
Loading

0 comments on commit 803762c

Please sign in to comment.