diff --git a/irohad/network/ordering_gate.hpp b/irohad/network/ordering_gate.hpp index 3a7dd23f56..6ab9304c65 100644 --- a/irohad/network/ordering_gate.hpp +++ b/irohad/network/ordering_gate.hpp @@ -18,8 +18,8 @@ #ifndef IROHA_ORDERING_SERVICE_HPP #define IROHA_ORDERING_SERVICE_HPP -#include -#include +#include "model/proposal.hpp" +#include "model/transaction.hpp" #include namespace iroha { @@ -30,12 +30,12 @@ namespace iroha { */ class OrderingGate { public: - /** * Propagate a signed transaction for further processing * @param transaction */ - virtual void propagate_transaction(std::shared_ptr transaction) = 0; + virtual void propagate_transaction( + std::shared_ptr transaction) = 0; /** * Return observable of all proposals in the consensus @@ -45,7 +45,7 @@ namespace iroha { virtual ~OrderingGate() = default; }; - }//namespace network -}// namespace iroha + } // namespace network +} // namespace iroha -#endif //IROHA_ORDERING_SERVICE_HPP +#endif // IROHA_ORDERING_SERVICE_HPP diff --git a/irohad/network/ordering_service.hpp b/irohad/network/ordering_service.hpp index 7eb3dfd919..8cd9fa9af7 100644 --- a/irohad/network/ordering_service.hpp +++ b/irohad/network/ordering_service.hpp @@ -36,6 +36,6 @@ namespace iroha { */ virtual void publishProposal(model::Proposal &&proposal) = 0; }; - } -} -#endif //IROHA_ORDERINGSERVICE_H + } // namespace network +} // namespace iroha +#endif // IROHA_ORDERINGSERVICE_H diff --git a/irohad/network/ordering_service_transport.hpp b/irohad/network/ordering_service_transport.hpp index bc17810db0..0d67887844 100644 --- a/irohad/network/ordering_service_transport.hpp +++ b/irohad/network/ordering_service_transport.hpp @@ -57,8 +57,8 @@ namespace iroha { * Publishes proposal over network * @param proposal : proposal to be published */ - virtual void publishProposal(model::Proposal&& proposal, - const std::vector& peers) = 0; + virtual void publishProposal(model::Proposal &&proposal, + const std::vector &peers) = 0; virtual ~OrderingServiceTransport() = default; }; diff --git a/irohad/network/peer_communication_service.hpp b/irohad/network/peer_communication_service.hpp index 0cb851a202..2bb01acb1b 100644 --- a/irohad/network/peer_communication_service.hpp +++ b/irohad/network/peer_communication_service.hpp @@ -18,8 +18,9 @@ #ifndef IROHA_PEER_COMMUNICATION_SERVICE_HPP #define IROHA_PEER_COMMUNICATION_SERVICE_HPP -#include -#include +#include "model/block.hpp" +#include "model/proposal.hpp" + #include namespace iroha { @@ -32,7 +33,6 @@ namespace iroha { */ class PeerCommunicationService { public: - /** * Propagate transaction in network * @param transaction - object for propagation @@ -48,12 +48,12 @@ namespace iroha { virtual rxcpp::observable on_proposal() = 0; /** - * Event is triggered when commit block arrives. - * @return observable with sequence of committed blocks. - * In common case observable will contain one element. - * But there are scenarios when consensus provide many blocks, e.g. - * on peer startup - peer will get all actual blocks. - */ + * Event is triggered when commit block arrives. + * @return observable with sequence of committed blocks. + * In common case observable will contain one element. + * But there are scenarios when consensus provide many blocks, e.g. + * on peer startup - peer will get all actual blocks. + */ virtual rxcpp::observable on_commit() = 0; virtual ~PeerCommunicationService() = default; diff --git a/irohad/ordering/impl/ordering_gate_transport_grpc.cpp b/irohad/ordering/impl/ordering_gate_transport_grpc.cpp index f9508846e9..bc29f147a2 100644 --- a/irohad/ordering/impl/ordering_gate_transport_grpc.cpp +++ b/irohad/ordering/impl/ordering_gate_transport_grpc.cpp @@ -19,7 +19,8 @@ using namespace iroha::ordering; grpc::Status OrderingGateTransportGrpc::onProposal( - ::grpc::ServerContext *context, const proto::Proposal *request, + ::grpc::ServerContext *context, + const proto::Proposal *request, ::google::protobuf::Empty *response) { log_->info("receive proposal"); @@ -31,7 +32,7 @@ grpc::Status OrderingGateTransportGrpc::onProposal( model::Proposal proposal(transactions); proposal.height = request->height(); - if(not subscriber_.expired()) + if (not subscriber_.expired()) subscriber_.lock()->onProposal(std::move(proposal)); else log_->error("(onProposal) No subscriber"); @@ -50,7 +51,6 @@ void OrderingGateTransportGrpc::propagate_transaction( log_->info("Propagate tx (on transport)"); auto call = new AsyncClientCall; - call->response_reader = client_->AsynconTransaction( &call->context, factory_.serialize(*transaction), &cq_); diff --git a/irohad/ordering/impl/ordering_gate_transport_grpc.hpp b/irohad/ordering/impl/ordering_gate_transport_grpc.hpp index dfdba3c9b3..8c1ef9dbf3 100644 --- a/irohad/ordering/impl/ordering_gate_transport_grpc.hpp +++ b/irohad/ordering/impl/ordering_gate_transport_grpc.hpp @@ -18,7 +18,6 @@ #define IROHA_ORDERING_GATE_TRANSPORT_GRPC_H #include -#include "ordering.grpc.pb.h" #include "logger/logger.hpp" #include "model/converters/pb_transaction_factory.hpp" #include "network/impl/async_grpc_client.hpp" diff --git a/irohad/ordering/impl/ordering_service_impl.hpp b/irohad/ordering/impl/ordering_service_impl.hpp index f86419d5f4..7108743293 100644 --- a/irohad/ordering/impl/ordering_service_impl.hpp +++ b/irohad/ordering/impl/ordering_service_impl.hpp @@ -22,9 +22,9 @@ #include #include +#include "network/impl/async_grpc_client.hpp" #include "network/ordering_service.hpp" #include "network/ordering_service_transport.hpp" -#include "network/impl/async_grpc_client.hpp" #include "ametsuchi/peer_query.hpp" #include "ordering.grpc.pb.h" @@ -49,7 +49,8 @@ namespace iroha { class OrderingServiceImpl : public network::OrderingService { public: OrderingServiceImpl( - std::shared_ptr wsv, size_t max_size, + std::shared_ptr wsv, + size_t max_size, size_t delay_milliseconds, std::shared_ptr transport); @@ -58,24 +59,23 @@ namespace iroha { * Enqueues transaction and publishes corresponding event * @param transaction */ - void onTransaction(const model::Transaction& transaction) override; + void onTransaction(const model::Transaction &transaction) override; ~OrderingServiceImpl() override; - protected: - /** - * Transform model proposal to transport object and send to peers - * @param proposal - object for propagation - */ - void publishProposal(model::Proposal &&proposal) override; + protected: + /** + * Transform model proposal to transport object and send to peers + * @param proposal - object for propagation + */ + void publishProposal(model::Proposal &&proposal) override; - private: + private: /** * Collect transactions from queue * Passes the generated proposal to publishProposal */ - void generateProposal() override ; - + void generateProposal() override; /** * Method update peers for sending proposal @@ -103,7 +103,6 @@ namespace iroha { const size_t delay_milliseconds_; std::shared_ptr transport_; size_t proposal_height; - }; } // namespace ordering } // namespace iroha diff --git a/irohad/ordering/impl/ordering_service_transport_grpc.cpp b/irohad/ordering/impl/ordering_service_transport_grpc.cpp index 31875684ea..44a7d6478a 100644 --- a/irohad/ordering/impl/ordering_service_transport_grpc.cpp +++ b/irohad/ordering/impl/ordering_service_transport_grpc.cpp @@ -29,10 +29,11 @@ grpc::Status OrderingServiceTransportGrpc::onTransaction( ::grpc::ServerContext *context, const protocol::Transaction *request, ::google::protobuf::Empty *response) { - if (subscriber_.expired()) + if (subscriber_.expired()) { log_->error("No subscriber"); - else + } else { subscriber_.lock()->onTransaction(*factory_.deserialize(*request)); + } return ::grpc::Status::OK; } diff --git a/irohad/ordering/impl/ordering_service_transport_grpc.hpp b/irohad/ordering/impl/ordering_service_transport_grpc.hpp index 314a6213b2..b32c79e737 100644 --- a/irohad/ordering/impl/ordering_service_transport_grpc.hpp +++ b/irohad/ordering/impl/ordering_service_transport_grpc.hpp @@ -46,8 +46,8 @@ namespace iroha { const protocol::Transaction *request, ::google::protobuf::Empty *response) override; + ~OrderingServiceTransportGrpc() = default; - ~OrderingServiceTransportGrpc() = default; private: std::weak_ptr subscriber_; model::converters::PbTransactionFactory factory_; diff --git a/test/module/irohad/ordering/ordering_gate_service_test.cpp b/test/module/irohad/ordering/ordering_gate_service_test.cpp index 636e9491ea..0b9da7a6cb 100644 --- a/test/module/irohad/ordering/ordering_gate_service_test.cpp +++ b/test/module/irohad/ordering/ordering_gate_service_test.cpp @@ -18,10 +18,10 @@ #include "framework/test_subscriber.hpp" #include "module/irohad/ametsuchi/ametsuchi_mocks.hpp" -#include "ordering/impl/ordering_service_transport_grpc.hpp" #include "ordering/impl/ordering_gate_impl.hpp" #include "ordering/impl/ordering_gate_transport_grpc.hpp" #include "ordering/impl/ordering_service_impl.hpp" +#include "ordering/impl/ordering_service_transport_grpc.hpp" using namespace iroha::ordering; using namespace iroha::model; @@ -43,23 +43,21 @@ class OrderingGateServiceTest : public ::testing::Test { counter = 2; } - void SetUp() override { } + void SetUp() override {} - void start() { + void start() { std::mutex mtx; std::condition_variable cv; thread = std::thread([&cv, this] { grpc::ServerBuilder builder; int port = 0; - builder.AddListeningPort(address, grpc::InsecureServerCredentials(), - &port); + builder.AddListeningPort( + address, grpc::InsecureServerCredentials(), &port); builder.RegisterService(gate_transport.get()); builder.RegisterService(service_transport.get()); - - server = builder.BuildAndStart(); ASSERT_NE(port, 0); ASSERT_TRUE(server); @@ -69,10 +67,9 @@ class OrderingGateServiceTest : public ::testing::Test { std::unique_lock lock(mtx); cv.wait_for(lock, std::chrono::seconds(1)); - } - void TearDown() override { + void TearDown() override { proposals.clear(); server->Shutdown(); if (thread.joinable()) { @@ -81,8 +78,7 @@ class OrderingGateServiceTest : public ::testing::Test { } TestSubscriber init(size_t times) { - auto wrapper = - make_test_subscriber(gate->on_proposal(), times); + auto wrapper = make_test_subscriber(gate->on_proposal(), times); wrapper.subscribe([this](auto proposal) { proposals.push_back(proposal); }); gate->on_proposal().subscribe([this](auto) { counter--; @@ -99,7 +95,7 @@ class OrderingGateServiceTest : public ::testing::Test { std::this_thread::sleep_for(20ms); } - std::string address {"0.0.0.0:50051"}; + std::string address{"0.0.0.0:50051"}; std::shared_ptr gate; std::shared_ptr service; @@ -113,11 +109,8 @@ class OrderingGateServiceTest : public ::testing::Test { Peer peer; std::shared_ptr gate_transport; std::shared_ptr service_transport; - }; - - TEST_F(OrderingGateServiceTest, SplittingBunchTransactions) { // 8 transaction -> proposal -> 2 transaction -> proposal @@ -127,12 +120,10 @@ TEST_F(OrderingGateServiceTest, SplittingBunchTransactions) { const size_t max_proposal = 100; const size_t commit_delay = 400; - service = std::make_shared( wsv, max_proposal, commit_delay, service_transport); service_transport->subscribe(service); - start(); std::unique_lock lk(m); auto wrapper = init(2); @@ -146,7 +137,6 @@ TEST_F(OrderingGateServiceTest, SplittingBunchTransactions) { send_transaction(9); cv.wait_for(lk, 10s); - std::this_thread::sleep_for(1s); ASSERT_EQ(proposals.size(), 2); ASSERT_EQ(proposals.at(0).transactions.size(), 8); diff --git a/test/module/irohad/ordering/ordering_service_test.cpp b/test/module/irohad/ordering/ordering_service_test.cpp index 0097a0dcca..cb1e2876ce 100644 --- a/test/module/irohad/ordering/ordering_service_test.cpp +++ b/test/module/irohad/ordering/ordering_service_test.cpp @@ -16,7 +16,6 @@ */ #include -#include #include "logger/logger.hpp" #include "network/ordering_service.hpp"