Skip to content

Commit

Permalink
Remove cout logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lebdron committed Aug 4, 2017
1 parent 540dbc0 commit 1984800
Show file tree
Hide file tree
Showing 29 changed files with 24 additions and 169 deletions.
6 changes: 2 additions & 4 deletions iroha-cli/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
* limitations under the License.
*/

#include "client.hpp"
#include <utility>
#include <fstream>
#include "client.hpp"
#include "ametsuchi/block_serializer.hpp"
#include "model/converters/pb_transaction_factory.hpp"

namespace iroha_cli {

CliClient::CliClient(std::string target_ip, int port)
: client_(std::move(target_ip), port) {}
: client_(std::move(target_ip), port) {}

CliClient::Status CliClient::sendTx(std::string json_tx) {
iroha::ametsuchi::BlockSerializer serializer;
auto tx_opt = serializer.deserialize(std::move(json_tx));
if (not tx_opt.has_value()) {
std::cout << "wrong format" << std::endl;
return WRONG_FORMAT;
}
auto model_tx = tx_opt.value();
Expand Down
4 changes: 0 additions & 4 deletions irohad/ametsuchi/impl/mutable_storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ namespace iroha {
const hash256_t &)>
function) {
transaction_->exec("SAVEPOINT savepoint_;");
std::cout << "[MS] starting block application" << std::endl;
std::cout << "[MS] top hash " << top_hash_.to_hexstring() << std::endl;
auto result = function(block, *executor_, *this, top_hash_);
if (result) {
std::cout << "[MS] block application success" << std::endl;
std::cout << "[MS] block height: " << block.height << std::endl;
block_store_.insert(std::make_pair(block.height, block));
top_hash_ = block.hash;
transaction_->exec("RELEASE SAVEPOINT savepoint_;");
Expand Down
9 changes: 0 additions & 9 deletions irohad/ametsuchi/impl/postgres_wsv_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ namespace iroha {
transaction_.quote(precision) + ", " + /*asset.data*/ "NULL" +
");");
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
return false;
}
return true;
Expand All @@ -96,7 +95,6 @@ namespace iroha {
" amount=EXCLUDED.amount, \n"
" permissions=EXCLUDED.permissions;");
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
return false;
}
return true;
Expand All @@ -112,7 +110,6 @@ namespace iroha {
" VALUES (" +
transaction_.quote(public_key) + ");");
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
return false;
}
return true;
Expand All @@ -129,7 +126,6 @@ namespace iroha {
transaction_.quote(account_id) + ", " +
transaction_.quote(public_key) + ");");
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
return false;
}
return true;
Expand All @@ -145,14 +141,12 @@ namespace iroha {
transaction_.quote(account_id) + " AND public_key=" +
transaction_.quote(public_key) + ";");
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
return false;
}
return true;
}

bool PostgresWsvCommand::insertPeer(const model::Peer &peer) {
std::cout << "[AM] insertPeer()" << std::endl;
pqxx::binarystring public_key(peer.pubkey.data(), peer.pubkey.size());
try {
transaction_.exec(
Expand All @@ -163,8 +157,6 @@ namespace iroha {
transaction_.quote(peer.address) + ", " +
/*peer.state*/ transaction_.quote(0) + ");");
} catch (const std::exception &e) {
std::cout << "[AM] insertPeer() db error" << std::endl;
std::cout << e.what() << std::endl;
return false;
}
return true;
Expand All @@ -179,7 +171,6 @@ namespace iroha {
transaction_.quote(public_key) + " AND address=" +
transaction_.quote(peer.address) + ";");
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
return false;
}
return true;
Expand Down
7 changes: 1 addition & 6 deletions irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

#include <ametsuchi/impl/postgres_wsv_query.hpp>
#include <iostream>

namespace iroha {
namespace ametsuchi {
Expand Down Expand Up @@ -45,8 +44,7 @@ namespace iroha {
" account.account_id = " +
transaction_.quote(account_id) + ";");
} catch (const std::exception &e) {
std::cout << "select error" << std::endl;
std::cout << e.what() << std::endl;
// TODO log
return nullopt;
}
if (result.size() != 1) {
Expand Down Expand Up @@ -171,12 +169,9 @@ namespace iroha {
"FROM \n"
" peer;");
} catch (const std::exception &e) {
std::cout << "select error" << std::endl;
std::cout << e.what() << std::endl;
return nullopt;
}
std::vector<Peer> peers;
std::cout << "[AM] number of peers: " << result.size() << std::endl;
for (const auto &row : result) {
model::Peer peer;
pqxx::binarystring public_key_str(row.at("public_key"));
Expand Down
9 changes: 3 additions & 6 deletions irohad/ametsuchi/impl/storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ namespace iroha {

auto block_store = FlatFile::create(block_store_dir);
if (!block_store) {
std::cout << "block store init error" << std::endl;
// TODO log error
return nullptr;
}

auto index = std::make_unique<cpp_redis::redis_client>();
try {
index->connect(redis_host, redis_port);
} catch (const cpp_redis::redis_error &e) {
std::cout << "redis init error" << std::endl;
// TODO log error
return nullptr;
}

Expand All @@ -142,7 +142,7 @@ namespace iroha {
try {
postgres_connection->activate();
} catch (const pqxx::broken_connection &e) {
std::cout << "postgres init error" << std::endl;
// TODO log error
return nullptr;
}
auto wsv_transaction = std::make_unique<pqxx::nontransaction>(
Expand Down Expand Up @@ -238,9 +238,6 @@ namespace iroha {

nonstd::optional<std::vector<model::Peer>> StorageImpl::getPeers() {
std::shared_lock<std::shared_timed_mutex> write(rw_lock_);

std::cout << "[AM] getPeers()" << std::endl;

return wsv_->getPeers();
}

Expand Down
1 change: 0 additions & 1 deletion irohad/consensus/yac/impl/yac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ namespace iroha {

void Yac::applyCommit(model::Peer from, CommitMessage commit) {
// todo apply to vote storage for verification
std::cout << "Yac applyCommit()" << std::endl;

auto storage_state = vote_storage_
.applyCommit(commit, cluster_order_.getNumberOfPeers());
Expand Down
8 changes: 0 additions & 8 deletions irohad/consensus/yac/impl/yac_gate_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,10 @@ namespace iroha {

rxcpp::observable<model::Block> YacGateImpl::on_commit() {
return hash_gate_->on_commit().map([this](auto commit_message) {
std::cout << "Yac hash commit received" << std::endl;
if (commit_message.votes.at(0).hash == current_block_.first) {
std::cout << "Signature before:" << std::endl;
std::cout << current_block_.second.sigs.front().pubkey.to_hexstring() << std::endl;
std::cout << current_block_.second.sigs.front().signature.to_hexstring() << std::endl;

current_block_.second.sigs.clear();
for (auto &&vote : commit_message.votes) {
current_block_.second.sigs.push_back(vote.signature);
std::cout << "New signature added:" << std::endl;
std::cout << current_block_.second.sigs.back().pubkey.to_hexstring() << std::endl;
std::cout << current_block_.second.sigs.back().signature.to_hexstring() << std::endl;
}
return current_block_.second;
}
Expand Down
50 changes: 3 additions & 47 deletions irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ Irohad::Irohad(const std::string &block_store_dir,
torii_port_(torii_port),
storage(StorageImpl::create(block_store_dir, redis_host, redis_port,
pg_conn)),
peer_number_(peer_number) {
std::cout << "irohad init - storage: " << storage << std::endl;
}
peer_number_(peer_number) {}

class MockBlockLoader : public iroha::network::BlockLoader {
public:
Expand All @@ -73,13 +71,9 @@ class MockCryptoProvider : public ModelCryptoProvider {
void Irohad::run() {
loop = uvw::Loop::create();

std::cout << "loop created" << std::endl;

auto torii_server =
std::make_unique<ServerRunner>("0.0.0.0:" + std::to_string(torii_port_));

std::cout << "torii server assigned" << std::endl;

std::thread server_thread([this, &torii_server] {
// Protobuf converters
auto pb_tx_factory =
Expand All @@ -89,8 +83,6 @@ void Irohad::run() {
auto pb_query_response_factory =
std::make_shared<PbQueryResponseFactory>();

std::cout << "proto factories created" << std::endl;

// Crypto Provider:
auto crypto_verifier =
std::make_shared<MockCryptoProvider>();
Expand All @@ -103,107 +95,73 @@ void Irohad::run() {
// Hash provider
auto hash_provider = std::make_shared<HashProviderImpl>();

std::cout << "crypto and hash providers created" << std::endl;

// Validators:
auto stateless_validator = createStatelessValidator(crypto_verifier);
auto stateful_validator = std::make_shared<StatefulValidatorImpl>();
auto chain_validator =
std::make_shared<ChainValidatorImpl>(crypto_verifier);

std::cout << "validators created" << std::endl;

auto orderer = std::make_shared<PeerOrdererImpl>(storage);

std::cout << "orderer created" << std::endl;

auto ordering = orderer->getInitialOrdering().value().getPeers();

std::cout << "peers retrieved from db. size: " << ordering.size() << std::endl;

// Ordering gate
OrderingInit ordering_init;
auto ordering_gate =
ordering_init.initOrderingGate(ordering, loop, 10, 5000);

std::cout << "ordering gate created" << std::endl;

// Simulator
auto simulator = createSimulator(ordering_gate, stateful_validator, storage,
storage, hash_provider);

std::cout << "simulator created" << std::endl;

// Consensus gate
YacInit yac_init;
auto consensus_gate = yac_init.initConsensusGate(
ordering.at(peer_number_).address, loop, orderer, simulator);

std::cout << "consensus gate created" << std::endl;

// Block loader
auto block_loader = std::make_shared<MockBlockLoader>();

std::cout << "block loader created" << std::endl;

// Synchronizer
auto synchronizer = initializeSynchronizer(consensus_gate, chain_validator,
storage, block_loader);

std::cout << "synchronizer created" << std::endl;

// PeerCommunicationService
auto pcs = createPeerCommunicationService(ordering_gate, synchronizer);

std::cout << "peer communication service created" << std::endl;

pcs->on_proposal().subscribe([](auto) {
std::cout << "~~~~~~~PROPOSAL! >_<~~~~~~~" << std::endl;
std::cout << "~~~~~~~PROPOSAL! =^._.^=~~~~~~~" << std::endl;
});

pcs->on_commit().subscribe([](auto) {
std::cout << "~~~~~~~COMMITED! ^_^~~~~~~~" << std::endl;
std::cout << "~~~~~~~COMMITTED! ^_^~~~~~~~" << std::endl;
});

// Torii:
// --- Transactions:
auto tx_processor = createTransactionProcessor(pcs, stateless_validator);

std::cout << "tx processor created" << std::endl;

auto comand_service = createCommandService(pb_tx_factory, tx_processor);

std::cout << "command service created" << std::endl;

// --- Queries
auto query_proccessing_factory =
createQueryProcessingFactory(storage, storage);

std::cout << "query processing factory created" << std::endl;

auto query_processor =
createQueryProcessor(std::move(query_proccessing_factory),
stateless_validator);

std::cout << "query processor created" << std::endl;

auto query_service = createQueryService(
pb_query_factory, pb_query_response_factory, query_processor);

std::cout << "query service created" << std::endl;

std::thread internal_thread([this, &ordering, &ordering_init, &yac_init, &ordering_gate] {
std::cout << "internal thread started" << std::endl;
std::cout << ordering_init.orderingService().get() << std::endl;
std::cout << yac_init.consensus_network.get() << std::endl;
grpc::ServerBuilder builder;
int port = 0;
builder.AddListeningPort(ordering.at(peer_number_).address, grpc::InsecureServerCredentials(), &port);
builder.RegisterService(ordering_gate.get());
builder.RegisterService(ordering_init.orderingService().get());
builder.RegisterService(yac_init.consensus_network.get());
auto server = builder.BuildAndStart();
std::cout << "internal server port: " << port << std::endl;
server->Wait();
});

Expand All @@ -229,7 +187,6 @@ std::shared_ptr<Simulator> Irohad::createSimulator(

ordering_gate->on_proposal().subscribe(
[simulator](auto proposal) {
std::cout << "Proposal height: " << proposal.height << std::endl;
simulator->process_proposal(proposal);
});

Expand All @@ -253,7 +210,6 @@ std::shared_ptr<Synchronizer> Irohad::initializeSynchronizer(
std::move(validator), mutableFactory, blockLoader);

consensus_gate->on_commit().subscribe([synchronizer](auto block) {
std::cout << "Block size: " << block.transactions.size() << std::endl;
synchronizer->process_commit(block);
});

Expand Down
10 changes: 0 additions & 10 deletions irohad/main/impl/raw_block_insertion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,21 @@ namespace iroha {

void BlockInserter::applyToLedger(std::vector<model::Block> blocks) {
auto storage = factory_->createMutableStorage();

std::cout << "mutable storage created" << std::endl;

for (auto &&block : blocks) {
auto result = storage->apply(block,
[](const auto& current_block, auto& executor,
auto& query, const auto& top_hash) {
for (const auto& tx : current_block.transactions) {
for (const auto& command : tx.commands) {
if (not command->execute(query, executor)) {
std::cout << "command execution failed" << std::endl;
return false;
}
}
}
return true;
});
std::cout << "block application result: " << result << std::endl;
}

std::cout << "blocks applied" << std::endl;

factory_->commit(std::move(storage));

std::cout << "storage committed" << std::endl;
};

nonstd::optional<std::string> BlockInserter::loadFile(std::string path) {
Expand Down
Loading

0 comments on commit 1984800

Please sign in to comment.