Skip to content
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: utxo to compressed account #544

Merged
merged 9 commits into from
Mar 28, 2024
Merged

Conversation

ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Mar 20, 2024

Changes:

  • replaced utxo with compressed account both in variables and comments
  • refactored tlv
  • commented serialized utxos and optimized instruction

@ananas-block ananas-block force-pushed the jorrit/refactor-utxo branch from 2b30c90 to 5f68101 Compare March 20, 2024 21:48
Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found some nits. not urgent but sharing for visibility regardless

};
};
},
{
name: 'outUtxos';
name: 'outputAccountHashes';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistency w input equivalent,

outputAccountHashes -> outputCompressedAccountHashes

type: {
vec: 'u64';
};
name: 'indexMtAccount';
Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (consistency) elsewhere a similar value is used in outputStateMerkleTreeAccountIndices

@SwenSchaeferjohann SwenSchaeferjohann force-pushed the jorrit/refactor-utxo branch 2 times, most recently from f0f35b1 to 5f68101 Compare March 22, 2024 22:55
pub tlv_data: TlvDataElement,
}

// TODO: parse utxos a more efficient way, since owner is sent multiple times this way
#[derive(Debug)]
#[account]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the struct InstructionDataTransfer is now used by the cpiSignatureAccount, so tagging it as anchor account breaks the IDL.
instead, we can tag it as regular type with AnchorDeserialize,also allows us to not have to prepend 8 bytes when deserializing and can use ::deserialize instead of try_deserialize_unchecked()

@@ -243,19 +241,20 @@ pub struct TransferInstruction<'info> {
pub self_program: Program<'info, crate::program::PspCompressedToken>,
}

// TODO: parse utxos a more efficient way, since owner is sent multiple times this way
// TODO: parse compressed_accounts a more efficient way, since owner is sent multiple times this way
// This struct is equivalent to the InstructionDataTransfer, but uses the imported types from the psp_compressed_pda
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)]
pub struct InstructionDataTransfer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we give this struct the same name as in compress-pda, we break the IDL.
(previously it just didn't break because compressed-pda was defining its InstructionDataTransfer struct as account not as type)
In my feature branch, I've temporarily renamed this to CompressedTokenInstructionDataTransfer in order to fix the IDL. there's probably a better name for it tho.

Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some more comments on what i found while working on #548 re: fixing IDL

}

#[derive(Clone, Copy, Debug, PartialEq, Eq, AnchorSerialize, AnchorDeserialize)]
pub struct TokenTransferOutUtxo {
pub struct TokenTransferOutputData {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TokenTransferOutputData still has index_mt_account so we're currently sending the same data to the chain twice. once as part of the TokenTransferOutputData and once in the output_state_merkle_tree_account_indices of the InstructionDataTransfer of compressed-token in line 487

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

pub input_compressed_accounts: Vec<CompressedAccountWithMerkleContext>,
pub output_compressed_accounts: Vec<CompressedAccount>,
// index of Merkle tree account in remaining accounts
pub output_state_merkle_tree_account_indices: Vec<u8>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for these to be fully useful in the mock-rpc (i.e. client/mock-rpc doesn't have to fetch additional data) we'd also have to emit the output_nullifier_queue_indices
and put them into the pubkey_array... but onchain doesn't have access to that data AFAIK since its only needed for spending accounts. instead of finding a workaround for this we should prolly make the PublicTransactionEvent smaller again, not emit the output_queues, and not emit any of the redundant info at all either and just implement a few additional steps in the test-rpc. cc @ananas-block

@ananas-block ananas-block force-pushed the jorrit/refactor-utxo branch from 9fd61ce to d691e58 Compare March 27, 2024 14:20
@ananas-block ananas-block marked this pull request as ready for review March 27, 2024 18:00
ananas-block and others added 6 commits March 27, 2024 18:06
* fix: enabled group access control, added more tests

* Update programs/compressed-pda/src/compressed_account.rs

Co-authored-by: Swen Schäferjohann <[email protected]>

* Update programs/account-compression/src/instructions/insert_into_indexed_array.rs

Co-authored-by: Swen Schäferjohann <[email protected]>

---------

Co-authored-by: Swen Schäferjohann <[email protected]>
* fix: enabled group access control, added more tests

* feat: add address checks and insert logic

* removed prints
@ananas-block ananas-block force-pushed the jorrit/refactor-utxo branch from 0d00e28 to 8347826 Compare March 27, 2024 18:07
@ananas-block ananas-block force-pushed the jorrit/refactor-utxo branch from 2cb969c to fa66793 Compare March 27, 2024 21:09
@ananas-block ananas-block force-pushed the jorrit/refactor-utxo branch from fa66793 to 03f10ad Compare March 27, 2024 21:21
Comment on lines 8 to 9
pub index_merkle_tree_account: u8,
pub index_nullifier_array_account: u8,
Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ananas-block should we just clean up the api now? i.e. merkle_tree_account_index and nullifier_array_account_index
such that the naming is consistent with _index suffix in leaf_index.

(and more consistent with use of nullifier queue elsewhere would be to do
nullifier_queue_account_index)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

pub relay_fee: Option<u64>,
pub de_compress_amount: Option<u64>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ananas-block do we want to add the is_compress: bool now?

@ananas-block ananas-block merged commit 31ea106 into main Mar 28, 2024
6 checks passed
@ananas-block ananas-block deleted the jorrit/refactor-utxo branch March 28, 2024 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants