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

Remove unnecessary witnesses #29

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

Remove unnecessary witnesses #29

sug0 opened this issue Nov 18, 2024 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@sug0
Copy link
Contributor

sug0 commented Nov 18, 2024

Updating the witness map doesn't remove incremental witnesses of leaf positions in the commitment tree related with notes that have already been spent (i.e. whose nullifiers have been revealed).

/// Update the merkle tree of witnesses the first time we
/// scan a new MASP transaction.
pub fn update_witness_map(
commitment_tree: &CommitmentTree,
tx_notes_index: &mut TxNoteMap,
witness_map: &WitnessMap,
indexed_tx: IndexedTx,
shielded: &namada_core::masp_primitives::transaction::Transaction,
) -> anyhow::Result<()> {
let mut note_pos = commitment_tree.size();
tx_notes_index.insert(indexed_tx, note_pos);
for so in shielded
.sapling_bundle()
.map_or(&vec![], |x| &x.shielded_outputs)
{
// Create merkle tree leaf node from note commitment
let node = Node::new(so.cmu.to_repr());
// Update each merkle tree in the witness map with the latest
// addition
witness_map.update(node).map_err(|note_pos| {
anyhow::anyhow!("Witness map is full at note position {note_pos}")
})?;
if !commitment_tree.append(node) {
anyhow::bail!("Note commitment tree is full");
}
// Finally, make it easier to construct merkle paths to this new
// note
let witness =
IncrementalWitness::<Node>::from_tree(&commitment_tree.get_tree());
witness_map.insert(note_pos, witness);
note_pos += 1;
}
Ok(())
}

If we could map nullifiers to note positions, we could stop updating their witnesses, thereby speeding up update_witness_map, and also decreasing the load on the database (since we won't need to store as much data, and likewise clients won't need to fetch as much data).

@sug0 sug0 added enhancement New feature or request 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 question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant