pub struct BatchedQueueAccount<'a> {
pub value_vecs: [ZeroCopyVecU64<'a, [u8; 32]>; 2],
pub hash_chain_stores: [ZeroCopyVecU64<'a, [u8; 32]>; 2],
/* private fields */
}
Expand description
Batched queue zero copy account. Used for output queues in light protocol. Output queues store compressed account hashes, to be appended to the associated batched Merkle tree in batches with a zero-knowledge proof (zkp), ie. it stores hashes and commits these to hash chains. Each hash chain is used as public input for a batch append zkp.
An output queue is configured with:
- 2 batches
- 2 value vecs (one for each batch) value vec length = batch size
- 2 hash chain vecs (one for each batch) hash chain store length = batch size /zkp batch size
Default config:
- 50,000 batch size
- 500 zkp batch size
Initialization:
- an output queue is initialized in combination with a state Merkle tree
init_batched_state_merkle_tree_from_account_info
For deserialization use:
- in program:
output_from_account_info
- in client:
output_from_bytes
To insert a value the account compression program uses:
insert_into_current_batch
A compressed account can be spent or read while in the output queue.
To spend, the account compression program uses:
- check_leaf_index_could_exist_in_batches in combination with
prove_inclusion_by_index_and_zero_out_leaf
To read, light the system program uses:
prove_inclusion_by_index
Fields§
§value_vecs: [ZeroCopyVecU64<'a, [u8; 32]>; 2]
§hash_chain_stores: [ZeroCopyVecU64<'a, [u8; 32]>; 2]
Implementations§
Source§impl<'a> BatchedQueueAccount<'a>
impl<'a> BatchedQueueAccount<'a>
Sourcepub fn output_from_account_info<A: AccountInfoTrait>(
account_info: &A,
) -> Result<BatchedQueueAccount<'a>, BatchedMerkleTreeError>
pub fn output_from_account_info<A: AccountInfoTrait>( account_info: &A, ) -> Result<BatchedQueueAccount<'a>, BatchedMerkleTreeError>
Deserialize an output BatchedQueueAccount from account info. Should be used in solana programs. Checks that:
- the program owner is the light account compression program,
- discriminator,
- queue type is output queue type.
Sourcepub fn output_from_bytes(
account_data: &'a mut [u8],
) -> Result<BatchedQueueAccount<'a>, BatchedMerkleTreeError>
pub fn output_from_bytes( account_data: &'a mut [u8], ) -> Result<BatchedQueueAccount<'a>, BatchedMerkleTreeError>
Deserialize a BatchedQueueAccount from bytes. Should only be used in client. Checks the discriminator and queue type.
pub fn init( account_data: &'a mut [u8], metadata: QueueMetadata, output_queue_batch_size: u64, output_queue_zkp_batch_size: u64, num_iters: u64, bloom_filter_capacity: u64, pubkey: Pubkey, ) -> Result<BatchedQueueAccount<'a>, BatchedMerkleTreeError>
Sourcepub fn insert_into_current_batch(
&mut self,
hash_chain_value: &[u8; 32],
current_slot: &u64,
) -> Result<(), BatchedMerkleTreeError>
pub fn insert_into_current_batch( &mut self, hash_chain_value: &[u8; 32], current_slot: &u64, ) -> Result<(), BatchedMerkleTreeError>
Insert a value into the current batch of this output queue account.
- insert value into a value vec and hash chain store.
- Increment next_index.
Sourcepub fn prove_inclusion_by_index(
&mut self,
leaf_index: u64,
hash_chain_value: &[u8; 32],
) -> Result<bool, BatchedMerkleTreeError>
pub fn prove_inclusion_by_index( &mut self, leaf_index: u64, hash_chain_value: &[u8; 32], ) -> Result<bool, BatchedMerkleTreeError>
Proves inclusion of leaf index if it exists in one of the batches.
- Iterate over all batches
- Check if leaf index could exist in the batch. 2.1 If yes, check whether value at index is equal to hash_chain_value. Throw error if not.
- Return true if leaf index exists in one of the batches.
Note, this method does not fail but returns false
if the leaf index is out of range for any batch.
Sourcepub fn prove_inclusion_by_index_and_zero_out_leaf(
&mut self,
leaf_index: u64,
hash_chain_value: &[u8; 32],
prove_by_index: bool,
) -> Result<(), BatchedMerkleTreeError>
pub fn prove_inclusion_by_index_and_zero_out_leaf( &mut self, leaf_index: u64, hash_chain_value: &[u8; 32], prove_by_index: bool, ) -> Result<(), BatchedMerkleTreeError>
Zero out a leaf by index if it exists in the queues hash_chain_value vec. If prove_by_index is true fail if leaf is not found.
pub fn get_metadata(&self) -> &BatchedQueueMetadata
pub fn get_metadata_mut(&mut self) -> &mut BatchedQueueMetadata
Sourcepub fn get_num_inserted_in_current_batch(&self) -> u64
pub fn get_num_inserted_in_current_batch(&self) -> u64
Returns the number of elements inserted in the current batch. If current batch state is inserted, returns 0.
Sourcepub fn is_associated(&self, pubkey: &Pubkey) -> bool
pub fn is_associated(&self, pubkey: &Pubkey) -> bool
Returns true if the pubkey is the associated Merkle tree of the queue.
Sourcepub fn check_is_associated(
&self,
pubkey: &Pubkey,
) -> Result<(), BatchedMerkleTreeError>
pub fn check_is_associated( &self, pubkey: &Pubkey, ) -> Result<(), BatchedMerkleTreeError>
Check if the pubkey is the associated Merkle tree of the queue.
Sourcepub fn tree_is_full(&self) -> bool
pub fn tree_is_full(&self) -> bool
Returns true if the tree is full.
Sourcepub fn check_tree_is_full(&self) -> Result<(), BatchedMerkleTreeError>
pub fn check_tree_is_full(&self) -> Result<(), BatchedMerkleTreeError>
Check if the tree is full.
pub fn pubkey(&self) -> &Pubkey
Methods from Deref<Target = BatchedQueueMetadata>§
Trait Implementations§
Source§impl<'a> Debug for BatchedQueueAccount<'a>
impl<'a> Debug for BatchedQueueAccount<'a>
Source§impl Deref for BatchedQueueAccount<'_>
impl Deref for BatchedQueueAccount<'_>
Source§impl DerefMut for BatchedQueueAccount<'_>
impl DerefMut for BatchedQueueAccount<'_>
Source§impl Discriminator for BatchedQueueAccount<'_>
impl Discriminator for BatchedQueueAccount<'_>
const LIGHT_DISCRIMINATOR: [u8; 8]
const LIGHT_DISCRIMINATOR_SLICE: &'static [u8] = b"queueacc"
fn discriminator() -> [u8; 8]
Source§impl<'a> PartialEq for BatchedQueueAccount<'a>
impl<'a> PartialEq for BatchedQueueAccount<'a>
impl<'a> StructuralPartialEq for BatchedQueueAccount<'a>
Auto Trait Implementations§
impl<'a> Freeze for BatchedQueueAccount<'a>
impl<'a> RefUnwindSafe for BatchedQueueAccount<'a>
impl<'a> Send for BatchedQueueAccount<'a>
impl<'a> Sync for BatchedQueueAccount<'a>
impl<'a> Unpin for BatchedQueueAccount<'a>
impl<'a> !UnwindSafe for BatchedQueueAccount<'a>
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> 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> 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.