referrerpolicy=no-referrer-when-downgrade

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

Statement store.

Implementations§

Source§

impl Store

Source

pub fn new_shared<Block, Client, BE>( path: &Path, config: Config, client: Arc<Client>, keystore: Arc<LocalKeystore>, prometheus: Option<&PrometheusRegistry>, task_spawner: Box<dyn SpawnNamed>, ) -> Result<Arc<Store>>
where Block: BlockT, Block::Hash: From<BlockHash>, BE: Backend<Block> + 'static, Client: HeaderBackend<Block> + StorageProvider<Block, BE> + Send + Sync + 'static,

Create a new shared store instance. There should only be one per process. path will be used to open a statement database or create a new one if it does not exist.

Source

pub fn set_retention_resolver( &self, resolver: Box<dyn Fn(&Statement) -> RetentionReasonMask + Send + Sync>, )

Install the resolver that derives the retention mask for each submitted statement.

Without it, the store persists every submission. Installation is first-wins: the resolver is wired once at node startup, so a second install means a wiring bug and is rejected loudly.

Source

pub fn maintain(&self)

Perform periodic store maintenance: re-check the tracked statements, permanently delete statements whose purge period has elapsed, and refresh store metrics.

Expired and evicted statements are not removed from the database immediately; they are kept in the EXPIRED column for DEFAULT_PURGE_AFTER_SEC (default 48h) to prevent re-acceptance while they may still be propagating over gossip. This method removes those whose purge period has passed.

Runs in a background task on a fixed interval (MAINTENANCE_PERIOD, 29s). Enforcing per-account and global limits — expiring over-quota statements — is handled separately by enforce_limits on its own interval (ENFORCE_LIMITS_PERIOD, 31s), kept distinct to avoid holding the index lock for too long during maintenance.

Source

pub fn as_statement_store_ext(self: Arc<Self>) -> StatementStoreExt

Returns self as StatementStoreExt.

Trait Implementations§

Source§

impl StatementStore for Store

Source§

fn statements(&self) -> Result<Vec<(Hash, Statement)>>

Return every statement currently in the store.

Takes a read lock on the query index, iterates all indexed hashes, reads and SCALE-decodes each statement from the STATEMENTS database column, and skips any entry that fails to decode.

Source§

fn statement(&self, hash: &Hash) -> Result<Option<Statement>>

Read a single statement directly from the STATEMENTS database column by hash and decode it. Returns Ok(None) if no statement with that hash is stored.

Source§

fn broadcasts(&self, match_all_topics: &[Topic]) -> Result<Vec<Vec<u8>>>

Return the data of all statements matching all of match_all_topics that have no decryption key (i.e. public broadcasts).

Filters the query index by topic (intersection; an empty list matches every broadcast), reads and decodes each match from the STATEMENTS column, and returns the plaintext data, skipping any inconsistent entries.

Source§

fn posted( &self, match_all_topics: &[Topic], dest: [u8; 32], ) -> Result<Vec<Vec<u8>>>

Return the (encrypted) data of all statements matching all of match_all_topics whose decryption key equals dest.

Same filtering and DB read as broadcasts, but keyed on dest rather than the absence of a decryption key.

Source§

fn posted_clear( &self, match_all_topics: &[Topic], dest: [u8; 32], ) -> Result<Vec<Vec<u8>>>

Like posted but returns the decrypted data.

For each match, looks up the ed25519 key identified by dest in the keystore and decrypts the statement data; statements are skipped when the key is unavailable or decryption fails.

Source§

fn broadcasts_stmt(&self, match_all_topics: &[Topic]) -> Result<Vec<Vec<u8>>>

Return the full SCALE-encoded statements matching all of match_all_topics that have no decryption key (i.e. public broadcasts).

Takes a read lock on the query index and filters by the absence of a decryption key and topics (intersection / AND — an empty topic list matches every broadcast), then reads, decodes and re-encodes each match from the STATEMENTS column, skipping inconsistent entries. Unlike broadcasts, which returns only the data, this returns the whole statement.

Source§

fn posted_stmt( &self, match_all_topics: &[Topic], dest: [u8; 32], ) -> Result<Vec<Vec<u8>>>

Return the full SCALE-encoded statements matching all of match_all_topics whose decryption key equals dest.

Takes a read lock on the query index and filters by decryption key (dest) and topics (intersection / AND — an empty topic list matches every statement keyed to dest), then reads, decodes and re-encodes each match from the STATEMENTS column, skipping inconsistent entries. Unlike posted, which returns only the (still-encrypted) data, this returns the whole statement.

Source§

fn posted_clear_stmt( &self, match_all_topics: &[Topic], dest: [u8; 32], ) -> Result<Vec<Vec<u8>>>

Return, for each statement matching all of match_all_topics whose decryption key equals dest, the SCALE-encoded statement concatenated with its decrypted data.

Filters as posted_stmt, then for each match looks up the ed25519 key identified by dest in the keystore and decrypts the statement data, appending the plaintext to the encoded statement. Statements are skipped when the key is unavailable or decryption fails.

Source§

fn submit(&self, statement: Statement, source: StatementSource) -> SubmitResult

Submit a statement to the store, validating it and enforcing constraints.

