-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
add the right prunable hash per tx to pruned get_blocks.bin call #10137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3251,8 +3251,10 @@ bool BlockchainLMDB::get_blocks_from(uint64_t start_height, size_t min_block_cou | |
| RCURSOR(blocks); | ||
| RCURSOR(tx_indices); | ||
| RCURSOR(txs_pruned); | ||
| if (!pruned) | ||
| if (pruned) | ||
| { | ||
| RCURSOR(txs_prunable_hash); | ||
| } else { | ||
| RCURSOR(txs_prunable); | ||
| } | ||
|
|
||
|
|
@@ -3324,14 +3326,33 @@ bool BlockchainLMDB::get_blocks_from(uint64_t start_height, size_t min_block_cou | |
| throw0(DB_ERROR(lmdb_error("Error attempting to retrieve transaction data from the db: ", result).c_str())); | ||
| tx_blob.assign((const char*)v.mv_data, v.mv_size); | ||
|
|
||
| if (!pruned) | ||
| { | ||
| if (pruned) { | ||
| // get the prunable hash | ||
|
|
||
| // Look up each transaction's tx_id | ||
| MDB_val_set(tx_hash_val, tx_hash); | ||
| result = mdb_cursor_get(m_cur_tx_indices, (MDB_val *)&zerokval, &tx_hash_val, MDB_GET_BOTH); | ||
| if (result) | ||
| throw0(DB_ERROR(lmdb_error("Error retrieving tx index for prunable hash: ", result).c_str())); | ||
|
|
||
| const txindex *tip = (const txindex *)tx_hash_val.mv_data; | ||
| MDB_val_set(val_tx_id_for_hash, tip->data.tx_id); | ||
|
|
||
| result = mdb_cursor_get(m_cur_txs_prunable_hash, &val_tx_id_for_hash, &v, MDB_SET); | ||
akildemir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (result) | ||
| throw0(DB_ERROR(lmdb_error("Error attempting to retrieve transaction data from the db: ", result).c_str())); | ||
|
|
||
| crypto::hash prunable_hash = *(const crypto::hash*)v.mv_data; | ||
| current_block.second.push_back(std::make_pair(prunable_hash, std::move(tx_blob))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NACK replacing the TXID with the prunable hash, this silently breaks the API of |
||
| } else { | ||
| // get the prunable data | ||
| result = mdb_cursor_get(m_cur_txs_prunable, &val_tx_id, &v, op); | ||
| if (result) | ||
| throw0(DB_ERROR(lmdb_error("Error attempting to retrieve transaction data from the db: ", result).c_str())); | ||
| tx_blob.append(reinterpret_cast<const char*>(v.mv_data), v.mv_size); | ||
| current_block.second.push_back(std::make_pair(tx_hash, std::move(tx_blob))); | ||
| } | ||
| current_block.second.push_back(std::make_pair(tx_hash, std::move(tx_blob))); | ||
|
|
||
| size += current_block.second.back().second.size(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip the TXID -> tx index lookup by using already existing
tx_id(terrible name 😢) variable. Tx on-chain indices are assigned in ascending order by 1) block, then 2) txs in block in specified order.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm trying to understand this and your next #10137 (comment) . if you mean it would be enough just to do
result = mdb_cursor_get(m_cur_txs_prunable_hash, &val_tx_id, &v, op);instead of first fetching the tx index, that doesn't work fortxs_prunable_hashtable like it would fortxs_prunedortxs_prunabletables. it gives the same prunable hash over over for all txs.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that you should do a
MDB_SETop first to first set the cursor to the entry attx_idfor the first transaction in the list, then doMDB_NEXTafterwards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply. Had a busy week. So it looks like I miss the
MDB_SETthat happens inside this if blockmonero/src/blockchain_db/lmdb/db_lmdb.cpp
Line 3301 in d32b5bf
MDB_SETfor tablestxs_prunableandtxs_prunedis inside the if block. I checkedBlockchainLMDB::get_blocks_fromis always called withskip_coinbaseistrueand it looks like the function won't return as intended if that were to be passed asfalsesince those tables would also be callingMDB_NEXTbeforeMDB_SET. Indeed, when I compiled it withfalse,monero-wallet-clicouldn't scan the chain. It immediately throws exceptionError: refresh failed: internal error: Exception in thread pool. Blocks received: 0.So I believe there is a bug there. If
skip_coinbaseis necessary for that function to work properly it shouldn't be a parameter? I think the original intention was to actually skip the coinbase tx in each block by retrieving the tx and ignoring the value of the call so that cursor moves to the next tx when calling withMDB_NEXTand that works as intended if we wanted to skip the coinbase txs but otherwise it misses theMDB_SETop to those tables. So a fix would be to always callMDB_SETand only ignore the value ifskip_coinbaseistrue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the
skip_coinbase=falsething is a bug. I opened #10166 to fix it. Perhaps you could rebase this PR on top of that? But yes, generally, you should doMDB_SETonce and thenMDB_NEXTafterwards for sequential keys.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I can rebase once that pr is merged 👍