Skip to content

Commit

Permalink
Update Solana SDK to 1.16 and Anchor to the latest change including it
Browse files Browse the repository at this point in the history
The newest solana-program crate was pulled unintentionally anyway
which resulted in unexpected errors due to incompatibility of
dependencies. More context: coral-xyz/anchor#2512
  • Loading branch information
vadorovsky committed Jun 6, 2023
1 parent a86a8a7 commit 3c6e33d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion light-merkle-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ description = "Sparse Merkle tree implementation"
license = "Apache-2.0"

[dependencies]
anchor-lang = "0.26"
anchor-lang = { git = "https://github.com/coral-xyz/anchor", rev = "1c6f86e5f7793ce6adefe9cbfa11939647c509ce" }
bytemuck = "1.13.1"

[dev-dependencies]
sha2 = "0.10"
Expand Down
37 changes: 37 additions & 0 deletions light-merkle-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::marker::PhantomData;
#[cfg(feature = "solana")]
use anchor_lang::prelude::*;

use bytemuck::{Pod, Zeroable};
use config::MerkleTreeConfig;
use hasher::{Hash, Hasher};

Expand All @@ -26,6 +27,7 @@ pub enum HashFunction {
// generics when generating IDL.
#[cfg_attr(feature = "solana", derive(AnchorSerialize, AnchorDeserialize))]
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
#[repr(C)]
pub struct MerkleTree<H, C>
where
H: Hasher,
Expand Down Expand Up @@ -153,6 +155,41 @@ where
}
}

/// The [`Pod`](bytemuck::Pod) trait is used under the hood by the
/// [`zero_copy`](anchor_lang::zero_copy) attribute macro and is required for
/// usage in zero-copy Solana accounts.
///
/// SAFETY: Generic parameters are used only as `PhantomData` and they don't
/// affect the layout of the struct nor its size or padding. The only reason
/// why we can't `#[derive(Pod)]` is because bytemuck is not aware of that and
/// it doesn't allow to derive `Pod` for structs with generic parameters.
/// Would be nice to fix that upstream:
/// https://github.com/Lokathor/bytemuck/issues/191
unsafe impl<H, C> Pod for MerkleTree<H, C>
where
H: Hasher + Copy + 'static,
C: MerkleTreeConfig + Copy + 'static,
{
}

/// The [`Zeroable`](bytemuck::Zeroable) trait is used under the hood by the
/// [`zero_copy`](anchor_lang::zero_copy) attribute macro and is required for
/// usage in zero-copy Solana accounts.
///
/// SAFETY: Generic parameters are used only as `PhantomData` and they don't
/// affect the layout of the struct nor its size or padding. The only reason
/// why we can't `#[derive(Zeroable)]` is because bytemuck is not aware of that
/// and it doesn't allow to derive `Zeroable` for structs with generic
/// parameters.
/// Would be nice to fix that upstream:
/// https://github.com/Lokathor/bytemuck/issues/191
unsafe impl<H, C> Zeroable for MerkleTree<H, C>
where
H: Hasher,
C: MerkleTreeConfig,
{
}

#[cfg(feature = "solana")]
impl<H, C> Owner for MerkleTree<H, C>
where
Expand Down

0 comments on commit 3c6e33d

Please sign in to comment.