-
Notifications
You must be signed in to change notification settings - Fork 296
Conversation
cmake/functions.cmake
Outdated
@@ -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:") |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like misleading comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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_; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment, also, looks misleading
test/framework/mock_stream.h
Outdated
#ifndef GRPCPP_TEST_MOCK_STREAM_H | ||
#define GRPCPP_TEST_MOCK_STREAM_H | ||
|
||
#include <stdint.h> |
There was a problem hiding this comment.
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 stdint
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy of https://github.com/grpc/grpc/blob/34e8e0a6400d8b529125a3b83ec1facf71acf99b/include/grpcpp/test/mock_stream.h .
I think it is because of uint32_t
here: https://github.com/hyperledger/iroha/blob/83bf44f91448474207c9fc99a837fef83be44bc0/test/framework/mock_stream.h#L73
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
test/framework/mock_stream.h
Outdated
MOCK_METHOD0_T(WritesDone, bool()); | ||
}; | ||
|
||
/// TODO: We do not support mocking an async RPC for now. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why to move rvalue?
There was a problem hiding this comment.
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()))}; |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works only for shared pointers, while transaction
is a unique pointer.
https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast
https://github.com/hyperledger/iroha/blob/83bf44f91448474207c9fc99a837fef83be44bc0/irohad/ordering/on_demand_os_transport.hpp#L64-L73
06899b7
to
f3bf2c2
Compare
Signed-off-by: Andrei Lebedev <[email protected]> Refactor with new async call Signed-off-by: Andrei Lebedev <[email protected]>
f3bf2c2
to
0e639e6
Compare
* 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]>
* 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]>
* 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]>
Description of the Change
Add gRPC client and server for on demand ordering service
Note