@@ -178,7 +178,8 @@ macro_rules! execute_program {
178
178
179
179
#[ macro_export]
180
180
macro_rules! execute_fee {
181
- ( $process: expr, $private_key: expr, $fee_record: expr, $priority_fee_microcredits: expr, $submission_url: expr, $fee_proving_key: expr, $fee_verifying_key: expr, $deployment_or_execution_id: expr, $rng: expr, $offline_query: expr, $minimum_execution_cost: expr) => { {
181
+ ( $process: expr, $private_key: expr, $fee_record: expr, $priority_fee_microcredits: expr, $node_url: expr, $fee_proving_key: expr, $fee_verifying_key: expr, $deployment_or_execution_id: expr, $rng: expr, $offline_query: expr, $minimum_execution_cost: expr) => { {
182
+ use :: snarkvm_ledger_query:: QueryTrait ;
182
183
if ( ( $fee_proving_key. is_some( ) && $fee_verifying_key. is_none( ) )
183
184
|| ( $fee_proving_key. is_none( ) && $fee_verifying_key. is_some( ) ) )
184
185
{
@@ -188,29 +189,31 @@ macro_rules! execute_fee {
188
189
) ;
189
190
}
190
191
192
+ let function_name = if $fee_record. is_some( ) {
193
+ IdentifierNative :: from_str( "fee_private" ) . unwrap( )
194
+ } else {
195
+ IdentifierNative :: from_str( "fee_public" ) . unwrap( )
196
+ } ;
197
+
191
198
if let Some ( fee_proving_key) = $fee_proving_key {
192
199
let credits = ProgramIDNative :: from_str( "credits.aleo" ) . unwrap( ) ;
193
- let fee = if $fee_record. is_some( ) {
194
- IdentifierNative :: from_str( "fee_private" ) . unwrap( )
195
- } else {
196
- IdentifierNative :: from_str( "fee_public" ) . unwrap( )
197
- } ;
198
- if Self :: contains_key( $process, & credits, & fee) {
200
+
201
+ if Self :: contains_key( $process, & credits, & function_name) {
199
202
log( "Fee proving & verifying keys were specified but a key already exists in the cache. Using cached keys" ) ;
200
203
} else {
201
204
log( "Inserting externally provided fee proving and verifying keys" ) ;
202
205
$process
203
- . insert_proving_key( & credits, & fee , ProvingKeyNative :: from( fee_proving_key) ) . map_err( |e| e. to_string( ) ) ?;
206
+ . insert_proving_key( & credits, & function_name , ProvingKeyNative :: from( fee_proving_key) ) . map_err( |e| e. to_string( ) ) ?;
204
207
if let Some ( fee_verifying_key) = $fee_verifying_key {
205
208
$process
206
- . insert_verifying_key( & credits, & fee , VerifyingKeyNative :: from( fee_verifying_key) )
209
+ . insert_verifying_key( & credits, & function_name , VerifyingKeyNative :: from( fee_verifying_key) )
207
210
. map_err( |e| e. to_string( ) ) ?;
208
211
}
209
212
}
210
213
} ;
211
214
212
215
log( "Authorizing Fee" ) ;
213
- let fee_authorization = match $fee_record {
216
+ let fee_authorization = match $fee_record. clone ( ) {
214
217
Some ( fee_record) => {
215
218
let fee_record_native = RecordPlaintextNative :: from_str( & fee_record. to_string( ) ) . unwrap( ) ;
216
219
$process. authorize_fee_private:: <CurrentAleo , _>(
@@ -239,16 +242,52 @@ macro_rules! execute_fee {
239
242
. map_err( |e| e. to_string( ) ) ?;
240
243
241
244
log( "Preparing inclusion proofs for fee execution" ) ;
242
- if let Some ( offline_query) = $offline_query. as_ref( ) {
245
+ let latest_height = if let Some ( offline_query) = $offline_query. as_ref( ) {
243
246
trace. prepare_async( offline_query) . await . map_err( |err| err. to_string( ) ) ?;
247
+ offline_query. current_block_height( ) . map_err( |e| e. to_string( ) ) ?
244
248
} else {
245
- let query = QueryNative :: from( $submission_url) ;
249
+ let credits = ProgramNative :: credits( ) . unwrap( ) ;
250
+ let function_name = IdentifierNative :: from_str( "split" ) . unwrap( ) ;
251
+ let view_key = ViewKeyNative :: try_from( PrivateKeyNative :: from( $private_key) ) . map_err( |err| err. to_string( ) ) ?;
252
+ let inputs = if let Some ( fee_record) = $fee_record {
253
+ vec![
254
+ :: wasm_bindgen:: JsValue :: from_str( & fee_record. to_string( ) ) ,
255
+ :: wasm_bindgen:: JsValue :: from_str( & format!( "{}u64" , $minimum_execution_cost) ) ,
256
+ :: wasm_bindgen:: JsValue :: from_str( & format!( "{}u64" , $minimum_execution_cost) ) ,
257
+ :: wasm_bindgen:: JsValue :: from_str( & format!( "{}" , $deployment_or_execution_id) )
258
+ ]
259
+ } else {
260
+ vec![
261
+ :: wasm_bindgen:: JsValue :: from_str( & format!( "{}u64" , $minimum_execution_cost) ) ,
262
+ :: wasm_bindgen:: JsValue :: from_str( & format!( "{}u64" , $minimum_execution_cost) ) ,
263
+ :: wasm_bindgen:: JsValue :: from_str( & format!( "{}" , $deployment_or_execution_id) )
264
+ ]
265
+ } ;
266
+ let query = SnapshotQuery :: try_from_inputs(
267
+ $node_url,
268
+ & credits,
269
+ & function_name,
270
+ & view_key,
271
+ & inputs,
272
+ )
273
+ . await
274
+ . map_err( |err| err. to_string( ) ) ?;
246
275
trace. prepare_async( & query) . await . map_err( |err| err. to_string( ) ) ?;
276
+ query. current_block_height( ) . map_err( |e| e. to_string( ) ) ?
247
277
} ;
278
+ let consensus_version = <CurrentNetwork as Network >:: CONSENSUS_VERSION ( latest_height) . map_err( |err| err. to_string( ) ) ?;
279
+ let inclusion_upgrade_height = <CurrentNetwork as Network >:: INCLUSION_UPGRADE_HEIGHT ( ) . map_err( |err| err. to_string( ) ) ?;
280
+ let inclusion_version = if latest_height >= inclusion_upgrade_height {
281
+ :: snarkvm_synthesizer:: prelude:: InclusionVersion :: V1
282
+ } else {
283
+ :: snarkvm_synthesizer:: prelude:: InclusionVersion :: V0
284
+ } ;
285
+
286
+ log( "Proving fee execution" ) ;
248
287
let fee = trace. prove_fee:: <CurrentAleo , _>( :: snarkvm_algorithms:: snark:: varuna:: VarunaVersion :: V2 , & mut StdRng :: from_entropy( ) ) . map_err( |e|e. to_string( ) ) ?;
249
288
250
289
log( "Verifying fee execution" ) ;
251
- $process. verify_fee( :: snarkvm_console :: prelude :: ConsensusVersion :: V8 , :: snarkvm_algorithms:: snark:: varuna:: VarunaVersion :: V2 , :: snarkvm_synthesizer :: prelude :: InclusionVersion :: V1 , & fee, $deployment_or_execution_id) . map_err( |e| e. to_string( ) ) ?;
290
+ $process. verify_fee( consensus_version , :: snarkvm_algorithms:: snark:: varuna:: VarunaVersion :: V2 , inclusion_version , & fee, $deployment_or_execution_id) . map_err( |e| e. to_string( ) ) ?;
252
291
253
292
fee
254
293
} }
@@ -261,8 +300,7 @@ macro_rules! calculate_minimum_fee {
261
300
let block_height = offline_query. current_block_height( ) . map_err( |e| e. to_string( ) ) ?;
262
301
block_height
263
302
} else {
264
- let query = QueryNative :: from( $node_url) ;
265
- let block_height = query. current_block_height_async( ) . await . map_err( |e| e. to_string( ) ) ?;
303
+ let block_height = latest_block_height( $node_url) . await . map_err( |e| e. to_string( ) ) ?;
266
304
block_height
267
305
} ;
268
306
let ( minimum_execution_cost, ( _, _) ) =
0 commit comments