Skip to content

Commit

Permalink
Merge pull request #116 from coingaming/B1M2-5848
Browse files Browse the repository at this point in the history
B1 m2 5848
  • Loading branch information
tim2CF authored Jul 18, 2022
2 parents bccadae + c781348 commit a6d0d00
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.47
v0.1.49
1 change: 1 addition & 0 deletions btc-lsp/src/BtcLsp/Import/Psql.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Database.Esqueleto.Legacy as X
(!=.),
(&&.),
(+=.),
(/=.),
(<.),
(=.),
(==.),
Expand Down
42 changes: 42 additions & 0 deletions btc-lsp/src/BtcLsp/Storage/Model/LnChan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module BtcLsp.Storage.Model.LnChan
getByChannelPointSql,
persistChannelUpdateSql,
persistOpenedChannelsSql,
persistClosedChannelsSql,
getBySwapIdSql,
getActiveNonSwapSql,
)
Expand All @@ -14,6 +15,7 @@ import BtcLsp.Import
import qualified BtcLsp.Import.Psql as Psql
import qualified BtcLsp.Storage.Model.SwapIntoLn as SwapIntoLn
import qualified BtcLsp.Storage.Util as Util
import qualified Data.Set as Set
import qualified LndClient.Data.Channel as Channel
import qualified LndClient.Data.Channel as Lnd
import qualified LndClient.Data.ChannelBackup as Lnd
Expand Down Expand Up @@ -295,3 +297,43 @@ persistOpenedChannelsSql cs = do
ct <- getCurrentTime
forM (sortOn (Channel.channelPoint . fst) cs) $
uncurry (upsertChannelSql ct Nothing)

getNonClosedSql ::
( MonadIO m
) =>
ReaderT Psql.SqlBackend m [Entity LnChan]
getNonClosedSql =
Psql.select $
Psql.from $ \row -> do
Psql.where_
( row Psql.^. LnChanStatus
Psql.!=. Psql.val LnChanStatusClosed
)
pure row

persistClosedChannelsSql ::
( MonadIO m
) =>
[Lnd.ChannelCloseSummary] ->
ReaderT Psql.SqlBackend m [Entity LnChan]
persistClosedChannelsSql [] = pure mempty
persistClosedChannelsSql csRaw = do
ct <- getCurrentTime
nonClosedList <- getNonClosedSql
let nonClosedSet =
fromList $
( \(Entity {entityVal = x}) ->
Lnd.ChannelPoint
(lnChanFundingTxId x)
(lnChanFundingVout x)
)
<$> nonClosedList
let csUpd =
sortOn CloseChannel.chPoint $
filter
( (`Set.member` nonClosedSet)
. CloseChannel.chPoint
)
csRaw
forM csUpd $
closedChannelUpsert ct
14 changes: 14 additions & 0 deletions btc-lsp/src/BtcLsp/Thread/LnChanWatcher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import qualified Data.Set as Set
import qualified LndClient.Data.Channel as Lnd hiding (outputIndex)
import qualified LndClient.Data.ChannelBackup as Bak
import qualified LndClient.Data.ChannelPoint as Lnd
import LndClient.Data.ClosedChannels (ClosedChannelsRequest (..))
import LndClient.Data.ListChannels
import qualified LndClient.RPC.Silent as LndSilent

Expand Down Expand Up @@ -56,8 +57,21 @@ syncChannelList = do
)
)
openedChans
closedChans <-
withLndT
LndSilent.closedChannels
( $
ClosedChannelsRequest
False
False
False
False
False
False
)
nonSwapSet <- lift . runSql $ do
void $ LnChan.persistOpenedChannelsSql openedChansBak
void $ LnChan.persistClosedChannelsSql closedChans
nonSwapList <- LnChan.getActiveNonSwapSql
pure . fromList $
( \(Entity {entityVal = x}) ->
Expand Down
6 changes: 5 additions & 1 deletion btc-lsp/test/LnChanWatcherSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ testFun = do
let r =
and
<$> sequence
[ (== LnChanStatusFullyResolved)
[ ( `elem`
[ LnChanStatusFullyResolved,
LnChanStatusClosed
]
)
. lnChanStatus
<$> ch
]
Expand Down
4 changes: 1 addition & 3 deletions btc-lsp/test/RefunderSpec.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}

module RefunderSpec
( spec,
)
Expand Down Expand Up @@ -108,6 +105,7 @@ spec = do
sleep1s -- Let Refunder to refund UTXO
res <- lift $ waitCond 10 (refundSucceded swp) []
liftIO $ res `shouldSatisfy` fst

-- ============================================================================
-- Following test is break LeaseOutput lnd method (LeaseOutput Breaks specifies how)
-- ============================================================================
Expand Down

0 comments on commit a6d0d00

Please sign in to comment.