-
Notifications
You must be signed in to change notification settings - Fork 67
feat: compressible
proc macro draft
#1857
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
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
if rent_recipient.key != &crate::create_dynamic_pda::RENT_RECIPIENT { | ||
return Err(LightSdkError::ConstraintViolation); | ||
} |
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.
no need to check the recipient if it is part of the account.
We can trust data from Solana and compressed accounts.
for params in &new_address_params { | ||
let address_tree_account = cpi_accounts | ||
.get_tree_account_info(params.address_merkle_tree_account_index as usize)?; | ||
if address_tree_account.pubkey() != *expected_address_space { | ||
msg!( | ||
"Invalid address space. Expected: {}. Found: {}.", | ||
expected_address_space, | ||
address_tree_account.pubkey() | ||
); | ||
return Err(LightSdkError::ConstraintViolation); | ||
} | ||
} |
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.
instead of checking it we could also hardcode it as a constant
if pda_accounts.len() != addresses.len() | ||
|| pda_accounts.len() != new_address_params.len() | ||
|| pda_accounts.len() != output_state_tree_indices.len() | ||
{ | ||
return Err(LightSdkError::ConstraintViolation); | ||
} |
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.
It's probably more dev friendly to bundle these into a struct so that it's not possible to create len mismatches.
struct CompressingPda {
account_info: AccountInfo,
address_params: PackedNewAddressParams,
out_tree_index: u8,
}
proof: ValidityProof, | ||
cpi_accounts: CpiAccounts<'_, 'info>, | ||
owner_program: &Pubkey, | ||
rent_recipient: &AccountInfo<'info>, |
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.
it's probably ok if its just a Pubkey. With Solana and anchor entrypoint, it safes CU to pass fewer AccountInfos and use instruction data instead. We can zero copy instruction data but not AccountInfos.
// Zero the compressed account | ||
compressed_account.account = A::default(); |
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.
this doesn't properly zero the compressed account.
Option 1:
- create a new
LightAccount
struct which only holds the address and no data.
This will add a lot of zeroes to the light system program cpi.
Option 2:
- add
zero_out
orremove_data
method toLightAccount
which removes the data. - maybe we need to add and set a bool flag in
LightAccount
Option 2 is probably better because we should keep the discriminator attached to the address.
In either case the clients need to handle this case that they cannot deserialize the empty account struct from the fetched compressed account because photon will not return any zero bytes if we don't send them in the light system program cpi.
@@ -11,7 +11,7 @@ proc-macro2 = { workspace = true } | |||
quote = { workspace = true } | |||
syn = { workspace = true } | |||
solana-pubkey = { workspace = true, features = ["curve25519", "sha2"] } | |||
|
|||
heck = "0.4.1" |
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.
what da heck
pub last_written_slot: u64, | ||
pub compression_delay: u64, |
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.
we should provide a header struct.
struct Header {
pub discriminator: [u8;8], // debatable
pub rent_recipient: [u8;32],
pub last_written_slot: u64,
pub compression_delay: u64, // can make this a u32 because we can just add it on `last_written_slot`
pub updatable: bool,
pub compress_sol: bool,
pub version: Enum(u16)
_padding: [u8;4], // for memory alignment so that we can do a zero copy
}
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.
the header should not be part of the compressed account, and should not derive LightHasher
.
No description provided.