Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Dec 14, 2023
1 parent bf4cd36 commit 5d9b62c
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,13 @@ struct assembled_block {
struct building_block {
// --------------------------------------------------------------------------------
struct building_block_common {
const vector<digest_type> new_protocol_feature_activations;
size_t num_new_protocol_features_that_have_activated = 0;
deque<transaction_metadata_ptr> pending_trx_metas;
deque<transaction_receipt> pending_trx_receipts;
std::variant<checksum256_type, digests_t> trx_mroot_or_receipt_digests {digests_t{}};
digests_t action_receipt_digests;
using checksum_or_digests = std::variant<checksum256_type, digests_t>;
const vector<digest_type> new_protocol_feature_activations;
size_t num_new_protocol_features_that_have_activated = 0;
deque<transaction_metadata_ptr> pending_trx_metas;
deque<transaction_receipt> pending_trx_receipts;
checksum_or_digests trx_mroot_or_receipt_digests {digests_t{}};
digests_t action_receipt_digests;

building_block_common(const vector<digest_type>& new_protocol_feature_activations) :
new_protocol_feature_activations(new_protocol_feature_activations)
Expand Down Expand Up @@ -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<transaction_metadata_ptr>& pending_trx_metas() {
return std::visit([](auto& bb) -> deque<transaction_metadata_ptr>& { return bb.pending_trx_metas; }, v);
}

deque<transaction_receipt>& pending_trx_receipts() {
return std::visit([](auto& bb) -> deque<transaction_receipt>& { 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);
}
Expand Down Expand Up @@ -1686,7 +1704,7 @@ struct controller_impl {
trx_context.billed_cpu_time_us,
trace->net_usage );

fc::move_append( std::get<building_block>(pending->_block_stage)._action_receipt_digests,
fc::move_append( std::get<building_block>(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 );
Expand Down Expand Up @@ -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<building_block>(pending->_block_stage)._pending_trx_receipts;
auto& bb = std::get<building_block>(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<building_block>(pending->_block_stage);
if( std::holds_alternative<digests_t>(bb._trx_mroot_or_receipt_digests) )
std::get<digests_t>(bb._trx_mroot_or_receipt_digests).emplace_back( r.digest() );
auto& mroot_or_digests = bb.trx_mroot_or_receipt_digests();
if( std::holds_alternative<digests_t>(mroot_or_digests) )
std::get<digests_t>(mroot_or_digests).emplace_back( r.digest() );
return r;
}

Expand Down Expand Up @@ -1900,13 +1919,14 @@ struct controller_impl {

auto restore = make_block_restore_point( trx->is_read_only() );

auto& bb = std::get<building_block>(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<building_block>(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;
Expand All @@ -1916,7 +1936,7 @@ struct controller_impl {
}

if ( !trx->is_read_only() ) {
fc::move_append( std::get<building_block>(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
Expand Down Expand Up @@ -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 ) {
Expand All @@ -2094,7 +2114,7 @@ struct controller_impl {
const auto& gpo = self.get_global_properties();

if (!hs_active) {
bb.apply_dpos<void>([&](building_block_dpos &bb_dpos) {
bb.apply_dpos<void>([&](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 ...
Expand All @@ -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 ) {
Expand Down

0 comments on commit 5d9b62c

Please sign in to comment.