aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortobtoht <tob@featherwallet.org>2025-03-24 02:56:05 +0000
committertobtoht <tob@featherwallet.org>2025-03-24 02:56:05 +0000
commitf373684b41c3ed2857d92c6827135e83be83f645 (patch)
treec8f5d8f52e93da9139e67b21a44a2de4689aef47 /src
parenta510409cd3c1c95848d6ab592fc91cd49c63ceae (diff)
parentce1c864b4d816a2511e99d757f7e62c9d1b36bcc (diff)
downloadmonzero-core-f373684b41c3ed2857d92c6827135e83be83f645.tar.gz
monzero-core-f373684b41c3ed2857d92c6827135e83be83f645.tar.xz
monzero-core-f373684b41c3ed2857d92c6827135e83be83f645.zip
Merge pull request #9853
ce1c864b4 cryptonote_protocol: fix handling of pruned blocks during sync (jeffro256)
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/blockchain.cpp2
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl38
2 files changed, 32 insertions, 8 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index d9615f9c0..021492ad2 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -4339,7 +4339,7 @@ leave:
{
tx = std::move(extra_txs_it->second.first);
txblob = std::move(extra_txs_it->second.second);
- tx_weight = get_transaction_weight(tx, txblob.size());
+ tx_weight = tx.pruned ? get_pruned_transaction_weight(tx) : get_transaction_weight(tx, txblob.size());
fee = get_tx_fee(tx);
pruned = tx.pruned;
extra_block_txs.txs_by_txid.erase(extra_txs_it);
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index bd1d440ba..2a6ad658d 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -81,6 +81,7 @@ namespace cryptonote
inline bool make_pool_supplement_from_block_entry(
const std::vector<cryptonote::tx_blob_entry>& tx_entries,
const CryptoHashContainer& blk_tx_hashes,
+ const bool allow_pruned,
cryptonote::pool_supplement& pool_supplement)
{
pool_supplement.nic_verified_hf_version = 0;
@@ -91,7 +92,7 @@ namespace cryptonote
return false;
}
- for (const auto& tx_entry: tx_entries)
+ for (const cryptonote::tx_blob_entry& tx_entry: tx_entries)
{
if (tx_entry.blob.size() > get_max_tx_size())
{
@@ -99,17 +100,38 @@ namespace cryptonote
return false;
}
+ const bool is_pruned = tx_entry.prunable_hash != crypto::null_hash;
+ if (is_pruned && !allow_pruned)
+ {
+ MERROR("Pruned transaction not allowed here");
+ return false;
+ }
+
cryptonote::transaction tx;
crypto::hash tx_hash;
- if (!cryptonote::parse_and_validate_tx_from_blob(tx_entry.blob, tx, tx_hash)
- || !blk_tx_hashes.count(tx_hash)
- || tx.pruned)
+ bool parse_success = false;
+ if (is_pruned)
+ {
+ if ((parse_success = cryptonote::parse_and_validate_tx_base_from_blob(tx_entry.blob, tx)))
+ tx_hash = cryptonote::get_pruned_transaction_hash(tx, tx_entry.prunable_hash);
+ }
+ else
{
- MERROR("failed to parse and/or validate unpruned transaction as inside block: "
+ parse_success = cryptonote::parse_and_validate_tx_from_blob(tx_entry.blob, tx, tx_hash);
+ }
+
+ if (!parse_success)
+ {
+ MERROR("failed to parse and/or validate transaction: "
<< epee::string_tools::buff_to_hex_nodelimer(tx_entry.blob)
);
return false;
}
+ else if (!blk_tx_hashes.count(tx_hash))
+ {
+ MERROR("transaction " << tx_hash << " not in block");
+ return false;
+ }
pool_supplement.txs_by_txid.emplace(tx_hash, std::make_pair(std::move(tx), tx_entry.blob));
}
@@ -146,7 +168,9 @@ namespace cryptonote
return false;
}
- return make_pool_supplement_from_block_entry(blk_entry.txs, blk_tx_hashes, pool_supplement);
+ // We set `allow_pruned` equal to whether this block entry is pruned since the pruned flag
+ // should be checked anyways by the time we deserialize transactions
+ return make_pool_supplement_from_block_entry(blk_entry.txs, blk_tx_hashes, blk_entry.pruned, pool_supplement);
}
@@ -619,7 +643,7 @@ namespace cryptonote
// can skip the mempool for faster block propagation. Later in the function, we will erase all
// transactions from the relayed block.
pool_supplement extra_block_txs;
- if (!make_pool_supplement_from_block_entry(arg.b.txs, blk_txids_set, extra_block_txs))
+ if (!make_pool_supplement_from_block_entry(arg.b.txs, blk_txids_set, /*allow_pruned=*/false, extra_block_txs))
{
LOG_ERROR_CCONTEXT
(