This commit is contained in:
Dmitry Zuikov 2023-07-18 09:18:20 +03:00
parent 95bcda9d8e
commit 2d7a760a4c
1 changed files with 22 additions and 6 deletions

View File

@ -38,9 +38,10 @@ import Data.HashSet qualified as HashSet
import Data.Maybe import Data.Maybe
import Data.Text qualified as Text import Data.Text qualified as Text
import Lens.Micro.Platform import Lens.Micro.Platform
import Data.Hashable hiding (Hashed) import Data.Hashable hiding (Hashed)
import UnliftIO
{- HLINT ignore "Use newtype instead of data" -} {- HLINT ignore "Use newtype instead of data" -}
type RefChanId e = PubKey 'Sign (Encryption e) type RefChanId e = PubKey 'Sign (Encryption e)
@ -129,14 +130,18 @@ instance ForRefChans e => Serialise (AcceptTran e)
data RefChanRound e = data RefChanRound e =
RefChanRound RefChanRound
{ _refChanKey :: HashRef -- ^ hash of the Propose transaction { _refChanRoundKey :: HashRef -- ^ hash of the Propose transaction
, _refChanRound :: HashMap (PubKey 'Sign (Encryption e)) () , _refChanRoundAccepts :: TVar (HashMap (PubKey 'Sign (Encryption e)) ())
} }
deriving stock (Typeable, Generic) deriving stock (Typeable, Generic)
makeLenses 'RefChanRound
newtype instance SessionKey e (RefChanRound e) = newtype instance SessionKey e (RefChanRound e) =
RefChanRoundKey HashRef RefChanRoundKey HashRef
deriving stock (Generic, Typeable) deriving stock (Generic, Eq, Typeable)
deriving newtype instance Hashable (SessionKey e (RefChanRound e))
type instance SessionData e (RefChanRound e) = RefChanRound e type instance SessionData e (RefChanRound e) = RefChanRound e
@ -247,6 +252,7 @@ refChanUpdateProto :: forall e s m . ( MonadIO m
, Pretty (Peer e) , Pretty (Peer e)
, Sessions e (KnownPeer e) m , Sessions e (KnownPeer e) m
, Sessions e (RefChanHeadBlock e) m , Sessions e (RefChanHeadBlock e) m
, Sessions e (RefChanRound e) m
, HasStorage m , HasStorage m
, HasGossip e (RefChanUpdate e) m , HasGossip e (RefChanUpdate e) m
, Signatures s , Signatures s
@ -403,12 +409,22 @@ refChanUpdateProto self pc adapter msg = do
(authorKey, _) <- MaybeT $ pure $ unboxSignedBox0 pbox (authorKey, _) <- MaybeT $ pure $ unboxSignedBox0 pbox
-- может и не надо второй раз проверять -- может, и не надо второй раз проверять
guard $ checkACL headBlock peerKey authorKey guard $ checkACL headBlock peerKey authorKey
defRound <- RefChanRound @e hashRef <$> newTVarIO (HashMap.singleton peerKey ())
debug $ "JUST GOT TRANSACTION FROM STORAGE! ABOUT TO CHECK IT" <+> pretty hashRef debug $ "JUST GOT TRANSACTION FROM STORAGE! ABOUT TO CHECK IT" <+> pretty hashRef
pure () rcRound <- lift $ fetch True defRound (RefChanRoundKey hashRef) id
atomically $ modifyTVar (view refChanRoundAccepts rcRound) (HashMap.insert peerKey ())
accepts <- atomically $ readTVar (view refChanRoundAccepts rcRound) <&> HashMap.size
-- FIXME: round!
when (accepts > 2) do
debug $ "ROUND!" <+> pretty accepts <+> pretty hashRef
-- TODO: implement-accept -- TODO: implement-accept
-- проверяем подпись пира -- проверяем подпись пира