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

Prune Merkle tree of bridge pool #2206

Merged
merged 4 commits into from
Dec 7, 2023
Merged

Conversation

yito88
Copy link
Member

@yito88 yito88 commented Nov 21, 2023

Describe your changes

closes #2110

Indicate on which release or other PRs this topic is based on

0.27.0

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

@yito88 yito88 changed the title Yuji/prune bp merkle tree Prune Merkle tree of bridge pool Nov 21, 2023
@yito88 yito88 requested review from sug0 and grarco November 22, 2023 11:43
@yito88 yito88 marked this pull request as ready for review November 22, 2023 11:43
let nonce = Uint::try_from_slice(&bytes)
.map_err(Error::BorshCodingError)?;
if nonce < current_nonce {
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this returning at the first epoch with an invalid nonce instead of the last one matching the current nonce?

Copy link
Member Author

Choose a reason for hiding this comment

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

The nonce was incremented to the current one during the epoch though the epoch has the invalid nonce at the starting height. The Merkle tree at the epoch starting would be required to rebuild one at a height (after the nonce was incremented) during the epoch. So, the Merkle tree in the epoch should have a valid nonce.
There is a corner case; the nonce was incremented at the same height when the epoch was updated. However, the Merkle tree snapshot would be pruned eventually.

storage.write(&bp_nonce_key, bytes).unwrap();

let bytes = types::encode(&Uint::default());
storage.write(&bp_nonce_key, bytes).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this second write since we've just written the same key?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, it's not needed

grarco
grarco previously approved these changes Nov 22, 2023
Copy link
Collaborator

@grarco grarco left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

grarco
grarco previously approved these changes Nov 24, 2023
@tzemanovic tzemanovic mentioned this pull request Nov 24, 2023
tzemanovic added a commit that referenced this pull request Nov 28, 2023
* origin/yuji/prune-bp-merkle-tree:
  remove unneeded write
  add test and changelog
  prune merkle trees of bridge pool
core/src/ledger/storage/mod.rs Outdated Show resolved Hide resolved
@tzemanovic tzemanovic merged commit 76023b7 into main Dec 7, 2023
14 checks passed
@tzemanovic tzemanovic deleted the yuji/prune-bp-merkle-tree branch December 7, 2023 17:59
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.

Prune old Bridge pool merkle trees
4 participants