Skip to content

Commit 90026a8

Browse files
authored
@peter/fix seal (#402)
* fix seal issue
1 parent 5a94554 commit 90026a8

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

node/storage/src/log_store/flow_store.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use append_merkle::{
1717
};
1818
use itertools::Itertools;
1919
use kvdb::DBTransaction;
20-
use parking_lot::{Mutex, RwLock};
20+
use parking_lot::RwLock;
2121
use shared_types::{ChunkArray, DataRoot, FlowProof};
2222
use ssz::{Decode, Encode};
2323
use ssz_derive::{Decode as DeriveDecode, Encode as DeriveEncode};
@@ -263,10 +263,13 @@ impl FlowWrite for FlowStore {
263263
)?;
264264
if self.seal_manager.seal_worker_available() && batch.is_complete() {
265265
for seal_index in 0..SEALS_PER_LOAD {
266-
to_seal_set.insert(
267-
chunk_index as usize * SEALS_PER_LOAD + seal_index,
268-
self.seal_manager.to_seal_version(),
269-
);
266+
// Only add seals that are not already sealed
267+
if !batch.is_seal_sealed(seal_index as u16) {
268+
to_seal_set.insert(
269+
chunk_index as usize * SEALS_PER_LOAD + seal_index,
270+
self.seal_manager.to_seal_version(),
271+
);
272+
}
270273
}
271274
}
272275

@@ -391,23 +394,17 @@ pub struct PadPair {
391394

392395
pub struct FlowDBStore {
393396
kvdb: Arc<dyn ZgsKeyValueDB>,
394-
// Mutex to prevent race condition between put_entry_batch_list and put_entry_raw
395-
write_mutex: Mutex<()>,
396397
}
397398

398399
impl FlowDBStore {
399400
pub fn new(kvdb: Arc<dyn ZgsKeyValueDB>) -> Self {
400-
Self {
401-
kvdb,
402-
write_mutex: Mutex::new(()),
403-
}
401+
Self { kvdb }
404402
}
405403

406404
fn put_entry_batch_list(
407405
&self,
408406
batch_list: Vec<(u64, EntryBatch)>,
409407
) -> Result<Vec<(u64, DataRoot)>> {
410-
let _lock = self.write_mutex.lock();
411408
let start_time = Instant::now();
412409
let mut completed_batches = Vec::new();
413410
let mut tx = self.kvdb.transaction();
@@ -429,7 +426,6 @@ impl FlowDBStore {
429426
}
430427

431428
fn put_entry_raw(&self, batch_list: Vec<(u64, EntryBatch)>) -> Result<()> {
432-
let _lock = self.write_mutex.lock();
433429
let mut tx = self.kvdb.transaction();
434430
for (batch_index, batch) in batch_list {
435431
tx.put(

node/storage/src/log_store/load_chunk/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ impl EntryBatch {
7171
pub fn is_complete(&self) -> bool {
7272
matches!(self.data, EntryBatchData::Complete(_))
7373
}
74+
75+
/// Check if a specific seal is already sealed
76+
pub fn is_seal_sealed(&self, seal_index: u16) -> bool {
77+
self.seal.is_sealed(seal_index)
78+
}
7479
}
7580

7681
impl EntryBatch {

0 commit comments

Comments
 (0)