Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Dec 3, 2024
1 parent a3e7612 commit c770f1f
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 23 deletions.
40 changes: 40 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[alias]
xtask = "run --package xtask --"

# On Windows
# ```
# cargo install -f cargo-binutils
# rustup component add llvm-tools-preview
# ```
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

# On Linux:
# - Ubuntu, `sudo apt-get install lld clang`
# - Arch, `sudo pacman -S lld clang`
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-unknown-linux-gnu]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-unknown-linux-musl]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

# On MacOS, `brew install llvm` and follow steps in `brew info llvm`
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]





27 changes: 20 additions & 7 deletions forester/src/batched_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,27 @@ pub struct BatchedOperations<R: RpcConnection, I: Indexer<R>> {
impl<R: RpcConnection, I: Indexer<R>> BatchedOperations<R, I> {
async fn is_batch_ready(&self) -> bool {
let mut rpc = self.rpc_pool.get_connection().await.unwrap();
// let is_batch_ready = {
// let mut output_queue_account =
// rpc.get_account(self.output_queue).await.unwrap().unwrap();
// let output_queue = ZeroCopyBatchedQueueAccount::from_bytes_mut(
// output_queue_account.data.as_mut_slice(),
// )
// .unwrap();
// let idx = output_queue.get_account().queue.next_full_batch_index;
// let batch = &output_queue.batches[idx as usize];
// println!("is_batch_ready: batch: {:?}", batch);
// batch.get_state() == BatchState::ReadyToUpdateTree
// };
// is_batch_ready

let is_batch_ready = {
let mut output_queue_account =
rpc.get_account(self.output_queue).await.unwrap().unwrap();
let mut output_queue_account = rpc.get_account(self.output_queue).await.unwrap().unwrap();
let output_queue = ZeroCopyBatchedQueueAccount::from_bytes_mut(
output_queue_account.data.as_mut_slice(),
)
.unwrap();
let idx = output_queue.get_account().queue.next_full_batch_index;
let batch = &output_queue.batches[idx as usize];
println!("is_batch_ready: batch: {:?}", batch);
batch.get_state() == BatchState::ReadyToUpdateTree
.unwrap();
output_queue.get_batch_num_inserted_in_current_batch() > 0
};
is_batch_ready
}
Expand Down Expand Up @@ -367,6 +377,9 @@ impl<R: RpcConnection, I: Indexer<R>> BatchedOperations<R, I> {
tx_hashes.push(*tx_hash);
}

let local_leaves_hashchain = calculate_hash_chain(&leaves);
assert_eq!(local_leaves_hashchain, leaves_hashchain);

let inputs = get_batch_update_inputs::<26>(
old_root,
tx_hashes,
Expand Down
2 changes: 1 addition & 1 deletion forester/tests/batched_op_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn test_batched() {
} else {
InitStateTreeAccountsInstructionData::test_default()
};

init(Some(LightValidatorConfig {
enable_indexer: false,
wait_time: 15,
Expand Down
4 changes: 2 additions & 2 deletions test-programs/registry-test/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ async fn test_custom_forester_batched() {
#[serial]
#[tokio::test]
async fn test_forester_batched() {
let devnet = false;
let devnet = true;
let tree_params = if devnet {
InitStateTreeAccountsInstructionData::default()
} else {
Expand All @@ -736,7 +736,7 @@ async fn test_forester_batched() {
)
.await;
let unregistered_forester_keypair = Keypair::new();
rpc.airdrop_lamports(&unregistered_forester_keypair.pubkey(), 1_000_000_000)
rpc.airdrop_lamports(&unregistered_forester_keypair.pubkey(), 100 * LAMPORTS_PER_SOL)
.await
.unwrap();
let merkle_tree_keypair = Keypair::new();
Expand Down
19 changes: 10 additions & 9 deletions test-utils/src/e2e_test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,16 @@ pub async fn init_program_test_env_forester<R: RpcConnection>(
let indexer: TestIndexer<R> = TestIndexer::init_from_env(
&env_accounts.forester.insecure_clone(),
env_accounts,
None, // Some(ProverConfig {
// run_mode: None,
// circuits: vec![
// ProofType::BatchAppendWithProofs,
// ProofType::BatchUpdate,
// ProofType::Inclusion,
// ProofType::NonInclusion,
// ],
// }),
// None,
Some(ProverConfig {
run_mode: None,
circuits: vec![
ProofType::BatchAppendWithProofs,
ProofType::BatchUpdate,
ProofType::Inclusion,
ProofType::NonInclusion,
],
}),
)
.await;

Expand Down
1 change: 1 addition & 0 deletions test-utils/src/indexer/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ impl<R: RpcConnection + Send + Sync + 'static> Indexer<R> for TestIndexer<R> {
.unwrap();

let batch = &merkle_tree.batches[batch_index];
println!("batch: {:?}", batch);
if batch.get_state() == BatchState::Inserted
|| batch.get_state() == BatchState::ReadyToUpdateTree
{
Expand Down
19 changes: 15 additions & 4 deletions test-utils/src/test_batch_forester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,28 @@ pub async fn is_batch_ready<R: RpcConnection>(
rpc: &mut R,
output_queue_pubkey: Pubkey,
) -> bool {
// let is_batch_ready = {
// let mut output_queue_account =
// rpc.get_account(output_queue_pubkey).await.unwrap().unwrap();
// let output_queue = ZeroCopyBatchedQueueAccount::from_bytes_mut(
// output_queue_account.data.as_mut_slice(),
// )
// .unwrap();
// let idx = output_queue.get_account().queue.next_full_batch_index;
// let batch = &output_queue.batches[idx as usize];
// println!("is_batch_ready: batch: {:?}", batch);
// batch.get_state() == BatchState::ReadyToUpdateTree
// };
// is_batch_ready

let is_batch_ready = {
let mut output_queue_account =
rpc.get_account(output_queue_pubkey).await.unwrap().unwrap();
let output_queue = ZeroCopyBatchedQueueAccount::from_bytes_mut(
output_queue_account.data.as_mut_slice(),
)
.unwrap();
let idx = output_queue.get_account().queue.next_full_batch_index;
let batch = &output_queue.batches[idx as usize];
println!("is_batch_ready: batch: {:?}", batch);
batch.get_state() == BatchState::ReadyToUpdateTree
output_queue.get_batch_num_inserted_in_current_batch() > 0
};
is_batch_ready
}

0 comments on commit c770f1f

Please sign in to comment.