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 #7809

Merged
merged 3 commits into from
Aug 28, 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 @@ -105,18 +105,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 ${time}us",
("time", now - start)("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 ${time}us",
("time", sig_start - start)("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 @@ -137,7 +138,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() }

flat_multimap<uint16_t, transaction_extension> transaction::validate_and_extract_extensions()const {
Expand Down
4 changes: 0 additions & 4 deletions unittests/misc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this check had to go because the digest_time was not exactly equivalent and we were already verifying that cpu_time2 was >0?

Is there any value in maintaining the invariant that cache hits/misses bill exactly the same amount?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any value in maintaining it.

// 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