@@ -119,6 +119,25 @@ impl VerifyBlockError {
119119 }
120120}
121121
122+ /// Converts an error from a `CommitSemanticallyVerifiedBlock` state request
123+ /// into a [`VerifyBlockError`].
124+ ///
125+ /// The state boxes commit errors as [`zs::CommitSemanticallyVerifiedError`], a
126+ /// newtype around [`zs::CommitBlockError`], so the wrapper must be unwrapped
127+ /// here for `is_duplicate_request()` and `misbehavior_score()` to classify
128+ /// duplicate blocks as benign.
129+ fn map_commit_error ( source : BoxError , hash : block:: Hash ) -> VerifyBlockError {
130+ if let Some ( commit_err) = source
131+ . downcast_ref :: < zs:: CommitSemanticallyVerifiedError > ( )
132+ . map ( zs:: CommitSemanticallyVerifiedError :: inner)
133+ . or_else ( || source. downcast_ref :: < zs:: CommitBlockError > ( ) )
134+ {
135+ return VerifyBlockError :: Commit ( commit_err. clone ( ) ) ;
136+ }
137+
138+ VerifyBlockError :: StateService { source, hash }
139+ }
140+
122141/// The maximum number of transparent signature operations allowed in a block.
123142///
124143/// # Consensus
@@ -380,13 +399,7 @@ where
380399 Ok ( hash)
381400 }
382401
383- Err ( source) => {
384- if let Some ( commit_err) = source. downcast_ref :: < zs:: CommitBlockError > ( ) {
385- return Err ( VerifyBlockError :: Commit ( commit_err. clone ( ) ) ) ;
386- }
387-
388- Err ( VerifyBlockError :: StateService { source, hash } )
389- }
402+ Err ( source) => Err ( map_commit_error ( source, hash) ) ,
390403
391404 _ => unreachable ! ( "wrong response for CommitSemanticallyVerifiedBlock" ) ,
392405 }
0 commit comments