Skip to content

feat: concurrent append and nullify for v2 state trees #1895

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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions forester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ light-hash-set = { workspace = true, features = ["solana"] }
light-hasher = { workspace = true }
light-merkle-tree-reference = { workspace = true }
light-registry = { workspace = true }
light-concurrent-merkle-tree = { workspace = true }
light-sparse-merkle-tree = { workspace = true }
light-prover-client = { workspace = true }
photon-api = { workspace = true }
forester-utils = { workspace = true }
light-client = { workspace = true, features = ["v2"] }
Expand Down
2 changes: 1 addition & 1 deletion forester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "GPL-3.0",
"scripts": {
"build": "cargo build",
"test": "source .env && RUST_LOG=forester=debug,forester_utils=debug cargo test --package forester e2e_test -- --nocapture",
"test": "source ./.env && RUST_LOG=forester=debug,forester_utils=debug cargo test --package forester e2e_test -- --nocapture",
"docker:build": "docker build --tag forester -f Dockerfile .."
},
"devDependencies": {
Expand Down
48 changes: 48 additions & 0 deletions forester/src/processor/v2/changelog_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::sync::Arc;
use std::collections::HashMap;

use anyhow::Result;
use light_sparse_merkle_tree::changelog::ChangelogEntry;
use solana_sdk::pubkey::Pubkey;
use tokio::sync::RwLock;
use tracing::debug;

pub static CHANGELOG_CACHE: tokio::sync::OnceCell<ChangelogCache> = tokio::sync::OnceCell::const_new();

pub async fn get_changelog_cache() -> &'static ChangelogCache {
CHANGELOG_CACHE.get_or_init(|| async { ChangelogCache::new() }).await
}

pub struct ChangelogCache {
changelogs: Arc<RwLock<HashMap<Pubkey, Vec<ChangelogEntry<32>>>>>,
}

impl ChangelogCache {
pub fn new() -> Self {
Self {
changelogs: Arc::new(RwLock::new(HashMap::new())),
}
}

pub async fn get_changelogs(&self, merkle_tree: &Pubkey) -> Vec<ChangelogEntry<32>> {
self.changelogs.read().await.get(merkle_tree).cloned().unwrap_or_default()
}


pub async fn append_changelogs(
&self,
merkle_tree: Pubkey,
new_changelogs: Vec<ChangelogEntry<32>>,
) -> Result<()> {
let mut changelogs = self.changelogs.write().await;
let entries = changelogs.entry(merkle_tree).or_insert_with(Vec::new);
let count = new_changelogs.len();
entries.extend(new_changelogs);

debug!("Appended {} changelogs for {:?}, total entries: {}",
count, merkle_tree, entries.len());
Ok(())
}


}
Loading
Loading