pub struct StateSync { /* private fields */ }Expand description
The state sync component encompasses the client’s sync logic. It is then used to request updates from the node and apply them to the relevant elements. The updates are then returned and can be applied to the store to persist the changes.
Implementations§
Source§impl StateSync
impl StateSync
Sourcepub fn new(
rpc_api: Arc<dyn NodeRpcClient>,
note_screener: Arc<dyn OnNoteReceived>,
tx_discard_delta: Option<u32>,
validator_config: ValidatorConfig,
) -> Self
pub fn new( rpc_api: Arc<dyn NodeRpcClient>, note_screener: Arc<dyn OnNoteReceived>, tx_discard_delta: Option<u32>, validator_config: ValidatorConfig, ) -> Self
Creates a new instance of the state sync component.
The nullifiers sync is enabled by default. To disable it, see
Self::disable_nullifier_sync.
§Arguments
rpc_api- The RPC client used to communicate with the node.note_screener- The note screener used to check the relevance of notes.tx_discard_delta- Number of blocks after which pending transactions are discarded.validator_config- The validator set and quorum the chain tip header must be signed by.
Sourcepub fn with_note_observer(self, observer: Arc<dyn NoteObserver>) -> Self
pub fn with_note_observer(self, observer: Arc<dyn NoteObserver>) -> Self
Attaches a NoteObserver to this sync component. Observers run in attachment order
before the screener verdict; failures are logged (tagged with NoteObserver::name) and
never abort sync.
Sourcepub fn disable_nullifier_sync(&mut self)
pub fn disable_nullifier_sync(&mut self)
Disables the nullifier sync.
When disabled, the component will not query the node for new nullifiers after each sync step. This is useful for clients that don’t need to track note consumption, such as faucets.
Sourcepub fn enable_nullifier_sync(&mut self)
pub fn enable_nullifier_sync(&mut self)
Enables the nullifier sync.
Sourcepub async fn sync_state(
&self,
current_partial_mmr: &mut PartialMmr,
input: StateSyncInput,
) -> Result<StateSyncUpdate, ClientError>
pub async fn sync_state( &self, current_partial_mmr: &mut PartialMmr, input: StateSyncInput, ) -> Result<StateSyncUpdate, ClientError>
Syncs the state of the client with the chain tip of the node, returning the updates that should be applied to the store.
Use Client::build_sync_input() to build the default
input, or assemble it manually for custom sync. The current_partial_mmr is taken by
mutable reference so callers can keep it in memory across syncs; it is only modified once
every check has passed.
During the sync process, the following steps are performed:
- Fetch sync data from the node (MMR delta, note inclusions, transactions).
- Update account states (fetch updated public accounts, flag mismatched private ones).
- Screen note inclusions via the configured
OnNoteReceivedcallback. - Process transaction inclusions (commit local txs, record external consumers, discard stale/expired txs, commit output notes).
- Recover the public notes a tracked account consumed but the client never tracked.
- Detect consumed notes via nullifier sync (optional, see
Self::disable_nullifier_sync). - Advance the partial MMR to the chain tip and track the screened blocks that still hold an unspent note.
Steps 1-2 are Self::fetch_state, 3-5 Self::derive_state_updates, 6
Self::fetch_nullifiers and 7 Self::build_update; each can be driven separately.
Sourcepub async fn fetch_state(
&self,
block_from: BlockNumber,
input: StateSyncInput,
) -> Result<ChainSyncData, ClientError>
pub async fn fetch_state( &self, block_from: BlockNumber, input: StateSyncInput, ) -> Result<ChainSyncData, ClientError>
Fetches the node’s view of everything that changed since block_from: the MMR delta, the
note inclusions, the transactions, and the account states.
Every node call that does not depend on note screening happens here, so a caller can run
this concurrently with another sync’s fetch. Interpreting the response is
Self::derive_state_updates’s, and the nullifier check Self::fetch_nullifiers’s. Both
run afterwards so a caller syncing more than one source can write the other source first,
and check nullifiers once across all of them.
Sourcepub async fn derive_state_updates(
&self,
chain_sync_data: &mut ChainSyncData,
) -> Result<(), ClientError>
pub async fn derive_state_updates( &self, chain_sync_data: &mut ChainSyncData, ) -> Result<(), ClientError>
Turns the node’s raw response into note and transaction updates.
Discards the local transactions the node superseded, screens the received notes for relevance, applies the transaction inclusions, and recovers the public notes the tracked accounts consumed, fetching those by id.
Sourcepub fn build_update(
chain_sync_data: ChainSyncData,
partial_mmr: &mut PartialMmr,
) -> Result<StateSyncUpdate, ClientError>
pub fn build_update( chain_sync_data: ChainSyncData, partial_mmr: &mut PartialMmr, ) -> Result<StateSyncUpdate, ClientError>
Verifies the fetched chain data against partial_mmr and turns it into the update to apply
to the store.
It applies the node’s delta, checks the resulting peaks against the chain tip header’s chain commitment, and tracks the screened note blocks that still hold an unspent note.
Sourcepub async fn fetch_nullifiers(
&self,
chain_sync_data: &mut ChainSyncData,
) -> Result<(), ClientError>
pub async fn fetch_nullifiers( &self, chain_sync_data: &mut ChainSyncData, ) -> Result<(), ClientError>
Checks the node for nullifiers of every note chain_sync_data could have consumed.
The query covers every note the tracker holds, including any the caller added from another sync path — so a transport-delivered note consumed within one sync is reported as consumed by that same sync.
No-op when the nullifier sync is disabled (see Self::disable_nullifier_sync) or when the
node reported no progress, since there is no block range to query.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for StateSync
impl !Send for StateSync
impl !Sync for StateSync
impl !UnwindSafe for StateSync
impl Freeze for StateSync
impl Unpin for StateSync
impl UnsafeUnpin for StateSync
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more