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

Implement sliding window algorithm for FMD params #4473

Merged
merged 7 commits into from
Jun 3, 2024

Conversation

cronokirby
Copy link
Contributor

Describe your changes

This adds a new algorithm for FMD parameters, which uses a sliding window approximation to target a specified number of detections over a given window. The idea is that if you set a window, of say, 1 day (in blocks), then the algorithm will then approximate the number of clues detected in the past day, and then use that to set the precision, so that the lowest precision such that at least the target number of detections will be generated, if that number of clues is seen over the upcoming window.

We could use a window of 1 day and 1000 detections or so as reasonable production parameters.

Issue ticket number and link

Closes #1087.

Checklist before requesting a review

  • If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason:

    This adds new possibilities to the chain parameters in a backwards-compatible way, but which will cause a consensus divergence if the new parameters are sent via governance etc. without an upgrade

@cronokirby cronokirby added the consensus-breaking breaking change to execution of on-chain data label May 24, 2024
@cratelyn cratelyn added the A-shielded-crypto Area: Cryptographic design for Penumbra's shielded transaction model label May 28, 2024
@cratelyn cratelyn added this to the Sprint 7 milestone May 28, 2024
@erwanor erwanor requested review from erwanor and hdevalence May 30, 2024 11:39
@redshiftzero redshiftzero self-requested a review May 30, 2024 19:17
);
}

let new_clues_in_block = clue_count_delta.1.saturating_sub(clue_count_delta.1);
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be amended, because this will always be equal to zero

Copy link
Member

Choose a reason for hiding this comment

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

also, candidly, i'm working out what index 0 and index 1 correspond to, a short comment would be helpful there

Copy link
Member

Choose a reason for hiding this comment

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

maybe destructuring the tuple in the method signature? (old_clue_count, new_clue_count): (u64, u64)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let new_clues_in_block = clue_count_delta.1.saturating_sub(clue_count_delta.1);
let new_clues_in_block = clue_count_delta.1.saturating_sub(clue_count_delta.0);

Copy link
Member

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

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

Looks good! One suggested change inline that we should make prior to merge

);
}

let new_clues_in_block = clue_count_delta.1.saturating_sub(clue_count_delta.1);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let new_clues_in_block = clue_count_delta.1.saturating_sub(clue_count_delta.1);
let new_clues_in_block = clue_count_delta.1.saturating_sub(clue_count_delta.0);

crates/core/component/shielded-pool/src/fmd.rs Outdated Show resolved Hide resolved
@cronokirby
Copy link
Contributor Author

I fixed the comments above, and then added a fix in terms of proto naming to correct the fact that the window should be measured in terms of update periods, and not blocks. e.g. a window of "4" means you consider the previous 4 update checks to the parameters, not the previous 4 blocks. (with the default update frequency of 16, this would be 64 blocks)

Copy link
Member

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

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

LGTM! my comments were addressed

@cronokirby cronokirby merged commit 75a0622 into main Jun 3, 2024
13 checks passed
@cronokirby cronokirby deleted the 1087-fmd-algorithm branch June 3, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shielded-crypto Area: Cryptographic design for Penumbra's shielded transaction model consensus-breaking breaking change to execution of on-chain data
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

FMD: initial Clue parameter selection
4 participants