@@ -2,12 +2,28 @@ use crate::proving::SolutionCandidates;
22use crate :: sector:: { sector_size, SectorContentsMap , SectorMetadataChecksummed } ;
33use crate :: { ReadAtOffset , ReadAtSync } ;
44use rayon:: prelude:: * ;
5+ use std:: io;
56use subspace_core_primitives:: crypto:: Scalar ;
67use subspace_core_primitives:: {
78 Blake3Hash , PublicKey , SBucket , SectorId , SectorIndex , SectorSlotChallenge , SolutionRange ,
89} ;
910use subspace_verification:: is_within_solution_range;
10- use tracing:: warn;
11+ use thiserror:: Error ;
12+
13+ /// Errors that happen during proving
14+ #[ derive( Debug , Error ) ]
15+ pub enum AuditingError {
16+ /// Failed read s-bucket
17+ #[ error( "Failed read s-bucket {s_bucket_audit_index} of sector {sector_index}: {error}" ) ]
18+ SBucketReading {
19+ /// Sector index
20+ sector_index : SectorIndex ,
21+ /// S-bucket audit index
22+ s_bucket_audit_index : SBucket ,
23+ /// Low-level error
24+ error : io:: Error ,
25+ } ,
26+ }
1127
1228/// Result of sector audit
1329#[ derive( Debug , Clone ) ]
@@ -42,7 +58,7 @@ pub fn audit_sector_sync<'a, Sector>(
4258 solution_range : SolutionRange ,
4359 sector : Sector ,
4460 sector_metadata : & ' a SectorMetadataChecksummed ,
45- ) -> Option < AuditResult < ' a , Sector > >
61+ ) -> Result < Option < AuditResult < ' a , Sector > > , AuditingError >
4662where
4763 Sector : ReadAtSync + ' a ,
4864{
@@ -55,26 +71,24 @@ where
5571 } = collect_sector_auditing_details ( public_key. hash ( ) , global_challenge, sector_metadata) ;
5672
5773 let mut s_bucket = vec ! [ 0 ; s_bucket_audit_size] ;
58- let read_s_bucket_result = sector. read_at ( & mut s_bucket, s_bucket_audit_offset_in_sector) ;
59-
60- if let Err ( error) = read_s_bucket_result {
61- warn ! (
62- %error,
63- sector_index = %sector_metadata. sector_index,
64- %s_bucket_audit_index,
65- "Failed read s-bucket" ,
66- ) ;
67- return None ;
68- }
74+ sector
75+ . read_at ( & mut s_bucket, s_bucket_audit_offset_in_sector)
76+ . map_err ( |error| AuditingError :: SBucketReading {
77+ sector_index : sector_metadata. sector_index ,
78+ s_bucket_audit_index,
79+ error,
80+ } ) ?;
6981
70- let ( winning_chunks, best_solution_distance) = map_winning_chunks (
82+ let Some ( ( winning_chunks, best_solution_distance) ) = map_winning_chunks (
7183 & s_bucket,
7284 global_challenge,
7385 & sector_slot_challenge,
7486 solution_range,
75- ) ?;
87+ ) else {
88+ return Ok ( None ) ;
89+ } ;
7690
77- Some ( AuditResult {
91+ Ok ( Some ( AuditResult {
7892 sector_index : sector_metadata. sector_index ,
7993 solution_candidates : SolutionCandidates :: new (
8094 public_key,
8599 winning_chunks. into ( ) ,
86100 ) ,
87101 best_solution_distance,
88- } )
102+ } ) )
89103}
90104
91105/// Audit the whole plot and generate streams of solutions
@@ -96,7 +110,7 @@ pub fn audit_plot_sync<'a, Plot>(
96110 plot : & ' a Plot ,
97111 sectors_metadata : & ' a [ SectorMetadataChecksummed ] ,
98112 maybe_sector_being_modified : Option < SectorIndex > ,
99- ) -> Vec < AuditResult < ' a , ReadAtOffset < ' a , Plot > > >
113+ ) -> Result < Vec < AuditResult < ' a , ReadAtOffset < ' a , Plot > > > , AuditingError >
100114where
101115 Plot : ReadAtSync + ' a ,
102116{
@@ -135,14 +149,11 @@ where
135149 & mut s_bucket,
136150 sector_auditing_info. s_bucket_audit_offset_in_sector ,
137151 ) {
138- warn ! (
139- %error,
140- sector_index = %sector_metadata. sector_index,
141- s_bucket_audit_index = %sector_auditing_info. s_bucket_audit_index,
142- "Failed read s-bucket" ,
143- ) ;
144-
145- return None ;
152+ return Some ( Err ( AuditingError :: SBucketReading {
153+ sector_index : sector_metadata. sector_index ,
154+ s_bucket_audit_index : sector_auditing_info. s_bucket_audit_index ,
155+ error,
156+ } ) ) ;
146157 }
147158
148159 let ( winning_chunks, best_solution_distance) = map_winning_chunks (
@@ -152,7 +163,7 @@ where
152163 solution_range,
153164 ) ?;
154165
155- Some ( AuditResult {
166+ Some ( Ok ( AuditResult {
156167 sector_index : sector_metadata. sector_index ,
157168 solution_candidates : SolutionCandidates :: new (
158169 public_key,
@@ -163,7 +174,7 @@ where
163174 winning_chunks. into ( ) ,
164175 ) ,
165176 best_solution_distance,
166- } )
177+ } ) )
167178 } )
168179 . collect ( )
169180}
0 commit comments