Skip to content

Commit

Permalink
Merge pull request #3007 from autonomys/fix-records-encoding
Browse files Browse the repository at this point in the history
Fix records encoding
  • Loading branch information
nazar-pc authored Sep 9, 2024
2 parents f73c757 + ca83100 commit 7b69fc7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/subspace-farmer-components/src/plotting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ fn record_encoding<PosTable>(
.drain(..)
.zip(encoded_chunks_used.iter_mut())
.filter_map(|(maybe_encoded_chunk, mut encoded_chunk_used)| {
// Last byte's bits all set to 1 represents missing proof, see above
if maybe_encoded_chunk[31] == u8::MAX {
// All bits set means no proof, see above
if maybe_encoded_chunk == [u8::MAX; Scalar::FULL_BYTES] {
None
} else {
*encoded_chunk_used = true;
Expand Down
35 changes: 32 additions & 3 deletions crates/subspace-farmer/src/single_disk_farm/farming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ use std::collections::HashSet;
use std::sync::Arc;
use std::time::Instant;
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::{PosSeed, PublicKey, SectorIndex, Solution, SolutionRange};
use subspace_core_primitives::{
HistorySize, PosSeed, PublicKey, Record, SectorIndex, SegmentIndex, Solution, SolutionRange,
};
use subspace_erasure_coding::ErasureCoding;
use subspace_farmer_components::auditing::{audit_plot_sync, AuditingError};
use subspace_farmer_components::proving::{ProvableSolutions, ProvingError};
use subspace_farmer_components::reading::ReadSectorRecordChunksMode;
use subspace_farmer_components::sector::SectorMetadataChecksummed;
use subspace_farmer_components::sector::{SectorMetadata, SectorMetadataChecksummed};
use subspace_farmer_components::ReadAtSync;
use subspace_proof_of_space::{Table, TableGenerator};
use subspace_rpc_primitives::{SlotInfo, SolutionResponse};
Expand Down Expand Up @@ -257,6 +259,7 @@ where
// Take mutex briefly to make sure farming is allowed right now
global_mutex.lock().await;

let mut problematic_sectors = Vec::new();
let result: Result<(), FarmingError> = try {
let start = Instant::now();
let sectors_metadata = sectors_metadata.read().await;
Expand Down Expand Up @@ -326,7 +329,13 @@ where
metrics
.observe_proving_time(&start.elapsed(), ProvingResult::Failed);
}
error!(%slot, %sector_index, %error, "Failed to prove");
error!(
%slot,
%sector_index,
%error,
"Failed to prove, scheduling sector for replotting"
);
problematic_sectors.push(sector_index);
// Do not error completely as disk corruption or other reasons why
// proving might fail
start = Instant::now();
Expand Down Expand Up @@ -423,6 +432,26 @@ where
handlers
.farming_notification
.call_simple(&FarmingNotification::NonFatalError(Arc::new(error)));

for sector_index in problematic_sectors.drain(..) {
// Inform others that this sector is being modified
sectors_being_modified.write().await.insert(sector_index);
// Replace metadata with a dummy one, so it will be picked up for replotting next
if let Some(existing_sector_metadata) = sectors_metadata
.write()
.await
.get_mut(sector_index as usize)
{
*existing_sector_metadata = SectorMetadataChecksummed::from(SectorMetadata {
sector_index,
pieces_in_sector: existing_sector_metadata.pieces_in_sector,
s_bucket_sizes: Box::new([0; Record::NUM_S_BUCKETS]),
history_size: HistorySize::from(SegmentIndex::ZERO),
});
}
// Inform others that this sector is no longer being modified
sectors_being_modified.write().await.remove(&sector_index);
}
} else {
non_fatal_errors = 0;
}
Expand Down

0 comments on commit 7b69fc7

Please sign in to comment.