Skip to content

Commit

Permalink
Use calculation that avoids possible negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Aug 27, 2019
1 parent 007ef41 commit 92065bd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions libraries/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,19 @@ fc::microseconds transaction::get_signature_keys( const vector<signature_type>&

std::unique_lock<std::mutex> lock(cache_mtx, std::defer_lock);
fc::microseconds sig_cpu_usage;
const auto digest_time = fc::time_point::now() - start;
for(const signature_type& sig : signatures) {
auto now = fc::time_point::now();
EOS_ASSERT( now < deadline, tx_cpu_usage_exceeded, "transaction signature verification executed for too long",
("now", now)("deadline", deadline)("start", start) );
auto sig_start = fc::time_point::now();
EOS_ASSERT( sig_start < deadline, tx_cpu_usage_exceeded, "transaction signature verification executed for too long",
("now", sig_start)("deadline", deadline)("start", start) );
public_key_type recov;
const auto& tid = id();
lock.lock();
recovery_cache_type::index<by_sig>::type::iterator it = recovery_cache.get<by_sig>().find( sig );
if( it == recovery_cache.get<by_sig>().end() || it->trx_id != tid ) {
lock.unlock();
recov = public_key_type( sig, digest );
fc::microseconds cpu_usage = fc::time_point::now() - start - sig_cpu_usage;
fc::microseconds cpu_usage = fc::time_point::now() - sig_start;
lock.lock();
recovery_cache.emplace_back( cached_pub_key{tid, recov, sig, cpu_usage} ); //could fail on dup signatures; not a problem
sig_cpu_usage += cpu_usage;
Expand All @@ -141,7 +142,7 @@ fc::microseconds transaction::get_signature_keys( const vector<signature_type>&
recovery_cache.erase( recovery_cache.begin());
lock.unlock();

return sig_cpu_usage;
return sig_cpu_usage + digest_time;
} FC_CAPTURE_AND_RETHROW() }

vector<transaction_extensions> transaction::validate_and_extract_extensions()const {
Expand Down

0 comments on commit 92065bd

Please sign in to comment.