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

Block factory #1622

Merged
merged 16 commits into from
Aug 17, 2018
Merged

Block factory #1622

merged 16 commits into from
Aug 17, 2018

Conversation

nickaleks
Copy link
Contributor

Description of the Change

This pull request adds factory for a block. It allows to polymorphically construct blocks in irohad

Benefits

Less dependency on protobuf

Possible Drawbacks

More code

Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	shared_model/backend/protobuf/common_objects/proto_common_objects_factory.hpp
#	shared_model/interfaces/common_objects/common_objects_factory.hpp
#	test/module/shared_model/backend_proto/common_objects/proto_common_objects_factory_test.cpp
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	shared_model/backend/protobuf/common_objects/proto_common_objects_factory.hpp
#	shared_model/interfaces/common_objects/common_objects_factory.hpp
#	test/module/shared_model/backend_proto/common_objects/proto_common_objects_factory_test.cpp
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	shared_model/backend/protobuf/common_objects/proto_common_objects_factory.hpp
#	shared_model/interfaces/common_objects/common_objects_factory.hpp
#	test/module/shared_model/backend_proto/common_objects/proto_common_objects_factory_test.cpp
Previously crypto signer accepted block inside a simulator,
now it is block variant

Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	shared_model/backend/protobuf/common_objects/proto_common_objects_factory.hpp
#	shared_model/interfaces/common_objects/common_objects_factory.hpp
#	test/module/shared_model/backend_proto/common_objects/proto_common_objects_factory_test.cpp
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	shared_model/backend/protobuf/common_objects/proto_common_objects_factory.hpp
#	shared_model/interfaces/common_objects/common_objects_factory.hpp
#	test/module/shared_model/backend_proto/common_objects/proto_common_objects_factory_test.cpp
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
reason, model.signatures(), model.payload());
if (not reason.second.empty()) {
answer.addReason(std::move(reason));
}
return answer;
}

private:
FieldValidator field_validator_;
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the reason to introduce 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 if we pass any_block_validator as a ModelValidator, it does not have field_validator inside, so using ModelValidator::field_validator fails to compile.

