11use std:: collections:: BTreeMap ;
22
33use crate :: { p2p_ready, SnarkPoolAction } ;
4- use openmina_core:: snark:: Snark ;
4+ use openmina_core:: snark:: { Snark , SnarkJobId } ;
55use p2p:: {
66 channels:: rpc:: { P2pChannelsRpcAction , P2pRpcId , P2pRpcRequest } ,
77 disconnection:: { P2pDisconnectionAction , P2pDisconnectionReason } ,
8- PeerId ,
8+ BroadcastMessageId , P2pNetworkPubsubAction , PeerId ,
99} ;
1010use snark:: { work_verify:: SnarkWorkVerifyAction , work_verify_effectful:: SnarkWorkVerifyId } ;
1111
@@ -124,10 +124,11 @@ impl SnarkPoolCandidatesState {
124124 }
125125 } ) ,
126126 on_error : redux:: callback!(
127- on_snark_pool_candidate_work_verify_error( ( req_id: SnarkWorkVerifyId , sender: String ) ) -> crate :: Action {
127+ on_snark_pool_candidate_work_verify_error( ( req_id: SnarkWorkVerifyId , sender: String , batch : Vec < SnarkJobId > ) ) -> crate :: Action {
128128 SnarkPoolCandidateAction :: WorkVerifyError {
129129 peer_id: sender. parse( ) . unwrap( ) ,
130130 verify_id: req_id,
131+ batch
131132 }
132133 } ) ,
133134 } ) ;
@@ -144,7 +145,11 @@ impl SnarkPoolCandidatesState {
144145 } => {
145146 state. verify_pending ( meta. time ( ) , peer_id, * verify_id, job_ids) ;
146147 }
147- SnarkPoolCandidateAction :: WorkVerifyError { peer_id, verify_id } => {
148+ SnarkPoolCandidateAction :: WorkVerifyError {
149+ peer_id,
150+ verify_id,
151+ batch,
152+ } => {
148153 state. verify_result ( meta. time ( ) , peer_id, * verify_id, Err ( ( ) ) ) ;
149154
150155 // TODO(binier): blacklist peer
@@ -154,6 +159,22 @@ impl SnarkPoolCandidatesState {
154159 peer_id,
155160 reason : P2pDisconnectionReason :: SnarkPoolVerifyError ,
156161 } ) ;
162+
163+ // TODO: This is not correct. We are rejecting all snark messages, but the fact that the batch
164+ // failed to verify means that there is at least one invalid snark in the batch, not that all of them
165+ // are invalid.
166+ // Instead, what should happen here is that we split the batch in two and try to verify the two batches
167+ // again. Repeating until batches don't fail to verify anymore, or each batch is of size 1.
168+ // It may also be worth capping the batch sizes to 10.
169+ for snark_job_id in batch {
170+ dispatcher. push ( P2pNetworkPubsubAction :: RejectMessage {
171+ message_id : Some ( BroadcastMessageId :: Snark {
172+ job_id : snark_job_id. clone ( ) ,
173+ } ) ,
174+ peer_id : None ,
175+ reason : "Snark work verification failed" . to_string ( ) ,
176+ } ) ;
177+ }
157178 }
158179 SnarkPoolCandidateAction :: WorkVerifySuccess {
159180 peer_id,
0 commit comments