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

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

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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