aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/cryptonote_core.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-03-05 14:09:19 +0200
committerRiccardo Spagni <ric@spagni.net>2019-03-05 14:09:19 +0200
commited6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77 (patch)
treeb5cb515fa3db4dea131a3e1a3162ce3ee820b946 /src/cryptonote_core/cryptonote_core.cpp
parent39d7d3113bfe3655e721fa08b132d3b7fbcfb9b3 (diff)
parentc4851024ced48988c9a61db2a89b0cfd0c56915a (diff)
downloadmonzero-core-ed6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77.tar.gz
monzero-core-ed6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77.tar.xz
monzero-core-ed6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77.zip
Merge pull request #5100
c4851024 wallet_rpc_server: avoid repeated string allocations when parsing (moneromooo-monero) 88c85c18 cryptonote: avoid double parsing blocks when syncing (moneromooo-monero) 9feda0ee cryptonote: speed up calculating coinbase tx prunable hash (moneromooo-monero) 238401d4 core: avoid double parsing blocks after hoh (moneromooo-monero) dc5a7609 blockchain: avoid unneeded block copy (moneromooo-monero) 79b4e9f3 save some database calls when getting top block hash and height (moneromooo-monero) 98278808 blockchain: avoid pointless transaction copy and temporary (moneromooo-monero) 07d655e4 blockchain: avoid duplicate block hash computation (moneromooo-monero) f75d51ab core: avoid calculating tx prefix hash when we don't need it (moneromooo-monero) b044d03a Avoid repeated (de)serialization when syncing (moneromooo-monero) b747e836 wallet2: don't calculate prefix hash when we don't need it (moneromooo-monero) e69477bf db: speedup block addition (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core/cryptonote_core.cpp')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp62
1 files changed, 37 insertions, 25 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 599f42774..6639db620 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -724,7 +724,7 @@ namespace cryptonote
return false;
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_incoming_tx_pre(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefixt_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::handle_incoming_tx_pre(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
{
tvc = boost::value_initialized<tx_verification_context>();
@@ -737,9 +737,8 @@ namespace cryptonote
}
tx_hash = crypto::null_hash;
- tx_prefixt_hash = crypto::null_hash;
- if(!parse_tx_from_blob(tx, tx_hash, tx_prefixt_hash, tx_blob))
+ if(!parse_tx_from_blob(tx, tx_hash, tx_blob))
{
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to parse, rejected");
tvc.m_verifivation_failed = true;
@@ -772,7 +771,7 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_incoming_tx_post(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefixt_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::handle_incoming_tx_post(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
{
if(!check_tx_syntax(tx))
{
@@ -906,7 +905,7 @@ namespace cryptonote
TRY_ENTRY();
CRITICAL_REGION_LOCAL(m_incoming_tx_lock);
- struct result { bool res; cryptonote::transaction tx; crypto::hash hash; crypto::hash prefix_hash; };
+ struct result { bool res; cryptonote::transaction tx; crypto::hash hash; };
std::vector<result> results(tx_blobs.size());
tvc.resize(tx_blobs.size());
@@ -917,7 +916,7 @@ namespace cryptonote
tpool.submit(&waiter, [&, i, it] {
try
{
- results[i].res = handle_incoming_tx_pre(*it, tvc[i], results[i].tx, results[i].hash, results[i].prefix_hash, keeped_by_block, relayed, do_not_relay);
+ results[i].res = handle_incoming_tx_pre(*it, tvc[i], results[i].tx, results[i].hash, keeped_by_block, relayed, do_not_relay);
}
catch (const std::exception &e)
{
@@ -947,7 +946,7 @@ namespace cryptonote
tpool.submit(&waiter, [&, i, it] {
try
{
- results[i].res = handle_incoming_tx_post(*it, tvc[i], results[i].tx, results[i].hash, results[i].prefix_hash, keeped_by_block, relayed, do_not_relay);
+ results[i].res = handle_incoming_tx_post(*it, tvc[i], results[i].tx, results[i].hash, keeped_by_block, relayed, do_not_relay);
}
catch (const std::exception &e)
{
@@ -983,7 +982,7 @@ namespace cryptonote
continue;
const size_t weight = get_transaction_weight(results[i].tx, it->size());
- ok &= add_new_tx(results[i].tx, results[i].hash, tx_blobs[i], results[i].prefix_hash, weight, tvc[i], keeped_by_block, relayed, do_not_relay);
+ ok &= add_new_tx(results[i].tx, results[i].hash, tx_blobs[i], weight, tvc[i], keeped_by_block, relayed, do_not_relay);
if(tvc[i].m_verifivation_failed)
{MERROR_VER("Transaction verification failed: " << results[i].hash);}
else if(tvc[i].m_verifivation_impossible)
@@ -1197,11 +1196,10 @@ namespace cryptonote
bool core::add_new_tx(transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
crypto::hash tx_hash = get_transaction_hash(tx);
- crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx);
blobdata bl;
t_serializable_object_to_blob(tx, bl);
size_t tx_weight = get_transaction_weight(tx, bl.size());
- return add_new_tx(tx, tx_hash, bl, tx_prefix_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
+ return add_new_tx(tx, tx_hash, bl, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
}
//-----------------------------------------------------------------------------------------------
size_t core::get_blockchain_total_transactions() const
@@ -1209,7 +1207,7 @@ namespace cryptonote
return m_blockchain_storage.get_total_transactions();
}
//-----------------------------------------------------------------------------------------------
- bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
if(m_mempool.have_tx(tx_hash))
{
@@ -1250,8 +1248,8 @@ namespace cryptonote
{
std::vector<std::pair<crypto::hash, cryptonote::blobdata>> txs;
cryptonote::transaction tx;
- crypto::hash tx_hash, tx_prefix_hash;
- if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash))
+ crypto::hash tx_hash;
+ if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash))
{
LOG_ERROR("Failed to parse relayed transaction");
return;
@@ -1332,7 +1330,13 @@ namespace cryptonote
m_miner.resume();
return false;
}
- prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ MERROR("Block found, but failed to prepare to add");
+ m_miner.resume();
+ return false;
+ }
m_blockchain_storage.add_new_block(b, bvc);
cleanup_handle_incoming_blocks(true);
//anyway - update miner template
@@ -1383,10 +1387,14 @@ namespace cryptonote
}
//-----------------------------------------------------------------------------------------------
- bool core::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks)
+ bool core::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks)
{
m_incoming_tx_lock.lock();
- m_blockchain_storage.prepare_handle_incoming_blocks(blocks);
+ if (!m_blockchain_storage.prepare_handle_incoming_blocks(blocks_entry, blocks))
+ {
+ cleanup_handle_incoming_blocks(false);
+ return false;
+ }
return true;
}
@@ -1403,7 +1411,7 @@ namespace cryptonote
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_incoming_block(const blobdata& block_blob, block_verification_context& bvc, bool update_miner_blocktemplate)
+ bool core::handle_incoming_block(const blobdata& block_blob, const block *b, block_verification_context& bvc, bool update_miner_blocktemplate)
{
TRY_ENTRY();
@@ -1419,14 +1427,18 @@ namespace cryptonote
return false;
}
- block b = AUTO_VAL_INIT(b);
- if(!parse_and_validate_block_from_blob(block_blob, b))
+ block lb;
+ if (!b)
{
- LOG_PRINT_L1("Failed to parse and validate new block");
- bvc.m_verifivation_failed = true;
- return false;
+ if(!parse_and_validate_block_from_blob(block_blob, lb))
+ {
+ LOG_PRINT_L1("Failed to parse and validate new block");
+ bvc.m_verifivation_failed = true;
+ return false;
+ }
+ b = &lb;
}
- add_new_block(b, bvc);
+ add_new_block(*b, bvc);
if(update_miner_blocktemplate && bvc.m_added_to_main_chain)
update_miner_block_template();
return true;
@@ -1466,9 +1478,9 @@ namespace cryptonote
return m_blockchain_storage.have_block(id);
}
//-----------------------------------------------------------------------------------------------
- bool core::parse_tx_from_blob(transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash, const blobdata& blob) const
+ bool core::parse_tx_from_blob(transaction& tx, crypto::hash& tx_hash, const blobdata& blob) const
{
- return parse_and_validate_tx_from_blob(blob, tx, tx_hash, tx_prefix_hash);
+ return parse_and_validate_tx_from_blob(blob, tx, tx_hash);
}
//-----------------------------------------------------------------------------------------------
bool core::check_tx_syntax(const transaction& tx) const