Skip to content

Commit

Permalink
add account proof crate
Browse files Browse the repository at this point in the history
  • Loading branch information
anoushk1234 committed Jan 16, 2024
1 parent 623dec4 commit 8f5242a
Show file tree
Hide file tree
Showing 11 changed files with 733 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ split-debuginfo = "packed"
[workspace]
members = [
"account-decoder",
"account-proof",
"accounts-bench",
"accounts-cluster-bench",
"accounts-db",
Expand Down Expand Up @@ -307,6 +308,7 @@ smpl_jwt = "0.7.1"
socket2 = "0.5.5"
soketto = "0.7"
solana-account-decoder = { path = "account-decoder", version = "=1.18.0" }
solana-account-proof = {path = "account-proof", version = "=1.18.0"}
solana-accounts-db = { path = "accounts-db", version = "=1.18.0" }
solana-address-lookup-table-program = { path = "programs/address-lookup-table", version = "=1.18.0" }
solana-banks-client = { path = "banks-client", version = "=1.18.0" }
Expand Down
24 changes: 24 additions & 0 deletions account-proof/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "solana-account-proof"
version.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
license.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
borsh = {workspace = true}
solana-sdk={workspace = true}
blake3={workspace=true}
rayon={worksapce=true}
rand={workspace=true}
solana-accounts-db={workspace=true}
solana-runtime={workspace=true}
anyhow={workspace=true}


[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
114 changes: 114 additions & 0 deletions account-proof/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// use solana_geyser_plugin_interface::geyser_plugin_interface::{ReplicaBlockInfoV2, SlotStatus};
use {
borsh::{BorshDeserialize, BorshSerialize},
solana_sdk::{hash::Hash, message::legacy::Message, pubkey::Pubkey, signature::Signature},
std::collections::HashMap,
};
pub mod utils;
pub type AccountHashAccumulator = HashMap<u64, AccountHashMap>;
pub type TransactionSigAccumulator = HashMap<u64, u64>;
pub type SlotHashProofAccumulator = HashMap<u64, (Hash, BankHashProof)>;
pub type VoteAccumulator = HashMap<u64, VoteHashMap>;
pub type VoteHashMap = HashMap<Signature, VoteInfo>;
pub type AccountHashMap = HashMap<Pubkey, (u64, Hash, AccountInfo)>;

#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)]
pub struct Proof {
pub path: Vec<usize>, // Position in the chunk (between 0 and 15) for each level.
pub siblings: Vec<Vec<Hash>>, // Sibling hashes at each level.
}

#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)]
pub struct BankHashComponents {
parent_bankhash: Hash,
accounts_delta_hash: Hash,
num_sigs: u64,
current_blockhash: Hash,
}

#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)]
pub struct Data {
pub pubkey: Pubkey,
pub hash: Hash,
pub account: AccountInfo,
}

#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)]
pub struct AccountDeltaProof(pub Pubkey, pub (Data, Proof));

#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)]
pub struct BankHashProof {
pub proofs: Vec<AccountDeltaProof>,
pub num_sigs: u64,
pub account_delta_root: Hash,
pub parent_bankhash: Hash,
pub blockhash: Hash,
}

#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)]
pub struct Update {
pub slot: u64,
pub root: Hash,
pub proof: BankHashProof,
}

#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
pub struct AccountInfo {
/// The Pubkey for the account
pub pubkey: Pubkey,

/// The lamports for the account
pub lamports: u64,

/// The Pubkey of the owner program account
pub owner: Pubkey,

/// This account's data contains a loaded program (and is now read-only)
pub executable: bool,

/// The epoch at which this account will next owe rent
pub rent_epoch: u64,

/// The data held in this account.
pub data: Vec<u8>,

/// A global monotonically increasing atomic number, which can be used
/// to tell the order of the account update. For example, when an
/// account is updated in the same slot multiple times, the update
/// with higher write_version should supersede the one with lower
/// write_version.
pub write_version: u64,

/// Slot number for this update
pub slot: u64,
}

impl Default for AccountInfo {
fn default() -> Self {
AccountInfo {
pubkey: Pubkey::default(),
lamports: 0,
owner: Pubkey::default(),
executable: false,
rent_epoch: 0,
data: Vec::new(),
write_version: 0,
slot: 0,
}
}
}

#[derive(Debug, Clone)]
pub struct TransactionInfo {
pub slot: u64,
pub num_sigs: u64,
}

#[derive(Debug, Clone)]
pub struct VoteInfo {
pub slot: u64,
pub signature: Signature,
pub vote_for_slot: u64,
pub vote_for_hash: Hash,
pub message: Message,
}
Loading

0 comments on commit 8f5242a

Please sign in to comment.