tari-project/tari

Add SQL concurrency check to key manager state `set_index`

Opened this issue · 0 comments

Regarding this code:

pub fn set_index(id: i32, index: Vec<u8>, conn: &mut SqliteConnection) -> Result<(), KeyManagerStorageError> {

Expected:
The SQL update should have a where clause protecting against concurrent writes. If thread1 reads the index, then thread2 reads the index and then thread2 writes before thread1, then thread1 should fail when it tries to write.
This is easily achieved by passing in the old value and adding a where clause to check the value is still what was read. Then the method can fail if the SQL affects no rows.