-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: zero copy vec #1469
refactor: zero copy vec #1469
Conversation
7c38f05
to
5e0c6de
Compare
|
||
/// `ZeroCopyVec` is a custom vector implementation which forbids | ||
/// post-initialization reallocations. The size is not known during compile | ||
/// time (that makes it different from arrays), but can be defined only once | ||
/// (that makes it different from [`Vec`](std::vec::Vec)). | ||
pub struct ZeroCopyVec<LEN, T> | ||
pub struct ZeroCopyVec<'a, L, T, const PAD: bool = true> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct ZeroCopyVec<'a, L, T, const PAD: bool = true> | |
#[repr(C)] | |
pub struct ZeroCopyVec<'a, L, T, const PAD: bool = true> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed all #[repr(C)]
in this crate since the structs ZeroCopySliceMut
, ZeroCopyVec
, and ZeroCopyCyclicVec
are not saved in bytes but just contain references in runtime.
zerocopy::Ref
doesn't derive #[repr(C)]
either see docs.
f2ce3e8
to
3f216d8
Compare
3f216d8
to
c3f5680
Compare
b950843
to
63e0a85
Compare
63e0a85
to
8dcceea
Compare
// // 15. functional - proof by index for account which is invalidated in the same tx | ||
// { | ||
// perform_create_pda_with_event( | ||
// &mut e2e_env.indexer, | ||
// &mut e2e_env.rpc, | ||
// &env, | ||
// &payer, | ||
// seed, | ||
// &data, | ||
// &ID, | ||
// None, | ||
// Some(vec![account_in_value_array.clone()]), | ||
// CreatePdaMode::ReadOnlyProofOfInsertedAccount, | ||
// ) | ||
// .await | ||
// .unwrap(); | ||
// } | ||
println!("post 15"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
// Doesn't yield the expected result due to unclean test setup | ||
// // 18. functional - 1 read only account by zkp 3 regular inputs && failing - zkp for invalidated account | ||
// { | ||
// let seed = [254u8; 32]; | ||
// let data = [5u8; 31]; | ||
// let mut input_accounts = Vec::new(); | ||
// let compressed_accounts = e2e_env.indexer.get_compressed_accounts_by_owner(&ID); | ||
// for i in 0..100 { | ||
// let input_account_in_mt = compressed_accounts.iter().find(|x| { | ||
// x.merkle_context.leaf_index == i | ||
// && x.merkle_context.merkle_tree_pubkey == env.batched_state_merkle_tree | ||
// && x.merkle_context.leaf_index | ||
// != account_not_in_value_array_and_in_mt | ||
// .merkle_context | ||
// .leaf_index | ||
// }); | ||
// if let Some(input_account_in_mt) = input_account_in_mt.clone() { | ||
// input_accounts.push(input_account_in_mt.clone()); | ||
// } | ||
// if input_accounts.len() == 3 { | ||
// break; | ||
// } | ||
// } | ||
// let result = perform_create_pda_with_event( | ||
// &mut e2e_env.indexer, | ||
// &mut e2e_env.rpc, | ||
// &env, | ||
// &payer, | ||
// seed, | ||
// &data, | ||
// &ID, | ||
// Some(input_accounts), | ||
// Some(vec![account_not_in_value_array_and_in_mt.clone()]), | ||
// CreatePdaMode::ReadOnlyZkpOfInsertedAccount, | ||
// ) | ||
// .await; | ||
// assert_rpc_error( | ||
// result, | ||
// 1, | ||
// SystemProgramError::ReadOnlyAccountDoesNotExist.into(), | ||
// ) | ||
// .unwrap(); | ||
// } | ||
// // 12. failing - zkp for invalidated account | ||
// { | ||
// let result = perform_create_pda_with_event( | ||
// &mut e2e_env.indexer, | ||
// &mut e2e_env.rpc, | ||
// &env, | ||
// &payer, | ||
// seed, | ||
// &data, | ||
// &ID, | ||
// Some(vec![account_not_in_value_array_and_in_mt.clone()]), | ||
// Some(vec![account_not_in_value_array_and_in_mt.clone()]), | ||
// CreatePdaMode::ReadOnlyZkpOfInsertedAccount, | ||
// ) | ||
// .await; | ||
// assert_rpc_error( | ||
// result, | ||
// 1, | ||
// SystemProgramError::ReadOnlyAccountDoesNotExist.into(), | ||
// ) | ||
// .unwrap(); | ||
// } | ||
// println!("post 12"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
// // The transaction inserts the address first, then checks read only addresses. | ||
// let result = perform_create_pda_with_event( | ||
// &mut test_indexer, | ||
// &mut rpc, | ||
// &env, | ||
// &payer, | ||
// seed, | ||
// &data, | ||
// &ID, | ||
// None, | ||
// None, | ||
// CreatePdaMode::ReadOnlyProofOfInsertedAddress, | ||
// ) | ||
// .await; | ||
// assert_rpc_error( | ||
// result, | ||
// 0, | ||
// SystemProgramError::ReadOnlyAddressAlreadyExists.into(), | ||
// ) | ||
// .unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
Changes:
light-zero-copy
WrappedMutPointer
,WrappedPointer
zerocopy
crateZeroCopyTraits
const PAD: bool
inZeroCopyVec
,ZeroCopyMutSlice
andZeroCopyCyclicVec
zerocopy::Unaligned
forL
&T
batched-merkle-tree
ZeroCopyVecUsize
withZeroCopyVecU64
(usize is no longer supported)BatchMetadata
inMerkleTreeAccount
&QueueAccount
refactorWrappedMutPointer
->zerocopy::Ref<&mut [u8], T>
From<u64>
forBatchState
zerocopy
traits forBatch
(KnownLayout, Immutable, IntoBytes, FromBytes
)Batch
replacedBatchState
withu64
(to satisfy zerocopy traits)Batch
replacedbloom_filter_is_wiped
bool
withu8
and added getters and setters which returnbool
(zerocopy traits don't supportbool
)merkle-tree-metadata
light_utils::pubkey::Pubkey
instead ofsolana_program::pubkey:.Pubkey
for zero copy compatibilitylight_utils
Pubkey
with derived zerocopy traits,solana_program::pubkey::Pubkey
andanchor_lang::prelude::Pubkey
conversionsaccount-compression
programGroupAccess
returnPubkey
instead of&Pubkey
necessary so that we can convertlight_utils::pubkey::Pubkey
toanchor::prelude::Pubkey
(conversion is necessary because we need to derive zerocopy traits)light-batched-merkle-trees
forbatch_append
,insert-into-queues
,light-system-program
check_program_owner_state_merkle_tree
added generic condition to distinguish between append and nullify as an additional safeguard in case that invalid accounts are passedinvoke/processor.rs
(prior reading an account that is modified in the same tx would fail, same for reading an address which is created in the same tx)
check_vec_capacity
to check vector capacity (it's basically free in terms of CU)