11use ledger:: {
2- scan_state:: transaction_logic:: { GenericCommand , UserCommand } ,
2+ scan_state:: transaction_logic:: { valid , GenericCommand , UserCommand } ,
33 transaction_pool:: {
44 diff:: { self , DiffVerified } ,
55 transaction_hash, ApplyDecision , TransactionPoolErrors ,
@@ -14,6 +14,7 @@ use openmina_core::{
1414} ;
1515use p2p:: channels:: transaction:: P2pChannelsTransactionAction ;
1616use redux:: callback;
17+ use snark:: user_command_verify:: { SnarkUserCommandVerifyAction , SnarkUserCommandVerifyId } ;
1718use std:: collections:: { BTreeMap , BTreeSet } ;
1819
1920use crate :: { BlockProducerAction , RpcAction } ;
@@ -107,21 +108,38 @@ impl TransactionPoolState {
107108 } ;
108109 let diff = diff:: Diff { list : commands } ;
109110
110- match substate. pool . verify ( diff , accounts ) {
111- Ok ( valids ) => {
112- let valids = valids
113- . into_iter ( )
114- . map ( transaction_hash :: hash_command )
115- . collect :: < Vec < _ > > ( ) ;
116- let best_tip_hash = substate . best_tip_hash . clone ( ) . unwrap ( ) ;
117- let diff = DiffVerified { list : valids } ;
111+ match substate
112+ . pool
113+ . prevalidate ( diff )
114+ . and_then ( |diff| substate . pool . convert_diff_to_verifiable ( diff , accounts ) )
115+ {
116+ Ok ( verifiable ) => {
117+ let ( dispatcher , global_state ) = state . into_dispatcher_and_state ( ) ;
118+ let req_id = global_state . snark . user_command_verify . next_req_id ( ) ;
118119
119- let dispatcher = state. into_dispatcher ( ) ;
120- dispatcher. push ( TransactionPoolAction :: ApplyVerifiedDiff {
121- best_tip_hash,
122- diff,
123- is_sender_local : from_rpc. is_some ( ) ,
120+ dispatcher. push ( SnarkUserCommandVerifyAction :: Init {
121+ req_id,
122+ commands : verifiable,
124123 from_rpc : * from_rpc,
124+ on_success : callback ! (
125+ on_snark_user_command_verify_success(
126+ ( req_id: SnarkUserCommandVerifyId , valids: Vec <valid:: UserCommand >, from_rpc: Option <RpcId >)
127+ ) -> crate :: Action {
128+ TransactionPoolAction :: VerifySuccess {
129+ valids,
130+ from_rpc,
131+ }
132+ }
133+ ) ,
134+ on_error : callback ! (
135+ on_snark_user_command_verify_error(
136+ ( req_id: SnarkUserCommandVerifyId , errors: Vec <String >)
137+ ) -> crate :: Action {
138+ TransactionPoolAction :: VerifyError {
139+ errors
140+ }
141+ }
142+ )
125143 } ) ;
126144 }
127145 Err ( e) => {
@@ -151,6 +169,23 @@ impl TransactionPoolState {
151169 }
152170 }
153171 }
172+ TransactionPoolAction :: VerifySuccess { valids, from_rpc } => {
173+ let valids = valids
174+ . iter ( )
175+ . cloned ( )
176+ . map ( transaction_hash:: hash_command)
177+ . collect :: < Vec < _ > > ( ) ;
178+ let best_tip_hash = substate. best_tip_hash . clone ( ) . unwrap ( ) ;
179+ let diff = DiffVerified { list : valids } ;
180+
181+ let dispatcher = state. into_dispatcher ( ) ;
182+ dispatcher. push ( TransactionPoolAction :: ApplyVerifiedDiff {
183+ best_tip_hash,
184+ diff,
185+ is_sender_local : from_rpc. is_some ( ) ,
186+ from_rpc : * from_rpc,
187+ } ) ;
188+ }
154189 TransactionPoolAction :: VerifyError { .. } => {
155190 // just logging the errors
156191 }
0 commit comments