diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 727a5d8add..0649557df9 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -289,12 +289,13 @@ struct assembled_block { struct building_block { // -------------------------------------------------------------------------------- struct building_block_common { - const vector new_protocol_feature_activations; - size_t num_new_protocol_features_that_have_activated = 0; - deque pending_trx_metas; - deque pending_trx_receipts; - std::variant trx_mroot_or_receipt_digests {digests_t{}}; - digests_t action_receipt_digests; + using checksum_or_digests = std::variant; + const vector new_protocol_feature_activations; + size_t num_new_protocol_features_that_have_activated = 0; + deque pending_trx_metas; + deque pending_trx_receipts; + checksum_or_digests trx_mroot_or_receipt_digests {digests_t{}}; + digests_t action_receipt_digests; building_block_common(const vector& new_protocol_feature_activations) : new_protocol_feature_activations(new_protocol_feature_activations) @@ -437,6 +438,23 @@ struct building_block { return std::visit([](const auto& bb) { return bb.get_block_num(); }, v); } + size_t& num_new_protocol_features_activated() { + return std::visit([](auto& bb) -> size_t& { return bb.num_new_protocol_features_that_have_activated; }, v); + } + + deque& pending_trx_metas() { + return std::visit([](auto& bb) -> deque& { return bb.pending_trx_metas; }, v); + } + + deque& pending_trx_receipts() { + return std::visit([](auto& bb) -> deque& { return bb.pending_trx_receipts; }, v); + } + + building_block_common::checksum_or_digests& trx_mroot_or_receipt_digests() { + return std::visit( + [](auto& bb) -> building_block_common::checksum_or_digests& { return bb.trx_mroot_or_receipt_digests; }, v); + } + digests_t& action_receipt_digests() { return std::visit([](auto& bb) -> digests_t& { return bb.action_receipt_digests; }, v); } @@ -1686,7 +1704,7 @@ struct controller_impl { trx_context.billed_cpu_time_us, trace->net_usage ); - fc::move_append( std::get(pending->_block_stage)._action_receipt_digests, + fc::move_append( std::get(pending->_block_stage).action_receipt_digests(), std::move(trx_context.executed_action_receipt_digests) ); trace->account_ram_delta = account_delta( gtrx.payer, trx_removal_ram_delta ); @@ -1810,15 +1828,16 @@ struct controller_impl { uint64_t cpu_usage_us, uint64_t net_usage ) { uint64_t net_usage_words = net_usage / 8; EOS_ASSERT( net_usage_words*8 == net_usage, transaction_exception, "net_usage is not divisible by 8" ); - auto& receipts = std::get(pending->_block_stage)._pending_trx_receipts; + auto& bb = std::get(pending->_block_stage); + auto& receipts = bb.pending_trx_receipts(); receipts.emplace_back( trx ); transaction_receipt& r = receipts.back(); r.cpu_usage_us = cpu_usage_us; r.net_usage_words = net_usage_words; r.status = status; - auto& bb = std::get(pending->_block_stage); - if( std::holds_alternative(bb._trx_mroot_or_receipt_digests) ) - std::get(bb._trx_mroot_or_receipt_digests).emplace_back( r.digest() ); + auto& mroot_or_digests = bb.trx_mroot_or_receipt_digests(); + if( std::holds_alternative(mroot_or_digests) ) + std::get(mroot_or_digests).emplace_back( r.digest() ); return r; } @@ -1900,13 +1919,14 @@ struct controller_impl { auto restore = make_block_restore_point( trx->is_read_only() ); + auto& bb = std::get(pending->_block_stage); trx->billed_cpu_time_us = trx_context.billed_cpu_time_us; if (!trx->implicit() && !trx->is_read_only()) { transaction_receipt::status_enum s = (trx_context.delay == fc::seconds(0)) ? transaction_receipt::executed : transaction_receipt::delayed; trace->receipt = push_receipt(*trx->packed_trx(), s, trx_context.billed_cpu_time_us, trace->net_usage); - std::get(pending->_block_stage)._pending_trx_metas.emplace_back(trx); + bb.pending_trx_metas().emplace_back(trx); } else { transaction_receipt_header r; r.status = transaction_receipt::executed; @@ -1916,7 +1936,7 @@ struct controller_impl { } if ( !trx->is_read_only() ) { - fc::move_append( std::get(pending->_block_stage)._action_receipt_digests, + fc::move_append( bb.action_receipt_digests(), std::move(trx_context.executed_action_receipt_digests) ); if ( !trx->is_dry_run() ) { // call the accept signal but only once for this transaction @@ -2070,7 +2090,7 @@ struct controller_impl { protocol_features.activate_feature( feature_digest, bb.block_num() ); - ++bb._num_new_protocol_features_that_have_activated; + ++bb.num_new_protocol_features_activated(); } if( num_preactivated_features_that_have_activated == num_preactivated_protocol_features ) { @@ -2094,7 +2114,7 @@ struct controller_impl { const auto& gpo = self.get_global_properties(); if (!hs_active) { - bb.apply_dpos([&](building_block_dpos &bb_dpos) { + bb.apply_dpos([&](building_block::building_block_dpos &bb_dpos) { pending_block_header_state& pbhs = bb_dpos._pending_block_header_state; if( gpo.proposed_schedule_block_num && // if there is a proposed schedule that was proposed in a block ... @@ -2106,13 +2126,13 @@ struct controller_impl { EOS_ASSERT( gpo.proposed_schedule.version == pbhs.active_schedule_version + 1, producer_schedule_exception, "wrong producer schedule version specified" ); - dpos_header._new_pending_producer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); + bb_dpos._new_pending_producer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); if( !replaying ) { ilog( "promoting proposed schedule (set in block ${proposed_num}) to pending; current block: ${n} lib: ${lib} schedule: ${schedule} ", ("proposed_num", *gpo.proposed_schedule_block_num)("n", pbhs.block_num) ("lib", hs_active ? hs_lib : pbhs.dpos_irreversible_blocknum) - ("schedule", dpos_header._new_pending_producer_schedule ) ); + ("schedule", bb_dpos._new_pending_producer_schedule ) ); } db.modify( gpo, [&]( auto& gp ) {