aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-17 04:54:24 +0000
committertv <tv@krebsco.de>2026-11-17 05:58:26 +0100
commitb501bbe41976769c7ea2f1976e26cd8ccb778515 (patch)
tree1c830b483e423a04f52e769fdca14c9ffa20d815 /src
parent1ec6ca0a3863ae8fb3f0cab84451e73adb3b452f (diff)
remake: test helpers proposing and committing against the protocol
For simulations of a coordinator that doesn't keep to the protocol: `testing::propose_again` proposes a remake's proposal again under a new ID, whatever is open, and `testing::commit_as` commits a remake at the node's heads now, whatever the votes and another decision, to a given epoch or to the epoch of the snapshot the node builds there.
Diffstat (limited to 'src')
-rw-r--r--src/remake/api.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/remake/api.rs b/src/remake/api.rs
index 5cd4db1..325f9ba 100644
--- a/src/remake/api.rs
+++ b/src/remake/api.rs
@@ -996,6 +996,72 @@ pub(crate) mod testing {
into_json(abort_by_id(host, id.to_owned(), query, Some(user.to_owned())).await).await
}
+ /// What a coordinator proposing against the protocol does: proposes remake `id`'s
+ /// proposal again, under a new ID, whatever is open. The new ID.
+ pub(crate) async fn propose_again<H: Host>(host: &H, id: &str) -> String {
+ use crate::remake::records;
+ let all = host.read_doc(records::load_all).await;
+ let (_, record) = all
+ .into_iter()
+ .find(|(other, _)| other == id)
+ .expect("the remake's record");
+ let again = format!("{id}-again-{}", host.now_millis().as_u64());
+ let written = again.clone();
+ host.commit_doc(move |doc| records::write_proposal(doc, &written, &record.proposal))
+ .await
+ .expect("the proposal written");
+ again
+ }
+
+ /// What a coordinator deciding against the protocol does: commits remake `id`, its own
+ /// and still undecided, at its heads now, whatever the votes and another decision, to
+ /// `to_epoch`, or, where none, to the epoch of the snapshot it builds there. The epoch
+ /// committed.
+ pub(crate) async fn commit_as<H: Host>(
+ host: &H,
+ id: &str,
+ to_epoch: Option<crate::document::replica::Epoch>,
+ ) -> crate::document::replica::Epoch {
+ use crate::remake::records::{self, Decision};
+ let all = host.read_doc(records::load_all).await;
+ let (_, record) = all
+ .into_iter()
+ .find(|(other, _)| other == id)
+ .expect("the remake's record");
+ let copy = host.read_doc(|doc| doc.clone()).await;
+ let base = copy.get_heads();
+ #[allow(unused_mut)]
+ let mut request = record
+ .snapshot_request_at(id, base.clone())
+ .expect("a snapshot request");
+ #[cfg(feature = "federation")]
+ {
+ request.held = crate::remake::snapshot::Held(Some(host.holding()));
+ }
+ let (snapshot, _) = crate::remake::snapshot::build_detached(copy, request)
+ .await
+ .expect("a snapshot");
+ let epoch = to_epoch.unwrap_or(snapshot.epoch);
+ let decision = Decision::Committed {
+ to_epoch: epoch.into(),
+ base_heads: record
+ .proposal
+ .base_heads
+ .is_none()
+ .then(|| records::encode_heads(&base)),
+ snapshot_bytes: snapshot.doc.save().len() as u64,
+ decided_at: host.now_millis(),
+ };
+ if epoch == snapshot.epoch {
+ host.remake().store_prebuilt(id, snapshot);
+ }
+ let id = id.to_owned();
+ host.commit_doc(move |doc| records::write_decision(doc, &id, &decision))
+ .await
+ .expect("the decision written");
+ epoch
+ }
+
/// `GET /admin/remakes/{id}`: the report, if the remake exists here.
pub(crate) async fn report<H: Host>(host: &H, id: &str) -> Option<JsonValue> {
let report = load_report(host, id).await?;