Skip to content
Snippets Groups Projects
Commit faada583 authored by Éloïs's avatar Éloïs
Browse files

[fix] blockchain: avoid nested transactions

parent 9d0473c3
Branches
Tags
1 merge request!193Resolve "Migrate high-volume DBs to LMDB"
...@@ -74,6 +74,7 @@ pub fn insert_new_fork_block( ...@@ -74,6 +74,7 @@ pub fn insert_new_fork_block(
/// Modify the main branch (function to call after a successful roolback) /// Modify the main branch (function to call after a successful roolback)
pub fn change_main_branch( pub fn change_main_branch(
db: &Db, db: &Db,
w: &mut DbWriter,
fork_tree: &mut ForkTree, fork_tree: &mut ForkTree,
old_current_blockstamp: Blockstamp, old_current_blockstamp: Blockstamp,
new_current_blockstamp: Blockstamp, new_current_blockstamp: Blockstamp,
...@@ -83,15 +84,12 @@ pub fn change_main_branch( ...@@ -83,15 +84,12 @@ pub fn change_main_branch(
let removed_blockstamps = fork_tree.get_removed_blockstamps(); let removed_blockstamps = fork_tree.get_removed_blockstamps();
// Remove too old blocks // Remove too old blocks
db.write(|mut w| {
let fork_blocks_store = db.get_store(FORK_BLOCKS); let fork_blocks_store = db.get_store(FORK_BLOCKS);
for blockstamp in removed_blockstamps { for blockstamp in removed_blockstamps {
let blockstamp_bytes: Vec<u8> = blockstamp.into(); let blockstamp_bytes: Vec<u8> = blockstamp.into();
fork_blocks_store.delete(w.as_mut(), &blockstamp_bytes)?; fork_blocks_store.delete(w.as_mut(), &blockstamp_bytes)?;
} }
Ok(())
Ok(w)
})
} }
#[cfg(test)] #[cfg(test)]
......
...@@ -146,6 +146,7 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) ...@@ -146,6 +146,7 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>)
// update main branch in fork tree // update main branch in fork tree
if let Err(err) = durs_bc_db_writer::blocks::fork_tree::change_main_branch( if let Err(err) = durs_bc_db_writer::blocks::fork_tree::change_main_branch(
&db, &db,
&mut w,
&mut bc.fork_tree, &mut bc.fork_tree,
old_current_blockstamp, old_current_blockstamp,
bc.current_blockstamp, bc.current_blockstamp,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment