From 4bc5eaab968533cc5c9a71968a9cee3aed629cde Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Mon, 6 May 2024 16:08:45 -0400 Subject: [PATCH] Don't change `produce_block()`. Add `produce_block_ex()`. --- .../testing/include/eosio/testing/tester.hpp | 31 ++++++++++------ libraries/testing/tester.cpp | 2 +- .../test/test_account_query_db.cpp | 12 +++---- tests/test_snapshot_information.cpp | 4 +-- unittests/api_tests.cpp | 36 +++++++++---------- unittests/block_tests.cpp | 20 +++++------ unittests/chain_tests.cpp | 2 +- unittests/finality_test_cluster.hpp | 2 +- unittests/forked_tests.cpp | 28 +++++++-------- unittests/partitioned_block_log_tests.cpp | 2 +- unittests/producer_schedule_if_tests.cpp | 24 ++++++------- unittests/producer_schedule_tests.cpp | 2 +- unittests/protocol_feature_tests.cpp | 20 +++++------ unittests/restart_chain_tests.cpp | 24 +++++++------ unittests/snapshot_tests.cpp | 20 ++++++----- unittests/state_history_tests.cpp | 2 +- unittests/test_cfd_transaction.cpp | 4 +-- 17 files changed, 127 insertions(+), 108 deletions(-) diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index 0ccc7a46d4..474c88c807 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -162,6 +162,7 @@ namespace eosio::testing { static const uint32_t DEFAULT_BILLED_CPU_TIME_US = 2000; static const fc::microseconds abi_serializer_max_time; + static constexpr fc::microseconds default_skip_time = fc::milliseconds(config::block_interval_ms); virtual ~base_tester() { lib_connection.disconnect(); @@ -186,9 +187,11 @@ namespace eosio::testing { void open( std::optional expected_chain_id = {} ); bool is_same_chain( base_tester& other ); - virtual produce_block_result_t produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false) = 0; - virtual signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) = 0; - virtual signed_block_ptr finish_block() = 0; + virtual produce_block_result_t produce_block_ex( fc::microseconds skip_time = default_skip_time, bool no_throw = false) = 0; + virtual signed_block_ptr produce_block( fc::microseconds skip_time = default_skip_time, bool no_throw = false) = 0; + virtual signed_block_ptr produce_empty_block( fc::microseconds skip_time = default_skip_time ) = 0; + virtual signed_block_ptr finish_block() = 0; + // produce one block and return traces for all applied transactions, both failed and executed signed_block_ptr produce_blocks( uint32_t n = 1, bool empty = false ); void produce_blocks_until_end_of_round(); @@ -576,11 +579,15 @@ namespace eosio::testing { using base_tester::produce_block; - produce_block_result_t produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false )override { + produce_block_result_t produce_block_ex( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override { return _produce_block(skip_time, false, no_throw); } - signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override { + signed_block_ptr produce_block( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override { + return _produce_block(skip_time, false, no_throw).block; + } + + signed_block_ptr produce_empty_block( fc::microseconds skip_time = default_skip_time ) override { unapplied_transactions.add_aborted( control->abort_block() ); return _produce_block(skip_time, true); } @@ -671,14 +678,18 @@ namespace eosio::testing { } } - produce_block_result_t produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false )override { + produce_block_result_t produce_block_ex( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override { auto produce_block_result = _produce_block(skip_time, false, no_throw); validate_push_block(produce_block_result.block); return produce_block_result; } - produce_block_result_t produce_block_no_validation( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) { - return _produce_block(skip_time, false, false); + signed_block_ptr produce_block( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override { + return produce_block_ex(skip_time, no_throw).block; + } + + signed_block_ptr produce_block_no_validation( fc::microseconds skip_time = default_skip_time ) { + return _produce_block(skip_time, false, false).block; } void validate_push_block(const signed_block_ptr& sb) { @@ -688,7 +699,7 @@ namespace eosio::testing { _wait_for_vote_if_needed(*validating_node); } - signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override { + signed_block_ptr produce_empty_block( fc::microseconds skip_time = default_skip_time )override { unapplied_transactions.add_aborted( control->abort_block() ); auto sb = _produce_block(skip_time, true); validate_push_block(sb); @@ -785,7 +796,7 @@ namespace eosio::testing { // ----------------------------------------------------------- finalizer_policy transition_to_Savanna(const std::function& block_callback = {}) { auto produce_block = [&]() { - auto b = t.produce_block().block; + auto b = t.produce_block(); if (block_callback) block_callback(b); return b; diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index b90ec47a0b..86899beb42 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -524,7 +524,7 @@ namespace eosio::testing { res = produce_empty_block(); } else { for( uint32_t i = 0; i < n; ++i ) - res = produce_block().block; + res = produce_block(); } return res; } diff --git a/plugins/chain_plugin/test/test_account_query_db.cpp b/plugins/chain_plugin/test/test_account_query_db.cpp index eeca55d6fe..4bda8dfc5d 100644 --- a/plugins/chain_plugin/test/test_account_query_db.cpp +++ b/plugins/chain_plugin/test/test_account_query_db.cpp @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(future_fork_test) { try { // create 10 blocks synced for (int i = 0; i < 10; i++) { - node_b.push_block(node_a.produce_block().block); + node_b.push_block(node_a.produce_block()); } // produce a block on node A with a new account and permission @@ -182,8 +182,8 @@ BOOST_AUTO_TEST_CASE(future_fork_test) { try { BOOST_TEST_REQUIRE(find_account_auth(pre_results, tester_account, "role"_n) == true); // have node B take over from head-1 and produce "future" blocks to overtake - node_a.push_block(node_b.produce_block(fc::milliseconds(config::block_interval_ms * 100)).block); - node_a.push_block(node_b.produce_block().block); + node_a.push_block(node_b.produce_block(fc::milliseconds(config::block_interval_ms * 100))); + node_a.push_block(node_b.produce_block()); // ensure the account was forked away const auto post_results = aq_db.get_accounts_by_authorizers(pars); @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(fork_test) { try { // create 10 blocks synced for (int i = 0; i < 10; i++) { - node_b.push_block(node_a.produce_block().block); + node_b.push_block(node_a.produce_block()); } // produce a block on node A with a new account and permission @@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(fork_test) { try { aq_db.cache_transaction_trace(trace_ptr4); // push b's onto a - node_a.push_block(node_b.produce_block().block); + node_a.push_block(node_b.produce_block()); const auto trace_ptr5 = node_b.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object() ("account", tester_account) @@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(fork_test) { try { ); aq_db.cache_transaction_trace(trace_ptr6); - node_a.push_block(node_b.produce_block().block); + node_a.push_block(node_b.produce_block()); // ensure the account was forked away const auto post_results = aq_db.get_accounts_by_authorizers(pars); diff --git a/tests/test_snapshot_information.cpp b/tests/test_snapshot_information.cpp index e51fc5cb2e..49aa25c431 100644 --- a/tests/test_snapshot_information.cpp +++ b/tests/test_snapshot_information.cpp @@ -30,12 +30,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_snapshot_information, SNAPSHOT_SUITE, snapsho chain.set_abi("snapshot"_n, test_contracts::snapshot_test_abi()); chain.produce_blocks(1); - auto block = chain.produce_block().block; + auto block = chain.produce_block(); BOOST_REQUIRE_EQUAL(block->block_num(), 6u); // ensure that test setup stays consistent with original snapshot setup // undo the auto-pending from tester chain.control->abort_block(); - auto block2 = chain.produce_block().block; + auto block2 = chain.produce_block(); BOOST_REQUIRE_EQUAL(block2->block_num(), 7u); // ensure that test setup stays consistent with original snapshot setup // undo the auto-pending from tester chain.control->abort_block(); diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index a4a3f8817c..5d2f4083be 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -225,7 +225,7 @@ std::pair _CallFunction(Tester& test, T if (!no_throw) { BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); } - auto block = test.produce_block().block; + auto block = test.produce_block(); return { res, block }; } } @@ -844,13 +844,13 @@ BOOST_AUTO_TEST_CASE(light_validation_skip_cfa) try { tester chain(setup_policy::full); std::vector blocks; - blocks.push_back(chain.produce_block().block); + blocks.push_back(chain.produce_block()); chain.create_account( "testapi"_n ); chain.create_account( "dummy"_n ); - blocks.push_back(chain.produce_block().block); + blocks.push_back(chain.produce_block()); chain.set_code( "testapi"_n, test_contracts::test_api_wasm() ); - blocks.push_back(chain.produce_block().block); + blocks.push_back(chain.produce_block()); cf_action cfa; signed_transaction trx; @@ -866,7 +866,7 @@ BOOST_AUTO_TEST_CASE(light_validation_skip_cfa) try { // run normal passing case auto sigs = trx.sign(chain.get_private_key("testapi"_n, "active"), chain.control->get_chain_id()); auto trace = chain.push_transaction(trx); - blocks.push_back(chain.produce_block().block); + blocks.push_back(chain.produce_block()); BOOST_REQUIRE(trace->receipt); BOOST_CHECK_EQUAL(trace->receipt->status, transaction_receipt::executed); @@ -1593,21 +1593,21 @@ BOOST_AUTO_TEST_CASE(inline_action_with_over_4k_limit) { try { tester chain2(setup_policy::full, db_read_mode::HEAD, {_4k + 100}); signed_block_ptr block; for (int n=0; n < 2; ++n) { - block = chain.produce_block().block; + block = chain.produce_block(); chain2.push_block(block); } chain.create_account( "testapi"_n ); for (int n=0; n < 2; ++n) { - block = chain.produce_block().block; + block = chain.produce_block(); chain2.push_block(block); } chain.set_code( "testapi"_n, test_contracts::test_api_wasm() ); - block = chain.produce_block().block; + block = chain.produce_block(); chain2.push_block(block); block = CALL_TEST_FUNCTION_WITH_BLOCK(chain, "test_transaction", "send_action_4k", {}).second; chain2.push_block(block); - block = chain.produce_block().block; + block = chain.produce_block(); chain2.push_block(block); } FC_LOG_AND_RETHROW() } @@ -1643,13 +1643,13 @@ BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try { tester chain2(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100}); signed_block_ptr block; for (int n=0; n < 2; ++n) { - block = chain.produce_block().block; + block = chain.produce_block(); chain2.push_block(block); } chain.create_accounts( {"testapi"_n, "testapi2"_n, "alice"_n} ); chain.set_code( "testapi"_n, test_contracts::test_api_wasm() ); chain.set_code( "testapi2"_n, test_contracts::test_api_wasm() ); - block = chain.produce_block().block; + block = chain.produce_block(); chain2.push_block(block); transaction_trace_ptr trace; @@ -1660,7 +1660,7 @@ BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try { block = CALL_TEST_FUNCTION_WITH_BLOCK(chain, "test_transaction", "send_deferred_transaction_4k_action", {} ).second; chain2.push_block(block); BOOST_CHECK(!trace); - block = chain.produce_block( fc::seconds(2) ).block; + block = chain.produce_block( fc::seconds(2) ); chain2.push_block(block); //check that it gets executed afterwards @@ -1672,7 +1672,7 @@ BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try { c.disconnect(); for (int n=0; n < 10; ++n) { - block = chain.produce_block().block; + block = chain.produce_block(); chain2.push_block(block); } @@ -3872,7 +3872,7 @@ BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try { fin_keys.set_finalizer_policy(0); // this block contains the header extension for the instant finality, savanna activated when it is LIB - auto block = t.produce_block().block; + auto block = t.produce_block(); std::optional ext = block->extract_header_extension(instant_finality_extension::extension_id()); BOOST_TEST(!!ext); @@ -3899,7 +3899,7 @@ BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try { auto lib_after_transition = t.lib_block->block_num(); // block after IF Critical Block is IF Proper Block - block = t.produce_block().block; + block = t.produce_block(); // lib must advance after 3 blocks t.produce_blocks(3); @@ -3920,7 +3920,7 @@ void test_finality_transition(const vector& accounts, // activate savanna t.set_finalizers(input); // this block contains the header extension for the instant finality, savanna activated when it is LIB - auto block = t.produce_block().block; + auto block = t.produce_block(); std::optional ext = block->extract_header_extension(instant_finality_extension::extension_id()); BOOST_TEST(!!ext); @@ -3932,7 +3932,7 @@ void test_finality_transition(const vector& accounts, block_num_type active_block_num = block->block_num(); while (active_block_num > t.lib_block->block_num()) { - block = t.produce_block().block; + block = t.produce_block(); } // lib_block is IF Genesis Block // block is IF Critical Block @@ -3945,7 +3945,7 @@ void test_finality_transition(const vector& accounts, auto lib_after_transition = t.lib_block->block_num(); // block after IF Critical Block is IF Proper Block - block = t.produce_block().block; + block = t.produce_block(); t.produce_blocks(4); if( lib_advancing_expected ) { diff --git a/unittests/block_tests.cpp b/unittests/block_tests.cpp index 005c2fec3f..aa9733a15c 100644 --- a/unittests/block_tests.cpp +++ b/unittests/block_tests.cpp @@ -13,7 +13,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_test) // First we create a valid block with valid transaction main.create_account("newacc"_n); - auto b = main.produce_block().block; + auto b = main.produce_block(); // Make a copy of the valid block and corrupt the transaction auto copy_b = std::make_shared(std::move(*b)); @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_mroot_test) // First we create a valid block with valid transaction main.create_account("newacc"_n); - auto b = main.produce_block().block; + auto b = main.produce_block(); // Make a copy of the valid block and corrupt the transaction auto copy_b = std::make_shared(std::move(*b)); @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_mroot_test) std::pair corrupt_trx_in_block(validating_tester& main, account_name act_name) { // First we create a valid block with valid transaction main.create_account(act_name); - signed_block_ptr b = main.produce_block_no_validation().block; + signed_block_ptr b = main.produce_block_no_validation(); // Make a copy of the valid block and corrupt the transaction auto copy_b = std::make_shared(b->clone()); @@ -137,13 +137,13 @@ BOOST_AUTO_TEST_CASE(trusted_producer_test) std::set producers = { "defproducera"_n, "defproducerb"_n, "defproducerc"_n, "defproducerd"_n }; for (auto prod : producers) main.create_account(prod); - auto b = main.produce_block().block; + auto b = main.produce_block(); std::vector schedule(producers.cbegin(), producers.cend()); auto trace = main.set_producers(schedule); while (b->producer != "defproducera"_n) { - b = main.produce_block().block; + b = main.produce_block(); } auto blocks = corrupt_trx_in_block(main, "tstproducera"_n); @@ -163,13 +163,13 @@ BOOST_AUTO_TEST_CASE(trusted_producer_verify_2nd_test) std::set producers = { "defproducera"_n, "defproducerb"_n, "defproducerc"_n, "defproducerd"_n }; for (auto prod : producers) main.create_account(prod); - auto b = main.produce_block().block; + auto b = main.produce_block(); std::vector schedule(producers.cbegin(), producers.cend()); auto trace = main.set_producers(schedule); while (b->producer != "defproducerc"_n) { - b = main.produce_block().block; + b = main.produce_block(); } auto blocks = corrupt_trx_in_block(main, "tstproducera"_n); @@ -189,13 +189,13 @@ BOOST_AUTO_TEST_CASE(untrusted_producer_test) std::set producers = { "defproducera"_n, "defproducerb"_n, "defproducerc"_n, "defproducerd"_n }; for (auto prod : producers) main.create_account(prod); - auto b = main.produce_block().block; + auto b = main.produce_block(); std::vector schedule(producers.cbegin(), producers.cend()); auto trace = main.set_producers(schedule); while (b->producer != "defproducerb"_n) { - b = main.produce_block().block; + b = main.produce_block(); } auto blocks = corrupt_trx_in_block(main, "tstproducera"_n); @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(broadcasted_block_test) bcasted_blk_by_recv_node = block; }); - auto b = producer_node.produce_block().block; + auto b = producer_node.produce_block(); receiving_node.push_block(b); bytes bcasted_blk_by_prod_node_packed = fc::raw::pack(*bcasted_blk_by_prod_node); diff --git a/unittests/chain_tests.cpp b/unittests/chain_tests.cpp index 22e86a9516..dc6a63914c 100644 --- a/unittests/chain_tests.cpp +++ b/unittests/chain_tests.cpp @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE( signal_validated_blocks ) try { validator.push_block(accepted_block); chain.create_account("hello"_n); - auto produced_block = chain.produce_block().block; + auto produced_block = chain.produce_block(); validator.push_block(accepted_block); BOOST_CHECK(produced_block->calculate_id() == accepted_id); BOOST_CHECK(accepted_id == validated_id); diff --git a/unittests/finality_test_cluster.hpp b/unittests/finality_test_cluster.hpp index 81bc4a6372..d0bcd0c737 100644 --- a/unittests/finality_test_cluster.hpp +++ b/unittests/finality_test_cluster.hpp @@ -174,7 +174,7 @@ class finality_test_cluster { // node0 produces a block and pushes it to node1 and node2 signed_block_ptr produce_and_push_block() { - auto b = node0.produce_block().block; + auto b = node0.produce_block(); for (size_t i=1; iproducer.to_string(), "b" ); for (size_t j = 0; j < 7; j ++) { @@ -171,11 +171,11 @@ BOOST_AUTO_TEST_CASE( forking ) try { wlog( "c1 blocks:" ); c.produce_blocks(3); - signed_block_ptr b = c.produce_block().block; + signed_block_ptr b = c.produce_block(); account_name expected_producer = "dan"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); - b = c.produce_block().block; + b = c.produce_block(); expected_producer = "sam"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); c.produce_blocks(10); @@ -197,14 +197,14 @@ BOOST_AUTO_TEST_CASE( forking ) try { wlog( "c2 blocks:" ); c2.produce_blocks(12); // pam produces 12 blocks - b = c2.produce_block( fc::milliseconds(config::block_interval_ms * 13) ).block; // sam skips over dan's blocks + b = c2.produce_block( fc::milliseconds(config::block_interval_ms * 13) ); // sam skips over dan's blocks expected_producer = "sam"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); c2.produce_blocks(11 + 12); wlog( "c1 blocks:" ); - b = c.produce_block( fc::milliseconds(config::block_interval_ms * 13) ).block; // dan skips over pam's blocks + b = c.produce_block( fc::milliseconds(config::block_interval_ms * 13) ); // dan skips over pam's blocks expected_producer = "dan"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); c.produce_blocks(11); @@ -221,11 +221,11 @@ BOOST_AUTO_TEST_CASE( forking ) try { wlog( "c1 blocks:" ); c.produce_blocks(24); - b = c.produce_block().block; // Switching active schedule to version 2 happens in this block. + b = c.produce_block(); // Switching active schedule to version 2 happens in this block. expected_producer = "pam"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); - b = c.produce_block().block; + b = c.produce_block(); expected_producer = "cam"_n; // BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); c.produce_blocks(10); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE( forking ) try { wlog( "now cam and dan rejoin sam and pam on c2" ); c2.produce_block( fc::milliseconds(config::block_interval_ms * 13) ); // cam skips over pam's blocks (this block triggers a block on this branch to become irreversible) c2.produce_blocks(11); // cam produces the remaining 11 blocks - b = c2.produce_block().block; // dan produces a block + b = c2.produce_block(); // dan produces a block // a node on chain 1 now gets all but the last block from chain 2 which should cause a fork switch wlog( "push c2 blocks (except for the last block by dan) to c1" ); @@ -586,11 +586,11 @@ BOOST_AUTO_TEST_CASE( push_block_returns_forked_transactions ) try { signed_block_ptr cb; c.produce_blocks(3); signed_block_ptr b; - cb = b = c.produce_block().block; + cb = b = c.produce_block(); account_name expected_producer = "dan"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); - b = c.produce_block().block; + b = c.produce_block(); expected_producer = "sam"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); c.produce_blocks(10); @@ -613,18 +613,18 @@ BOOST_AUTO_TEST_CASE( push_block_returns_forked_transactions ) try { signed_block_ptr c2b; wlog( "c2 blocks:" ); c2.produce_blocks(12); // pam produces 12 blocks - b = c2b = c2.produce_block( fc::milliseconds(config::block_interval_ms * 13) ).block; // sam skips over dan's blocks + b = c2b = c2.produce_block( fc::milliseconds(config::block_interval_ms * 13) ); // sam skips over dan's blocks expected_producer = "sam"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); // save blocks for verification of forking later std::vector c2blocks; for( size_t i = 0; i < 11 + 12; ++i ) { - c2blocks.emplace_back( c2.produce_block().block ); + c2blocks.emplace_back( c2.produce_block() ); } wlog( "c1 blocks:" ); - b = c.produce_block( fc::milliseconds(config::block_interval_ms * 13) ).block; // dan skips over pam's blocks + b = c.produce_block( fc::milliseconds(config::block_interval_ms * 13) ); // dan skips over pam's blocks expected_producer = "dan"_n; BOOST_REQUIRE_EQUAL( b->producer.to_string(), expected_producer.to_string() ); // create accounts on c1 which will be forked out @@ -750,7 +750,7 @@ BOOST_AUTO_TEST_CASE( push_block_returns_forked_transactions ) try { }) ; // produce block which will apply the unapplied transactions - produce_block_result_t produce_block_result = c.produce_block(fc::milliseconds(config::block_interval_ms), true); + produce_block_result_t produce_block_result = c.produce_block_ex(fc::milliseconds(config::block_interval_ms), true); std::vector& traces = produce_block_result.traces; BOOST_REQUIRE_EQUAL( 4u, traces.size() ); diff --git a/unittests/partitioned_block_log_tests.cpp b/unittests/partitioned_block_log_tests.cpp index fb1e3d740a..3d091ca3b8 100644 --- a/unittests/partitioned_block_log_tests.cpp +++ b/unittests/partitioned_block_log_tests.cpp @@ -44,7 +44,7 @@ struct restart_from_block_log_test_fixture { chain.produce_blocks(1); chain.create_account("replay3"_n); chain.produce_blocks(1); - auto cutoff_block = chain.produce_block().block; + auto cutoff_block = chain.produce_block(); cutoff_block_num = cutoff_block->block_num(); chain.produce_blocks(10); diff --git a/unittests/producer_schedule_if_tests.cpp b/unittests/producer_schedule_if_tests.cpp index 543b7a503a..6f83e19992 100644 --- a/unittests/producer_schedule_if_tests.cpp +++ b/unittests/producer_schedule_if_tests.cpp @@ -33,7 +33,7 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activat BOOST_TEST(control->head_block_num() == expected_block_num); } - auto b = produce_block().block; + auto b = produce_block(); BOOST_TEST( b->confirmed == 0); // must be 0 after instant finality is enabled // Check if the producer is the same as what we expect @@ -58,7 +58,7 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activat // enable instant_finality set_finalizers(producers); - auto setfin_block = produce_block().block; // this block contains the header extension of the finalizer set + auto setfin_block = produce_block(); // this block contains the header extension of the finalizer set for (block_num_type active_block_num = setfin_block->block_num(); active_block_num > lib_block->block_num(); produce_block()) { set_producers({"initc"_n, "inite"_n}); // should be ignored since in transition @@ -179,8 +179,8 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t BOOST_CHECK_EQUAL( true, compare_schedules( bob_alice_sch, control->active_producers() ) ); // get to next producer round - auto prod = produce_block().block->producer; - for (auto b = produce_block().block; b->producer == prod; b = produce_block().block); + auto prod = produce_block()->producer; + for (auto b = produce_block(); b->producer == prod; b = produce_block()); // test no change to active schedule set_producers( {"bob"_n,"alice"_n} ); // same as before, so no change @@ -203,8 +203,8 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t BOOST_CHECK_EQUAL( true, compare_schedules( bob_carol_sch, control->active_producers() ) ); // get to next producer round - prod = produce_block().block->producer; - for (auto b = produce_block().block; b->producer == prod; b = produce_block().block); + prod = produce_block()->producer; + for (auto b = produce_block(); b->producer == prod; b = produce_block()); // test change in same block where there is an existing proposed that is the same set_producers( {"bob"_n,"alice"_n} ); @@ -225,8 +225,8 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t BOOST_CHECK_EQUAL( true, compare_schedules( bob_carol_sch, control->active_producers() ) ); // get to next producer round - prod = produce_block().block->producer; - for (auto b = produce_block().block; b->producer == prod; b = produce_block().block); + prod = produce_block()->producer; + for (auto b = produce_block(); b->producer == prod; b = produce_block()); // test two in-flight // round A [1,2,..12], next_round B [1,2,..12], next_next_round C [1,2,..12], D [1,2,..12] @@ -249,8 +249,8 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t BOOST_CHECK_EQUAL( true, compare_schedules( bob_alice_sch, control->active_producers() ) ); // get to next producer round - prod = produce_block().block->producer; - for (auto b = produce_block().block; b->producer == prod; b = produce_block().block); + prod = produce_block()->producer; + for (auto b = produce_block(); b->producer == prod; b = produce_block()); // test two in-flight, P1 == P3, so no change // round A [1,2,..12], next_round B [1,2,..12], next_next_round C [1,2,..12], D [1,2,..12] @@ -273,8 +273,8 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t BOOST_CHECK_EQUAL( true, compare_schedules( bob_carol_sch, control->active_producers() ) ); // get to next producer round - prod = produce_block().block->producer; - for (auto b = produce_block().block; b->producer == prod; b = produce_block().block); + prod = produce_block()->producer; + for (auto b = produce_block(); b->producer == prod; b = produce_block()); // test two in-flight, ultimately no change produce_block(); // 1 diff --git a/unittests/producer_schedule_tests.cpp b/unittests/producer_schedule_tests.cpp index 06d790e5b3..ad894303b1 100644 --- a/unittests/producer_schedule_tests.cpp +++ b/unittests/producer_schedule_tests.cpp @@ -638,7 +638,7 @@ BOOST_AUTO_TEST_CASE( extra_signatures_test ) try { remote.block_signing_private_keys.emplace(get_public_key("alice"_n, "bs2"), get_private_key("alice"_n, "bs2")); // Generate the block that will be corrupted. - auto valid_block = remote.produce_block().block; + auto valid_block = remote.produce_block(); BOOST_REQUIRE( valid_block->producer == "alice"_n ); diff --git a/unittests/protocol_feature_tests.cpp b/unittests/protocol_feature_tests.cpp index dd222aa0a1..3342019a8c 100644 --- a/unittests/protocol_feature_tests.cpp +++ b/unittests/protocol_feature_tests.cpp @@ -1100,7 +1100,7 @@ BOOST_AUTO_TEST_CASE( protocol_activatation_works_after_transition_to_savanna ) // activate savanna c.set_finalizers(policy_input); - auto block = c.produce_block().block; // this block contains the header extension for the instant finality + auto block = c.produce_block(); // this block contains the header extension for the instant finality std::optional ext = block->extract_header_extension(instant_finality_extension::extension_id()); BOOST_TEST(!!ext); @@ -1108,7 +1108,7 @@ BOOST_AUTO_TEST_CASE( protocol_activatation_works_after_transition_to_savanna ) BOOST_TEST(!!fin_policy); BOOST_TEST(fin_policy->finalizers.size() == accounts.size()); - block = c.produce_block().block; // savanna now active + block = c.produce_block(); // savanna now active auto fb = c.control->fetch_block_by_id(block->calculate_id()); BOOST_REQUIRE(!!fb); BOOST_TEST(fb == block); @@ -1676,9 +1676,9 @@ BOOST_AUTO_TEST_CASE( producer_schedule_change_extension_test ) { try { // will bear an extension making header-only validators aware of it, and therefore block N + 2 is the first block // where a block may bear a downstream extension. c.preactivate_protocol_features( {*d} ); - remote.push_block(c.produce_block().block); + remote.push_block(c.produce_block()); - auto last_legacy_block = c.produce_block().block; + auto last_legacy_block = c.produce_block(); { // ensure producer_schedule_change_extension is rejected @@ -1722,7 +1722,7 @@ BOOST_AUTO_TEST_CASE( producer_schedule_change_extension_test ) { try { remote.push_block(last_legacy_block); // propagate header awareness of the activation. - auto first_new_block = c.produce_block().block; + auto first_new_block = c.produce_block(); { // create a bad block that has the producer schedule change extension that is valid but not warranted by actions in the block @@ -1763,7 +1763,7 @@ BOOST_AUTO_TEST_CASE( producer_schedule_change_extension_test ) { try { } remote.push_block(first_new_block); - remote.push_block(c.produce_block().block); + remote.push_block(c.produce_block()); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_legacy_test ) { try { @@ -1782,7 +1782,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_legacy_test ) { try { c.produce_block(); // ensure the last legacy block contains a new_producers - auto last_legacy_block = c.produce_block().block; + auto last_legacy_block = c.produce_block(); BOOST_REQUIRE_EQUAL(last_legacy_block->new_producers.has_value(), true); // promote to active schedule @@ -1816,7 +1816,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_extension_test ) { try { c.produce_block(); // ensure the first possible new block contains a producer_schedule_change_extension - auto first_new_block = c.produce_block().block; + auto first_new_block = c.produce_block(); BOOST_REQUIRE_EQUAL(first_new_block->new_producers.has_value(), false); BOOST_REQUIRE_EQUAL(first_new_block->header_extensions.size(), 1u); BOOST_REQUIRE_EQUAL(first_new_block->header_extensions.at(0).first, producer_schedule_change_extension::extension_id()); @@ -2283,7 +2283,7 @@ BOOST_AUTO_TEST_CASE( block_validation_before_stage_1_test ) { try { // Produce a block containing a delayed trx constexpr uint32_t delay_sec = 10; tester1.push_action("payloadless"_n, "doit"_n, "payloadless"_n, mutable_variant_object(), tester1.DEFAULT_EXPIRATION_DELTA, delay_sec); - auto b = tester1.produce_block().block; + auto b = tester1.produce_block(); // Push the block to another chain. The block should be validated BOOST_REQUIRE_NO_THROW(tester2.push_block(b)); @@ -2304,7 +2304,7 @@ BOOST_AUTO_TEST_CASE( block_validation_after_stage_1_test ) { try { // Create a block with valid transaction tester1.create_account("newacc"_n); - auto b = tester1.produce_block().block; + auto b = tester1.produce_block(); // Make a copy of the block auto copy_b = std::make_shared(std::move(*b)); diff --git a/unittests/restart_chain_tests.cpp b/unittests/restart_chain_tests.cpp index d10394369d..99b10d4f1c 100644 --- a/unittests/restart_chain_tests.cpp +++ b/unittests/restart_chain_tests.cpp @@ -66,10 +66,14 @@ class replay_tester : public base_tester { } using base_tester::produce_block; - produce_block_result_t produce_block(fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false) override { + produce_block_result_t produce_block_ex(fc::microseconds skip_time = default_skip_time, bool no_throw = false) override { return _produce_block(skip_time, false, no_throw); } + signed_block_ptr produce_block(fc::microseconds skip_time = default_skip_time, bool no_throw = false) override { + return produce_block_ex(skip_time, no_throw).block; + } + signed_block_ptr produce_empty_block(fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms)) override { unapplied_transactions.add_aborted(control->abort_block()); @@ -87,9 +91,9 @@ BOOST_AUTO_TEST_CASE(test_existing_state_without_block_log) { tester chain; std::vector blocks; - blocks.push_back(chain.produce_block().block); - blocks.push_back(chain.produce_block().block); - blocks.push_back(chain.produce_block().block); + blocks.push_back(chain.produce_block()); + blocks.push_back(chain.produce_block()); + blocks.push_back(chain.produce_block()); tester other; for (const auto& new_block : blocks) { @@ -103,9 +107,9 @@ BOOST_AUTO_TEST_CASE(test_existing_state_without_block_log) { // restarting chain with no block log and no genesis other.open(); - blocks.push_back(chain.produce_block().block); - blocks.push_back(chain.produce_block().block); - blocks.push_back(chain.produce_block().block); + blocks.push_back(chain.produce_block()); + blocks.push_back(chain.produce_block()); + blocks.push_back(chain.produce_block()); chain.control->abort_block(); for (const auto& new_block : blocks) { @@ -117,9 +121,9 @@ BOOST_AUTO_TEST_CASE(test_restart_with_different_chain_id) { tester chain; std::vector blocks; - blocks.push_back(chain.produce_block().block); - blocks.push_back(chain.produce_block().block); - blocks.push_back(chain.produce_block().block); + blocks.push_back(chain.produce_block()); + blocks.push_back(chain.produce_block()); + blocks.push_back(chain.produce_block()); tester other; for (const auto& new_block : blocks) { diff --git a/unittests/snapshot_tests.cpp b/unittests/snapshot_tests.cpp index cb59d6ba20..101dadad4a 100644 --- a/unittests/snapshot_tests.cpp +++ b/unittests/snapshot_tests.cpp @@ -64,10 +64,14 @@ class snapshotted_tester : public base_tester { init(copied_config, snapshot); } - produce_block_result_t produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false )override { + produce_block_result_t produce_block_ex( fc::microseconds skip_time = default_skip_time, bool no_throw = false )override { return _produce_block(skip_time, false, no_throw); } + signed_block_ptr produce_block( fc::microseconds skip_time = default_skip_time, bool no_throw = false )override { + return produce_block_ex(skip_time, no_throw).block; + } + signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override { control->abort_block(); return _produce_block(skip_time, true); @@ -233,7 +237,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_exhaustive_snapshot, SNAPSHOT_SUITE, snapshot ); // produce block - auto new_block = chain.produce_block().block; + auto new_block = chain.produce_block(); // undo the auto-pending from tester chain.control->abort_block(); @@ -293,7 +297,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_replay_over_snapshot, SNAPSHOT_SUITE, snapsho ); // produce & push block - snap_chain.push_block(chain.produce_block().block); + snap_chain.push_block(chain.produce_block()); } // verify the hash at the end @@ -312,7 +316,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_replay_over_snapshot, SNAPSHOT_SUITE, snapsho } verify_integrity_hash(*chain.control, *replay_chain.control); - auto block = chain.produce_block().block; + auto block = chain.produce_block(); chain.control->abort_block(); snap_chain.push_block(block); replay_chain.push_block(block); @@ -554,7 +558,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_restart_with_existing_state_and_truncated_blo snapshotted_tester snap_chain(chain.get_config(), SNAPSHOT_SUITE::get_reader(snapshot), ordinal++); verify_integrity_hash(*chain.control, *snap_chain.control); - auto block = chain.produce_block().block; + auto block = chain.produce_block(); chain.control->abort_block(); snap_chain.push_block(block); verify_integrity_hash(*chain.control, *snap_chain.control); @@ -565,7 +569,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_restart_with_existing_state_and_truncated_blo snap_chain.open(); verify_integrity_hash(*chain.control, *snap_chain.control); - block = chain.produce_block().block; + block = chain.produce_block(); chain.control->abort_block(); snap_chain.push_block(block); verify_integrity_hash(*chain.control, *snap_chain.control); @@ -583,7 +587,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_restart_with_existing_state_and_truncated_blo chain_cfg.blog = eosio::chain::empty_blocklog_config{}; // use empty block log snapshotted_tester snap_chain(chain_cfg, SNAPSHOT_SUITE::get_reader(snapshot), ordinal++); verify_integrity_hash(*chain.control, *snap_chain.control); - auto block = chain.produce_block().block; + auto block = chain.produce_block(); chain.control->abort_block(); snap_chain.push_block(block); verify_integrity_hash(*chain.control, *snap_chain.control); @@ -594,7 +598,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_restart_with_existing_state_and_truncated_blo snap_chain.open(); verify_integrity_hash(*chain.control, *snap_chain.control); - block = chain.produce_block().block; + block = chain.produce_block(); chain.control->abort_block(); snap_chain.push_block(block); verify_integrity_hash(*chain.control, *snap_chain.control); diff --git a/unittests/state_history_tests.cpp b/unittests/state_history_tests.cpp index 92d3f900c1..cac7d5e9e2 100644 --- a/unittests/state_history_tests.cpp +++ b/unittests/state_history_tests.cpp @@ -788,7 +788,7 @@ bool test_fork(uint32_t stride, uint32_t max_retained_files) { auto create_account_traces = chain2.create_accounts( {"adam"_n} ); auto create_account_trace_id = create_account_traces[0]->id; - auto b = chain2.produce_block().block; + auto b = chain2.produce_block(); chain2.produce_blocks(11+12); for( uint32_t start = fork_block_num + 1, end = chain2.control->head_block_num(); start <= end; ++start ) { diff --git a/unittests/test_cfd_transaction.cpp b/unittests/test_cfd_transaction.cpp index f067247d1e..611c999336 100644 --- a/unittests/test_cfd_transaction.cpp +++ b/unittests/test_cfd_transaction.cpp @@ -7,9 +7,9 @@ std::vector deploy_test_api(eosio::testing::test std::vector result; chain.create_account("testapi"_n); chain.create_account("dummy"_n); - result.push_back(chain.produce_block().block); + result.push_back(chain.produce_block()); chain.set_code("testapi"_n, eosio::testing::test_contracts::test_api_wasm()); - result.push_back(chain.produce_block().block); + result.push_back(chain.produce_block()); return result; }