aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/openapi.yaml17
-rw-r--r--docs/store.md6
-rw-r--r--src/api/events.rs5
-rw-r--r--src/federation/fold.rs2
-rw-r--r--src/federation/held.rs2
-rw-r--r--src/federation/store/memory.rs31
-rw-r--r--src/federation/store/mod.rs3
-rw-r--r--src/federation/store/testfold.rs2
8 files changed, 54 insertions, 14 deletions
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 349f943..5c90037 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1417,14 +1417,15 @@ paths:
tags: [Events]
summary: The store
description: |
- The store's ID (its root's), its checkpoint's ID, its heads (what a new event
- builds on) and how many events it took after its checkpoint, as this node reads
- it now; the event it stopped at, if any (`stopped`: a version event writing a
- version that passed, which this continuum doesn't read), why, and how many
- events it holds back since, that one among them, taking nothing and refusing
- nothing until upgraded or told to drop it (`/admin/events/drop`); the party this
- node is of (`party`, `--store-party`), and whether it votes for it by itself
- (`votesByItself`), and so casts votes by hand (`POST /admin/events/vote`).
+ The store's ID (its root's), its checkpoint's ID, its heads, as many as an event
+ may name (64), the earliest taken first (what a new event builds on), and how many
+ events it took after its checkpoint, as this node reads it now; the event it
+ stopped at, if any (`stopped`: a version event writing a version that passed,
+ which this continuum doesn't read), why, and how many events it holds back since,
+ that one among them, taking nothing and refusing nothing until upgraded or told to
+ drop it (`/admin/events/drop`); the party this node is of (`party`,
+ `--store-party`), and whether it votes for it by itself (`votesByItself`), and so
+ casts votes by hand (`POST /admin/events/vote`).
responses:
'200':
description: The store.
diff --git a/docs/store.md b/docs/store.md
index ad98f9f..d5159f6 100644
--- a/docs/store.md
+++ b/docs/store.md
@@ -100,7 +100,9 @@ A fold says, of its events:
* **what an event builds on**, read from its bytes; bytes that aren't one of its events
are none, and are refused;
* **how large an event may be**, which the document judges a change by
- ([On Automerge](#on-automerge));
+ ([On Automerge](#on-automerge)), and how many events it may build on: a new event
+ builds on the heads of what a node holds, as many as that, the earliest taken first, so
+ that what is written merges what stayed apart the longest;
* **whether an event is taken where its history reads as a given state**: judging. A
root is taken only as its own store's, never by judging;
* **the state a checkpoint and the events after it read as**, built by adding the events
@@ -126,6 +128,8 @@ pub trait Fold {
type State: Clone;
/// The most bytes an event may have: larger ones are none.
const LARGEST: usize;
+ /// The most events an event may build on.
+ const DEPENDENCIES: usize = usize::MAX;
/// What the event builds on; `None` where its bytes are none of this fold's events.
fn dependencies(event: &[u8]) -> Option<Vec<Id>>;
/// Whether the event is taken where its history reads as `at`, as far as it reads it.
diff --git a/src/api/events.rs b/src/api/events.rs
index 214882a..b13de63 100644
--- a/src/api/events.rs
+++ b/src/api/events.rs
@@ -81,7 +81,8 @@ fn why(refusal: &Refusal) -> String {
}
}
-/// `GET /events`: the store's ID, its checkpoint's, its heads, how many events it took
+/// `GET /events`: the store's ID, its checkpoint's, its heads, as many as an event may
+/// name, what a new event builds on (`Store::building_on`), how many events it took
/// after its checkpoint, the event it stopped at, if any, the node's party, and whether
/// the node votes for it by itself.
async fn summary(State(state): State<AppState>) -> Response {
@@ -94,7 +95,7 @@ async fn summary(State(state): State<AppState>) -> Response {
json!({
"store": store.id().to_string(),
"checkpoint": Id::of(store.checkpoint()).to_string(),
- "heads": ids(store.heads()),
+ "heads": ids(store.building_on()),
"taken": store.taken().len(),
"stopped": stopped,
"party": party,
diff --git a/src/federation/fold.rs b/src/federation/fold.rs
index 7986a13..46f56e1 100644
--- a/src/federation/fold.rs
+++ b/src/federation/fold.rs
@@ -626,6 +626,8 @@ impl Fold for Federation {
const LARGEST: usize = event::LARGEST;
+ const DEPENDENCIES: usize = event::DEPENDENCIES;
+
fn dependencies(event: &[u8]) -> Option<Vec<Id>> {
Event::read(event).map(|event| event.deps().to_vec())
}
diff --git a/src/federation/held.rs b/src/federation/held.rs
index 93e2505..8d9d095 100644
--- a/src/federation/held.rs
+++ b/src/federation/held.rs
@@ -728,7 +728,7 @@ impl Holding {
return Ok(Vec::new());
}
let current = store.state().current().clone();
- let heads = store.heads();
+ let heads = store.building_on();
let line = crate::access::sshsig::PublicKey(voter.key.verifying_key().to_bytes()).line();
let mut record = record.clone();
let mut signed = Vec::new();
diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs
index 8493735..05479e3 100644
--- a/src/federation/store/memory.rs
+++ b/src/federation/store/memory.rs
@@ -263,8 +263,8 @@ impl<F: Fold> Store<F> {
ordered
}
- /// What a new event builds on: the events nothing else held builds on, or the
- /// checkpoint's heads where nothing came after it.
+ /// The heads of what the store holds: the events nothing else held builds on, in the
+ /// order taken, or the checkpoint's heads where nothing came after it.
pub(crate) fn heads(&self) -> Vec<Id> {
let built_on: HashSet<&Id> = self
.events
@@ -284,6 +284,15 @@ impl<F: Fold> Store<F> {
}
}
+ /// What a new event builds on: its heads, as many as an event may name
+ /// (`Fold::DEPENDENCIES`), the earliest taken first, so that what is written merges
+ /// what stayed apart the longest.
+ pub(crate) fn building_on(&self) -> Vec<Id> {
+ let mut heads = self.heads();
+ heads.truncate(F::DEPENDENCIES);
+ heads
+ }
+
/// Offers an event: it is taken once the store holds its dependencies, where the fold
/// takes it at its history.
pub(crate) fn offer(&mut self, bytes: Vec<u8>) -> Offered {
@@ -1139,6 +1148,24 @@ mod tests {
assert!(store.drop_taken(&[lock]).is_err());
}
+ /// A new event builds on as many heads as an event may name, the earliest taken first:
+ /// a later one merges the rest.
+ #[test]
+ fn a_new_event_builds_on_the_earliest_heads_an_event_may_name() {
+ let mut store = store();
+ let root = store.id();
+ let apart: Vec<Id> = (0..=TestFold::DEPENDENCIES)
+ .map(|n| taken(store.offer(testfold::put(&[root], &format!("k{n}"), "1"))))
+ .collect();
+ assert_eq!(store.heads(), apart);
+ assert_eq!(store.building_on(), apart[..TestFold::DEPENDENCIES]);
+ let merged = taken(store.offer(testfold::put(&store.building_on(), "m", "1")));
+ assert_eq!(
+ store.building_on(),
+ vec![apart[TestFold::DEPENDENCIES], merged]
+ );
+ }
+
/// Heads leave out what is neither among them, in their history, nor above them.
#[test]
fn heads_leave_out_what_is_beside_them() {
diff --git a/src/federation/store/mod.rs b/src/federation/store/mod.rs
index c80f5b8..d2028da 100644
--- a/src/federation/store/mod.rs
+++ b/src/federation/store/mod.rs
@@ -79,6 +79,9 @@ pub(crate) trait Fold {
/// The most bytes an event may have: larger ones are none.
const LARGEST: usize;
+ /// The most events an event may build on: what a new event builds on is no more.
+ const DEPENDENCIES: usize = usize::MAX;
+
/// What the event builds on; `None` where its bytes are none of this fold's events.
fn dependencies(event: &[u8]) -> Option<Vec<Id>>;
diff --git a/src/federation/store/testfold.rs b/src/federation/store/testfold.rs
index 17e039b..6dd1460 100644
--- a/src/federation/store/testfold.rs
+++ b/src/federation/store/testfold.rs
@@ -295,6 +295,8 @@ impl Fold for TestFold {
const LARGEST: usize = 64 * 1024;
+ const DEPENDENCIES: usize = 8;
+
fn dependencies(event: &[u8]) -> Option<Vec<Id>> {
decode(event).map(|(deps, _)| deps)
}