diff --git a/lib/Internal/Utils.hs b/lib/Internal/Utils.hs index 25633a3..b492eac 100644 --- a/lib/Internal/Utils.hs +++ b/lib/Internal/Utils.hs @@ -693,14 +693,12 @@ rebalanceTotalEntrySet , utTotalValue } = do - (fval, fs, tpairs) <- rebalanceDebit bc utFromRO utFromUnk + (fval, fs, tpairs) <- rebalanceDebit utCurrency utFromRO utFromUnk let f0val = utTotalValue - fval - modify $ mapAdd_ (f0Acnt, bc) f0val + modify $ mapAdd_ (f0Acnt, utCurrency) f0val let tsLinked = tpairs ++ (unlink f0val <$> f0links) - ts <- rebalanceCredit bc utTotalValue utTo0 utToUnk utToRO tsLinked + ts <- rebalanceCredit utCurrency utTotalValue utTo0 utToUnk utToRO tsLinked return (f0 {ueValue = StaticValue f0val} : fs ++ ts) - where - bc = utCurrency rebalanceFullEntrySet :: FullUpdateEntrySet -> State EntryBals [UEBalanced] rebalanceFullEntrySet @@ -714,14 +712,13 @@ rebalanceFullEntrySet , utCurrency } = do - (ftot, fs, tpairs) <- rebalanceDebit bc rs ls - ts <- rebalanceCredit bc ftot utTo0 utToUnk utToRO tpairs + (ftot, fs, tpairs) <- rebalanceDebit utCurrency rs ls + ts <- rebalanceCredit utCurrency ftot utTo0 utToUnk utToRO tpairs return (fs ++ ts) where (rs, ls) = case utFrom0 of Left x -> (x : utFromRO, utFromUnk) Right x -> (utFromRO, x : utFromUnk) - bc = utCurrency rebalanceDebit :: BCKey @@ -755,7 +752,7 @@ rebalanceCredit -> [UE_RO] -> [UEBalanced] -> State EntryBals [UEBalanced] -rebalanceCredit k tot t0 us rs bs = do +rebalanceCredit k tot t0@UpdateEntry {ueAcnt = t0Acnt} us rs bs = do (tval, ts) <- fmap (second catMaybes) $ sumM goTo $ @@ -763,7 +760,9 @@ rebalanceCredit k tot t0 us rs bs = do (UETLinked <$> bs) ++ (UETUnk <$> us) ++ (UETReadOnly <$> rs) - return (t0 {ueValue = StaticValue (-(tot + tval))} : ts) + let t0val = -(tot + tval) + modify $ mapAdd_ (t0Acnt, k) t0val + return (t0 {ueValue = StaticValue t0val} : ts) where idx = projectUET ueIndex ueIndex ueIndex goTo (UETReadOnly e) = (,Nothing) <$> updateFixed k e