Struct miden_node_store::state::State
source · pub struct State { /* private fields */ }Expand description
The rollup state
Implementations§
source§impl State
impl State
sourcepub async fn load(
db: Db,
block_store: Arc<BlockStore>,
) -> Result<Self, StateInitializationError>
pub async fn load( db: Db, block_store: Arc<BlockStore>, ) -> Result<Self, StateInitializationError>
Loads the state from the db.
sourcepub async fn apply_block(&self, block: Block) -> Result<(), ApplyBlockError>
pub async fn apply_block(&self, block: Block) -> Result<(), ApplyBlockError>
Apply changes of a new block to the DB and in-memory data structures.
§Note on state consistency
The server contains in-memory representations of the existing trees, the in-memory representation must be kept consistent with the committed data, this is necessary so to provide consistent results for all endpoints. In order to achieve consistency, the following steps are used:
- the request data is validated, prior to starting any modifications.
- block is being saved into the store in parallel with updating the DB, but before committing. This block is considered as candidate and not yet available for reading because the latest block pointer is not updated yet.
- a transaction is open in the DB and the writes are started.
- while the transaction is not committed, concurrent reads are allowed, both the DB and the in-memory representations, which are consistent at this stage.
- prior to committing the changes to the DB, an exclusive lock to the in-memory data is acquired, preventing concurrent reads to the in-memory data, since that will be out-of-sync w.r.t. the DB.
- the DB transaction is committed, and requests that read only from the DB can proceed to use the fresh data.
- the in-memory structures are updated, including the latest block pointer and the lock is released.
sourcepub async fn get_block_header(
&self,
block_num: Option<BlockNumber>,
include_mmr_proof: bool,
) -> Result<(Option<BlockHeader>, Option<MmrProof>), GetBlockHeaderError>
pub async fn get_block_header( &self, block_num: Option<BlockNumber>, include_mmr_proof: bool, ) -> Result<(Option<BlockHeader>, Option<MmrProof>), GetBlockHeaderError>
Queries a BlockHeader from the database, and returns it alongside its inclusion proof.
If None is given as the value of block_num, the data for the latest BlockHeader is
returned.
sourcepub async fn check_nullifiers(&self, nullifiers: &[Nullifier]) -> Vec<SmtProof>
pub async fn check_nullifiers(&self, nullifiers: &[Nullifier]) -> Vec<SmtProof>
Generates membership proofs for each one of the nullifiers against the latest nullifier
tree.
Note: these proofs are invalidated once the nullifier tree is modified, i.e. on a new block.
sourcepub async fn get_notes_by_id(
&self,
note_ids: Vec<NoteId>,
) -> Result<Vec<NoteRecord>, DatabaseError>
pub async fn get_notes_by_id( &self, note_ids: Vec<NoteId>, ) -> Result<Vec<NoteRecord>, DatabaseError>
Queries a list of NoteRecord from the database.
If the provided list of NoteId given is empty or no NoteRecord matches the provided NoteId an empty list is returned.
sourcepub async fn sync_state(
&self,
block_num: BlockNumber,
account_ids: &[AccountId],
note_tag_prefixes: &[u32],
nullifier_prefixes: &[u32],
) -> Result<(StateSyncUpdate, MmrDelta), StateSyncError>
pub async fn sync_state( &self, block_num: BlockNumber, account_ids: &[AccountId], note_tag_prefixes: &[u32], nullifier_prefixes: &[u32], ) -> Result<(StateSyncUpdate, MmrDelta), StateSyncError>
Loads data to synchronize a client.
The client’s request contains a list of tag prefixes, this method will return the first block with a matching tag, or the chain tip. All the other values are filter based on this block range.
§Arguments
block_num: The last block know by the client, updates start from the next block.account_ids: Include the account’s hash if their last change was in the result’s block range.note_tag_prefixes: Only the 16 high bits of the tags the client is interested in, result will include notes with matching prefixes, the first block with a matching note determines the block range.nullifier_prefixes: Only the 16 high bits of the nullifiers the client is interested in, results will include nullifiers matching prefixes produced in the given block range.
sourcepub async fn get_block_inputs(
&self,
account_ids: &[AccountId],
nullifiers: &[Nullifier],
unauthenticated_notes: Vec<NoteId>,
) -> Result<BlockInputs, GetBlockInputsError>
pub async fn get_block_inputs( &self, account_ids: &[AccountId], nullifiers: &[Nullifier], unauthenticated_notes: Vec<NoteId>, ) -> Result<BlockInputs, GetBlockInputsError>
Returns data needed by the block producer to construct and prove the next block.
sourcepub async fn get_transaction_inputs(
&self,
account_id: AccountId,
nullifiers: &[Nullifier],
unauthenticated_notes: Vec<NoteId>,
) -> Result<TransactionInputs, DatabaseError>
pub async fn get_transaction_inputs( &self, account_id: AccountId, nullifiers: &[Nullifier], unauthenticated_notes: Vec<NoteId>, ) -> Result<TransactionInputs, DatabaseError>
Returns data needed by the block producer to verify transactions validity.
sourcepub async fn list_nullifiers(
&self,
) -> Result<Vec<(Nullifier, u32)>, DatabaseError>
pub async fn list_nullifiers( &self, ) -> Result<Vec<(Nullifier, u32)>, DatabaseError>
Lists all known nullifiers with their inclusion blocks, intended for testing.
sourcepub async fn list_accounts(&self) -> Result<Vec<AccountInfo>, DatabaseError>
pub async fn list_accounts(&self) -> Result<Vec<AccountInfo>, DatabaseError>
Lists all known accounts, with their ids, latest state hash, and block at which the account was last modified, intended for testing.
sourcepub async fn list_notes(&self) -> Result<Vec<NoteRecord>, DatabaseError>
pub async fn list_notes(&self) -> Result<Vec<NoteRecord>, DatabaseError>
Lists all known notes, intended for testing.
sourcepub async fn get_account_details(
&self,
id: AccountId,
) -> Result<AccountInfo, DatabaseError>
pub async fn get_account_details( &self, id: AccountId, ) -> Result<AccountInfo, DatabaseError>
Returns details for public (on-chain) account.
sourcepub async fn load_block(
&self,
block_num: BlockNumber,
) -> Result<Option<Vec<u8>>, DatabaseError>
pub async fn load_block( &self, block_num: BlockNumber, ) -> Result<Option<Vec<u8>>, DatabaseError>
Loads a block from the block store. Return Ok(None) if the block is not found.
sourcepub async fn latest_block_num(&self) -> BlockNumber
pub async fn latest_block_num(&self) -> BlockNumber
Returns the latest block number.
Auto Trait Implementations§
impl !Freeze for State
impl !RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl !UnwindSafe for State
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Requestsource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightBlack.
§Example
println!("{}", value.bright_black());source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightGreen.
§Example
println!("{}", value.bright_green());source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightYellow.
§Example
println!("{}", value.bright_yellow());source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightMagenta.
§Example
println!("{}", value.bright_magenta());source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightWhite.
§Example
println!("{}", value.bright_white());source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightBlack.
§Example
println!("{}", value.on_bright_black());source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightGreen.
§Example
println!("{}", value.on_bright_green());source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightYellow.
§Example
println!("{}", value.on_bright_yellow());source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightBlue.
§Example
println!("{}", value.on_bright_blue());source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightMagenta.
§Example
println!("{}", value.on_bright_magenta());source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightCyan.
§Example
println!("{}", value.on_bright_cyan());source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightWhite.
§Example
println!("{}", value.on_bright_white());source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self with the
attr()
set to
Attribute::Underline.
§Example
println!("{}", value.underline());source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self with the
attr()
set to
Attribute::RapidBlink.
§Example
println!("{}", value.rapid_blink());source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);