Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,563 changes: 395 additions & 2,168 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ path = "src/tools/tree_validator/main.rs"
ark-serialize = "0.5"
ark-bn254 = "0.5"

anchor-lang = "0.29.0"
anyhow = "1.0.79"
async-std = { version = "1", features = ["attributes", "tokio1"] }
async-trait = "0.1.85"
Expand Down Expand Up @@ -81,15 +80,14 @@ solana-pubkey = "2.3.0"

solana-transaction-status = "1.18.0"

light-zero-copy = { version = "0.4.0", features = ["solana"] }
light-concurrent-merkle-tree = { version = "3.0.0", features = ["solana"] }
light-batched-merkle-tree = { version = "0.5.0", features = ["solana"] }
light-merkle-tree-metadata = { version = "0.5.0", features = ["solana"] }
light-compressed-account = { version = "0.5.0", features = ["anchor"] }
light-hasher = { version = "4.0.0", features = ["solana"] }
light-zero-copy = { version = "0.4.0" }
light-concurrent-merkle-tree = { version = "3.0.0" }
light-batched-merkle-tree = { version = "0.5.0" }
light-merkle-tree-metadata = { version = "0.5.0" }
light-compressed-account = { version = "0.5.0" }
light-hasher = { version = "4.0.0" }
light-poseidon = "0.3.0"
light-indexed-merkle-tree = "3.0.0"
account-compression = "2.0.0"

