ouroboros-consensus-diffusion-0.18.0.0: Integration for the Ouroboros Network layer
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.Node.DbMarker

Description

Special file we store in the DB dir to avoid unintended deletions

Synopsis

Documentation

data DbMarkerError Source #

Constructors

NetworkMagicMismatch

There was a dbMarkerFile in the database folder, but it contained a different NetworkMagic than the expected one. This indicates that this database folder corresponds to another net.

Fields

NoDbMarkerAndNotEmpty

The database folder contained no dbMarkerFile, but also contained some files. Either the given folder is a non-database folder or it is a database folder, but its dbMarkerFile has been deleted.

Fields

CorruptDbMarker

The database folder contained a dbMarkerFile that could not be read. The file has been tampered with or it was corrupted somehow.

Fields

checkDbMarker Source #

Arguments

∷ ∀ m h. MonadThrow m 
HasFS m h 
MountPoint

Database directory. Should be the mount point of the HasFS. Used in error messages.

NetworkMagic 
→ m (Either DbMarkerError ()) 

Check database marker

The database folder will contain folders for the ImmutableDB (immutable), the VolatileDB (volatile), and the LedgerDB (ledger). All three subdatabases can delete files from these folders, e.g., outdated files or files that are deemed invalid.

For example, when starting a node that will connect to a testnet with a database folder containing mainnet blocks, these blocks will be deemed invalid and will be deleted. This would throw away a perfectly good chain, possibly consisting of gigabytes of data that will have to be synched again.

To protect us from unwanted deletion of valid files, we first check whether we have been given the path to the right database folder. We do this by reading the NetworkMagic of the net from a file stored in the root of the database folder. This file's name is defined in dbMarkerFile.

  • If the NetworkMagic from the file matches that of the net, we have the right database folder.
  • If not, we are opening the wrong database folder and abort by throwing a DbMarkerError.
  • If there is no such file and the folder is empty, we create it and store the net's NetworkMagic in it.
  • If there is no such file, but the folder is not empty, we throw a DbMarkerError, because we have likely been given the wrong path, maybe to a folder containing user or system files. This includes the case that the dbMarkerFile has been deleted.
  • If there is such a dbMarkerFile, but it could not be read or its contents could not be parsed, we also throw a DbMarkerError.

Note that an FsError can also be thrown.

For the benefit of testing only

dbMarkerFileText Source #

For legacy reasons it was using ProtocolMagicId not NetworkMagic which are really the same thing.

dbMarkerParseMonad m ⇒ FilePathByteStringExceptT DbMarkerError m NetworkMagic Source #

Parse contents of the DB marker file

Must be inverse to dbMarkerContents