Skip to content

Commit 9902c37

Browse files
authored
feat: protocol config (#986)
Conceptual Changes: - foresters need to be registered with `forester_account`s - foresters need to register to epochs to forest Changes: - refactor registry program folder structure - moved everything from the decentralization and contention prevention test into the program - selection is not used yet - claim functionality is not implemented yet Note: - security and failing tests are not implemented yet - rewards are not implemented yet - implementation is insecure, security checks are missing - leaving `msg!` prints in registry program for now for debugging
1 parent 3867c58 commit 9902c37

File tree

69 files changed

+5210
-1414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+5210
-1414
lines changed

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"pubkey":"C388ZXSoy5p9uQUpPAtFoJHwcYhts2Xu2ArWNJUgYyji","account":{"lamports":1781760,"data":["QuAuAqeJeGsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMqaOwAAAAACAAAAAAAAAADKmjsAAAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA=","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":128}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"pubkey":"5Tpw5vUpnXzSKgGpEGHuxMRFtTz6Gt6hozVqu8e5fiqt","account":{"lamports":2345520,"data":["HXXTjWOP+nLMuMIVdedaPnWzorVHJCIvMcPXWnMDRUrSS6K/PzOqzAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADKmjsAAAAAAgAAAAAAAAAAypo7AAAAAGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAA=","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":209}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"pubkey":"8KEKiyAMugpKq9XCGzx81UtTBuytByW8arm9EaBVpD5k","account":{"lamports":1670400,"data":["92V2ansKL5ECY+L7WEJcIRnY07lwy9TuaZBIebD9aqhznpq8Pv+mUf0AAAAAAAAAAP//////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":112}}
1+
{"pubkey":"8KEKiyAMugpKq9XCGzx81UtTBuytByW8arm9EaBVpD5k","account":{"lamports":1844400,"data":["YLDvkgH+Y5ICY+L7WEJcIRnY07lwy9TuaZBIebD9aqhznpq8Pv+mUf0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADKmjsAAAAAAgAAAAAAAAAAypo7AAAAAGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":137}}

cli/accounts/registered_forester_epoch_pda_DFiGEbaz75wSdqy9bpeWacqLWrqAwWBfqh4iSYtejiwK.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"pubkey":"BqDEaVeLffn32a2EnsmvFFmGK4ZZgqYrDkAxpGXc1ogj","account":{"lamports":1670400,"data":["BesVNs5W82rMuMIVdedaPnWzorVHJCIvMcPXWnMDRUrSS6K/PzOqzAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":112}}

examples/token-escrow/programs/token-escrow/tests/test_compressed_pda.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ async fn test_escrow_with_compressed_pda() {
108108
let rpc_error = RpcError::TransactionError(transaction_error);
109109
assert!(matches!(result, Err(error) if error.to_string() == rpc_error.to_string()));
110110

111-
rpc.warp_to_slot(lock_up_time + 1).unwrap();
112-
111+
rpc.warp_to_slot(lockup_end + 1).unwrap();
113112
perform_withdrawal_with_event(
114113
&mut rpc,
115114
&mut test_indexer,

forester/src/nullifier/address/processor.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use crate::{ForesterConfig, RpcPool};
88
use account_compression::utils::constants::{
99
ADDRESS_MERKLE_TREE_CHANGELOG, ADDRESS_MERKLE_TREE_INDEXED_CHANGELOG,
1010
};
11-
use light_registry::sdk::{
11+
12+
use light_registry::account_compression_cpi::sdk::{
1213
create_update_address_merkle_tree_instruction, UpdateAddressMerkleTreeInstructionInputs,
1314
};
1415
use light_test_utils::indexer::Indexer;
@@ -268,8 +269,8 @@ pub async fn update_merkle_tree<R: RpcConnection>(
268269
) -> Result<bool, ForesterError> {
269270
let start = Instant::now();
270271

271-
let update_ix =
272-
create_update_address_merkle_tree_instruction(UpdateAddressMerkleTreeInstructionInputs {
272+
let update_ix = create_update_address_merkle_tree_instruction(
273+
UpdateAddressMerkleTreeInstructionInputs {
273274
authority: config.payer_keypair.pubkey(),
274275
address_merkle_tree: tree_data.tree_pubkey,
275276
address_queue: tree_data.queue_pubkey,
@@ -283,7 +284,9 @@ pub async fn update_merkle_tree<R: RpcConnection>(
283284
indexed_changelog_index: ((account_data.proof.root_seq - 1)
284285
% ADDRESS_MERKLE_TREE_INDEXED_CHANGELOG)
285286
as u16,
286-
});
287+
},
288+
0, // TODO: add correct epoch
289+
);
287290

288291
// Prepare the instructions
289292
let instructions = vec![

forester/src/nullifier/state/processor.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use crate::operations::fetch_state_queue_data;
55
use crate::tree_sync::TreeData;
66
use crate::{ForesterConfig, RpcPool};
77
use account_compression::utils::constants::STATE_MERKLE_TREE_CHANGELOG;
8-
use light_registry::sdk::{create_nullify_instruction, CreateNullifyInstructionInputs};
8+
use light_registry::account_compression_cpi::sdk::{
9+
create_nullify_instruction, CreateNullifyInstructionInputs,
10+
};
911
use light_test_utils::indexer::Indexer;
1012
use light_test_utils::rpc::rpc_connection::RpcConnection;
1113
use log::{debug, error, info, warn};
@@ -276,16 +278,19 @@ async fn nullify_state<R: RpcConnection>(
276278
let change_log_index = root_seq % STATE_MERKLE_TREE_CHANGELOG;
277279
debug!("change_log_index: {:?}", change_log_index);
278280

279-
let ix = create_nullify_instruction(CreateNullifyInstructionInputs {
280-
nullifier_queue: tree_data.queue_pubkey,
281-
merkle_tree: tree_data.tree_pubkey,
282-
change_log_indices: vec![change_log_index],
283-
leaves_queue_indices: vec![leaves_queue_index],
284-
indices: vec![leaf_index],
285-
proofs: vec![proof],
286-
authority: payer.pubkey(),
287-
derivation: Pubkey::from_str(&config.external_services.derivation).unwrap(),
288-
});
281+
let ix = create_nullify_instruction(
282+
CreateNullifyInstructionInputs {
283+
nullifier_queue: tree_data.queue_pubkey,
284+
merkle_tree: tree_data.tree_pubkey,
285+
change_log_indices: vec![change_log_index],
286+
leaves_queue_indices: vec![leaves_queue_index],
287+
indices: vec![leaf_index],
288+
proofs: vec![proof],
289+
authority: payer.pubkey(),
290+
derivation: Pubkey::from_str(&config.external_services.derivation).unwrap(),
291+
},
292+
0,
293+
);
289294

290295
let instructions = vec![
291296
ComputeBudgetInstruction::set_compute_unit_limit(config.cu_limit),

forester/src/rollover/operations.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use std::ops::DerefMut;
22
use std::sync::Arc;
33

44
use anchor_lang::{system_program, InstructionData, ToAccountMetas};
5+
use light_registry::account_compression_cpi::sdk::{
6+
create_rollover_address_merkle_tree_instruction, create_rollover_state_merkle_tree_instruction,
7+
CreateRolloverMerkleTreeInstructionInputs,
8+
};
59
use log::info;
610
use solana_sdk::instruction::Instruction;
711
use solana_sdk::pubkey::Pubkey;
@@ -19,10 +23,6 @@ use account_compression::{
1923
};
2024
use light_hasher::Poseidon;
2125
use light_merkle_tree_reference::MerkleTree;
22-
use light_registry::sdk::{
23-
create_rollover_address_merkle_tree_instruction, create_rollover_state_merkle_tree_instruction,
24-
CreateRolloverMerkleTreeInstructionInputs,
25-
};
2626
use light_test_utils::address_merkle_tree_config::{
2727
get_address_bundle_config, get_state_bundle_config,
2828
};
@@ -320,6 +320,7 @@ pub async fn create_rollover_address_merkle_tree_instructions<R: RpcConnection>(
320320
old_queue: *nullifier_queue_pubkey,
321321
old_merkle_tree: *merkle_tree_pubkey,
322322
},
323+
0, // TODO: make epoch dynamic
323324
);
324325
vec![
325326
create_nullifier_queue_instruction,
@@ -368,14 +369,16 @@ pub async fn create_rollover_state_merkle_tree_instructions<R: RpcConnection>(
368369
&account_compression::ID,
369370
Some(new_state_merkle_tree_keypair),
370371
);
371-
let instruction =
372-
create_rollover_state_merkle_tree_instruction(CreateRolloverMerkleTreeInstructionInputs {
372+
let instruction = create_rollover_state_merkle_tree_instruction(
373+
CreateRolloverMerkleTreeInstructionInputs {
373374
authority: *authority,
374375
new_queue: new_nullifier_queue_keypair.pubkey(),
375376
new_merkle_tree: new_state_merkle_tree_keypair.pubkey(),
376377
old_queue: *nullifier_queue_pubkey,
377378
old_merkle_tree: *merkle_tree_pubkey,
378-
});
379+
},
380+
0, // TODO: make epoch dynamic
381+
);
379382
vec![
380383
create_nullifier_queue_instruction,
381384
create_state_merkle_tree_instruction,

0 commit comments

Comments
 (0)