blockchain: fill in cumulative block weight for alt blocks

This commit is contained in:
moneromooo-monero 2019-09-17 17:03:28 +00:00
parent 2c171a9b02
commit 01f660f60f
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 86 additions and 0 deletions

View file

@ -1803,6 +1803,34 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
}
bei.cumulative_difficulty += current_diff;
bei.block_cumulative_weight = cryptonote::get_transaction_weight(b.miner_tx);
for (const crypto::hash &txid: b.tx_hashes)
{
cryptonote::tx_memory_pool::tx_details td;
cryptonote::blobdata blob;
if (m_tx_pool.get_transaction_info(txid, td))
{
bei.block_cumulative_weight += td.weight;
}
else if (m_db->get_pruned_tx_blob(txid, blob))
{
cryptonote::transaction tx;
if (!cryptonote::parse_and_validate_tx_base_from_blob(blob, tx))
{
MERROR_VER("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative) refers to unparsable transaction hash " << txid << ".");
bvc.m_verifivation_failed = true;
return false;
}
bei.block_cumulative_weight += cryptonote::get_pruned_transaction_weight(tx);
}
else
{
// we can't determine the block weight, set it to 0 and break out of the loop
bei.block_cumulative_weight = 0;
break;
}
}
// add block to alternate blocks storage,
// as well as the current "alt chain" container
CHECK_AND_ASSERT_MES(!m_db->get_alt_block(id, NULL, NULL), false, "insertion of new alternative block returned as it already exists");