Skip to content

Commit

Permalink
GH-985 Add ability to retroactively pause timer when resuming billing…
Browse files Browse the repository at this point in the history
… timer. Cleanup transaction_timer so that its deadline matches _deadline of transaction_context
  • Loading branch information
heifner committed Nov 11, 2024
1 parent 9a6c881 commit 01c0ebd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace eosio::chain {
}

void pause_billing_timer();
void resume_billing_timer();
void resume_billing_timer(fc::time_point resume_from = fc::time_point{});

uint32_t update_billed_cpu_time( fc::time_point now );

Expand Down
15 changes: 7 additions & 8 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,11 @@ namespace eosio::chain {
add_net_usage( initial_net_usage ); // Fail early if current net usage is already greater than the calculated limit

if(control.skip_trx_checks()) {
transaction_timer.start( fc::time_point::maximum() );
} else {
transaction_timer.start( _deadline );
checktime(); // Fail early if deadline has already been exceeded
_deadline = block_deadline;
}

transaction_timer.start( _deadline );
checktime(); // Fail early if deadline has already been exceeded
is_initialized = true;
}

Expand Down Expand Up @@ -494,16 +493,16 @@ namespace eosio::chain {
}

void transaction_context::pause_billing_timer() {
if( explicit_billed_cpu_time || pseudo_start == fc::time_point() ) return; // either irrelevant or already paused

paused_time = fc::time_point::now();
billed_time = paused_time - pseudo_start;
pseudo_start = fc::time_point();
transaction_timer.stop();
}

void transaction_context::resume_billing_timer() {
if( explicit_billed_cpu_time || pseudo_start != fc::time_point() ) return; // either irrelevant or already running
void transaction_context::resume_billing_timer(fc::time_point resume_from) {
if (resume_from != fc::time_point()) {
paused_time = resume_from;
}

auto now = fc::time_point::now();
auto paused = now - paused_time;
Expand Down

0 comments on commit 01c0ebd

Please sign in to comment.