Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ All notable changes to Craqle are documented here.

## 0.3.2 - Unreleased

### Added

- `CraqleNode::set_policy_with` takes a `PolicyWrite` with an explicit durability.
`WalAlreadyDurable` sets the policy locally without publishing it or creating the graph topic.

### Changed

- Integrates Irokle 0.3.2 at revision `209f881af3fa4b8ed16e2ca0a0315d663029329e`.
Expand Down
54 changes: 47 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,10 +1410,13 @@ pub struct CraqleNode {
reindex_gate: std::sync::Mutex<Option<ReindexGate>>,
}

struct PolicyWrite<'a> {
graph: &'a GraphId,
policy: GraphPolicy,
durability: CraqleRequestDurability,
/// A graph policy write for [`CraqleNode::set_policy_with`].
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PolicyWrite<'a> {
pub graph: &'a GraphId,
pub policy: GraphPolicy,
/// Only a publishing durability emits an Irokle event and creates the graph topic.
pub durability: CraqleRequestDurability,
}

struct BatchFinish<'a> {
Expand Down Expand Up @@ -3390,9 +3393,25 @@ impl CraqleNode {
graph: &GraphId,
policy: GraphPolicy,
) -> Result<()> {
let policy = policy.normalized();
self.ensure_policy_action(graph, &policy, auth, Action::Write)?;
self.persist_graph_policy(graph, policy)?;
self.set_policy_with(
auth,
PolicyWrite {
graph,
policy,
durability: CraqleRequestDurability::Durable,
},
)
}

/// Set the hidden access policy described by `write`.
pub fn set_policy_with(&self, auth: &dyn Authorizer, write: PolicyWrite<'_>) -> Result<()> {
let policy = write.policy.normalized();
self.ensure_policy_action(write.graph, &policy, auth, Action::Write)?;
if !write.durability.persists_fjall() {
self.persist_policy(PolicyWrite { policy, ..write })?;
return Ok(());
}
self.persist_graph_policy(write.graph, policy)?;
self.persist_fjall()
}

Expand Down Expand Up @@ -6770,6 +6789,27 @@ mod tests {
PUBLISH_STALL_MICROS.store(0, Ordering::Relaxed);
}

/// A local policy write must not mint a topic genesis that forks the holders' topic.
#[test]
fn local_policy_unpublished() {
let dir = tempfile::tempdir().unwrap();
let node = sync_node(&dir);
let graph = GraphId::new("urn:test:local-policy");

node.set_policy_with(
&writer_auth(),
PolicyWrite {
graph: &graph,
policy: policy_at("local"),
durability: CraqleRequestDurability::WalAlreadyDurable,
},
)
.unwrap();

assert_eq!(node.store.graph_policy(&graph).unwrap(), policy_at("local"));
assert_eq!(node.bind_irokle_topic(&graph).unwrap(), None);
}

/// The policy a peer replaying this graph's topic ends up on.
fn last_published_policy(node: &CraqleNode, graph: &GraphId) -> GraphPolicy {
let sync = node.sync.clone().expect("sync node");
Expand Down
Loading