Skip to content

Commit e87e9ba

Browse files
parsonsmattKtorZ
authored andcommitted
[CBR-446] Use acid-state fix
- uses a temporary fork of acid-state which incorporates a fix for a memory leak when the process goes for a long time without checkpointing - Removes the checkpointing process in the BListener codebase, as that was a work-around for the acid-state problem.
1 parent 24a3249 commit e87e9ba

File tree

4 files changed

+9
-33
lines changed

4 files changed

+9
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Cabal & Stack
22
.stack-work/
3+
.stack-work-profile/
34
*/dist
45
dist-newstyle/
56
.ghc.environment.*

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ stylish: ## Run stylish-haskell on the entire project
1010
build-all: ## Build everything, including benchmarks and tests, but don't run them
1111
stack build --fast --bench --no-run-benchmarks --test --no-run-tests
1212

13+
build-profile: ## Build with profiling in a special .stack-work directory.
14+
stack build --profile --work-dir .stack-work-profile
15+
1316
ghcid: ## Pass DIR=package-directory to run that directory's ghcid command.
1417
ifeq ($(DIR),)
1518
echo "You must specify the package directory for this command."

stack.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ packages:
125125
commit: 5d8ff2b07b9df35cf61329a3d975e2c8cf95c12a
126126
extra-dep: true
127127

128-
# Waiting on the flexible types PR to be merged:
129-
# https://github.com/acid-state/acid-state/pull/94
128+
# Waiting on the space leak bug fix PR to be merged:
129+
# https://github.com/acid-state/acid-state/pull/104
130130
- location:
131131
git: https://github.com/parsonsmatt/acid-state
132-
commit: 63ac55ae020655104936d8a90ccc6a939642cd0d
132+
commit: a1b23e2056f134e53f705a694ab85deeecabec5c
133133
extra-dep: true
134134

135135
# Required for explorer.

wallet-new/src/Cardano/Wallet/Kernel/BListener.hs

+2-30
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ module Cardano.Wallet.Kernel.BListener (
1212
import Universum hiding (State)
1313

1414
import Control.Concurrent.MVar (modifyMVar_)
15-
import Control.Lens (to, _Just)
15+
import Control.Lens (_Just)
1616
import Control.Monad.Except (throwError)
17-
import Data.Acid (createCheckpoint)
1817
import Data.Acid.Advanced (update')
1918
import Data.List (scanl')
2019
import qualified Data.List.NonEmpty as NE
@@ -27,11 +26,10 @@ import qualified Formatting.Buildable
2726
import Pos.Chain.Block (HeaderHash)
2827
import Pos.Chain.Genesis (Config (..))
2928
import Pos.Chain.Txp (TxId)
30-
import Pos.Core (getSlotIndex, siSlotL)
3129
import Pos.Core.Chrono (OldestFirst (..))
3230
import Pos.Crypto (EncryptedSecretKey)
3331
import Pos.DB.Block (getBlund)
34-
import Pos.Util.Log (Severity (Info, Warning))
32+
import Pos.Util.Log (Severity (..))
3533

3634
import Cardano.Wallet.Kernel.DB.AcidState (ApplyBlock (..),
3735
ObservableRollbackUseInTestsOnly (..), SwitchToFork (..),
@@ -138,32 +136,7 @@ applyBlock :: PassiveWallet
138136
applyBlock pw@PassiveWallet{..} b = do
139137
k <- Node.getSecurityParameter _walletNode
140138
runExceptT (applyOneBlock k Nothing b) >>= either (handleApplyBlockErrors k) pure
141-
142139
where
143-
-- | Interim fix, see CBR-438 and
144-
-- https://github.com/acid-state/acid-state/issues/103. In brief, when
145-
-- the note initially syncs and lots of blocks gets passed to the wallet
146-
-- worker, a new `ApplyBlock` acidic transaction will be committed on the
147-
-- transaction log but not written to disk _yet_ (that's what checkpoints
148-
-- are for). However, this might lead to memory leaks if such checkpointing
149-
-- step doesn't happen fast enough. Therefore, every time we apply a block,
150-
-- we decrement this counter and when it reaches 0, we enforce a new
151-
-- checkpoint.
152-
createCheckpointIfNeeded :: IO ()
153-
createCheckpointIfNeeded = do
154-
-- Look at the 'ResolvedBlock' 's 'SlotId', and assess if a new
155-
-- checkpoint is needed by doing @localBlockIx `modulo` someConstant@
156-
-- where @someConstant@ is chosen to be 1000.
157-
let blockSlotIx = b ^. rbContext
158-
. bcSlotId
159-
. fromDb
160-
. siSlotL
161-
. to getSlotIndex
162-
checkpointNeeded = (blockSlotIx - 1) `mod` 1000 == 0
163-
when checkpointNeeded $ do
164-
_walletLogMessage Info "applyBlock: making an acid-state DB checkpoint..."
165-
createCheckpoint _wallets
166-
167140
handleApplyBlockErrors :: Node.SecurityParameter
168141
-> NonEmptyMap HdAccountId ApplyBlockFailed
169142
-> IO ()
@@ -222,7 +195,6 @@ applyBlock pw@PassiveWallet{..} b = do
222195
Right confirmed -> do
223196
modifyMVar_ _walletSubmission (return . Submission.remPending confirmed)
224197
mapM_ (putTxMeta _walletMeta) metas
225-
createCheckpointIfNeeded
226198
return $ Right ()
227199

228200
-- Determine if a failure in 'ApplyBlock' was due to the account being ahead, behind,

0 commit comments

Comments
 (0)