sqlx = { version = "0.6.2", features = [
"macros",
Expand Down
2 changes: 1 addition & 1 deletion src/api/method/get_multiple_new_address_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub async fn get_multiple_new_address_proofs_helper(
let queued_address = SerializablePubkey::try_from(queued_address)?;
return Err(PhotonApiError::ValidationError(format!(
"Address {} already exists",
address
queued_address
)));
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/common/typedefs/serializable_pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ impl SerializablePubkey {
}
}

impl anchor_lang::AnchorDeserialize for SerializablePubkey {
impl BorshDeserialize for SerializablePubkey {
fn deserialize(buf: &mut &[u8]) -> Result<Self, std::io::Error> {
<SolanaPubkey as BorshDeserialize>::deserialize(buf).map(SerializablePubkey)
if buf.len() < 32 {
return Err(std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
"Buffer underflow",
));
}
let (pubkey_bytes, rest) = buf.split_at(32);
*buf = rest;
let array: [u8; 32] = pubkey_bytes.try_into().expect("slice with incorrect length");
Ok(SerializablePubkey(SolanaPubkey::new_from_array(array)))
}

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, std::io::Error> {
Expand All @@ -41,7 +50,7 @@ impl anchor_lang::AnchorDeserialize for SerializablePubkey {
}
}

impl anchor_lang::AnchorSerialize for SerializablePubkey {
impl borsh::BorshSerialize for SerializablePubkey {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> Result<(), std::io::Error> {
writer.write_all(&self.0.to_bytes())
}
Comment on lines +44 to 47
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

write_all needs the Write trait in scope here.
writer.write_all will not compile until the Write trait is imported or the call is fully qualified. Please update the call accordingly.

-        writer.write_all(&self.0.to_bytes())
+        std::io::Write::write_all(writer, &self.0.to_bytes())
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
impl borsh::BorshSerialize for SerializablePubkey {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> Result<(), std::io::Error> {
writer.write_all(&self.0.to_bytes())
}
impl borsh::BorshSerialize for SerializablePubkey {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> Result<(), std::io::Error> {
std::io::Write::write_all(writer, &self.0.to_bytes())
}
🤖 Prompt for AI Agents
In src/common/typedefs/serializable_pubkey.rs around lines 53 to 56, the call to
writer.write_all(...) requires the Write trait to be in scope; either add use
std::io::Write; at the top of the file or change the call to the fully-qualified
form std::io::Write::write_all(writer, &self.0.to_bytes()); make that single
change so the serialize method compiles without altering the method signature.

Expand Down Expand Up @@ -109,7 +118,7 @@ impl From<[u8; 32]> for SerializablePubkey {

impl From<LightPubkey> for SerializablePubkey {
fn from(pubkey: LightPubkey) -> Self {
SerializablePubkey(pubkey.into())
SerializablePubkey(SolanaPubkey::from(pubkey.to_bytes()))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/typedefs/token_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anchor_lang::{AnchorDeserialize, AnchorSerialize};
use borsh::{BorshDeserialize, BorshSerialize};
use num_enum::TryFromPrimitive;
use serde::Serialize;
use utoipa::ToSchema;
Expand All @@ -14,8 +14,8 @@ use super::{
Debug,
PartialEq,
Eq,
AnchorSerialize,
AnchorDeserialize,
BorshSerialize,
BorshDeserialize,
TryFromPrimitive,
ToSchema,
Serialize,
Expand All @@ -31,7 +31,7 @@ pub enum AccountState {
}

#[derive(
Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize, Clone, ToSchema, Serialize, Default,
Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, Clone, ToSchema, Serialize, Default,
)]
#[serde(rename_all = "camelCase")]
pub struct TokenData {
Expand Down
4 changes: 2 additions & 2 deletions src/common/typedefs/unsigned_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'de> Deserialize<'de> for UnsignedInteger {
}
}

impl anchor_lang::AnchorDeserialize for UnsignedInteger {
impl borsh::BorshDeserialize for UnsignedInteger {
fn deserialize(buf: &mut &[u8]) -> Result<Self, std::io::Error> {
if buf.len() < 8 {
return Err(std::io::Error::new(
Expand All @@ -85,7 +85,7 @@ impl anchor_lang::AnchorDeserialize for UnsignedInteger {
}
}

impl anchor_lang::AnchorSerialize for UnsignedInteger {
impl borsh::BorshSerialize for UnsignedInteger {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> Result<(), std::io::Error> {
writer.write_all(&self.0.to_le_bytes())
}
Expand Down
34 changes: 17 additions & 17 deletions src/ingester/parser/indexer_events.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/// Copied from the Light repo. We copy them instead of importing from the Light repo in order
/// to avoid having to import all of Light's dependencies.
use anchor_lang::prelude::*;
use borsh::{BorshDeserialize, BorshSerialize};
use light_compressed_account::indexer_event::event::{BatchNullifyContext, NewAddress};
use solana_pubkey::Pubkey;
use light_compressed_account::Pubkey;

#[derive(Debug, PartialEq, Eq, Default, Clone, AnchorSerialize, AnchorDeserialize)]
#[derive(Debug, PartialEq, Eq, Default, Clone, BorshSerialize, BorshDeserialize)]
pub struct OutputCompressedAccountWithPackedContext {
pub compressed_account: CompressedAccount,
pub merkle_tree_index: u8,
}

#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, Default, Eq, PartialEq)]
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, Default, Eq, PartialEq)]
pub struct MerkleTreeSequenceNumberV2 {
pub tree_pubkey: Pubkey,
pub queue_pubkey: Pubkey,
pub tree_type: u64,
pub seq: u64,
}

#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, Default, Eq, PartialEq)]
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, Default, Eq, PartialEq)]
pub struct MerkleTreeSequenceNumberV1 {
pub pubkey: Pubkey,
pub seq: u64,
}

#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, Eq, PartialEq)]
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, Eq, PartialEq)]
pub enum MerkleTreeSequenceNumber {
V1(MerkleTreeSequenceNumberV1),
V2(MerkleTreeSequenceNumberV2),
Expand All @@ -45,7 +45,7 @@ impl MerkleTreeSequenceNumber {
}
}

#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, Default, PartialEq, Eq)]
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, Default, PartialEq, Eq)]
pub struct PublicTransactionEvent {
pub input_compressed_account_hashes: Vec<[u8; 32]>,
pub output_compressed_account_hashes: Vec<[u8; 32]>,
Expand All @@ -70,15 +70,15 @@ pub struct BatchPublicTransactionEvent {
pub batch_input_accounts: Vec<BatchNullifyContext>,
}

#[derive(Debug, PartialEq, Eq, Default, Clone, AnchorSerialize, AnchorDeserialize)]
#[derive(Debug, PartialEq, Eq, Default, Clone, BorshSerialize, BorshDeserialize)]
pub struct CompressedAccount {
pub owner: Pubkey,
pub lamports: u64,
pub address: Option<[u8; 32]>,
pub data: Option<CompressedAccountData>,
}

#[derive(Debug, PartialEq, Eq, Default, Clone, AnchorSerialize, AnchorDeserialize)]
#[derive(Debug, PartialEq, Eq, Default, Clone, BorshSerialize, BorshDeserialize)]
pub struct CompressedAccountData {
pub discriminator: [u8; 8],
pub data: Vec<u8>,
Expand All @@ -89,7 +89,7 @@ pub struct CompressedAccountData {
/// [`StateMerkleTree`](light_merkle_tree_program::state::StateMerkleTree)
/// change. Indexers can use this type of events to re-build a non-sparse
/// version of the state Merkle tree.
#[derive(AnchorDeserialize, AnchorSerialize, Clone, Eq, PartialEq, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, Eq, PartialEq, Debug)]
#[repr(C)]
pub enum MerkleTreeEvent {
V1(ChangelogEvent),
Expand All @@ -102,14 +102,14 @@ pub enum MerkleTreeEvent {

/// Node of the Merkle path with an index representing the position in a
/// non-sparse Merkle tree.
#[derive(AnchorDeserialize, AnchorSerialize, Clone, Debug, Eq, PartialEq)]
#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, Eq, PartialEq)]
pub struct PathNode {
pub node: [u8; 32],
pub index: u32,
}

/// Version 1 of the [`ChangelogEvent`](light_merkle_tree_program::state::ChangelogEvent).
#[derive(AnchorDeserialize, AnchorSerialize, PartialEq, Eq, Clone, Debug)]
#[derive(BorshDeserialize, BorshSerialize, PartialEq, Eq, Clone, Debug)]
pub struct ChangelogEvent {
/// Public key of the tree.
pub id: [u8; 32],
Expand All @@ -121,7 +121,7 @@ pub struct ChangelogEvent {
pub index: u32,
}

#[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Clone, Debug)]
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug)]
pub struct NullifierEvent {
/// Public key of the tree.
pub id: [u8; 32],
Expand All @@ -134,15 +134,15 @@ pub struct NullifierEvent {
pub seq: u64,
}

#[derive(Debug, Default, Clone, Copy, AnchorSerialize, AnchorDeserialize, Eq, PartialEq)]
#[derive(Debug, Default, Clone, Copy, BorshSerialize, BorshDeserialize, Eq, PartialEq)]
pub struct RawIndexedElement {
pub value: [u8; 32],
pub next_index: usize,
pub next_value: [u8; 32],
pub index: usize,
}

#[derive(AnchorDeserialize, AnchorSerialize, PartialEq, Eq, Debug, Clone)]
#[derive(BorshDeserialize, BorshSerialize, PartialEq, Eq, Debug, Clone)]
pub struct IndexedMerkleTreeUpdate {
pub new_low_element: RawIndexedElement,
/// Leaf hash in new_low_element.index.
Expand All @@ -153,7 +153,7 @@ pub struct IndexedMerkleTreeUpdate {
pub new_high_element_hash: [u8; 32],
}

#[derive(AnchorDeserialize, AnchorSerialize, Clone, PartialEq, Eq, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Eq, Debug)]
pub struct IndexedMerkleTreeEvent {
/// Public key of the tree.
pub id: [u8; 32],
Expand All @@ -165,7 +165,7 @@ pub struct IndexedMerkleTreeEvent {
}

#[repr(C)]
#[derive(AnchorDeserialize, AnchorSerialize, Debug, PartialEq, Clone, Eq)]
#[derive(BorshDeserialize, BorshSerialize, Debug, PartialEq, Clone, Eq)]
pub struct BatchEvent {
pub merkle_tree_pubkey: [u8; 32],
pub batch_index: u64,
Expand Down
9 changes: 5 additions & 4 deletions src/ingester/parser/tx_event_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ingester::parser::state_update::{AccountTransaction, StateUpdate};
use crate::ingester::parser::tree_info::TreeInfo;
use crate::ingester::parser::{get_compression_program_id, NOOP_PROGRAM_ID};
use crate::ingester::typedefs::block_info::{Instruction, TransactionInfo};
use anchor_lang::AnchorDeserialize;
use borsh::BorshDeserialize;
use light_compressed_account::TreeType;
use log::info;
use solana_sdk::signature::Signature;
Expand Down Expand Up @@ -74,19 +74,20 @@ where
.zip(transaction_event.output_leaf_indices.iter())
{
let tree = transaction_event.pubkey_array[out_account.merkle_tree_index as usize];
let tree_and_queue = match TreeInfo::get_by_pubkey(conn, &tree)
let tree_solana = solana_pubkey::Pubkey::new_from_array(tree.to_bytes());
let tree_and_queue = match TreeInfo::get_by_pubkey(conn, &tree_solana)
.await
.map_err(|e| IngesterError::ParserError(format!("Failed to get tree info: {}", e)))?
{
Some(info) => info,
None => {
if super::SKIP_UNKNOWN_TREES {
log::warn!("Skipping unknown tree: {}", tree.to_string());
log::warn!("Skipping unknown tree: {}", tree_solana);
continue;
} else {
return Err(IngesterError::ParserError(format!(
"Missing queue for tree: {}",
tree.to_string()
tree_solana
)));
}
}
Expand Down
26 changes: 14 additions & 12 deletions src/ingester/parser/tx_event_parser_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ use light_compressed_account::Pubkey as LightPubkey;
use solana_pubkey::Pubkey;
use solana_sdk::signature::Signature;

// Helper function for pubkey conversion
fn to_light_pubkey(pubkey: &Pubkey) -> LightPubkey {
LightPubkey::from(pubkey.to_bytes())
}

pub fn parse_public_transaction_event_v2(
program_ids: &[Pubkey],
instructions: &[Vec<u8>],
accounts: Vec<Vec<Pubkey>>,
) -> Option<Vec<BatchPublicTransactionEvent>> {
let light_program_ids: Vec<LightPubkey> = program_ids.iter().map(|p| (*p).into()).collect();
let light_program_ids: Vec<LightPubkey> = program_ids.iter().map(|p| to_light_pubkey(p)).collect();
let light_accounts: Vec<Vec<LightPubkey>> = accounts
.into_iter()
.map(|acc_vec| acc_vec.into_iter().map(|acc| acc.into()).collect())
.map(|acc_vec| acc_vec.into_iter().map(|acc| to_light_pubkey(&acc)).collect())
.collect();
let events =
event_from_light_transaction(&light_program_ids, instructions, light_accounts).ok()?;
Expand All @@ -44,7 +49,7 @@ pub fn parse_public_transaction_event_v2(
.iter()
.map(|x| OutputCompressedAccountWithPackedContext {
compressed_account: CompressedAccount {
owner: x.compressed_account.owner.into(),
owner: x.compressed_account.owner,
lamports: x.compressed_account.lamports,
address: x.compressed_account.address,
data: x.compressed_account.data.as_ref().map(|d| {
Expand All @@ -64,7 +69,7 @@ pub fn parse_public_transaction_event_v2(
.sequence_numbers
.iter()
.map(|x| MerkleTreeSequenceNumberV1 {
pubkey: x.tree_pubkey.into(),
pubkey: x.tree_pubkey,
seq: x.seq,
})
.collect(),
Expand All @@ -75,10 +80,7 @@ pub fn parse_public_transaction_event_v2(
.compress_or_decompress_lamports,
pubkey_array: public_transaction_event
.event
.pubkey_array
.into_iter()
.map(|p| p.into())
.collect(),
.pubkey_array,
message: public_transaction_event.event.message,
};

Expand All @@ -89,8 +91,8 @@ pub fn parse_public_transaction_event_v2(
.input_sequence_numbers
.iter()
.map(|x| MerkleTreeSequenceNumberV2 {
tree_pubkey: x.tree_pubkey.into(),
queue_pubkey: x.queue_pubkey.into(),
tree_pubkey: x.tree_pubkey,
queue_pubkey: x.queue_pubkey,
tree_type: x.tree_type,
seq: x.seq,
})
Expand All @@ -99,8 +101,8 @@ pub fn parse_public_transaction_event_v2(
.address_sequence_numbers
.iter()
.map(|x| MerkleTreeSequenceNumberV2 {
tree_pubkey: x.tree_pubkey.into(),
queue_pubkey: x.queue_pubkey.into(),
tree_pubkey: x.tree_pubkey,
queue_pubkey: x.queue_pubkey,
tree_type: x.tree_type,
seq: x.seq,
})
Expand Down
1 change: 1 addition & 0 deletions src/monitor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod queue_hash_cache;
mod queue_monitor;
pub mod tree_metadata_sync;
pub mod v1_tree_accounts;

use std::{
sync::{
Expand Down
Loading
Loading