Skip to content

refactor!(stump): Move updated data to its own function#81

Open
Davidson-Souza wants to merge 3 commits into
mit-dci:mainfrom
Davidson-Souza:swift-sync
Open

refactor!(stump): Move updated data to its own function#81
Davidson-Souza wants to merge 3 commits into
mit-dci:mainfrom
Davidson-Souza:swift-sync

Conversation

@Davidson-Souza

Copy link
Copy Markdown
Collaborator

Before this change, modify would return the data needed to update a proof for the new block. This requires additional internal computation and extra allocations. During IBD we may never use this, since proof update is only meant for updating a few blocks worth of changes. Now there's a method specific to pull the modify_data, and modify itself will only return a new Stump.

When refactoring the addition function, I've modified it a little to allow a smarter one with a very nice property: it can pretend that it added a node, but actually represent it as deleted. The goal here is to do a Swift Sync-style protocol where you don't need deletions.

If a txout is already spent, you give an empty hash (BitcoinNodeHash::empty()). This will be exactly equivalent as giving this txo's hash and later on calling delete for with this txo's hash. However, it does this with only one call to modify and doesn't require proofs to achieve that.

This is an API breaking change, as modify now only returns one parameter, otherwise the behavior stays unchanged.

@Davidson-Souza Davidson-Souza marked this pull request as ready for review January 2, 2026 17:40
Comment thread src/accumulator/stump.rs Outdated
Comment thread src/stump/mod.rs
Comment thread src/stump/mod.rs
@Davidson-Souza

Copy link
Copy Markdown
Collaborator Author

Pushed 427a309 with minor docs updates suggested by @jaoleal

@luisschwab

Copy link
Copy Markdown
Contributor

@Davidson-Souza do you have a Floresta branch using this PR?

@Davidson-Souza

Copy link
Copy Markdown
Collaborator Author

@luisschwab

@Davidson-Souza do you have a Floresta branch using this PR?

No, waiting on Jose's pr with swift sync stuff

@JoseSK999

Copy link
Copy Markdown
Contributor

It's time 🎅🏻

@luisschwab

luisschwab commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

nit: on the commit description: the ! comes after the (*), ie: refactor(stump)!: ..., per the Conventional Commit specification.

@Davidson-Souza Davidson-Souza force-pushed the swift-sync branch 4 times, most recently from 78d99d9 to d86c319 Compare March 19, 2026 20:11
Comment thread src/stump/mod.rs
proof: &Proof<Hash>,
) -> Result<(Self, UpdateData<Hash>), StumpError> {
let (intermediate, mut computed_roots) = self.remove(del_hashes, proof)?;
) -> Result<Self, StumpError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no longer return UpdateData, a rebase issue? What is it for btw, I wonder

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, modify would return the data needed to update a proof for the new block. This requires additional internal computation and extra allocations. During IBD we may never use this, since proof update is only meant for updating a few blocks worth of changes. Now there's a method specific to pull the modify_data, and modify itself will only return a new Stump.

@luisschwab

Copy link
Copy Markdown
Contributor

Needs rebase

@Davidson-Souza

Copy link
Copy Markdown
Collaborator Author

Rebased

@rustaceanrob

Copy link
Copy Markdown

Unable to offer conceptual review but code LGTM

Comment thread examples/proof_update.rs Outdated
let stump = s.modify(&new_utxos, &[utxos[0]], &p1).unwrap();

// and the proof
let update_data = s.get_update_data(&utxos, &[], &Proof::default()).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: why aren't we passing here the deleted utxos[0] and the proof p1? Maybe a comment about it, it's confusing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everywhere else you pass the delete hashes and proof in get_update_data, so it seems wrong

Comment thread src/proof/mod.rs Outdated
Comment on lines 473 to 474
/// in the path to the root. This function returns the calculated roots and the hashes
/// that were calculated in the process.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function no longer returns those hashes no? (forest nodes)

Comment thread src/proof/mod.rs Outdated
/// proofs, it doesn't compute the roots after the deletion, only the roots that are
/// needed for verification (i.e. the current accumulator).
/// needed for verification (i.e. the current accumulator). `calculate_hashes_delete` also
/// won't return the hashes that were calculated, we won't need them for updating the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, better?

Suggested change
/// won't return the hashes that were calculated, we won't need them for updating the
/// doesn't return the nodes that were calculated, as we won't need them for updating the

@JoseSK999 JoseSK999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More nits

Comment thread src/proof/mod.rs
"29590a14c1b09384b94a2c0e94bf821ca75b62eacebc47893397ca88e3bbcbd7",
"4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a",
"2b77298feac78ab51bc5079099a074c6d789bd350442f5079fcba2b3402694e5",
"726fdd3b432cc59e68487d126e70f0db74a236267f8daeae30b31839a4e7ebed",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a question, is there a different place where we could repurpose these constants to check the computed hashes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use similar tests in several other places, I don't think removing this here would be any problem.

Comment thread src/stump/mod.rs Outdated
Comment thread src/stump/mod.rs Outdated
Comment thread src/stump/mod.rs Outdated
Comment thread src/stump/mod.rs Outdated
Comment thread src/stump/mod.rs Outdated
Comment thread src/stump/mod.rs Outdated
Comment thread src/stump/mod.rs Outdated
@Davidson-Souza

Copy link
Copy Markdown
Collaborator Author

Applied docs suggestions by @JoseSK999

@JoseSK999

Copy link
Copy Markdown
Contributor

First 3 comments not addressed yet

Before this change, `modify` would return the data needed to update
a proof for the new block. This requires additional internal
computation and extra allocations. During IBD we may never use this,
since proof update is only meant for updating a few blocks worth of
changes. Now there's a method specific to pull the modify_data, and
`modify` itself will only return a new Stump.

When refactoring the addition function, I've modified it a little
to allow a smarter one with a very nice property: it can pretend that
it added a node, but actually represent it as deleted. The goal here
is to do a Swift Sync-style protocol where you don't need deletions.

If a txout is already spent, you give an empty hash
(BitcoinNodeHash::empty()). This will be exactly equivalent as giving
this txo's hash and later on calling delete for with this txo's hash.
However, it does this with only one call to modify and doesn't require
proofs to achieve that.

This is an API breaking change, as modify now only returns one parameter,
otherwise the behavior stays unchanged.
@Davidson-Souza

Davidson-Souza commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

First 3 comments not addressed yet

Shoot, sorry! Should be fixed now

Comment thread src/stump/mod.rs
Ok(new_stump)
}

/// Return the data needed to update a proof with the changes made a block.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made in a block

Comment thread src/stump/mod.rs
let mut h = 0;
let mut to_add = *add;
while (pos >> h) & 1 == 1 {
let root = roots.pop().unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants