From 2addbeb72daf5ec973f90dedebe83aec1599dfef Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Thu, 14 Mar 2024 13:57:00 +0300 Subject: [PATCH] fetch lwwref --- hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App.hs | 7 ++++--- .../hbs2-git-client-lib/HBS2/Git/Client/App/Types.hs | 4 +++- .../HBS2/Git/Client/App/Types/GitEnv.hs | 1 + hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Import.hs | 8 +++++++- hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Prelude.hs | 2 ++ hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/RefLog.hs | 6 ++++++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App.hs b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App.hs index 3b1a17b0..d31c3fa4 100644 --- a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App.hs +++ b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App.hs @@ -134,9 +134,10 @@ runGitCLI o m = do void $ ContT $ withAsync $ runMessagingUnix client - peerAPI <- makeServiceCaller @PeerAPI (fromString soname) - refLogAPI <- makeServiceCaller @RefLogAPI (fromString soname) + peerAPI <- makeServiceCaller @PeerAPI (fromString soname) + refLogAPI <- makeServiceCaller @RefLogAPI (fromString soname) storageAPI <- makeServiceCaller @StorageAPI (fromString soname) + lwwAPI <- makeServiceCaller @LWWRefAPI (fromString soname) let endpoints = [ Endpoint @UNIX peerAPI , Endpoint @UNIX refLogAPI @@ -158,7 +159,7 @@ runGitCLI o m = do progress <- ContT $ withAsync (drawProgress q) - env <- lift $ newGitEnv ip o git cpath conf peerAPI refLogAPI storageAPI + env <- lift $ newGitEnv ip o git cpath conf peerAPI refLogAPI lwwAPI storageAPI lift $ runReaderT setupLogging env lift $ withGitEnv env (evolveDB >> m) `finally` do diff --git a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types.hs b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types.hs index 03bc2be2..163ea65e 100644 --- a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types.hs +++ b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types.hs @@ -60,10 +60,11 @@ newGitEnv :: GitPerks m -> Config -> ServiceCaller PeerAPI UNIX -> ServiceCaller RefLogAPI UNIX + -> ServiceCaller LWWRefAPI UNIX -> ServiceCaller StorageAPI UNIX -> m GitEnv -newGitEnv p opts path cpath conf peer reflog sto = do +newGitEnv p opts path cpath conf peer reflog lww sto = do let dbfile = cpath "state.db" let dOpt = dbPipeOptsDef { dbLogger = \x -> debug ("state:" <+> pretty x) } db <- newDBPipeEnv dOpt dbfile @@ -79,6 +80,7 @@ newGitEnv p opts path cpath conf peer reflog sto = do conf peer reflog + lww (AnyStorage (StorageClient sto)) db p diff --git a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types/GitEnv.hs b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types/GitEnv.hs index 83c851a2..ffdb85e6 100644 --- a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types/GitEnv.hs +++ b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/App/Types/GitEnv.hs @@ -35,6 +35,7 @@ data GitEnv = , _config :: Config , _peerAPI :: ServiceCaller PeerAPI UNIX , _refLogAPI :: ServiceCaller RefLogAPI UNIX + , _lwwRefAPI :: ServiceCaller LWWRefAPI UNIX , _storage :: AnyStorage -- ServiceCaller StorageAPI UNIX , _db :: DBPipeEnv , _progress :: AnyProgress diff --git a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Import.hs b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Import.hs index c2b3734e..9f314d44 100644 --- a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Import.hs +++ b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Import.hs @@ -74,6 +74,10 @@ importRepoWait lwwKey = do subscribeLWWRef lwwKey + -- void $ try @_ @SomeException (getRefLogMerkl puk) + + fetchLWWRef lwwKey + flip fix (IWaitLWWBlock 20) $ \next -> \case IWaitLWWBlock w | w <= 0 -> do @@ -85,10 +89,12 @@ importRepoWait lwwKey = do case lww of Nothing -> do - pause @'Seconds 2 + pause @'Seconds 5 + fetchLWWRef lwwKey next (IWaitLWWBlock (pred w)) Just (LWWBlockData{..}) -> do + void $ try @_ @SomeException (getRefLogMerkle lwwRefLogPubKey) next (IWaitRefLog 20 lwwRefLogPubKey) IWaitRefLog w puk | w <= 0 -> do diff --git a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Prelude.hs b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Prelude.hs index 41b295b4..156789d3 100644 --- a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Prelude.hs +++ b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/Prelude.hs @@ -16,6 +16,7 @@ module HBS2.Git.Client.Prelude , module HBS2.Net.Proto.Service , module HBS2.Peer.RPC.API.Peer , module HBS2.Peer.RPC.API.RefLog + , module HBS2.Peer.RPC.API.LWWRef , module HBS2.Peer.RPC.API.Storage , module HBS2.Peer.RPC.Client.StorageClient @@ -53,6 +54,7 @@ import HBS2.Net.Proto.Service import HBS2.Peer.RPC.API.Peer import HBS2.Peer.RPC.API.RefLog +import HBS2.Peer.RPC.API.LWWRef import HBS2.Peer.RPC.API.Storage import HBS2.Peer.RPC.Client.StorageClient diff --git a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/RefLog.hs b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/RefLog.hs index 98ede6a8..3eddc93e 100644 --- a/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/RefLog.hs +++ b/hbs21-git/hbs2-git-client-lib/HBS2/Git/Client/RefLog.hs @@ -26,6 +26,12 @@ subscribeLWWRef puk = do api <- asks _peerAPI void $ callService @RpcPollAdd api (fromLwwRefKey puk, "lwwref", 17) +fetchLWWRef :: (GitPerks m, MonadReader GitEnv m) => LWWRefKey HBS2Basic -> m () +fetchLWWRef key = do + api <- asks _lwwRefAPI + void $ race (pause @'Seconds 1) (callService @RpcLWWRefFetch api key) + + getRefLogMerkle :: (GitPerks m, MonadReader GitEnv m) => RefLogId -> m (Maybe HashRef) getRefLogMerkle puk = do