lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

commit bc7f87e69aa66624522a058d84c69225c6720221
parent 6f513d1cdcedc64b98e6530d958956a069c2da90
Author: triesap <tyson@radroots.org>
Date:   Tue, 28 Jul 2026 16:23:12 +0000

event_store: isolate duplicate preflight drift

- require capacity deltas for unique inserts
- preserve the typed state-drift diagnostic
- cover the impossible race deterministically
- update the governed production source hash

Diffstat:
Mcontracts/event_store_production_sources.toml | 2+-
Mcrates/event_store/src/store/protocol_reconciliation_v1.rs | 25++++++++++++++++++-------
2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/contracts/event_store_production_sources.toml b/contracts/event_store_production_sources.toml @@ -107,7 +107,7 @@ sha256 = "5ebd237e8f475184480938472e472ff8f4a7ea7b9f46f9d6100520d1c2d643c4" [[sources]] path = "crates/event_store/src/store/protocol_reconciliation_v1.rs" -sha256 = "7ec2486d535128c4230ec11664b5996203a483bf3a786ecba2594fd6eb2b244f" +sha256 = "cadc558979750f4b75d7e89847af63a728c963334f2aa7b553bdf0a297524ec4" [[sources]] path = "crates/event_store/src/store/protocol_storage_v1.rs" diff --git a/crates/event_store/src/store/protocol_reconciliation_v1.rs b/crates/event_store/src/store/protocol_reconciliation_v1.rs @@ -10,8 +10,9 @@ use crate::nip09::reconciliation_v1::{ persist_event_coordinate_after_insert, synchronize_after_insert, validate_source_raw_authority, }; use crate::source_maintenance_v1::{ - advance_source_capacity_after_insert_v1, preflight_unique_raw_source_append_v1, - raw_source_capacity_delta_v1, validate_source_capacity_authority_fast_v1, + RawSourceCapacityDeltaV1, advance_source_capacity_after_insert_v1, + preflight_unique_raw_source_append_v1, raw_source_capacity_delta_v1, + validate_source_capacity_authority_fast_v1, }; use radroots_event::contract::registry_v7::RadrootsEventContract; use radroots_event::envelope::{RadrootsEventEnvelope, RadrootsEventKindClass}; @@ -135,11 +136,7 @@ pub(super) async fn ingest_event_protocol_reconciliation_v1( .decision; if inserted { let capacity_delta = - capacity_delta.ok_or_else(|| RadrootsEventStoreError::SourceCapacityStateDrift { - reason: format!( - "unique raw event `{event_id}` was inserted after duplicate preflight" - ), - })?; + require_unique_raw_event_capacity_delta(event_id.as_str(), capacity_delta)?; synchronize_after_insert( tx, ingest, @@ -649,6 +646,15 @@ async fn upsert_head( Ok(()) } +fn require_unique_raw_event_capacity_delta( + event_id: &str, + capacity_delta: Option<RawSourceCapacityDeltaV1>, +) -> Result<RawSourceCapacityDeltaV1, RadrootsEventStoreError> { + capacity_delta.ok_or_else(|| RadrootsEventStoreError::SourceCapacityStateDrift { + reason: format!("unique raw event `{event_id}` was inserted after duplicate preflight"), + }) +} + fn i64_from_u64(field: &'static str, value: u64) -> Result<i64, RadrootsEventStoreError> { match i64::try_from(value) { Ok(value) => Ok(value), @@ -792,6 +798,11 @@ mod tests { .expect_err("malformed coordinate"), RadrootsRawHeadDecision::MalformedCoordinate ); + assert!(matches!( + require_unique_raw_event_capacity_delta("event-id", None), + Err(RadrootsEventStoreError::SourceCapacityStateDrift { reason }) + if reason == "unique raw event `event-id` was inserted after duplicate preflight" + )); } #[tokio::test]