Skip to content

Commit

Permalink
fix: blind writes in ssi
Browse files Browse the repository at this point in the history
  • Loading branch information
arriqaaq committed Nov 18, 2024
1 parent 54406cd commit a7e55da
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
58 changes: 35 additions & 23 deletions src/storage/kv/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,32 +254,44 @@ impl CommitTracker {
/// Checks if a transaction has conflicts with committed transactions.
/// It acquires a lock on the read set and checks if there are any conflict keys in the read set.
fn has_conflict(&self, txn: &Transaction) -> bool {
if txn.read_set.is_empty() {
false
} else {
// For each object in the changeset of the already committed transactions, check if it lies
// within the predicates of the current transaction.
for committed_tx in self.committed_transactions.iter() {
if committed_tx.ts > txn.read_ts {
for conflict_key in committed_tx.conflict_keys.iter() {
for rs_entry in txn.read_key_ranges.iter() {
if key_in_range(conflict_key, &rs_entry.start, &rs_entry.end) {
return true;
}
}
}
}
}

// For each object in the changeset of the already committed transactions, check if it lies
// within the predicates of the current transaction.
let predicate_conflict = if !txn.read_key_ranges.is_empty() {
self.committed_transactions
.iter()
.filter(|committed_txn| committed_txn.ts > txn.read_ts)
.any(|committed_txn| {
txn.read_set
.iter()
.any(|read| committed_txn.conflict_keys.contains(&read.key))
.filter(|committed_tx| committed_tx.ts > txn.read_ts)
.any(|committed_tx| {
committed_tx.conflict_keys.iter().any(|conflict_key| {
txn.read_key_ranges.iter().any(|rs_entry| {
key_in_range(conflict_key, &rs_entry.start, &rs_entry.end)
})
})
})
}
} else {
false
};

let read_set_conflict = self
.committed_transactions
.iter()
.filter(|committed_tx| committed_tx.ts > txn.read_ts)
.any(|committed_tx| {
txn.read_set
.iter()
.any(|read| committed_tx.conflict_keys.contains(&read.key))
});

let write_set_conflict = self
.committed_transactions
.iter()
.filter(|committed_tx| committed_tx.ts > txn.read_ts)
.any(|committed_tx| {
txn.write_set
.keys()
.any(|write_key| committed_tx.conflict_keys.contains(write_key))
});

predicate_conflict || read_set_conflict || write_set_conflict
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/storage/kv/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,9 @@ mod tests {
Err(err) => {
matches!(err, Error::TransactionReadConflict)
}
_ => false,
_ => {
false
}
});
}

Expand Down Expand Up @@ -1257,7 +1259,7 @@ mod tests {
}
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn mvcc_serialized_snapshot_isolation_scan() {
mvcc_with_scan_tests(true).await;
}
Expand Down

0 comments on commit a7e55da

Please sign in to comment.