Trait linera_storage::Storage

source ·
pub trait Storage: Sized {
    type Context: Context<Extra = ChainRuntimeContext<Self>> + Clone + Send + Sync + 'static;
    type Clock: Clock;

Show 28 methods // Required methods fn clock(&self) -> &Self::Clock; fn load_chain<'life0, 'async_trait>( &'life0 self, id: ChainId, ) -> Pin<Box<dyn Future<Output = Result<ChainStateView<Self::Context>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn contains_blob<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<bool, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn missing_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], ) -> Pin<Box<dyn Future<Output = Result<Vec<BlobId>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn contains_blob_state<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<bool, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_hashed_confirmed_block<'life0, 'async_trait>( &'life0 self, hash: CryptoHash, ) -> Pin<Box<dyn Future<Output = Result<Hashed<ConfirmedBlock>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_blob<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<Blob, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Blob>>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn read_blob_state<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<BlobState, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_blob_states<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], ) -> Pin<Box<dyn Future<Output = Result<Vec<BlobState>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn read_hashed_confirmed_blocks_downward<'life0, 'async_trait>( &'life0 self, from: CryptoHash, limit: u32, ) -> Pin<Box<dyn Future<Output = Result<Vec<Hashed<ConfirmedBlock>>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn write_blob<'life0, 'life1, 'async_trait>( &'life0 self, blob: &'life1 Blob, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn write_blobs_and_certificate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, blobs: &'life1 [Blob], certificate: &'life2 ConfirmedBlockCertificate, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn write_blob_state<'life0, 'life1, 'async_trait>( &'life0 self, blob_id: BlobId, blob_state: &'life1 BlobState, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn maybe_write_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blobs: &'life1 [Blob], ) -> Pin<Box<dyn Future<Output = Result<Vec<bool>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn maybe_write_blob_state<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, blob_state: BlobState, ) -> Pin<Box<dyn Future<Output = Result<Epoch, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn maybe_write_blob_states<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], blob_state: BlobState, overwrite: bool, ) -> Pin<Box<dyn Future<Output = Result<Vec<Epoch>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn write_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blobs: &'life1 [Blob], ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn contains_certificate<'life0, 'async_trait>( &'life0 self, hash: CryptoHash, ) -> Pin<Box<dyn Future<Output = Result<bool, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_certificate<'life0, 'async_trait>( &'life0 self, hash: CryptoHash, ) -> Pin<Box<dyn Future<Output = Result<ConfirmedBlockCertificate, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_certificates<'life0, 'async_trait, I>( &'life0 self, hashes: I, ) -> Pin<Box<dyn Future<Output = Result<Vec<ConfirmedBlockCertificate>, ViewError>> + Send + 'async_trait>> where I: 'async_trait + IntoIterator<Item = CryptoHash> + Send, Self: 'async_trait, 'life0: 'async_trait; fn read_event<'life0, 'async_trait>( &'life0 self, id: EventId, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn write_events<'life0, 'async_trait>( &'life0 self, events: impl 'async_trait + IntoIterator<Item = (EventId, Vec<u8>)> + Send, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn wasm_runtime(&self) -> Option<WasmRuntime>; // Provided methods fn load_active_chain<'life0, 'async_trait>( &'life0 self, id: ChainId, ) -> Pin<Box<dyn Future<Output = Result<ChainStateView<Self::Context>, ChainError>> + Send + 'async_trait>> where ChainRuntimeContext<Self>: ExecutionRuntimeContext, Self: Sync + 'async_trait, 'life0: 'async_trait { ... } fn create_chain<'life0, 'async_trait>( &'life0 self, committee: Committee, admin_id: ChainId, description: ChainDescription, owner: Owner, balance: Amount, timestamp: Timestamp, ) -> Pin<Box<dyn Future<Output = Result<(), ChainError>> + Send + 'async_trait>> where ChainRuntimeContext<Self>: ExecutionRuntimeContext, Self: Sync + 'async_trait, 'life0: 'async_trait { ... } fn load_contract<'life0, 'life1, 'async_trait>( &'life0 self, application_description: &'life1 UserApplicationDescription, ) -> Pin<Box<dyn Future<Output = Result<UserContractCode, ExecutionError>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn load_service<'life0, 'life1, 'async_trait>( &'life0 self, application_description: &'life1 UserApplicationDescription, ) -> Pin<Box<dyn Future<Output = Result<UserServiceCode, ExecutionError>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... }
}
Expand description

