Skip to content

Commit

Permalink
GH-985 Reset transaction_context on oc interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Nov 12, 2024
1 parent 76e2cc7 commit d77773e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions libraries/chain/include/eosio/chain/transaction_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace eosio::chain {
std::optional<digests_t> digests_l; // legacy
std::optional<digests_t> digests_s; // savanna

action_digests_t(store_which_t sw) {
explicit action_digests_t(store_which_t sw) {
if (sw == store_which_t::legacy || sw == store_which_t::both)
digests_l = digests_t{};
if (sw == store_which_t::savanna || sw == store_which_t::both)
Expand Down Expand Up @@ -101,6 +101,7 @@ namespace eosio::chain {
class transaction_context {
private:
void initialize();
void reset();
void init( uint64_t initial_net_usage);

public:
Expand All @@ -114,7 +115,7 @@ namespace eosio::chain {
transaction_metadata::trx_type type = transaction_metadata::trx_type::input);
~transaction_context();

void init_for_implicit_trx( uint64_t initial_net_usage = 0 );
void init_for_implicit_trx();

void init_for_input_trx( uint64_t packed_trx_unprunable_size,
uint64_t packed_trx_prunable_size );
Expand Down
20 changes: 15 additions & 5 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,23 @@ namespace eosio::chain {
initialize();
}

void transaction_context::reset() {
undo();
*trace = transaction_trace{}; // reset trace
initialize();
resume_billing_timer(start);

auto sw = executed_action_receipts.store_which();
executed_action_receipts = action_digests_t{sw};
bill_to_accounts.clear();
validate_ram_usage.clear();
}

void transaction_context::initialize() {
if (!control.skip_db_sessions() && !is_read_only()) {
undo_session.emplace(control.mutable_db().start_undo_session(true));
}

*trace = transaction_trace{};
trace->id = id;
trace->block_num = control.head().block_num() + 1;
trace->block_time = control.pending_block_time();
Expand Down Expand Up @@ -245,15 +256,15 @@ namespace eosio::chain {
is_initialized = true;
}

void transaction_context::init_for_implicit_trx( uint64_t initial_net_usage )
void transaction_context::init_for_implicit_trx()
{
const transaction& trx = packed_trx.get_transaction();
if( trx.transaction_extensions.size() > 0 ) {
disallow_transaction_extensions( "no transaction extensions supported yet for implicit transactions" );
}

published = control.pending_block_time();
init( initial_net_usage);
init(0);
}

void transaction_context::init_for_input_trx( uint64_t packed_trx_unprunable_size,
Expand Down Expand Up @@ -355,8 +366,7 @@ namespace eosio::chain {
break;
} catch ( const fc::exception& e ) {
if (e.code() == interrupt_oc_exception::code_value) {
initialize(); // resets undo session
resume_billing_timer(start);
reset();
continue;
}
throw;
Expand Down

0 comments on commit d77773e

Please sign in to comment.