Skip to content

Commit 8a7768d

Browse files
committed
fix: release the chainstate db before locking the sortition db
This ordering needs to be maintained to avoid deadlock.
1 parent 6b05a3f commit 8a7768d

File tree

1 file changed

+9
-9
lines changed
  • stackslib/src/chainstate/nakamoto

1 file changed

+9
-9
lines changed

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,15 @@ impl NakamotoChainState {
19921992
next_ready_block.header.consensus_hash
19931993
);
19941994

1995+
// this will panic if the Clarity commit fails.
1996+
clarity_commit.commit();
1997+
chainstate_tx.commit()
1998+
.unwrap_or_else(|e| {
1999+
error!("Failed to commit chainstate transaction after committing Clarity block. The chainstate database is now corrupted.";
2000+
"error" => ?e);
2001+
panic!()
2002+
});
2003+
19952004
// set stacks block accepted
19962005
let mut sort_tx = sort_db.tx_handle_begin(canonical_sortition_tip)?;
19972006
sort_tx.set_stacks_block_accepted(
@@ -2000,15 +2009,6 @@ impl NakamotoChainState {
20002009
next_ready_block.header.chain_length,
20012010
)?;
20022011

2003-
// this will panic if the Clarity commit fails.
2004-
clarity_commit.commit();
2005-
chainstate_tx.commit()
2006-
.unwrap_or_else(|e| {
2007-
error!("Failed to commit chainstate transaction after committing Clarity block. The chainstate database is now corrupted.";
2008-
"error" => ?e);
2009-
panic!()
2010-
});
2011-
20122012
// as a separate transaction, mark this block as processed.
20132013
// This is done separately so that the staging blocks DB, which receives writes
20142014
// from the network to store blocks, will be available for writes while a block is

0 commit comments

Comments
 (0)