Skip to content

Commit

Permalink
Merge pull request #1247 from input-output-hk/kderme/release-fix-stak…
Browse files Browse the repository at this point in the history
…e-rollback

Fix stake address rollback | Release version
  • Loading branch information
kderme authored Sep 12, 2022
2 parents 9851786 + 50b074d commit ca94be4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
22 changes: 22 additions & 0 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ unitTests iom knownMigrations =
, test "sync bigger chain" bigChain
, test "rollback while db-sync is off" restartAndRollback
, test "rollback further" rollbackFurther
, test "rollback stake address cache" stakeAddressRollback
]
, testGroup "different configs"
[ test "genesis config without pool" configNoPools
Expand Down Expand Up @@ -323,6 +324,27 @@ rollbackFurther =
where
testLabel = "rollbackFurther"

stakeAddressRollback :: IOManager -> [(Text, Text)] -> Assertion
stakeAddressRollback =
withFullConfig babbageConfig testLabel $ \interpreter mockServer dbSync -> do
startDBSync dbSync
blk <- forgeNextFindLeaderAndSubmit interpreter mockServer []
blk' <- withBabbageFindLeaderAndSubmit interpreter mockServer $ \st -> do
let poolId = resolvePool (PoolIndex 0) st
tx1 <- Babbage.mkSimpleDCertTx
[ (StakeIndexNew 1, DCertDeleg . RegKey)
, (StakeIndexNew 1, \stCred -> DCertDeleg $ Delegate $ Delegation stCred poolId) ]
st
Right [tx1]
assertBlockNoBackoff dbSync 2
atomically $ rollback mockServer (blockPoint blk)
assertBlockNoBackoff dbSync 1
atomically $ addBlock mockServer blk'
void $ forgeNextFindLeaderAndSubmit interpreter mockServer []
assertBlockNoBackoff dbSync 3
where
testLabel = "stakeAddressRollback"

configNoPools :: IOManager -> [(Text, Text)] -> Assertion
configNoPools =
withFullConfig "config2" testLabel $ \_ _ dbSync -> do
Expand Down
6 changes: 3 additions & 3 deletions cardano-db-sync/src/Cardano/DbSync/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ rollbackStakeAddr ci mBlockNo nBlocks = do
then liftIO $ atomically $ writeTVar (cStakeCreds ci) Map.empty
else do
initMp <- liftIO $ readTVarIO (cStakeCreds ci)
stakeAddrIds <- DB.queryStakeAddressIdsAfter blockNo
let stakeAddrIdsSet = Set.fromList stakeAddrIds
let !mp = Map.filter (`Set.member` stakeAddrIdsSet) initMp
stakeAddrIdsToDelete <- DB.queryStakeAddressIdsAfter blockNo
let stakeAddrIdsSetToDelete = Set.fromList stakeAddrIdsToDelete
let !mp = Map.filter (`Set.notMember` stakeAddrIdsSetToDelete) initMp
liftIO $ atomically $ writeTVar (cStakeCreds ci) mp

queryRewardAccountWithCache
Expand Down
1 change: 1 addition & 0 deletions cardano-db-sync/src/Cardano/DbSync/Rollback.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ rollbackToPoint env point = do
-- 'length xs' here gives an approximation of the blocks deleted. An approximation
-- is good enough, since it is only used to decide on the best policy and is not
-- important for correctness.
-- We need to first cleanup the cache and then delete the blocks from db.
lift $ rollbackCache cache mBlockNo (fromIntegral $ length xs)
deleted <- lift $ DB.deleteCascadeAfter prevId
liftIO . logInfo trce $
Expand Down

0 comments on commit ca94be4

Please sign in to comment.