Communicate with a persistent storage using the “views” abstraction.

Required Associated Types§

source

type Context: Context<Extra = ChainRuntimeContext<Self>> + Clone + Send + Sync + 'static

The low-level storage implementation in use.

source

type Clock: Clock

The clock type being used.

Required Methods§

source

fn clock(&self) -> &Self::Clock

Returns the current wall clock time.

source

fn load_chain<'life0, 'async_trait>( &'life0 self, id: ChainId, ) -> Pin<Box<dyn Future<Output = Result<ChainStateView<Self::Context>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Loads the view of a chain state.

§Notes

Each time this method is called, a new ChainStateView is created. If there are multiple instances of the same chain active at any given moment, they will race to access persistent storage. This can lead to invalid states and data corruption.

Other methods that also create ChainStateView instances that can cause conflicts are: load_active_chain and create_chain.

source

fn contains_blob<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<bool, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Tests the existence of a blob with the given blob ID.

source

fn missing_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], ) -> Pin<Box<dyn Future<Output = Result<Vec<BlobId>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns what blobs from the input are missing from storage.

source

fn contains_blob_state<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<bool, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Tests existence of a blob state with the given blob ID.

source

fn read_hashed_confirmed_block<'life0, 'async_trait>( &'life0 self, hash: CryptoHash, ) -> Pin<Box<dyn Future<Output = Result<Hashed<ConfirmedBlock>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the hashed certificate value with the given hash.

source

fn read_blob<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<Blob, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the blob with the given blob ID.

source

fn read_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Blob>>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reads the blobs with the given blob IDs.

source

fn read_blob_state<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, ) -> Pin<Box<dyn Future<Output = Result<BlobState, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the blob state with the given blob ID.

source

fn read_blob_states<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], ) -> Pin<Box<dyn Future<Output = Result<Vec<BlobState>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reads the blob states with the given blob IDs.

source

