Remove WalletWrite::transactionally
This commit is contained in:
parent
a74cc8b231
commit
16289750e8
|
@ -205,15 +205,6 @@ pub struct SentTransaction<'a> {
|
||||||
/// This trait encapsulates the write capabilities required to update stored
|
/// This trait encapsulates the write capabilities required to update stored
|
||||||
/// wallet data.
|
/// wallet data.
|
||||||
pub trait WalletWrite: WalletRead {
|
pub trait WalletWrite: WalletRead {
|
||||||
/// Perform one or more write operations of this trait transactionally.
|
|
||||||
/// Implementations of this method must ensure that all mutations to the
|
|
||||||
/// state of the data store made by the provided closure must be performed
|
|
||||||
/// atomically and modifications to state must be automatically rolled back
|
|
||||||
/// if the provided closure returns an error.
|
|
||||||
fn transactionally<F, A>(&mut self, f: F) -> Result<A, Self::Error>
|
|
||||||
where
|
|
||||||
F: FnOnce(&mut Self) -> Result<A, Self::Error>;
|
|
||||||
|
|
||||||
fn insert_pruned_block(
|
fn insert_pruned_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
block: &PrunedBlock,
|
block: &PrunedBlock,
|
||||||
|
@ -241,21 +232,6 @@ pub trait WalletWrite: WalletRead {
|
||||||
///
|
///
|
||||||
/// There may be restrictions on how far it is possible to rewind.
|
/// There may be restrictions on how far it is possible to rewind.
|
||||||
fn rewind_to_height(&mut self, block_height: BlockHeight) -> Result<(), Self::Error>;
|
fn rewind_to_height(&mut self, block_height: BlockHeight) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Mark the specified transaction as spent and record the nullifier.
|
|
||||||
fn mark_spent(&mut self, tx_ref: Self::TxRef, nf: &Nullifier) -> Result<(), Self::Error>;
|
|
||||||
|
|
||||||
/// Remove all incremental witness data before the specified block height.
|
|
||||||
// TODO: this is a backend-specific optimization that probably shouldn't be part of
|
|
||||||
// the public API
|
|
||||||
fn prune_witnesses(&mut self, from_height: BlockHeight) -> Result<(), Self::Error>;
|
|
||||||
|
|
||||||
/// Remove the spent marker from any received notes that had been spent in a
|
|
||||||
/// transaction constructed by the wallet, but which transaction had not been mined
|
|
||||||
/// by the specified block height.
|
|
||||||
// TODO: this is a backend-specific optimization that probably shouldn't be part of
|
|
||||||
// the public API
|
|
||||||
fn update_expired_notes(&mut self, from_height: BlockHeight) -> Result<(), Self::Error>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This trait provides sequential access to raw blockchain data via a callback-oriented
|
/// This trait provides sequential access to raw blockchain data via a callback-oriented
|
||||||
|
@ -471,13 +447,6 @@ pub mod testing {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalletWrite for MockWalletDB {
|
impl WalletWrite for MockWalletDB {
|
||||||
fn transactionally<F, A>(&mut self, f: F) -> Result<A, Self::Error>
|
|
||||||
where
|
|
||||||
F: FnOnce(&mut Self) -> Result<A, Self::Error>,
|
|
||||||
{
|
|
||||||
f(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn insert_pruned_block(
|
fn insert_pruned_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
_block: &PrunedBlock,
|
_block: &PrunedBlock,
|
||||||
|
@ -503,17 +472,5 @@ pub mod testing {
|
||||||
fn rewind_to_height(&mut self, _block_height: BlockHeight) -> Result<(), Self::Error> {
|
fn rewind_to_height(&mut self, _block_height: BlockHeight) -> Result<(), Self::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_spent(&mut self, _tx_ref: Self::TxRef, _nf: &Nullifier) -> Result<(), Self::Error> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prune_witnesses(&mut self, _from_height: BlockHeight) -> Result<(), Self::Error> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_expired_notes(&mut self, _from_height: BlockHeight) -> Result<(), Self::Error> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,12 +339,6 @@ where
|
||||||
&witnesses,
|
&witnesses,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Prune the stored witnesses (we only expect rollbacks of at most 100 blocks).
|
|
||||||
data.prune_witnesses(current_height - 100)?;
|
|
||||||
|
|
||||||
// Update now-expired transactions that didn't get mined.
|
|
||||||
data.update_expired_notes(current_height)?;
|
|
||||||
|
|
||||||
let spent_nf: Vec<Nullifier> = txs
|
let spent_nf: Vec<Nullifier> = txs
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|tx| tx.shielded_spends.iter().map(|spend| spend.nf))
|
.flat_map(|tx| tx.shielded_spends.iter().map(|spend| spend.nf))
|
||||||
|
|
|
@ -359,10 +359,10 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
|
impl<'a, P: consensus::Parameters> DataConnStmtCache<'a, P> {
|
||||||
fn transactionally<F, A>(&mut self, f: F) -> Result<A, Self::Error>
|
fn transactionally<F, A>(&mut self, f: F) -> Result<A, SqliteClientError>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> Result<A, Self::Error>,
|
F: FnOnce(&mut Self) -> Result<A, SqliteClientError>,
|
||||||
{
|
{
|
||||||
self.wallet_db.conn.execute("BEGIN IMMEDIATE", NO_PARAMS)?;
|
self.wallet_db.conn.execute("BEGIN IMMEDIATE", NO_PARAMS)?;
|
||||||
match f(self) {
|
match f(self) {
|
||||||
|
@ -385,7 +385,9 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
|
||||||
fn insert_pruned_block(
|
fn insert_pruned_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
block: &PrunedBlock,
|
block: &PrunedBlock,
|
||||||
|
@ -427,6 +429,12 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prune the stored witnesses (we only expect rollbacks of at most 100 blocks).
|
||||||
|
wallet::prune_witnesses(up, block.block_height - 100)?;
|
||||||
|
|
||||||
|
// Update now-expired transactions that didn't get mined.
|
||||||
|
wallet::update_expired_notes(up, block.block_height)?;
|
||||||
|
|
||||||
Ok(new_witnesses)
|
Ok(new_witnesses)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -485,18 +493,6 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
|
||||||
fn rewind_to_height(&mut self, block_height: BlockHeight) -> Result<(), Self::Error> {
|
fn rewind_to_height(&mut self, block_height: BlockHeight) -> Result<(), Self::Error> {
|
||||||
wallet::rewind_to_height(self.wallet_db, block_height)
|
wallet::rewind_to_height(self.wallet_db, block_height)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_spent(&mut self, tx_ref: Self::TxRef, nf: &Nullifier) -> Result<(), Self::Error> {
|
|
||||||
wallet::mark_spent(self, tx_ref, nf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prune_witnesses(&mut self, below_height: BlockHeight) -> Result<(), Self::Error> {
|
|
||||||
wallet::prune_witnesses(self, below_height)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_expired_notes(&mut self, height: BlockHeight) -> Result<(), Self::Error> {
|
|
||||||
wallet::update_expired_notes(self, height)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BlockDB(Connection);
|
pub struct BlockDB(Connection);
|
||||||
|
|
Loading…
Reference in New Issue