From d77773e90fcec35e122d1730dfd602331751f49f Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 12 Nov 2024 11:00:01 -0600 Subject: [PATCH] GH-985 Reset transaction_context on oc interrupt --- .../eosio/chain/transaction_context.hpp | 5 +++-- libraries/chain/transaction_context.cpp | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/libraries/chain/include/eosio/chain/transaction_context.hpp b/libraries/chain/include/eosio/chain/transaction_context.hpp index 37e9b6de30..a661feec15 100644 --- a/libraries/chain/include/eosio/chain/transaction_context.hpp +++ b/libraries/chain/include/eosio/chain/transaction_context.hpp @@ -38,7 +38,7 @@ namespace eosio::chain { std::optional digests_l; // legacy std::optional 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) @@ -101,6 +101,7 @@ namespace eosio::chain { class transaction_context { private: void initialize(); + void reset(); void init( uint64_t initial_net_usage); public: @@ -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 ); diff --git a/libraries/chain/transaction_context.cpp b/libraries/chain/transaction_context.cpp index b78c12bdba..56422864ae 100644 --- a/libraries/chain/transaction_context.cpp +++ b/libraries/chain/transaction_context.cpp @@ -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(); @@ -245,7 +256,7 @@ 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 ) { @@ -253,7 +264,7 @@ namespace eosio::chain { } published = control.pending_block_time(); - init( initial_net_usage); + init(0); } void transaction_context::init_for_input_trx( uint64_t packed_trx_unprunable_size, @@ -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;