Skip to content
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

Block in place while updating witness map #28

Open
sug0 opened this issue Nov 18, 2024 · 0 comments
Open

Block in place while updating witness map #28

sug0 opened this issue Nov 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@sug0
Copy link
Contributor

sug0 commented Nov 18, 2024

Updating the witness map is a fairly expensive operation, since we must append new nodes to a tree. This operation is linear to the amount of notes that haven't been spent yet, and each insertion is logarithmic. In total, we spendO(N log N) time, which is less than ideal, since that code is run from an async context.

for (idx, Transaction { masp_txs, .. }) in
block_data.transactions.into_iter()
{
for (masp_tx_index, masp_tx) in masp_txs.into_iter().enumerate() {
let indexed_tx = IndexedTx {
block_height,
block_index: TxIndex(idx as u32),
masp_tx_index: MaspTxIndex(masp_tx_index),
};
update_witness_map(
&commitment_tree,
&mut tx_notes_index,
&witness_map,
indexed_tx,
&masp_tx,
)
.into_masp_error()?;
shielded_txs.insert(indexed_tx, masp_tx);
}
}

Since this blocks tokio from yielding the current worker thread, we should resort to tokio::task::block_in_place around this for loop.

@sug0 sug0 added enhancement New feature or request question Further information is requested and removed question Further information is requested labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant