1
- use std:: ops:: DerefMut ;
2
1
use std:: sync:: Arc ;
3
2
4
3
use light_registry:: account_compression_cpi:: sdk:: {
@@ -15,7 +14,7 @@ use solana_sdk::transaction::Transaction;
15
14
use tokio:: sync:: Mutex ;
16
15
17
16
use crate :: errors:: ForesterError ;
18
- use crate :: { ForesterConfig , RpcPool } ;
17
+ use crate :: ForesterConfig ;
19
18
use account_compression:: utils:: constants:: {
20
19
STATE_MERKLE_TREE_CANOPY_DEPTH , STATE_MERKLE_TREE_HEIGHT ,
21
20
} ;
@@ -40,15 +39,14 @@ use light_test_utils::{
40
39
} ;
41
40
42
41
pub async fn is_tree_ready_for_rollover < R : RpcConnection > (
43
- rpc : Arc < Mutex < R > > ,
42
+ rpc : & mut R ,
44
43
tree_pubkey : Pubkey ,
45
44
tree_type : TreeType ,
46
45
) -> Result < bool , ForesterError > {
47
46
info ! (
48
47
"Checking if tree is ready for rollover: {:?}" ,
49
48
tree_pubkey. to_string( )
50
49
) ;
51
- let mut rpc = rpc. lock ( ) . await ;
52
50
match tree_type {
53
51
TreeType :: State => {
54
52
let account = rpc
@@ -63,7 +61,7 @@ pub async fn is_tree_ready_for_rollover<R: RpcConnection>(
63
61
}
64
62
let merkle_tree =
65
63
get_concurrent_merkle_tree :: < StateMerkleTreeAccount , R , Poseidon , 26 > (
66
- & mut rpc,
64
+ rpc,
67
65
tree_pubkey,
68
66
)
69
67
. await ;
@@ -87,7 +85,7 @@ pub async fn is_tree_ready_for_rollover<R: RpcConnection>(
87
85
88
86
let merkle_tree =
89
87
get_indexed_merkle_tree :: < AddressMerkleTreeAccount , R , Poseidon , usize , 26 , 16 > (
90
- & mut rpc,
88
+ rpc,
91
89
tree_pubkey,
92
90
)
93
91
. await ;
@@ -104,18 +102,17 @@ pub async fn is_tree_ready_for_rollover<R: RpcConnection>(
104
102
#[ allow( dead_code) ]
105
103
pub async fn rollover_state_merkle_tree < R : RpcConnection , I : Indexer < R > > (
106
104
config : Arc < ForesterConfig > ,
107
- rpc_pool : Arc < RpcPool < R > > ,
105
+ rpc : & mut R ,
108
106
indexer : Arc < Mutex < I > > ,
109
107
tree_accounts : & TreeAccounts ,
110
108
) -> Result < ( ) , ForesterError > {
111
109
let new_nullifier_queue_keypair = Keypair :: new ( ) ;
112
110
let new_merkle_tree_keypair = Keypair :: new ( ) ;
113
111
let new_cpi_signature_keypair = Keypair :: new ( ) ;
114
112
115
- let rpc = rpc_pool. get_connection ( ) . await ;
116
113
let rollover_signature = perform_state_merkle_tree_roll_over_forester (
117
114
& config. payer_keypair ,
118
- rpc. clone ( ) ,
115
+ rpc,
119
116
& new_nullifier_queue_keypair,
120
117
& new_merkle_tree_keypair,
121
118
& new_cpi_signature_keypair,
@@ -146,7 +143,7 @@ pub async fn rollover_state_merkle_tree<R: RpcConnection, I: Indexer<R>>(
146
143
#[ allow( clippy:: too_many_arguments) ]
147
144
pub async fn perform_state_merkle_tree_roll_over_forester < R : RpcConnection > (
148
145
payer : & Keypair ,
149
- context : Arc < Mutex < R > > ,
146
+ context : & mut R ,
150
147
new_queue_keypair : & Keypair ,
151
148
new_address_merkle_tree_keypair : & Keypair ,
152
149
new_cpi_context_keypair : & Keypair ,
@@ -155,7 +152,7 @@ pub async fn perform_state_merkle_tree_roll_over_forester<R: RpcConnection>(
155
152
old_cpi_context_pubkey : & Pubkey ,
156
153
) -> Result < solana_sdk:: signature:: Signature , RpcError > {
157
154
let instructions = create_rollover_state_merkle_tree_instructions (
158
- context. clone ( ) ,
155
+ context,
159
156
& payer. pubkey ( ) ,
160
157
new_queue_keypair,
161
158
new_address_merkle_tree_keypair,
@@ -165,7 +162,6 @@ pub async fn perform_state_merkle_tree_roll_over_forester<R: RpcConnection>(
165
162
old_cpi_context_pubkey,
166
163
)
167
164
. await ;
168
- let mut context = context. lock ( ) . await ;
169
165
let blockhash = context. get_latest_blockhash ( ) . await . unwrap ( ) ;
170
166
let transaction = Transaction :: new_signed_with_payer (
171
167
& instructions,
@@ -178,16 +174,15 @@ pub async fn perform_state_merkle_tree_roll_over_forester<R: RpcConnection>(
178
174
179
175
pub async fn rollover_address_merkle_tree < R : RpcConnection , I : Indexer < R > > (
180
176
config : Arc < ForesterConfig > ,
181
- rpc_pool : Arc < RpcPool < R > > ,
177
+ rpc : & mut R ,
182
178
indexer : Arc < Mutex < I > > ,
183
179
tree_data : & TreeAccounts ,
184
180
) -> Result < ( ) , ForesterError > {
185
181
let new_nullifier_queue_keypair = Keypair :: new ( ) ;
186
182
let new_merkle_tree_keypair = Keypair :: new ( ) ;
187
- let rpc = rpc_pool. get_connection ( ) . await ;
188
183
perform_address_merkle_tree_roll_over (
189
184
& config. payer_keypair ,
190
- rpc. clone ( ) ,
185
+ rpc,
191
186
& new_nullifier_queue_keypair,
192
187
& new_merkle_tree_keypair,
193
188
& tree_data. merkle_tree ,
@@ -205,22 +200,21 @@ pub async fn rollover_address_merkle_tree<R: RpcConnection, I: Indexer<R>>(
205
200
206
201
pub async fn perform_address_merkle_tree_roll_over < R : RpcConnection > (
207
202
payer : & Keypair ,
208
- context : Arc < Mutex < R > > ,
203
+ context : & mut R ,
209
204
new_queue_keypair : & Keypair ,
210
205
new_address_merkle_tree_keypair : & Keypair ,
211
206
old_merkle_tree_pubkey : & Pubkey ,
212
207
old_queue_pubkey : & Pubkey ,
213
208
) -> Result < solana_sdk:: signature:: Signature , RpcError > {
214
209
let instructions = create_rollover_address_merkle_tree_instructions (
215
- context. clone ( ) ,
210
+ context,
216
211
& payer. pubkey ( ) ,
217
212
new_queue_keypair,
218
213
new_address_merkle_tree_keypair,
219
214
old_merkle_tree_pubkey,
220
215
old_queue_pubkey,
221
216
)
222
217
. await ;
223
- let mut context = context. lock ( ) . await ;
224
218
let blockhash = context. get_latest_blockhash ( ) . await . unwrap ( ) ;
225
219
let transaction = Transaction :: new_signed_with_payer (
226
220
& instructions,
@@ -232,16 +226,15 @@ pub async fn perform_address_merkle_tree_roll_over<R: RpcConnection>(
232
226
}
233
227
234
228
pub async fn create_rollover_address_merkle_tree_instructions < R : RpcConnection > (
235
- rpc : Arc < Mutex < R > > ,
229
+ rpc : & mut R ,
236
230
authority : & Pubkey ,
237
231
new_nullifier_queue_keypair : & Keypair ,
238
232
new_address_merkle_tree_keypair : & Keypair ,
239
233
merkle_tree_pubkey : & Pubkey ,
240
234
nullifier_queue_pubkey : & Pubkey ,
241
235
) -> Vec < Instruction > {
242
- let mut rpc = rpc. lock ( ) . await ;
243
236
let ( merkle_tree_config, queue_config) = get_address_bundle_config (
244
- rpc. deref_mut ( ) ,
237
+ rpc,
245
238
AddressMerkleTreeAccounts {
246
239
merkle_tree : * merkle_tree_pubkey,
247
240
queue : * nullifier_queue_pubkey,
@@ -250,7 +243,7 @@ pub async fn create_rollover_address_merkle_tree_instructions<R: RpcConnection>(
250
243
. await ;
251
244
let ( merkle_tree_rent_exemption, queue_rent_exemption) =
252
245
get_rent_exemption_for_address_merkle_tree_and_queue (
253
- rpc. deref_mut ( ) ,
246
+ rpc,
254
247
& merkle_tree_config,
255
248
& queue_config,
256
249
)
@@ -291,7 +284,7 @@ pub async fn create_rollover_address_merkle_tree_instructions<R: RpcConnection>(
291
284
292
285
#[ allow( clippy:: too_many_arguments) ]
293
286
pub async fn create_rollover_state_merkle_tree_instructions < R : RpcConnection > (
294
- rpc : Arc < Mutex < R > > ,
287
+ rpc : & mut R ,
295
288
authority : & Pubkey ,
296
289
new_nullifier_queue_keypair : & Keypair ,
297
290
new_state_merkle_tree_keypair : & Keypair ,
@@ -300,9 +293,8 @@ pub async fn create_rollover_state_merkle_tree_instructions<R: RpcConnection>(
300
293
nullifier_queue_pubkey : & Pubkey ,
301
294
old_cpi_context_pubkey : & Pubkey ,
302
295
) -> Vec < Instruction > {
303
- let mut rpc = rpc. lock ( ) . await ;
304
296
let ( merkle_tree_config, queue_config) = get_state_bundle_config (
305
- rpc. deref_mut ( ) ,
297
+ rpc,
306
298
StateMerkleTreeAccounts {
307
299
merkle_tree : * merkle_tree_pubkey,
308
300
nullifier_queue : * nullifier_queue_pubkey,
@@ -311,12 +303,8 @@ pub async fn create_rollover_state_merkle_tree_instructions<R: RpcConnection>(
311
303
)
312
304
. await ;
313
305
let ( state_merkle_tree_rent_exemption, queue_rent_exemption) =
314
- get_rent_exemption_for_state_merkle_tree_and_queue (
315
- rpc. deref_mut ( ) ,
316
- & merkle_tree_config,
317
- & queue_config,
318
- )
319
- . await ;
306
+ get_rent_exemption_for_state_merkle_tree_and_queue ( rpc, & merkle_tree_config, & queue_config)
307
+ . await ;
320
308
let create_nullifier_queue_instruction = create_account_instruction (
321
309
authority,
322
310
queue_rent_exemption. size ,
0 commit comments