Skip to content

Commit

Permalink
Merge pull request #738 from AntelopeIO/GH-737-move-block
Browse files Browse the repository at this point in the history
[1.0.1] Should never move from a signed_block in a shared_ptr
  • Loading branch information
heifner authored Sep 11, 2024
2 parents 7d6fd0d + f2f83e3 commit bb12b12
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions unittests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( block_with_invalid_tx_test, T, testers )
auto b = main.produce_block();

// Make a copy of the valid block and corrupt the transaction
auto copy_b = std::make_shared<signed_block>(std::move(*b));
auto copy_b = std::make_shared<signed_block>(b->clone());
auto signed_tx = std::get<packed_transaction>(copy_b->transactions.back().trx).get_signed_transaction();
auto& act = signed_tx.actions.back();
auto act_data = act.template data_as<newaccount>();
Expand Down Expand Up @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( block_with_invalid_tx_mroot_test, T, testers )
auto b = main.produce_block();

// Make a copy of the valid block and corrupt the transaction
auto copy_b = std::make_shared<signed_block>(std::move(*b));
auto copy_b = std::make_shared<signed_block>(b->clone());
const auto& packed_trx = std::get<packed_transaction>(copy_b->transactions.back().trx);
auto signed_tx = packed_trx.get_signed_transaction();

Expand Down
4 changes: 2 additions & 2 deletions unittests/forked_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ BOOST_AUTO_TEST_CASE( forking ) try {
}
wlog( "end push c2 blocks to c1" );
wlog( "now push dan's block to c1 but first corrupt it so it is a bad block" );
signed_block bad_block = std::move(*b);
signed_block bad_block{b->clone()};
bad_block.action_mroot = bad_block.previous;
auto bad_id = bad_block.calculate_id();
auto bad_block_btf = c.control->create_block_handle_future( bad_id, std::make_shared<signed_block>(std::move(bad_block)) );
auto bad_block_btf = c.control->create_block_handle_future( bad_id, std::make_shared<signed_block>(bad_block.clone()) );
c.control->abort_block();
controller::block_report br;
BOOST_REQUIRE_EXCEPTION(c.control->push_block( br, bad_block_btf.get(), {}, trx_meta_cache_lookup{} ), fc::exception,
Expand Down
2 changes: 1 addition & 1 deletion unittests/protocol_feature_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ BOOST_AUTO_TEST_CASE( block_validation_after_stage_1_test ) { try {
auto b = tester1.produce_block();

// Make a copy of the block
auto copy_b = std::make_shared<signed_block>(std::move(*b));
auto copy_b = std::make_shared<signed_block>(b->clone());
// Retrieve the last transaction
auto signed_tx = std::get<packed_transaction>(copy_b->transactions.back().trx).get_signed_transaction();
// Make a delayed transaction by forcing delay_sec greater than 0
Expand Down

0 comments on commit bb12b12

Please sign in to comment.