@@ -27,7 +27,6 @@ use crate::{
27
27
execute_program,
28
28
log,
29
29
process_inputs,
30
- programs:: SnapshotQuery ,
31
30
types:: native:: {
32
31
CurrentAleo ,
33
32
CurrentNetwork ,
@@ -39,24 +38,15 @@ use crate::{
39
38
} ,
40
39
} ;
41
40
use snarkvm_algorithms:: snark:: varuna:: VarunaVersion ;
42
- use snarkvm_console:: {
43
- network:: { ConsensusVersion } ,
44
- types:: Field ,
45
- } ;
41
+ use snarkvm_console:: network:: { ConsensusVersion , Network } ;
46
42
use snarkvm_ledger_query:: QueryTrait ;
47
- use snarkvm_synthesizer:: prelude:: {
48
- InclusionVersion ,
49
- cost_in_microcredits_v1,
50
- execution_cost_v1,
51
- execution_cost_v2,
52
- } ;
43
+ use snarkvm_synthesizer:: prelude:: { InclusionVersion , cost_in_microcredits_v1, execution_cost_v1, execution_cost_v2} ;
53
44
54
45
use core:: ops:: Add ;
55
46
use js_sys:: { Array , Object } ;
56
47
use rand:: { SeedableRng , rngs:: StdRng } ;
57
48
use std:: str:: FromStr ;
58
49
59
-
60
50
#[ wasm_bindgen]
61
51
impl ProgramManager {
62
52
/// Execute an arbitrary function locally
@@ -121,23 +111,13 @@ impl ProgramManager {
121
111
let mut execution_response = if prove_execution {
122
112
log ( "Preparing inclusion proofs for execution" ) ;
123
113
if let Some ( offline_query) = offline_query {
124
- trace. prepare_async ( & offline_query) . await . map_err ( |e| e . to_string ( ) ) ?;
114
+ trace. prepare_async ( & offline_query) . await . map_err ( |err| err . to_string ( ) ) ?;
125
115
} else {
126
- // NEW: try snapshot query, fallback to QueryNative (TODO, for now)
127
- let commitments = snapshot_helpers:: collect_commitments_from_trace ( & trace) ?;
128
- match snapshot_helpers:: build_snapshot_query ( node_url, & commitments) . await {
129
- Ok ( snapshot_query) => {
130
- trace. prepare_async ( & snapshot_query) . await . map_err ( |e| e. to_string ( ) ) ?;
131
- }
132
- Err ( _e) => {
133
- // TODO: remove this fallback once snapshot builder is implemented
134
- let query = QueryNative :: from ( node_url) ;
135
- trace. prepare_async ( & query) . await . map_err ( |err| err. to_string ( ) ) ?;
136
- }
137
- }
116
+ let query = QueryNative :: from ( node_url) ;
117
+ // todo change this to new query struct and to try_from rather than from
118
+ trace. prepare_async ( & query) . await . map_err ( |err| err. to_string ( ) ) ?;
138
119
}
139
120
140
-
141
121
log ( "Proving execution" ) ;
142
122
let locator = program_native. id ( ) . to_string ( ) . add ( "/" ) . add ( function) ;
143
123
let execution =
@@ -223,20 +203,10 @@ impl ProgramManager {
223
203
if let Some ( offline_query) = offline_query. as_ref ( ) {
224
204
trace. prepare_async ( offline_query) . await . map_err ( |err| err. to_string ( ) ) ?;
225
205
} else {
226
- // NEW: try snapshot query, fallback to QueryNative (TODO, for now)
227
- let commitments = snapshot_helpers:: collect_commitments_from_trace ( & trace) ?;
228
- match snapshot_helpers:: build_snapshot_query ( node_url, & commitments) . await {
229
- Ok ( snapshot_query) => {
230
- trace. prepare_async ( & snapshot_query) . await . map_err ( |e| e. to_string ( ) ) ?;
231
- }
232
- Err ( _e) => {
233
- let query = QueryNative :: from ( node_url) ;
234
- trace. prepare_async ( & query) . await . map_err ( |err| err. to_string ( ) ) ?;
235
- }
236
- }
206
+ let query = QueryNative :: from ( node_url) ;
207
+ trace. prepare_async ( & query) . await . map_err ( |err| err. to_string ( ) ) ?;
237
208
}
238
209
239
-
240
210
log ( "Proving execution" ) ;
241
211
let locator = program_native. id ( ) . to_string ( ) . add ( "/" ) . add ( function) ;
242
212
let execution = trace
@@ -356,23 +326,11 @@ impl ProgramManager {
356
326
trace. prepare_async ( & offline_query) . await . map_err ( |err| err. to_string ( ) ) ?;
357
327
block_height
358
328
} else {
359
- // try snapshot query, fallback to QueryNative (TODO, for now)
360
- let commitments = snapshot_helpers:: collect_commitments_from_trace ( & trace) ?;
361
- match snapshot_helpers:: build_snapshot_query ( node_url, & commitments) . await {
362
- Ok ( snapshot_query) => {
363
- let bh = snapshot_query. current_block_height ( ) . map_err ( |e| e. to_string ( ) ) ?;
364
- trace. prepare_async ( & snapshot_query) . await . map_err ( |e| e. to_string ( ) ) ?;
365
- bh
366
- }
367
- Err ( _e) => {
368
- let query = QueryNative :: from ( node_url) ;
369
- let bh = query. current_block_height_async ( ) . await . map_err ( |e| e. to_string ( ) ) ?;
370
- trace. prepare_async ( & query) . await . map_err ( |err| err. to_string ( ) ) ?;
371
- bh
372
- }
373
- }
329
+ let query = QueryNative :: from ( node_url) ;
330
+ let block_height = query. current_block_height_async ( ) . await . map_err ( |e| e. to_string ( ) ) ?;
331
+ trace. prepare_async ( & query) . await . map_err ( |err| err. to_string ( ) ) ?;
332
+ block_height
374
333
} ;
375
-
376
334
let execution =
377
335
trace. prove_execution :: < CurrentAleo , _ > ( & locator, VarunaVersion :: V2 , rng) . map_err ( |e| e. to_string ( ) ) ?;
378
336
@@ -431,51 +389,6 @@ impl ProgramManager {
431
389
}
432
390
}
433
391
434
- mod snapshot_helpers {
435
- use super :: * ;
436
- type StateRootNative = <CurrentNetwork as snarkvm_console:: network:: Network >:: StateRoot ;
437
-
438
- pub fn collect_commitments_from_trace < T > (
439
- _trace : & T ,
440
- ) -> Result < Vec < Field < CurrentNetwork > > , String > {
441
- Ok ( vec ! [ ] )
442
- }
443
-
444
- pub async fn build_snapshot_query (
445
- node_url : & str ,
446
- commitments : & [ Field < CurrentNetwork > ] ,
447
- ) -> Result < SnapshotQuery , String > {
448
- let ( state_root, block_height) = snapshot_head ( node_url) . await ?;
449
- let mut query = SnapshotQuery :: new ( block_height, & state_root_to_string ( state_root) ) ?;
450
-
451
- for c in commitments {
452
- let c_str = c. to_string ( ) ;
453
- let sp_str = fetch_state_path_at_root ( node_url, & c_str, & state_root_to_string ( state_root) ) . await ?;
454
- query. add_state_path ( & c_str, & sp_str) ?;
455
- }
456
- Ok ( query)
457
- }
458
-
459
- // Prefer an API that returns both in one call; otherwise fetch root then height immediately.
460
- async fn snapshot_head ( node_url : & str ) -> Result < ( StateRootNative , u32 ) , String > {
461
- // TODO: call existing client / REST: (root, height)
462
- Err ( "snapshot_head() not implemented" . into ( ) )
463
- }
464
-
465
- async fn fetch_state_path_at_root (
466
- node_url : & str ,
467
- commitment : & str ,
468
- state_root : & str ,
469
- ) -> Result < String , String > {
470
- // TODO: call endpoint that returns a StatePath string for (commitment, state_root)
471
- Err ( "fetch_state_path_at_root() not implemented" . into ( ) )
472
- }
473
-
474
- fn state_root_to_string ( root : StateRootNative ) -> String {
475
- root. to_string ( )
476
- }
477
- }
478
-
479
392
#[ cfg( test) ]
480
393
mod tests {
481
394
use super :: * ;
@@ -517,4 +430,4 @@ mod tests {
517
430
518
431
assert ! ( transaction. is_execute( ) ) ;
519
432
}
520
- }
433
+ }
0 commit comments