1515
1616use super :: * ;
1717use console:: program:: { FinalizeType , Future , Register } ;
18- use snarkvm_synthesizer_program:: { Await , FinalizeRegistersState , Operand , RegistersTrait } ;
18+ use snarkvm_synthesizer_program:: { Await , FinalizeRegistersState , FinalizeStoreTrait , Operand , RegistersTrait } ;
1919use snarkvm_utilities:: try_vm_runtime;
2020
2121use std:: collections:: HashSet ;
@@ -332,7 +332,8 @@ fn finalize_constructor<N: Network, P: FinalizeStorage<N>>(
332332 let constructor_types = stack. get_constructor_types ( ) ?. clone ( ) ;
333333
334334 // Initialize the finalize registers.
335- let mut registers = FinalizeRegisters :: new ( state, transition_id, * program_id. name ( ) , constructor_types, nonce) ;
335+ let mut registers =
336+ FinalizeRegisters :: new ( state, Some ( transition_id) , * program_id. name ( ) , constructor_types, Some ( nonce) ) ;
336337
337338 // Determine the scope name.
338339 let scope_name = Identifier :: < N > :: from_str ( "constructor" ) ?;
@@ -447,8 +448,13 @@ fn finalize_transition<N: Network, P: FinalizeStorage<N>>(
447448 // Otherwise, query the call graph for the child transition ID corresponding to the future that is being awaited.
448449 let consensus_version = N :: CONSENSUS_VERSION ( state. block_height ( ) ) ?;
449450 let transition_id = if ( ConsensusVersion :: V1 ..=ConsensusVersion :: V2 ) . contains ( & consensus_version) {
450- // Get the current transition ID.
451- let transition_id = registers. transition_id ( ) ;
451+ // Get the current transition ID. The finalize path always initializes
452+ // registers with `Some(transition_id)`; only the query path uses `None`,
453+ // and `await` is forbidden on the query path, so this is unreachable
454+ // there. Treat `None` as a logic error.
455+ let transition_id = registers
456+ . transition_id ( )
457+ . ok_or_else ( || anyhow ! ( "Cannot resolve a child transition ID without a transition ID" ) ) ?;
452458 // Get the child transition ID.
453459 match call_graph. get ( transition_id) {
454460 Some ( transitions) => match transitions. get ( call_counter) {
@@ -570,10 +576,10 @@ fn initialize_finalize_state<N: Network>(
570576 // Initialize the registers.
571577 let mut registers = FinalizeRegisters :: new (
572578 state,
573- transition_id,
579+ Some ( transition_id) ,
574580 * future. function_name ( ) ,
575581 stack. get_finalize_types ( future. function_name ( ) ) ?. clone ( ) ,
576- nonce,
582+ Some ( nonce) ,
577583 ) ;
578584
579585 // Store the inputs. The argument count is guaranteed to match the finalize's declared inputs
@@ -589,9 +595,12 @@ fn initialize_finalize_state<N: Network>(
589595}
590596
591597// A helper function to finalize all commands except `await`, updating the finalize operations and the counter.
598+ //
599+ // Generic over the store so the query evaluator (which passes either the canonical
600+ // `FinalizeStore` or a read-only historic adapter) can reuse this dispatch.
592601#[ inline]
593- fn finalize_command_except_await < N : Network > (
594- store : & FinalizeStore < N , impl FinalizeStorage < N > > ,
602+ pub ( crate ) fn finalize_command_except_await < N : Network > (
603+ store : & impl FinalizeStoreTrait < N > ,
595604 stack : & impl StackTrait < N > ,
596605 registers : & mut FinalizeRegisters < N > ,
597606 positions : & HashMap < Identifier < N > , usize > ,
0 commit comments