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

Tree states to support per-slot state diffs #4475

Closed
jimmygchen opened this issue Jul 7, 2023 · 1 comment
Closed

Tree states to support per-slot state diffs #4475

jimmygchen opened this issue Jul 7, 2023 · 1 comment
Assignees
Labels
database tree-states Upcoming state and database overhaul

Comments

@jimmygchen
Copy link
Member

Description

Currently the HDiff logic does not support per-slot state diffs, and it would be nice to support this.

This requires the following (from @michaelsproul):

  • Re-writing the epoch-centric code in HDiff to work with slots instead.
  • Changing the on-disk DB format as the above change will break it.
  • Add some config for the "hierarchy exponents" to the OnDiskStoreConfig

Relevant code:

impl HierarchyConfig {
pub fn to_moduli(&self) -> Result<HierarchyModuli, Error> {
self.validate()?;
let moduli = self.exponents.iter().map(|n| 1 << n).collect();
Ok(HierarchyModuli { moduli })
}
pub fn validate(&self) -> Result<(), Error> {
if self.exponents.len() > 2
&& self
.exponents
.iter()
.tuple_windows()
.all(|(small, big)| small < big && *big < u64::BITS as u8)
{
Ok(())
} else {
Err(Error::InvalidHierarchy)
}
}
}
impl HierarchyModuli {
pub fn storage_strategy(&self, epoch: Epoch) -> Result<StorageStrategy, Error> {
let last = self.moduli.last().copied().ok_or(Error::InvalidHierarchy)?;
if epoch % last == 0 {
return Ok(StorageStrategy::Snapshot);
}
let diff_from = self.moduli.iter().rev().find_map(|&n| {
(epoch % n == 0).then(|| {
// Diff from the previous state.
(epoch - 1) / n * n
})
});
Ok(diff_from.map_or(StorageStrategy::Nothing, StorageStrategy::DiffFrom))
}
/// Return the smallest epoch greater than or equal to `epoch` at which a full snapshot should
/// be stored.
pub fn next_snapshot_epoch(&self, epoch: Epoch) -> Result<Epoch, Error> {
let last = self.moduli.last().copied().ok_or(Error::InvalidHierarchy)?;
if epoch % last == 0 {
Ok(epoch)
} else {
Ok((epoch / last + 1) * last)
}
}
}

@michaelsproul I'll likely need some help understanding this, so adding you if you have some time to pair or chat!

@jimmygchen
Copy link
Member Author

Completed in #4652 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database tree-states Upcoming state and database overhaul
Projects
None yet
Development

No branches or pull requests

2 participants