Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

On demand OS transport #1635

Merged
merged 1 commit into from
Aug 18, 2018
Merged

On demand OS transport #1635

merged 1 commit into from
Aug 18, 2018

Conversation

lebdron
Copy link
Contributor

@lebdron lebdron commented Aug 8, 2018

Description of the Change

Add gRPC client and server for on demand ordering service

  • Add gRPC mock class generation
  • Unit tests for both client and server! No need to run real server with threads for unit tests
  • Reuse server notification interface in client - each peer is represented with corresponding notification interface

Note

  • Factory is not covered with unit tests due to necessary hardcoded creation of real network channel. It will be covered by integration tests in next pull requests
  • mock_stream.h is copied from gRPC repo with an addition of mock method, because it is not provided after installation

@@ -82,10 +82,13 @@ endfunction()
function(compile_proto_only_grpc_to_cpp PROTO)
string(REGEX REPLACE "\\.proto$" ".grpc.pb.h" GEN_GRPC_PB_HEADER ${PROTO})
string(REGEX REPLACE "\\.proto$" ".grpc.pb.cc" GEN_GRPC_PB ${PROTO})
if(TESTING)
set(GENERATE_MOCKS "generate_mock_code=true:")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't clear that this line is related to grpc mocks, maybe add a comment about it?

#include "backend/protobuf/proposal.hpp"
#include "network/impl/grpc_channel_builder.hpp"

using namespace iroha::ordering::transport;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like good policy: use only one namespace in the cpp file which is provided by the header file.

This is ofc not an issue to your PR but a topic for a discussion.

std::function<OnDemandOsClientGrpc::TimepointType()> time_provider,
OnDemandOsClientGrpc::TimeoutType timeout);

std::unique_ptr<OdOsNotification> create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit unobvious why we use factory here? Why are we required to use both: ctor and factory? I suggest putting the answer to the comment here.

std::shared_ptr<OdOsNotification> ordering_service)
: ordering_service_(ordering_service) {}

// proto::OnDemandOrdering::Service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like misleading comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Methods below are implementation of proto::OnDemandOrdering::Service interface, so this line shows that property. Similar approach is used in client: https://github.com/hyperledger/iroha/blob/83bf44f91448474207c9fc99a837fef83be44bc0/irohad/ordering/impl/on_demand_os_client_grpc.hpp#L33-L38

Copy link
Contributor

@muratovv muratovv Aug 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe write it more explicitly. Such as

// ----| proto::OnDemandOrdering::Service |-----

fitted for the line?

const proto::TransactionsCollection *request,
::google::protobuf::Empty *response) {
OdOsNotification::CollectionType transactions;
for (const auto &i : request->transactions()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename i with tx or something simular.


private:
std::function<OnDemandOsClientGrpc::TimepointType()> time_provider_;
std::chrono::milliseconds timeout_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add semantic for the variable, in comments or in the name.

explicit OnDemandOsServerGrpc(
std::shared_ptr<OdOsNotification> ordering_service);

// proto::OnDemandOrdering::Service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment, also, looks misleading

#ifndef GRPCPP_TEST_MOCK_STREAM_H
#define GRPCPP_TEST_MOCK_STREAM_H

#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to use stdinthere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why we can't remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because uint32_t is defined in stdint.h

MOCK_METHOD0_T(WritesDone, bool());
};

/// TODO: We do not support mocking an async RPC for now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a task for that. Also, what is the reason for that?

Copy link
Contributor Author

@lebdron lebdron Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mock_stream.h is copied from gRPC repo with an addition of mock method, because it is not provided after installation

I did not want to make any modifications to this file. Do you suggest removing the todo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, yes. I think this todo will mislead readers of the file.

void OnDemandOsClientGrpc::onTransactions(CollectionType &&transactions) {
proto::TransactionsCollection message;
for (auto &transaction : transactions) {
*message.add_transactions() = std::move(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why to move rvalue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The moment when rvalue gets a name (transactions in this case), it becomes an lvalue. So it has to be called with std::move to become an rvalue again.

return boost::none;
}
return ProposalType{std::make_unique<shared_model::proto::Proposal>(
std::move(response.proposal()))};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, I think move on function call is redundant

proto::TransactionsCollection message;
for (auto &transaction : transactions) {
*message.add_transactions() = std::move(
static_cast<shared_model::proto::Transaction *>(transaction.get())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use std::static_pointer_cast instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lebdron lebdron changed the base branch from trunk/bft_os to trunk/bft-os August 16, 2018 13:16
Signed-off-by: Andrei Lebedev <[email protected]>

Refactor with new async call

Signed-off-by: Andrei Lebedev <[email protected]>
@lebdron lebdron merged commit 7ab8e34 into trunk/bft-os Aug 18, 2018
@lebdron lebdron deleted the feature/bft-os-transport branch August 19, 2018 13:44
lebdron added a commit that referenced this pull request Sep 4, 2018
* BFT OS trunk

* On demand OS transport (#1635)

* On demand OS connection manager (#1645)

* On-demand ordering gate and related fixes (#1675)

Signed-off-by: Andrei Lebedev <[email protected]>
nickaleks pushed a commit that referenced this pull request Sep 10, 2018
* BFT OS trunk

* On demand OS transport (#1635)

* On demand OS connection manager (#1645)

* On-demand ordering gate and related fixes (#1675)

Signed-off-by: Andrei Lebedev <[email protected]>
bakhtin pushed a commit that referenced this pull request Nov 2, 2018
* BFT OS trunk

* On demand OS transport (#1635)

* On demand OS connection manager (#1645)

* On-demand ordering gate and related fixes (#1675)

Signed-off-by: Andrei Lebedev <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants