Skip to content

Commit

Permalink
rocksdb-store: moved check back, oops
Browse files Browse the repository at this point in the history
  • Loading branch information
delbonis committed Jan 30, 2025
1 parent fb2cac4 commit 1ff4722
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/rocksdb-store/src/chain_state/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ impl ChainstateDatabase for ChainstateDb {
}

fn put_write_batch(&self, idx: u64, batch: strata_state::state_op::WriteBatch) -> DbResult<()> {
if self.db.get::<WriteBatchSchema>(&idx)?.is_some() {
return Err(DbError::OverwriteStateUpdate(idx));
}

// Make sure we always have a contiguous range of batches.
// FIXME this *could* be a race condition / TOCTOU issue, but we're only
// going to be writing from a single thread anyways so it should be fine
Expand All @@ -57,10 +61,6 @@ impl ChainstateDatabase for ChainstateDb {
None => return Err(DbError::NotBootstrapped),
}

if self.db.get::<WriteBatchSchema>(&idx)?.is_some() {
return Err(DbError::OverwriteStateUpdate(idx));
}

// TODO maybe do this in a tx to make sure we don't race/TOCTOU it
self.db.put::<WriteBatchSchema>(&idx, &batch)?;

Expand Down

0 comments on commit 1ff4722

Please sign in to comment.