Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 390d7a0

Browse files
committed
Make applyHistoricalBlock return (), and fix moving-target bug.
1 parent b1d32b3 commit 390d7a0

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

wallet-new/src/Cardano/Wallet/Kernel/DB/AcidState.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ applyHistoricalBlock :: SecurityParameter
265265
-> InDb SlotId
266266
-> SlotCount
267267
-> Map HdAccountId PrefilteredBlock
268-
-> Update DB (Map HdAccountId (Set TxId))
268+
-> Update DB ()
269269
applyHistoricalBlock k (InDb slotId) slotCount blocks =
270-
runUpdateNoErrors $ zoom dbHdWallets $
270+
void $ runUpdateNoErrors $ zoom dbHdWallets $
271271
updateAccounts =<< mkUpdates <$> use hdWalletsAccounts
272272
where
273273
mkUpdates :: IxSet HdAccount -> [AccountUpdate Void (Set TxId)]
@@ -319,12 +319,12 @@ applyHistoricalBlock k (InDb slotId) slotCount blocks =
319319

320320
isUpToDate :: HdAccountWithinK -> Bool
321321
isUpToDate st = let cur = st ^. hdWithinKHistorical . currentCheckpoint
322-
tgt = st ^. hdWithinKCurrent . currentCheckpoint
322+
tgt = st ^. hdWithinKCurrent . oldestCheckpoint
323323
in checkpointDistance cur tgt == 1
324324

325325
isWithinK :: HdAccountOutsideK -> Bool
326326
isWithinK st = let cur = st ^. hdOutsideKHistorical
327-
tgt = st ^. hdOutsideKCurrent . currentCheckpoint
327+
tgt = st ^. hdOutsideKCurrent . oldestCheckpoint
328328
SecurityParameter k0 = k
329329
in checkpointDistance cur tgt <= fromIntegral k0
330330

wallet-new/src/Cardano/Wallet/Kernel/DB/Spec.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ module Cardano.Wallet.Kernel.DB.Spec (
3434
, currentSlotId
3535
, currentAddressMeta
3636
, currentForeign
37+
-- ** Convenience: accessors for other checkpoints
38+
, oldestCheckpoint
3739
) where
3840

3941
import Universum
4042

41-
import Control.Lens (from, _Wrapped)
43+
import Control.Lens (Getter, from, to, _Wrapped)
4244
import Control.Lens.TH (makeLenses)
4345
import Data.Coerce (coerce)
46+
import qualified Data.List.NonEmpty as NE
4447
import Data.SafeCopy (base, deriveSafeCopy)
4548
import Formatting (bprint, build, (%))
4649
import qualified Formatting.Buildable
@@ -279,6 +282,13 @@ currentSlotId = currentCheckpoint . cpSlotId
279282
currentAddressMeta addr = currentCheckpoint . cpAddressMeta addr
280283
currentForeign = currentCheckpoint . cpForeign
281284

285+
{-------------------------------------------------------------------------------
286+
Convenience: accessors for other checkpoints
287+
-------------------------------------------------------------------------------}
288+
289+
oldestCheckpoint :: Getter (NewestFirst NonEmpty c) c
290+
oldestCheckpoint = _Wrapped . to NE.last
291+
282292
{-------------------------------------------------------------------------------
283293
Pretty-printing
284294
-------------------------------------------------------------------------------}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ import Cardano.Wallet.Kernel.DB.InDb (InDb (..))
2929
import Cardano.Wallet.Kernel.DB.TxMeta.Types
3030
import Cardano.Wallet.Kernel.Decrypt (decryptAddress)
3131
import Cardano.Wallet.Kernel.Internal (WalletRestorationInfo (..),
32-
walletMeta, walletNode, walletRestorationTask,
33-
walletSubmission, wallets, wriCurrentSlot, wriTargetSlot)
32+
walletMeta, walletNode, walletRestorationTask, wallets,
33+
wriCurrentSlot, wriTargetSlot)
3434
import Cardano.Wallet.Kernel.NodeStateAdaptor (LockContext (..),
3535
SecurityParameter (..), getSecurityParameter,
3636
getSlotCount, withNodeState)
3737
import Cardano.Wallet.Kernel.PrefilterTx (PrefilteredBlock, WalletKey,
3838
toHdAddressId)
39-
import qualified Cardano.Wallet.Kernel.Submission as Submission
4039
import Cardano.Wallet.Kernel.Types (WalletId)
4140

4241
import Pos.Chain.Block (BlockHeader, Blund, HeaderHash, blockHeader,
@@ -158,9 +157,7 @@ restoreWalletHistoryAsync wallet wId target tgtSlot prefilter = do
158157
say (" about to apply block for " <> pretty (mb ^. mainBlockSlot)
159158
<> " with k=" <> pretty k0 <> " and slotCount=" <> pretty slotCount
160159
<> " slotId=" <> pretty slotId <> ", tgtSlot=" <> pretty tgtSlot)
161-
confirmed <- update (wallet ^. wallets)
162-
(ApplyHistoricalBlock k (InDb slotId) slotCount prefilteredBlocks)
163-
modifyMVar_ (wallet ^. walletSubmission) (return . Submission.remPending confirmed)
160+
update (wallet ^. wallets) (ApplyHistoricalBlock k (InDb slotId) slotCount prefilteredBlocks)
164161

165162
-- Update our progress
166163
say "updating progress..."

0 commit comments

Comments
 (0)