Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clean state initialization #3514

Merged
merged 1 commit into from
Dec 2, 2021

Conversation

jasagredo
Copy link
Contributor

@jasagredo jasagredo commented Nov 30, 2021

Due to the unmasking of exceptions during ChainDB initialization, it is the case right now that the exit code is different from DatabaseCorruption and therefore the withCheckedDb function considers that it has to create the clean file. Because of this, a Ctrl+C during initialization would skip the validation on the next startup.

This PR ensures that the clean file is only removed after the chainDB is initialized (and therefore potentially modified) and from that point on it can be created again.

initial status killed when on SIGKILL on DatabaseCorruption on other exception (e.g. ^C)
clean during initialization unclean → clean clean → unclean clean
clean after initialization unclean unclean clean
unclean during initialization unclean unclean clean → unclean
unclean after initialization unclean unclean clean

@jasagredo jasagredo force-pushed the jasagredo/fix-clean-state-initialization branch from 1e9c1e8 to 2b39adc Compare November 30, 2021 15:27
Copy link
Member

@dnadales dnadales left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it'd like to go through this over a call.

ouroboros-consensus/src/Ouroboros/Consensus/Node.hs Outdated Show resolved Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Node.hs Outdated Show resolved Hide resolved
Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this does what we want, but I think there's a more suitable implementation; one that doesn't use a mutvar "unnecessarily".

I'm thinking something like:

llrnWithCheckedDB :: forall a. (LastShutDownWasClean -> m (a, ThisShutDownWasClean)) -> m a

Or maybe something like

llrnWithCheckedDB :: forall a. (LastShutDownWasClean -> (forall b. m b -> m b) -> m a) -> m a

Where the passes wrapper is applied to the continuation of initialization, and it's the part that removes the marker (if present) and installs the handler that writes it.

Let's chat about it.

ouroboros-consensus/src/Ouroboros/Consensus/Node.hs Outdated Show resolved Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Node.hs Outdated Show resolved Hide resolved
@jasagredo jasagredo force-pushed the jasagredo/fix-clean-state-initialization branch 2 times, most recently from 0ffe572 to 173744c Compare December 1, 2021 08:44
@jasagredo jasagredo force-pushed the jasagredo/fix-clean-state-initialization branch 2 times, most recently from 3e61223 to 978924c Compare December 1, 2021 15:54
@jasagredo jasagredo force-pushed the jasagredo/fix-clean-state-initialization branch from 887aeef to 1a72165 Compare December 2, 2021 15:26
@nfrisby nfrisby force-pushed the jasagredo/fix-clean-state-initialization branch from 1a72165 to 51fea95 Compare December 2, 2021 18:14
@nfrisby
Copy link
Contributor

nfrisby commented Dec 2, 2021

I amended your commit with a tiny change, just renaming wrapper:

$ git show
commit ec01f675b0fe647b04e55d6c246d7bfe60bbc18b (HEAD -> jasagredo/fix-clean-state-initialization)
Author: Nicolas Frisby <nick.frisby@iohk.io>
Date:   Thu Dec 2 10:13:48 2021 -0800

    TOSQUASH: rename wrapper

diff --git a/ouroboros-consensus/src/Ouroboros/Consensus/Node.hs b/ouroboros-consensus/src/Ouroboros/Consensus/Node.hs
index f530ebe37..7c655a3bb 100644
--- a/ouroboros-consensus/src/Ouroboros/Consensus/Node.hs
+++ b/ouroboros-consensus/src/Ouroboros/Consensus/Node.hs
@@ -282,7 +282,7 @@ runWith :: forall m addrNTN addrNTC versionDataNTN versionDataNTC blk p2p.
   -> m ()
 runWith RunNodeArgs{..} LowLevelRunNodeArgs{..} =
 
-    llrnWithCheckedDB $ \(LastShutDownWasClean lastShutDownWasClean) wrapper ->
+    llrnWithCheckedDB $ \(LastShutDownWasClean lastShutDownWasClean) continueWithCleanChainDB ->
     withRegistry $ \registry -> do
       let systemStart :: SystemStart
           systemStart = getSystemStart (configBlock cfg)
@@ -315,7 +315,7 @@ runWith RunNodeArgs{..} LowLevelRunNodeArgs{..} =
       chainDB <- openChainDB registry inFuture cfg initLedger
                 llrnChainDbArgsDefaults customiseChainDbArgs'
 
-      wrapper chainDB $ do
+      continueWithCleanChainDB chainDB $ do
         btime <-
           hardForkBlockchainTime $
           llrnCustomiseHardForkBlockchainTimeArgs $

I squashed that into your commit and force-pushed it back up.

Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@nfrisby
Copy link
Contributor

nfrisby commented Dec 2, 2021

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Dec 2, 2021

@iohk-bors iohk-bors bot merged commit 1102632 into master Dec 2, 2021
@iohk-bors iohk-bors bot deleted the jasagredo/fix-clean-state-initialization branch December 2, 2021 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants