Fix transactionality in rewind_to_height
This commit is contained in:
parent
4c2cda48e6
commit
903ef58ec6
|
@ -341,28 +341,28 @@ pub fn rewind_to_height<P: consensus::Parameters>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start an SQL transaction for rewinding.
|
// Start an SQL transaction for rewinding.
|
||||||
conn.0.execute("BEGIN IMMEDIATE", NO_PARAMS)?;
|
let tx = conn.0.unchecked_transaction()?;
|
||||||
|
|
||||||
// Decrement witnesses.
|
// Decrement witnesses.
|
||||||
conn.0.execute(
|
tx.execute(
|
||||||
"DELETE FROM sapling_witnesses WHERE block > ?",
|
"DELETE FROM sapling_witnesses WHERE block > ?",
|
||||||
&[u32::from(block_height)],
|
&[u32::from(block_height)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Un-mine transactions.
|
// Un-mine transactions.
|
||||||
conn.0.execute(
|
tx.execute(
|
||||||
"UPDATE transactions SET block = NULL, tx_index = NULL WHERE block > ?",
|
"UPDATE transactions SET block = NULL, tx_index = NULL WHERE block > ?",
|
||||||
&[u32::from(block_height)],
|
&[u32::from(block_height)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Now that they aren't depended on, delete scanned blocks.
|
// Now that they aren't depended on, delete scanned blocks.
|
||||||
conn.0.execute(
|
tx.execute(
|
||||||
"DELETE FROM blocks WHERE height > ?",
|
"DELETE FROM blocks WHERE height > ?",
|
||||||
&[u32::from(block_height)],
|
&[u32::from(block_height)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Commit the SQL transaction, rewinding atomically.
|
// Commit the SQL transaction, rewinding atomically.
|
||||||
conn.0.execute("COMMIT", NO_PARAMS)?;
|
tx.commit()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue