From 0165ae70037928c5dd3d20edca6ef046046eebcd Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 24 Aug 2020 15:18:36 -0600 Subject: [PATCH] Minor renamings. --- zcash_client_backend/src/data_api/chain.rs | 16 ++++++++-------- zcash_client_backend/src/data_api/mod.rs | 8 ++++---- zcash_client_sqlite/src/lib.rs | 14 +++++++------- zcash_client_sqlite/src/scan.rs | 7 +------ 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/zcash_client_backend/src/data_api/chain.rs b/zcash_client_backend/src/data_api/chain.rs index 78b674614..4053bcd66 100644 --- a/zcash_client_backend/src/data_api/chain.rs +++ b/zcash_client_backend/src/data_api/chain.rs @@ -255,16 +255,16 @@ where } // database updates for each block are transactional - data.transactionally(&mut data.get_mutator()?, |mutator| { + data.transactionally(&mut data.get_update_ops()?, |db_update| { // Insert the block into the database. - mutator.insert_block(height, block_hash, block_time, &tree)?; + db_update.insert_block(height, block_hash, block_time, &tree)?; for tx in txs { - let tx_row = mutator.put_tx(&tx, height)?; + let tx_row = db_update.put_tx(&tx, height)?; // Mark notes as spent and remove them from the scanning cache for spend in &tx.shielded_spends { - mutator.mark_spent(tx_row, &spend.nf)?; + db_update.mark_spent(tx_row, &spend.nf)?; } nullifiers.retain(|(nf, _acc)| { @@ -280,7 +280,7 @@ where output.witness.position() as u64, ); - let note_id = mutator.put_note(&output, &nf, tx_row)?; + let note_id = db_update.put_note(&output, &nf, tx_row)?; // Save witness for note. witnesses.push((note_id, output.witness)); @@ -292,14 +292,14 @@ where // Insert current witnesses into the database. for (note_id, witness) in witnesses.iter() { - mutator.insert_witness(*note_id, witness, last_height)?; + db_update.insert_witness(*note_id, witness, last_height)?; } // Prune the stored witnesses (we only expect rollbacks of at most 100 blocks). - mutator.prune_witnesses(last_height - 100)?; + db_update.prune_witnesses(last_height - 100)?; // Update now-expired transactions that didn't get mined. - mutator.update_expired_notes(last_height)?; + db_update.update_expired_notes(last_height)?; Ok(()) }) diff --git a/zcash_client_backend/src/data_api/mod.rs b/zcash_client_backend/src/data_api/mod.rs index 27ca46527..527b7ff89 100644 --- a/zcash_client_backend/src/data_api/mod.rs +++ b/zcash_client_backend/src/data_api/mod.rs @@ -19,7 +19,7 @@ pub mod error; pub trait DBOps { type Error; type NoteRef: Copy; // Backend-specific note identifier - type Mutator: DBUpdate; + type UpdateOps: DBUpdate; fn init_db(&self) -> Result<(), Self::Error>; @@ -81,11 +81,11 @@ pub trait DBOps { fn get_nullifiers(&self) -> Result, AccountId)>, Self::Error>; - fn get_mutator(&self) -> Result; + fn get_update_ops(&self) -> Result; - fn transactionally(&self, mutator: &mut Self::Mutator, f: F) -> Result<(), Self::Error> + fn transactionally(&self, mutator: &mut Self::UpdateOps, f: F) -> Result<(), Self::Error> where - F: FnOnce(&mut Self::Mutator) -> Result<(), Self::Error>; + F: FnOnce(&mut Self::UpdateOps) -> Result<(), Self::Error>; // fn put_sent_note(tx_ref: Self::TxRef, output: DecryptedOutput) -> Result<(), Self::Error>; // diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index ccd2c046f..d16416d42 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -77,7 +77,7 @@ impl DataConnection { impl<'a> DBOps for &'a DataConnection { type Error = SqliteClientError; type NoteRef = NoteId; - type Mutator = DBMutator<'a>; + type UpdateOps = DataConnStmtCache<'a>; fn init_db(&self) -> Result<(), Self::Error> { init::init_data_database(self).map_err(SqliteClientError::from) @@ -169,9 +169,9 @@ impl<'a> DBOps for &'a DataConnection { query::get_nullifiers(self) } - fn get_mutator(&self) -> Result { + fn get_update_ops(&self) -> Result { Ok( - DBMutator { + DataConnStmtCache { conn: self, stmt_insert_block: self.0.prepare( "INSERT INTO blocks (height, hash, time, sapling_tree) @@ -220,9 +220,9 @@ impl<'a> DBOps for &'a DataConnection { ) } - fn transactionally(&self, mutator: &mut Self::Mutator, f: F) -> Result<(), Self::Error> + fn transactionally(&self, mutator: &mut Self::UpdateOps, f: F) -> Result<(), Self::Error> where - F: FnOnce(&mut Self::Mutator) -> Result<(), Self::Error>, + F: FnOnce(&mut Self::UpdateOps) -> Result<(), Self::Error>, { self.0.execute("BEGIN IMMEDIATE", NO_PARAMS)?; match f(mutator) { @@ -247,7 +247,7 @@ impl<'a> DBOps for &'a DataConnection { } } -pub struct DBMutator<'a> { +pub struct DataConnStmtCache<'a> { conn: &'a DataConnection, stmt_insert_block: Statement<'a>, stmt_insert_tx: Statement<'a>, @@ -262,7 +262,7 @@ pub struct DBMutator<'a> { stmt_update_expired: Statement<'a>, } -impl<'a> DBUpdate for DBMutator<'a> { +impl<'a> DBUpdate for DataConnStmtCache<'a> { type Error = SqliteClientError; type TxRef = i64; type NoteRef = NoteId; diff --git a/zcash_client_sqlite/src/scan.rs b/zcash_client_sqlite/src/scan.rs index a376d2807..b6034f12f 100644 --- a/zcash_client_sqlite/src/scan.rs +++ b/zcash_client_sqlite/src/scan.rs @@ -229,7 +229,7 @@ pub fn decrypt_and_store_transaction( #[cfg(test)] mod tests { - use rusqlite::{Connection, NO_PARAMS}; + use rusqlite::Connection; use tempfile::NamedTempFile; @@ -303,11 +303,6 @@ mod tests { ) .to_string() ); - - //FIXME: scan_cached_blocks is leaving the database in an invalid - //transactional state on error; this rollback should be intrinsic - //to the failure path. - db_data.0.execute("ROLLBACK", NO_PARAMS).unwrap(); } }