Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Correct cpu_usage calculation when more than one signature - 1.7.x #7808

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions libraries/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,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;
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 @@ -131,7 +132,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() }


Expand Down
4 changes: 0 additions & 4 deletions unittests/misc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,6 @@ BOOST_AUTO_TEST_CASE(transaction_test) { try {
BOOST_CHECK(cpu_time1 > fc::microseconds(0));
BOOST_CHECK(cpu_time2 > fc::microseconds(0));

// verify that hitting cache still indicates same billable time
// if we remove cache so that the second is a real time calculation then remove this check
BOOST_CHECK(cpu_time1 == cpu_time2);

// pack
uint32_t pack_size = fc::raw::pack_size( pkt );
vector<char> buf(pack_size);
Expand Down