fn read_hashed_confirmed_blocks_downward<'life0, 'async_trait>( &'life0 self, from: CryptoHash, limit: u32, ) -> Pin<Box<dyn Future<Output = Result<Vec<Hashed<ConfirmedBlock>>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the hashed certificate values in descending order from the given hash.

source

fn write_blob<'life0, 'life1, 'async_trait>( &'life0 self, blob: &'life1 Blob, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes the given blob.

source

fn write_blobs_and_certificate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, blobs: &'life1 [Blob], certificate: &'life2 ConfirmedBlockCertificate, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Writes blobs and certificate

source

fn write_blob_state<'life0, 'life1, 'async_trait>( &'life0 self, blob_id: BlobId, blob_state: &'life1 BlobState, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes the given blob state.

source

fn maybe_write_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blobs: &'life1 [Blob], ) -> Pin<Box<dyn Future<Output = Result<Vec<bool>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes the given blobs, but only if they already have a blob state. Returns true for the blobs that were written.

source

fn maybe_write_blob_state<'life0, 'async_trait>( &'life0 self, blob_id: BlobId, blob_state: BlobState, ) -> Pin<Box<dyn Future<Output = Result<Epoch, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempts to write the given blob state. Returns the latest Epoch to have used this blob.

source

fn maybe_write_blob_states<'life0, 'life1, 'async_trait>( &'life0 self, blob_ids: &'life1 [BlobId], blob_state: BlobState, overwrite: bool, ) -> Pin<Box<dyn Future<Output = Result<Vec<Epoch>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Attempts to write the given blob state. Returns the latest Epoch to have used this blob.

source

fn write_blobs<'life0, 'life1, 'async_trait>( &'life0 self, blobs: &'life1 [Blob], ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes several blobs.

source

fn contains_certificate<'life0, 'async_trait>( &'life0 self, hash: CryptoHash, ) -> Pin<Box<dyn Future<Output = Result<bool, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Tests existence of the certificate with the given hash.

source

fn read_certificate<'life0, 'async_trait>( &'life0 self, hash: CryptoHash, ) -> Pin<Box<dyn Future<Output = Result<ConfirmedBlockCertificate, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the certificate with the given hash.

source

fn read_certificates<'life0, 'async_trait, I>( &'life0 self, hashes: I, ) -> Pin<Box<dyn Future<Output = Result<Vec<ConfirmedBlockCertificate>, ViewError>> + Send + 'async_trait>>
where I: 'async_trait + IntoIterator<Item = CryptoHash> + Send, Self: 'async_trait, 'life0: 'async_trait,

Reads a number of certificates

source

fn read_event<'life0, 'async_trait>( &'life0 self, id: EventId, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the event with the given ID.

source

fn write_events<'life0, 'async_trait>( &'life0 self, events: impl 'async_trait + IntoIterator<Item = (EventId, Vec<u8>)> + Send, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Writes a vector of events.

source

fn wasm_runtime(&self) -> Option<WasmRuntime>

Selects the WebAssembly runtime to use for applications (if any).

Provided Methods§

source

fn load_active_chain<'life0, 'async_trait>( &'life0 self, id: ChainId, ) -> Pin<Box<dyn Future<Output = Result<ChainStateView<Self::Context>, ChainError>> + Send + 'async_trait>>
where ChainRuntimeContext<Self>: ExecutionRuntimeContext, Self: Sync + 'async_trait, 'life0: 'async_trait,

Loads the view of a chain state and checks that it is active.

§Notes

Each time this method is called, a new ChainStateView is created. If there are multiple instances of the same chain active at any given moment, they will race to access persistent storage. This can lead to invalid states and data corruption.

Other methods that also create ChainStateView instances that can cause conflicts are: load_chain and create_chain.

source

fn create_chain<'life0, 'async_trait>( &'life0 self, committee: Committee, admin_id: ChainId, description: ChainDescription, owner: Owner, balance: Amount, timestamp: Timestamp, ) -> Pin<Box<dyn Future<Output = Result<(), ChainError>> + Send + 'async_trait>>
where ChainRuntimeContext<Self>: ExecutionRuntimeContext, Self: Sync + 'async_trait, 'life0: 'async_trait,

Initializes a chain in a simple way (used for testing and to create a genesis state).

§Notes

This method creates a new ChainStateView instance. If there are multiple instances of the same chain active at any given moment, they will race to access persistent storage. This can lead to invalid states and data corruption.

Other methods that also create ChainStateView instances that can cause conflicts are: load_chain and load_active_chain.

source

fn load_contract<'life0, 'life1, 'async_trait>( &'life0 self, application_description: &'life1 UserApplicationDescription, ) -> Pin<Box<dyn Future<Output = Result<UserContractCode, ExecutionError>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Creates a UserContractCode instance using the bytecode in storage referenced by the application_description.

source

fn load_service<'life0, 'life1, 'async_trait>( &'life0 self, application_description: &'life1 UserApplicationDescription, ) -> Pin<Box<dyn Future<Output = Result<UserServiceCode, ExecutionError>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Creates a [linera-sdk::UserContract] instance using the bytecode in storage referenced by the application_description.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Store, C> Storage for DbStorage<Store, C>
where Store: KeyValueStore + Clone + Send + Sync + 'static, C: Clock + Clone + Send + Sync + 'static, Store::Error: Send + Sync,

§

type Context = ViewContext<ChainRuntimeContext<DbStorage<Store, C>>, Store>

§

type Clock = C