Minor renamings.
This commit is contained in:
parent
746c4c9a00
commit
0165ae7003
|
@ -255,16 +255,16 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// database updates for each block are transactional
|
// 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.
|
// 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 {
|
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
|
// Mark notes as spent and remove them from the scanning cache
|
||||||
for spend in &tx.shielded_spends {
|
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)| {
|
nullifiers.retain(|(nf, _acc)| {
|
||||||
|
@ -280,7 +280,7 @@ where
|
||||||
output.witness.position() as u64,
|
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.
|
// Save witness for note.
|
||||||
witnesses.push((note_id, output.witness));
|
witnesses.push((note_id, output.witness));
|
||||||
|
@ -292,14 +292,14 @@ where
|
||||||
|
|
||||||
// Insert current witnesses into the database.
|
// Insert current witnesses into the database.
|
||||||
for (note_id, witness) in witnesses.iter() {
|
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).
|
// 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.
|
// Update now-expired transactions that didn't get mined.
|
||||||
mutator.update_expired_notes(last_height)?;
|
db_update.update_expired_notes(last_height)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub mod error;
|
||||||
pub trait DBOps {
|
pub trait DBOps {
|
||||||
type Error;
|
type Error;
|
||||||
type NoteRef: Copy; // Backend-specific note identifier
|
type NoteRef: Copy; // Backend-specific note identifier
|
||||||
type Mutator: DBUpdate<Error = Self::Error, NoteRef = Self::NoteRef>;
|
type UpdateOps: DBUpdate<Error = Self::Error, NoteRef = Self::NoteRef>;
|
||||||
|
|
||||||
fn init_db(&self) -> Result<(), Self::Error>;
|
fn init_db(&self) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
|
@ -81,11 +81,11 @@ pub trait DBOps {
|
||||||
|
|
||||||
fn get_nullifiers(&self) -> Result<Vec<(Vec<u8>, AccountId)>, Self::Error>;
|
fn get_nullifiers(&self) -> Result<Vec<(Vec<u8>, AccountId)>, Self::Error>;
|
||||||
|
|
||||||
fn get_mutator(&self) -> Result<Self::Mutator, Self::Error>;
|
fn get_update_ops(&self) -> Result<Self::UpdateOps, Self::Error>;
|
||||||
|
|
||||||
fn transactionally<F>(&self, mutator: &mut Self::Mutator, f: F) -> Result<(), Self::Error>
|
fn transactionally<F>(&self, mutator: &mut Self::UpdateOps, f: F) -> Result<(), Self::Error>
|
||||||
where
|
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>;
|
// fn put_sent_note(tx_ref: Self::TxRef, output: DecryptedOutput) -> Result<(), Self::Error>;
|
||||||
//
|
//
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl DataConnection {
|
||||||
impl<'a> DBOps for &'a DataConnection {
|
impl<'a> DBOps for &'a DataConnection {
|
||||||
type Error = SqliteClientError;
|
type Error = SqliteClientError;
|
||||||
type NoteRef = NoteId;
|
type NoteRef = NoteId;
|
||||||
type Mutator = DBMutator<'a>;
|
type UpdateOps = DataConnStmtCache<'a>;
|
||||||
|
|
||||||
fn init_db(&self) -> Result<(), Self::Error> {
|
fn init_db(&self) -> Result<(), Self::Error> {
|
||||||
init::init_data_database(self).map_err(SqliteClientError::from)
|
init::init_data_database(self).map_err(SqliteClientError::from)
|
||||||
|
@ -169,9 +169,9 @@ impl<'a> DBOps for &'a DataConnection {
|
||||||
query::get_nullifiers(self)
|
query::get_nullifiers(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_mutator(&self) -> Result<Self::Mutator, Self::Error> {
|
fn get_update_ops(&self) -> Result<Self::UpdateOps, Self::Error> {
|
||||||
Ok(
|
Ok(
|
||||||
DBMutator {
|
DataConnStmtCache {
|
||||||
conn: self,
|
conn: self,
|
||||||
stmt_insert_block: self.0.prepare(
|
stmt_insert_block: self.0.prepare(
|
||||||
"INSERT INTO blocks (height, hash, time, sapling_tree)
|
"INSERT INTO blocks (height, hash, time, sapling_tree)
|
||||||
|
@ -220,9 +220,9 @@ impl<'a> DBOps for &'a DataConnection {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transactionally<F>(&self, mutator: &mut Self::Mutator, f: F) -> Result<(), Self::Error>
|
fn transactionally<F>(&self, mutator: &mut Self::UpdateOps, f: F) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self::Mutator) -> Result<(), Self::Error>,
|
F: FnOnce(&mut Self::UpdateOps) -> Result<(), Self::Error>,
|
||||||
{
|
{
|
||||||
self.0.execute("BEGIN IMMEDIATE", NO_PARAMS)?;
|
self.0.execute("BEGIN IMMEDIATE", NO_PARAMS)?;
|
||||||
match f(mutator) {
|
match f(mutator) {
|
||||||
|
@ -247,7 +247,7 @@ impl<'a> DBOps for &'a DataConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DBMutator<'a> {
|
pub struct DataConnStmtCache<'a> {
|
||||||
conn: &'a DataConnection,
|
conn: &'a DataConnection,
|
||||||
stmt_insert_block: Statement<'a>,
|
stmt_insert_block: Statement<'a>,
|
||||||
stmt_insert_tx: Statement<'a>,
|
stmt_insert_tx: Statement<'a>,
|
||||||
|
@ -262,7 +262,7 @@ pub struct DBMutator<'a> {
|
||||||
stmt_update_expired: Statement<'a>,
|
stmt_update_expired: Statement<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DBUpdate for DBMutator<'a> {
|
impl<'a> DBUpdate for DataConnStmtCache<'a> {
|
||||||
type Error = SqliteClientError;
|
type Error = SqliteClientError;
|
||||||
type TxRef = i64;
|
type TxRef = i64;
|
||||||
type NoteRef = NoteId;
|
type NoteRef = NoteId;
|
||||||
|
|
|
@ -229,7 +229,7 @@ pub fn decrypt_and_store_transaction<P: consensus::Parameters>(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use rusqlite::{Connection, NO_PARAMS};
|
use rusqlite::Connection;
|
||||||
|
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
|
@ -303,11 +303,6 @@ mod tests {
|
||||||
)
|
)
|
||||||
.to_string()
|
.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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue