mirror of https://github.com/voidlizard/hbs2
wip, cleanup round data
This commit is contained in:
parent
133bc329f6
commit
c28f5dee50
|
@ -133,7 +133,7 @@ data RefChanRound e =
|
||||||
RefChanRound
|
RefChanRound
|
||||||
{ _refChanRoundKey :: HashRef -- ^ hash of the Propose transaction
|
{ _refChanRoundKey :: HashRef -- ^ hash of the Propose transaction
|
||||||
, _refChanHeadKey :: RefChanHeadKey (Encryption e)
|
, _refChanHeadKey :: RefChanHeadKey (Encryption e)
|
||||||
, _refChanRoundTS :: TimeSpec
|
, _refChanRoundTTL :: TimeSpec
|
||||||
, _refChanRoundClosed :: TVar Bool
|
, _refChanRoundClosed :: TVar Bool
|
||||||
, _refChanRoundPropose :: TVar (Maybe (ProposeTran e)) -- ^ propose transaction itself
|
, _refChanRoundPropose :: TVar (Maybe (ProposeTran e)) -- ^ propose transaction itself
|
||||||
, _refChanRoundTrans :: TVar (HashSet HashRef)
|
, _refChanRoundTrans :: TVar (HashSet HashRef)
|
||||||
|
@ -359,10 +359,15 @@ refChanUpdateProto self pc adapter msg = do
|
||||||
|
|
||||||
-- если не смогли сохранить транзу, то и Accept разослать
|
-- если не смогли сохранить транзу, то и Accept разослать
|
||||||
-- не сможем
|
-- не сможем
|
||||||
|
-- это правильно, так как транза содержит ссылку на RefChanId
|
||||||
|
-- следовательно, для другого рефчана будет другая транза
|
||||||
hash <- MaybeT $ liftIO $ putBlock sto (serialise msg)
|
hash <- MaybeT $ liftIO $ putBlock sto (serialise msg)
|
||||||
ts <- liftIO getTimeCoarse
|
ts <- liftIO getTimeCoarse
|
||||||
|
|
||||||
defRound <- RefChanRound @e (HashRef hash) refchanKey ts
|
let toWait = TimeoutSec (fromIntegral $ 2 * view refChanHeadWaitAccept headBlock)
|
||||||
|
let ttl = ts + fromNanoSecs (fromIntegral $ toNanoSeconds toWait)
|
||||||
|
|
||||||
|
defRound <- RefChanRound @e (HashRef hash) refchanKey ttl
|
||||||
<$> newTVarIO False
|
<$> newTVarIO False
|
||||||
<*> newTVarIO Nothing
|
<*> newTVarIO Nothing
|
||||||
<*> newTVarIO (HashSet.singleton (HashRef hash)) -- save propose
|
<*> newTVarIO (HashSet.singleton (HashRef hash)) -- save propose
|
||||||
|
@ -375,6 +380,9 @@ refChanUpdateProto self pc adapter msg = do
|
||||||
|
|
||||||
lift $ gossip msg
|
lift $ gossip msg
|
||||||
|
|
||||||
|
-- FIXME: random-delay-to-avoid-race
|
||||||
|
-- выглядит не очень хорошо, 100ms
|
||||||
|
-- и не гарантирует от гонок
|
||||||
pause @'Seconds 0.10
|
pause @'Seconds 0.10
|
||||||
|
|
||||||
-- FIXME: check-if-we-authorized
|
-- FIXME: check-if-we-authorized
|
||||||
|
|
|
@ -188,17 +188,13 @@ refChanWorker env brains = do
|
||||||
se <- MaybeT $ find @e x id
|
se <- MaybeT $ find @e x id
|
||||||
|
|
||||||
closed <- readTVarIO (view refChanRoundClosed se)
|
closed <- readTVarIO (view refChanRoundClosed se)
|
||||||
let ts = view refChanRoundTS se
|
let ttl = view refChanRoundTTL se
|
||||||
|
|
||||||
-- FIXME: use-wait-from-head
|
when (closed || ttl <= now) do
|
||||||
let expired = toNanoSecs (now - ts) > toNanoSecs ( round (60*1e9) )
|
|
||||||
|
|
||||||
when (closed || expired) do
|
|
||||||
lift $ expire x
|
lift $ expire x
|
||||||
atomically $ modifyTVar rounds (HashSet.delete x)
|
atomically $ modifyTVar rounds (HashSet.delete x)
|
||||||
debug $ "CLEANUP ROUND" <+> pretty x
|
debug $ "CLEANUP ROUND" <+> pretty x
|
||||||
|
|
||||||
|
|
||||||
refChanWriter = forever do
|
refChanWriter = forever do
|
||||||
pause @'Seconds 1
|
pause @'Seconds 1
|
||||||
_ <- atomically $ peekTQueue (view refChanWorkerEnvWriteQ env)
|
_ <- atomically $ peekTQueue (view refChanWorkerEnvWriteQ env)
|
||||||
|
|
Loading…
Reference in New Issue