@@ -19,6 +19,7 @@ target_link_libraries(block_loader
rxcpp
shared_model_interfaces
shared_model_proto_backend
shared_model_stateless_validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, but is it really necessary?

* If @param block_variant contains block, return it.
* If empty block return error
*/
iroha::expected::Result<std::shared_ptr<Block>, std::string> getNonEmptyBlock(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function needed? As I see, later you unpack nonempty block with it and then immediately write a visitor again, but to unpack a result created by yourself. Maybe, it's better to match the block emptiness directly in the code, so you wouldn't have two visitors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure what do you mean by this comment. Block Factory returns result, and I would need to add visit_in_place inside match in order to retrieve block. Since the empty block is an error case in block loader, it is logical to apply this sort of transformation

: validator_(std::move(statefulValidator)),
ametsuchi_factory_(std::move(factory)),
block_queries_(std::move(blockQuery)),
crypto_signer_(std::move(crypto_signer)) {
crypto_signer_(std::move(crypto_signer)),
block_factory_(std::move(block_factory)) {
log_ = logger::log("Simulator");
Copy link
Contributor

Choose a reason for hiding this comment

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

To ctor initialisation, please


if (not txs.empty()) {
std::for_each(
std::begin(txs), std::end(txs), [&block_payload](const auto &tx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Capturing block_payload, which is a pointer, by reference? Is it good?

#define IROHA_PROTO_BLOCK_FACTORY_HPP

#include "backend/protobuf/block.hpp"
#include "backend/protobuf/empty_block.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, this include can be moved to cpp file

@@ -183,7 +185,7 @@ namespace shared_model {
// gap for future transactions
time_t future_gap_;
// time provider callback
TimeFunction time_provider_;
mutable TimeFunction time_provider_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not removing mutable here and const from setTime(...)?

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 validaton methods are const, and they use setTime

@@ -29,19 +29,22 @@ namespace shared_model {
public:
explicit SignableModelValidator(
FieldValidator &&validator = FieldValidator())
: ModelValidator(std::move(validator)) {}
: ModelValidator(validator), field_validator_(validator) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there sense to move it, when you pass it second time?


using testing::A;
using testing::Return;

using wPeer = std::shared_ptr<shared_model::interface::Peer>;
using wBlock = std::shared_ptr<shared_model::interface::Block>;

using namespace shared_model::validation;
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant, the same using in 40 line

@@ -76,14 +85,18 @@ class BlockLoaderTest : public testing::Test {
}

auto getBaseBlockBuilder() const {
iroha::protocol::Transaction proto_tx;
shared_model::proto::Transaction tx(proto_tx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just shared_model::proto::Transaction tx{iroha::protocol::Transaction{}}?

@@ -74,6 +75,13 @@ namespace shared_model {
crypto_signer_expecter->sign(signable);
}

template <>
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't second template a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, because it is a template function of a template class

Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Copy link
Contributor

@Akvinikym Akvinikym left a comment

Choose a reason for hiding this comment

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

Also please pay attention PR is not built

@@ -7,6 +7,7 @@
#include "ametsuchi/impl/postgres_ordering_service_persistent_state.hpp"
#include "ametsuchi/impl/wsv_restorer_impl.hpp"
#include "backend/protobuf/common_objects/proto_common_objects_factory.hpp"
#include "backend/protobuf/proto_proposal_factory.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it used in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, check line 154

shared_model::interface::Block>> &result) {
subscriber.on_next(std::move(result.value));
},
[this, &context](iroha::expected::Error<std::string> &error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

const iroha::expected::Error<std::string> &error?

return result.match(
[](iroha::expected::Value<std::shared_ptr<shared_model::interface::Block>>
&v) { return boost::make_optional(std::move(v.value)); },
[this](iroha::expected::Error<std::string> &e)
Copy link
Contributor

Choose a reason for hiding this comment

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

const?


/**
* Create block variant with nonempty block
* @return Error if block is empty, or if it is invalid
Copy link
Contributor

Choose a reason for hiding this comment

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

Clear, but as I understand, we document every parameter and return values

* Create block
* @param txs - if it is empty, create EmptyBlock,
* else create regular block
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Some parameters are not described

@@ -76,14 +83,18 @@ class BlockLoaderTest : public testing::Test {
}

auto getBaseBlockBuilder() const {
// iroha::protocol::Transaction proto_tx;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

@@ -23,39 +23,46 @@
#include "builders/protobuf/transport_builder.hpp"
#include "interfaces/common_objects/peer.hpp"
#include "network/impl/grpc_channel_builder.hpp"
#include "validators/default_validator.hpp"

using namespace iroha::ametsuchi;
using namespace iroha::network;
using namespace shared_model::crypto;
using namespace shared_model::interface;
namespace val = shared_model::validation;
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not used anymore

.createdTime(proposal.createdTime())
.build());
auto height = block_queries_->getTopBlockHeight() + 1;
auto block = block_factory_->unsafeCreateBlock(height,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would height be the same as previously in case of an empty block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, since it used proposal height, which is the same as the (last block height + 1)

crypto_signer);

Simulator(const Simulator &) = delete;
Simulator &operator=(const Simulator &) = delete;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have you removed it? Does C++ delete these methods by default if there is a custom constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are automatically deleted now that one of the members of simulator is unique_ptr, since it is not copyable.

@@ -231,6 +247,8 @@ TEST_F(BlockLoaderTest, ValidWhenBlockMissing) {
auto present =
getBaseBlockBuilder().build().signAndAddSignature(key).finish();

auto variant = shared_model::interface::BlockVariant(wBlock(clone(present)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems that it is not used

Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
Signed-off-by: Nikita Alekseev <[email protected]>

# Conflicts:
#	irohad/ordering/impl/ordering_gate_transport_grpc.hpp
#	irohad/ordering/impl/ordering_service_impl.cpp
#	test/module/irohad/validation/CMakeLists.txt
Merge pull request #3 from laSinteZ/patch-1

fix: const "size" not matching size of message
Signed-off-by: Nikita Alekseev <[email protected]>
@nickaleks nickaleks merged commit 32a558f into develop Aug 17, 2018
@nickaleks nickaleks deleted the feature/block_factory branch August 17, 2018 07:36
bakhtin pushed a commit that referenced this pull request Nov 2, 2018
Add factory for blocks in shared model

This allows for polymorphic construction of blocks.

Signed-off-by: Nikita Alekseev <[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