Runs the following pipeline, short-circuiting on the first failure:

  1. Expiry check — reject if the statement’s expiration timestamp is already in the past (SubmitResult::Invalid(InvalidReason::AlreadyExpired)).
  2. Encoding size check — reject if the encoded statement exceeds MAX_STATEMENT_SIZE (InvalidReason::EncodingTooLarge).
  3. Topics check — reject a statement without topics (InvalidReason::NoTopics).
  4. Duplicate check — a statement already in the store is reported Known: the hash covers the whole content, so a duplicate carries nothing to renew. A recently evicted statement may be resubmitted (renewed) by Chain and Local sources but not by Network (SubmitResult::KnownExpired).
  5. Proof & signature — extract the account from the proof and verify the signature (InvalidReason::NoProof / InvalidReason::BadProof).
  6. Allowance — read the account’s allowance (StatementAllowance: max count and size) directly from chain state at the best block (via the statement_allowance_key storage key — not a runtime call); reject with SubmitResult::Rejected(NoAllowance) if none is set. The best block is used for responsiveness. Limit enforcement takes the larger of the best and the finalized allowance, so a statement accepted here outlives the finality lag; it is evicted later if the allowance it relied on leaves the best chain or a lower allowance is finalized.
  7. Constraint check & eviction — check the account’s record, enforcing per-account limits (count, size, one statement per channel, higher priority replaces lower) and global limits (DEFAULT_MAX_TOTAL_STATEMENTS, DEFAULT_MAX_TOTAL_SIZE), evicting lower-priority statements of the same account as needed (SubmitResult::Rejected if it still does not fit).
  8. Persist — commit the statement, its index rows, any evictions and the refreshed counters atomically, then update the caches and the in-memory query index.

Returns SubmitResult::New on success.

Source§

fn remove(&self, hash: &Hash) -> Result<()>

Soft-delete a statement by hash: drop it and its index rows from the database, and record it in the EXPIRED column so it cannot be re-accepted until its purge period elapses (see maintain). No-op if the statement is unknown.

Source§

fn remove_by(&self, who: [u8; 32]) -> Result<()>

Remove every statement authored by who, applying the same soft-delete as remove to each, in a single atomic commit.

Source§

fn take_recent_statements(&self) -> Result<Vec<(u64, Hash, Statement)>>

Return recent statements with their admission sequence numbers, oldest admission first, and clear the internal index. Read more
Source§

fn hold_statements(&self, hashes: &[Hash])

Keep the statements from removal as propagated, one hold per occurrence of a hash. A statement may leave the store once its last hold is released, so only a caller still holding a hash can extend its holds. Read more
Source§

fn release_statements(&self, hashes: &[Hash])

Release one hold per occurrence of a hash, ignoring hashes without holds.
Source§

fn admission_watermark(&self) -> Result<u64>

One past the newest assigned admission sequence number. Read more
Source§

fn admitted_statements( &self, cursor: u64, watermark: u64, scan_limit: usize, filter: &mut dyn FnMut(&Hash, &[u8], &Statement) -> FilterDecision, ) -> Result<AdmittedBatch>

Walk the admission journal from cursor (inclusive) towards watermark (exclusive), collecting statements through a filter callback. Read more
Source§

fn has_statement(&self, hash: &Hash) -> bool

Check if statement exists in the store Read more
Source§

fn statements_by_hashes( &self, hashes: &[Hash], filter: &mut dyn FnMut(&Hash, &[u8], &Statement) -> FilterDecision, ) -> Result<(Vec<(Hash, Statement)>, usize)>

Fetch statements by their hashes with a filter callback. Read more
Source§

fn subscription_topics(&self) -> HashSet<Topic>

Topics across all live statement subscriptions, for advertising topic affinity. Read more
Source§

impl StatementStoreSubscriptionApi for Store

Source§

fn subscribe_statement( &self, topic_filter: OptimizedTopicFilter, ) -> Result<(Vec<Vec<u8>>, Sender<StatementEvent>, SubscriptionStatementsStream)>

Subscribe to statements matching the topic filter. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl !UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedConversion for T

Source§

fn checked_from<T>(t: T) -> Option<Self>
where Self: TryFrom<T>,

Convert from a value of T into an equivalent instance of Option<Self>. Read more
Source§

fn checked_into<T>(self) -> Option<T>
where Self: TryInto<T>,

Consume self to return Some equivalent value of Option<T>. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T, U> DefensiveTruncateInto<U> for T

Source§

fn defensive_truncate_into(self) -> U

Defensively truncate a value and convert it into its bounded form.
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> IntoKey<U> for T
where U: FromKey<T>,

Source§

fn into_key(self) -> U

§

impl<Src, Dest> IntoTuple<Dest> for Src
where Dest: FromTuple<Src>,

§

fn into_tuple(self) -> Dest

Source§

impl<T> IsType<T> for T

Source§

fn from_ref(t: &T) -> &T

Cast reference.
Source§

fn into_ref(&self) -> &T

Cast reference.
Source§

fn from_mut(t: &mut T) -> &mut T

Cast mutable reference.
Source§

fn into_mut(&mut self) -> &mut T

Cast mutable reference.
Source§

impl<T, Outer> IsWrappedBy<Outer> for T
where Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

Source§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

Source§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatedConversion for T

Source§

fn saturated_from<T>(t: T) -> Self
where Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
Source§

fn saturated_into<T>(self) -> T
where Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoKey<U> for T
where U: TryFromKey<T>,

Source§

type Error = <U as TryFromKey<T>>::Error

Source§

fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>

Source§

impl<S, T> UncheckedInto<T> for S
where T: UncheckedFrom<S>,

Source§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
Source§

impl<T, S> UniqueSaturatedInto<T> for S
where T: Bounded, S: TryInto<T>,

Source§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T