Skip to main content

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 maintain(&self)

Perform periodic store maintenance: 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. 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).
  4. Proof & signature — extract the account from the proof and verify the signature (InvalidReason::NoProof / InvalidReason::BadProof).
  5. 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; a statement accepted here may later be evicted when limits are enforced against the finalized block.
  6. 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).
  7. 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 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§

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 !UnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin 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
Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
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.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

Source§

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

Source§

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> JsonSchemaMaybe for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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