Skip to content

Commit

Permalink
Merge pull request #562 from AntelopeIO/GH-329-subjective-deadline
Browse files Browse the repository at this point in the history
Include subjective cpu limit in trx deadline
  • Loading branch information
heifner authored Dec 19, 2022
2 parents 22daed5 + 304948a commit 167bcf7
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,29 @@ namespace eosio { namespace chain {
billing_timer_exception_code = deadline_exception::code_value;
}

// Explicit billed_cpu_time_us should be used, block_deadline will be maximum unless in test code
if( explicit_billed_cpu_time ) {
_deadline = block_deadline;
deadline_exception_code = deadline_exception::code_value;
} else {
deadline_exception_code = billing_timer_exception_code;
}

if( !explicit_billed_cpu_time ) {
// Fail early if amount of the previous speculative execution is within 10% of remaining account cpu available
int64_t validate_account_cpu_limit = account_cpu_limit - subjective_cpu_bill_us + leeway.count(); // Add leeway to allow powerup
// Possibly limit deadline to account subjective cpu left
if( subjective_cpu_bill_us > 0 && (start + fc::microseconds(validate_account_cpu_limit) < _deadline) ) {
_deadline = start + fc::microseconds(validate_account_cpu_limit);
billing_timer_exception_code = tx_cpu_usage_exceeded::code_value;
}

// Fail early if amount of the previous speculative execution is within 10% of remaining account cpu available
if( validate_account_cpu_limit > 0 )
validate_account_cpu_limit -= EOS_PERCENT( validate_account_cpu_limit, 10 * config::percent_1 );
if( validate_account_cpu_limit < 0 ) validate_account_cpu_limit = 0;
validate_account_cpu_usage_estimate( billed_cpu_time_us, validate_account_cpu_limit, subjective_cpu_bill_us );
}

// Explicit billed_cpu_time_us should be used, block_deadline will be maximum unless in test code
if( explicit_billed_cpu_time ) {
_deadline = block_deadline;
deadline_exception_code = deadline_exception::code_value;
} else {
deadline_exception_code = billing_timer_exception_code;
}

eager_net_limit = (eager_net_limit/8)*8; // Round down to nearest multiple of word size (8 bytes) so check_net_usage can be efficient

if( initial_net_usage > 0 )
Expand Down

0 comments on commit 167bcf7

Please sign in to comment.