abort.rs (3759B)
1 //! Shared explicit cleanup selectors and reports, without backend qualification. 2 use super::*; 3 use crate::workspace::AttachmentInput; 4 use radroots_domain::{OrderId, UnixSeconds}; 5 6 /// Original-operation selectors. These values supply no nonissuance proof. 7 pub struct StockAbortRequest { 8 binding: WorkspaceBinding, 9 minimum: InventoryCheckpointRef, 10 operation: OperationId, 11 digest: CommandDigest, 12 } 13 impl StockAbortRequest { 14 pub const fn new( 15 binding: WorkspaceBinding, 16 minimum: InventoryCheckpointRef, 17 operation: OperationId, 18 digest: CommandDigest, 19 ) -> Self { 20 Self { 21 binding, 22 minimum, 23 operation, 24 digest, 25 } 26 } 27 pub const fn binding(&self) -> &WorkspaceBinding { 28 &self.binding 29 } 30 pub const fn minimum_checkpoint(&self) -> InventoryCheckpointRef { 31 self.minimum 32 } 33 pub const fn operation_id(&self) -> OperationId { 34 self.operation 35 } 36 pub const fn command_digest(&self) -> CommandDigest { 37 self.digest 38 } 39 /// Original recovery metadata, never evidence of admission or completion. 40 pub fn attempt(&self) -> CommitAttempt { 41 CommitAttempt::new( 42 self.binding.input().workspace_id(), 43 self.operation, 44 self.digest, 45 None, 46 ) 47 } 48 } 49 impl core::fmt::Debug for StockAbortRequest { 50 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 51 f.write_str("StockAbortRequest(<redacted>)") 52 } 53 } 54 55 /// Reported original cleanup, distinct from cancellation or delivery. 56 pub struct StockAbortReceipt { 57 attempt: CommitAttempt, 58 order: OrderId, 59 at: UnixSeconds, 60 checkpoint: InventoryCheckpointRef, 61 pools: Vec<PoolSnapshot>, 62 } 63 impl StockAbortReceipt { 64 /// Checks bounded report metadata only. A qualified store must authenticate 65 /// the original absence and effects and confirm its actual atomic commit. 66 pub fn from_committed_store( 67 namespace: &AttachmentInput, 68 attempt: CommitAttempt, 69 order: OrderId, 70 at: UnixSeconds, 71 checkpoint: InventoryCheckpointRef, 72 pools: Vec<PoolSnapshot>, 73 ) -> Result<Self, OperationError> { 74 if attempt.workspace_id() != namespace.workspace_id() 75 || attempt.transaction_id().is_none() 76 || checkpoint.authority() != namespace.authority() 77 || checkpoint.revision().get() == 0 78 || checkpoint.authorization().is_none() 79 || pools.len() > 64 80 || pools.iter().any(|pool| pool.version().get() < 3) 81 || pools.windows(2).any(|pair| pair[0].id() >= pair[1].id()) 82 { 83 return Err(OperationError::RecoveryRequired); 84 } 85 Ok(Self { 86 attempt, 87 order, 88 at, 89 checkpoint, 90 pools, 91 }) 92 } 93 pub const fn attempt(&self) -> CommitAttempt { 94 self.attempt 95 } 96 pub const fn order_id(&self) -> OrderId { 97 self.order 98 } 99 pub const fn aborted_at(&self) -> UnixSeconds { 100 self.at 101 } 102 pub const fn checkpoint(&self) -> InventoryCheckpointRef { 103 self.checkpoint 104 } 105 pub fn released_pools(&self) -> &[PoolSnapshot] { 106 &self.pools 107 } 108 /// Transfers the original reported after-images without another copy. 109 pub fn into_released_pools(self) -> Vec<PoolSnapshot> { 110 self.pools 111 } 112 } 113 impl core::fmt::Debug for StockAbortReceipt { 114 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 115 f.write_str("StockAbortReceipt(<redacted>)") 116 } 117 } 118 #[derive(Debug)] 119 pub enum StockAbortOutcome { 120 Aborted(Box<StockAbortReceipt>), 121 Unknown(CommitAttempt), 122 }