diff --git a/hbs2-peer/app/BlockDownload.hs b/hbs2-peer/app/BlockDownload.hs index 8faa35ec..2015d4b7 100644 --- a/hbs2-peer/app/BlockDownload.hs +++ b/hbs2-peer/app/BlockDownload.hs @@ -493,12 +493,15 @@ blockDownloadLoop env0 = do liftIO $ atomically $ writeTVar tinfo alive po <- asks (view peerPostponed) >>= liftIO . readTVarIO + ba <- asks (view blockBanned ) >>= liftIO . Cache.size wipNum <- liftIO $ Cache.size wip notice $ "maintain blocks wip" <+> pretty wipNum <+> "postponed" <+> pretty (HashMap.size po) + <+> "banned" + <+> pretty ba withDownload env0 do @@ -522,6 +525,12 @@ postponedLoop :: forall e m . ( MyPeer e postponedLoop env0 = do e <- ask + + void $ liftIO $ async $ withPeerM e $ withDownload env0 do + pause @'Seconds 60 + ban <- asks (view blockBanned) + void $ liftIO $ Cache.purgeExpired ban + void $ liftIO $ async $ withPeerM e $ withDownload env0 do po <- asks (view peerPostponed) diff --git a/hbs2-peer/app/PeerTypes.hs b/hbs2-peer/app/PeerTypes.hs index 8bd6d4ab..f785346d 100644 --- a/hbs2-peer/app/PeerTypes.hs +++ b/hbs2-peer/app/PeerTypes.hs @@ -279,10 +279,12 @@ addDownload h = do tinq <- asks (view blockInQ) wipCnt <- asks (view blocksWipCnt) - doAdd <- do liftIO $ atomically $ stateTVar tinq - \hm -> case HashMap.lookup h hm of - Nothing -> (True, HashMap.insert h () hm) - Just{} -> (False, HashMap.insert h () hm) + -- doAdd <- do liftIO $ atomically $ stateTVar tinq + -- \hm -> case HashMap.lookup h hm of + -- Nothing -> (True, HashMap.insert h () hm) + -- Just{} -> (False, HashMap.insert h () hm) + + doAdd <- isBlockHereCached h <&> not notPostponed <- liftIO $ readTVarIO po <&> isNothing . HashMap.lookup h