Skip to content

Commit ca94be4

Browse files
authored
Merge pull request #1247 from input-output-hk/kderme/release-fix-stake-rollback
Fix stake address rollback | Release version
2 parents 9851786 + 50b074d commit ca94be4

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ unitTests iom knownMigrations =
7777
, test "sync bigger chain" bigChain
7878
, test "rollback while db-sync is off" restartAndRollback
7979
, test "rollback further" rollbackFurther
80+
, test "rollback stake address cache" stakeAddressRollback
8081
]
8182
, testGroup "different configs"
8283
[ test "genesis config without pool" configNoPools
@@ -323,6 +324,27 @@ rollbackFurther =
323324
where
324325
testLabel = "rollbackFurther"
325326

327+
stakeAddressRollback :: IOManager -> [(Text, Text)] -> Assertion
328+
stakeAddressRollback =
329+
withFullConfig babbageConfig testLabel $ \interpreter mockServer dbSync -> do
330+
startDBSync dbSync
331+
blk <- forgeNextFindLeaderAndSubmit interpreter mockServer []
332+
blk' <- withBabbageFindLeaderAndSubmit interpreter mockServer $ \st -> do
333+
let poolId = resolvePool (PoolIndex 0) st
334+
tx1 <- Babbage.mkSimpleDCertTx
335+
[ (StakeIndexNew 1, DCertDeleg . RegKey)
336+
, (StakeIndexNew 1, \stCred -> DCertDeleg $ Delegate $ Delegation stCred poolId) ]
337+
st
338+
Right [tx1]
339+
assertBlockNoBackoff dbSync 2
340+
atomically $ rollback mockServer (blockPoint blk)
341+
assertBlockNoBackoff dbSync 1
342+
atomically $ addBlock mockServer blk'
343+
void $ forgeNextFindLeaderAndSubmit interpreter mockServer []
344+
assertBlockNoBackoff dbSync 3
345+
where
346+
testLabel = "stakeAddressRollback"
347+
326348
configNoPools :: IOManager -> [(Text, Text)] -> Assertion
327349
configNoPools =
328350
withFullConfig "config2" testLabel $ \_ _ dbSync -> do

cardano-db-sync/src/Cardano/DbSync/Cache.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ rollbackStakeAddr ci mBlockNo nBlocks = do
216216
then liftIO $ atomically $ writeTVar (cStakeCreds ci) Map.empty
217217
else do
218218
initMp <- liftIO $ readTVarIO (cStakeCreds ci)
219-
stakeAddrIds <- DB.queryStakeAddressIdsAfter blockNo
220-
let stakeAddrIdsSet = Set.fromList stakeAddrIds
221-
let !mp = Map.filter (`Set.member` stakeAddrIdsSet) initMp
219+
stakeAddrIdsToDelete <- DB.queryStakeAddressIdsAfter blockNo
220+
let stakeAddrIdsSetToDelete = Set.fromList stakeAddrIdsToDelete
221+
let !mp = Map.filter (`Set.notMember` stakeAddrIdsSetToDelete) initMp
222222
liftIO $ atomically $ writeTVar (cStakeCreds ci) mp
223223

224224
queryRewardAccountWithCache

cardano-db-sync/src/Cardano/DbSync/Rollback.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ rollbackToPoint env point = do
5858
-- 'length xs' here gives an approximation of the blocks deleted. An approximation
5959
-- is good enough, since it is only used to decide on the best policy and is not
6060
-- important for correctness.
61+
-- We need to first cleanup the cache and then delete the blocks from db.
6162
lift $ rollbackCache cache mBlockNo (fromIntegral $ length xs)
6263
deleted <- lift $ DB.deleteCascadeAfter prevId
6364
liftIO . logInfo trce $

0 commit comments

Comments
 (0)