summaryrefslogtreecommitdiffstats
path: root/src/remake/snapshot.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 04:13:11 +0100
committertv <tv@krebsco.de>2026-10-26 04:13:11 +0100
commitd668ce2ff8f308e54c1c7a2c145cb3479cab899d (patch)
tree851ceb314782a9428cac36d48fb5abc5805ead5f /src/remake/snapshot.rs
parentc13cee08dedeb8e73560f9bf9f7154c9fa089e2d (diff)
move protocol paths to dedicated module
Diffstat (limited to 'src/remake/snapshot.rs')
-rw-r--r--src/remake/snapshot.rs33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/remake/snapshot.rs b/src/remake/snapshot.rs
index 20569e0..301b32f 100644
--- a/src/remake/snapshot.rs
+++ b/src/remake/snapshot.rs
@@ -30,17 +30,10 @@ use sha2::{Digest, Sha256};
use super::kind::{DEFAULT_KIND, RemakeKind, Translator, by_name};
use super::records::{EpochRecord, Policy};
+use crate::document::meta::{self, EPOCHS, REMAKES, VOTES};
use crate::document::replica::Epoch;
use crate::document::store::{self, StoreError};
-pub(crate) const META_ROOT: &str = "_continuum";
-pub(crate) const REMAKES: &str = "remakes";
-/// The votes register (`records`).
-pub(crate) const VOTES: &str = "votes";
-pub(crate) const EPOCHS: &str = "epochs";
-/// The swarm ID, written once by the genesis node (`swarm::bootstrap`).
-pub(crate) const SWARM: &str = "swarm";
-
/// Everything that determines a snapshot besides the base content.
pub(crate) struct SnapshotParams<'a> {
/// ID of the committed remake; seeds the snapshot actor.
@@ -230,7 +223,7 @@ pub(crate) fn verify_document(doc: &mut AutoCommit, epoch: Epoch) -> Result<Epoc
/// generation it has metadata for, whose snapshot change is the document's only change
/// without dependencies (verified). For a document loaded from a backup.
pub(crate) fn epoch_of(doc: &mut AutoCommit) -> Result<Epoch, String> {
- let generation = store::keys_at(doc, &[META_ROOT.to_owned(), EPOCHS.to_owned()])
+ let generation = store::keys_at(doc, &meta::path(&[EPOCHS]))
.map_err(|error| error.to_string())?
.iter()
.filter_map(|key| key.parse::<u64>().ok())
@@ -270,11 +263,7 @@ pub(crate) fn read_epoch_metadata(
/// Path of the metadata record for an epoch generation.
pub(crate) fn epoch_metadata_path(generation: u64) -> Vec<String> {
- vec![
- META_ROOT.to_owned(),
- EPOCHS.to_owned(),
- generation.to_string(),
- ]
+ meta::path(&[EPOCHS, generation.to_string().as_str()])
}
/// Builds the snapshot of `source` at `params.base_heads`.
@@ -303,17 +292,17 @@ pub(crate) fn build(
// Protocol data carries forward, whatever the kind: forget records, earlier epochs'
// metadata (rejoining nodes need it). Remake records and the votes register describe
// the old epoch's protocol and stay behind.
- match store::delete_path(&mut snapshot, &[META_ROOT.to_owned()], false) {
+ match store::delete_path(&mut snapshot, &meta::path(&[]), false) {
Ok(()) | Err(StoreError::NotFound) => {}
Err(error) => return Err(error.into()),
}
- let mut protocol_keys = store::keys_at(&base, &[META_ROOT.to_owned()])?;
+ let mut protocol_keys = store::keys_at(&base, &meta::path(&[]))?;
protocol_keys.sort();
for key in protocol_keys
.into_iter()
.filter(|key| key != REMAKES && key != VOTES)
{
- store::copy_path(&base, &mut snapshot, &[META_ROOT.to_owned(), key])?;
+ store::copy_path(&base, &mut snapshot, &meta::path(&[key.as_str()]))?;
}
let mut base_heads: Vec<String> = params.base_heads.iter().map(|h| h.to_string()).collect();
@@ -422,7 +411,7 @@ mod tests {
/// The user-visible view, without our own metadata.
fn user_view(doc: &AutoCommit) -> JsonValue {
let mut view = store::read_path(doc, &[]).unwrap().unwrap();
- view.as_object_mut().unwrap().remove(META_ROOT);
+ view.as_object_mut().unwrap().remove(meta::ROOT);
view
}
@@ -580,19 +569,19 @@ mod tests {
let mut a = doc(b"actor-a");
store::write_path(
&mut a,
- &[META_ROOT.into(), REMAKES.into(), "c-1".into()],
+ &meta::path(&[REMAKES, "c-1"]),
&json!({ "state": "committed" }),
)
.unwrap();
store::write_path(
&mut a,
- &[META_ROOT.into(), VOTES.into(), "pk".into()],
+ &meta::path(&[VOTES, "pk"]),
&json!({ "remake": "c-1", "at": 1 }),
)
.unwrap();
store::write_path(
&mut a,
- &[META_ROOT.into(), "forgotten".into(), "pk".into()],
+ &meta::path(&[meta::FORGOTTEN, "pk"]),
&json!({ "at": 1 }),
)
.unwrap();
@@ -602,7 +591,7 @@ mod tests {
let policy = json!({ "replayWindow": { "epochs": 1 } });
let snap = build(&mut a, &params(&heads, &policy)).unwrap();
- let meta = store::read_path(&snap.doc, &[META_ROOT.into()])
+ let meta = store::read_path(&snap.doc, &meta::path(&[]))
.unwrap()
.unwrap();
assert!(meta.get(REMAKES).is_none());