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

Implement non-copyable block #1542

Merged
merged 17 commits into from
Jul 13, 2018
Merged

Implement non-copyable block #1542

merged 17 commits into from
Jul 13, 2018

Conversation

nickaleks
Copy link
Contributor

@nickaleks nickaleks commented Jul 5, 2018

Description of the Change

This Pull Request refactors proto block to be non-copy constructible. Adds move semantics for the block.

Benefits

Block no longer can be copied. Additionally, moving a block is faster

Possible Drawbacks

Cannot copy blocks

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	irohad/ametsuchi/impl/temporary_wsv_impl.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
@l4l l4l added needs-review pr awaits review from maintainers refactoring internal stuff, that are changed/removed that doesn't affect client code labels Jul 6, 2018
This prevents initialization bug from old versions of gcc (pre 7.2)

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
It enforces no-copy for all derived classes

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
CMakeLists.txt Outdated
@@ -110,6 +110,8 @@ include_directories(

SET(IROHA_ROOT_PROJECT ON)

add_definitions(-DBOOST_NO_RTTI)
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls, add a comment with the purpose of usage of the flag.

return rxcpp::observable<>::create<PostgresBlockQuery::wBlock>(
[block{std::move(block)}](const auto &s) {
if (block) {
[i, this](const auto &s) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename i and s with some more meaningful names?

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 is just a counter so i think its fine. s will be renamed

@@ -1,4 +1,5 @@
add_library(shared_model_proto_backend
block.cpp
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, block.cpp should be moved to impl/ folder regards to the rest files in the target.

public:
using TransportType = Proto;

template <typename Transport>
Copy link
Contributor

Choose a reason for hiding this comment

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

Add use case of ctor. The documentation should contain information about copy/move semantic of ctor.

@@ -63,7 +66,7 @@ namespace shared_model {
if (boost::size(object_.signatures()) == 0) {
throw std::invalid_argument("Cannot get object without signatures");
}
return object_;
return std::move(object_);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about the safety of this method because its class may be in bindings. So, here we have to care about signAndAddSignature method and check that this method works correctly.

st.SetIterationTime(elapsed_seconds.count());
}

BENCHMARK_DEFINE_F(BlockBenchmark, TransportCopyTest)(benchmark::State &st) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add documentation about a semantic of the performance test. Also, this issue is related to tests below.

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
* NOTE: finish() moves internal object, so it is unsafe to call it more
* than once on the single instance.
* NOTE: finish() moves internal object, so calling methods after
* finish() throws an exception
*/
template <typename T>
class UnsignedWrapper {
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls, add move ctor for the class.

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
block.value()));
}
s.on_completed();
[i, this](const auto &block_observer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[](auto &&x) { return wBlock(clone(x)); })));
auto block = loader->retrieveBlock(peer_key, kPrevHash);
.WillOnce(Return(rxcpp::observable<>::just(wBlock(clone(present)))));
auto block = loader->retrieveBlock(peer_key, Hash(std::string(32, '0')));
Copy link
Contributor

Choose a reason for hiding this comment

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

32 looks like magic, so maybe use kPrevHash?

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>

# Conflicts:
#	test/benchmark/CMakeLists.txt
#	test/benchmark/bm_proto_creation.cpp
@sorabot
Copy link

sorabot commented Jul 13, 2018

SonarQube analysis reported 1 issue

  1. MINOR transport_builder_test.cpp#L159: The function 'createInvalidProposal' is never used. rule

@nickaleks nickaleks merged commit aca7f7f into develop Jul 13, 2018
@nickaleks nickaleks deleted the feature/noncopyable_block branch July 13, 2018 08:35
l4l pushed a commit that referenced this pull request Jul 25, 2018
Implement non-copyable block

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
Implement non-copyable block

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
Implement non-copyable block

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
Implement non-copyable block

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
Implement non-copyable block

Signed-off-by: Nikita Alekseev <n.alekseev2104@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-review pr awaits review from maintainers refactoring internal stuff, that are changed/removed that doesn't affect client code
Development

Successfully merging this pull request may close these issues.

None yet

5 participants