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
#6)

* Update Solana SDK to 1.16 and Anchor to the latest change including it

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

* Add CI tests
  • Loading branch information
vadorovsky authored Jun 6, 2023
1 parent a86a8a7 commit 31858bc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: test

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test

- name: Run cargo fmt
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
with:
command: fmt
args: --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
with:
command: clippy
args: -- -D warnings
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 31858bc

Please sign in to comment.