pub struct GenericTreeServer<S: ShardStore<H = MerkleHashVote, CheckpointId = u32>> { /* private fields */ }Expand description
An append-only Poseidon Merkle tree server backed by any shardtree::store::ShardStore.
Use the type aliases TreeServer (KV-backed) and MemoryTreeServer
(in-memory) rather than naming this type directly.
Methods that mutate the tree return Result so storage failures are visible to
callers. For MemoryTreeServer the error type is Infallible, so those
results can be safely .unwrap()-ed; for TreeServer the error type is
crate::kv_shard_store::KvError and must be propagated.
Implementations§
Source§impl GenericTreeServer<KvShardStore>
impl GenericTreeServer<KvShardStore>
Sourcepub fn new(cb: KvCallbacks, next_position: u64) -> Self
pub fn new(cb: KvCallbacks, next_position: u64) -> Self
Create a new KV-backed tree server.
next_position is CommitmentTreeState.NextIndex from KV (0 on first
boot). On a cold start, latest_checkpoint is initialised from the
maximum checkpoint ID persisted in the KV store, so that root()
returns the correct value even before the first checkpoint after restart.
Source§impl GenericTreeServer<KvShardStore>
impl GenericTreeServer<KvShardStore>
Sourcepub fn append_from_kv(
&mut self,
cursor: u64,
count: u64,
) -> Result<(), AppendFromKvError>
pub fn append_from_kv( &mut self, cursor: u64, count: u64, ) -> Result<(), AppendFromKvError>
Append count leaves starting at cursor by reading them directly
from the application KV store via KV callbacks, skipping the Go-side
leaf fetch and CGO serialization round-trip.
Each leaf is stored at 0x02 || u64 BE index in the Cosmos KV store
(the CommitmentLeafKey format from types/keys.go). On success, the
tree’s internal leaf count advances by count.
This is the production delta-append path: a single CGO call to this
function replaces the newLeaves allocation + per-leaf KV read loop
that was previously done in ensureTreeLoaded.
Source§impl<S> GenericTreeServer<S>
impl<S> GenericTreeServer<S>
Sourcepub fn append(&mut self, leaf: Fp) -> Result<u64, ShardTreeError<S::Error>>
pub fn append(&mut self, leaf: Fp) -> Result<u64, ShardTreeError<S::Error>>
Append a single leaf (e.g. one VAN from MsgDelegateVote).
The leaf is marked so witnesses can be generated for it later. Returns the leaf index.
Sourcepub fn append_two(
&mut self,
first: Fp,
second: Fp,
) -> Result<u64, ShardTreeError<S::Error>>
pub fn append_two( &mut self, first: Fp, second: Fp, ) -> Result<u64, ShardTreeError<S::Error>>
Append two leaves (e.g. new VAN + VC from MsgCastVote).
Returns the index of the first leaf.
Sourcepub fn checkpoint(
&mut self,
height: u32,
) -> Result<(), CheckpointError<S::Error>>
pub fn checkpoint( &mut self, height: u32, ) -> Result<(), CheckpointError<S::Error>>
Snapshot the current tree state at the given block height.
Called by EndBlocker after processing all transactions in a block. The root at this checkpoint becomes a valid anchor for ZKP #2 / ZKP #3.
§Errors
Returns CheckpointError::NotMonotonic if height is not strictly
greater than the previous checkpoint height.
Returns CheckpointError::Tree if the underlying shard store fails.
Sourcepub fn root_at_height(&self, height: u32) -> Option<Fp>
pub fn root_at_height(&self, height: u32) -> Option<Fp>
Root at a specific checkpoint height (anchor lookup).
Returns None if the checkpoint does not exist.
Sourcepub fn set_next_position(&mut self, pos: u64)
pub fn set_next_position(&mut self, pos: u64)
Set the leaf count directly (e.g. to restore after a cold start when
next_position was not passed to TreeServer::new).
Auto Trait Implementations§
impl<S> Freeze for GenericTreeServer<S>where
S: Freeze,
impl<S> RefUnwindSafe for GenericTreeServer<S>where
S: RefUnwindSafe,
impl<S> Send for GenericTreeServer<S>where
S: Send,
impl<S> Sync for GenericTreeServer<S>where
S: Sync,
impl<S> Unpin for GenericTreeServer<S>where
S: Unpin,
impl<S> UnsafeUnpin for GenericTreeServer<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for GenericTreeServer<S>where
S: UnwindSafe,
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.