Skip to content

Commit 5860060

Browse files
committed
dmq: moved TTL parsing to the codec
1 parent 0de6f88 commit 5860060

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

decentralized-message-queue/src/DMQ/Diffusion/NodeKernel.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Ouroboros.Network.TxSubmission.Inbound.V2.Registry
3333
import Ouroboros.Network.TxSubmission.Mempool.Simple (Mempool (..))
3434
import Ouroboros.Network.TxSubmission.Mempool.Simple qualified as Mempool
3535

36-
import DMQ.Protocol.SigSubmission.Type (Sig (..), SigId, sigTTLToPOSIXSeconds)
36+
import DMQ.Protocol.SigSubmission.Type (Sig (..), SigId, SigTTL (..))
3737

3838

3939
data NodeKernel ntnAddr m =
@@ -121,9 +121,9 @@ mempoolWorker (Mempool v) = loop
121121
(sigs :: Seq.Seq Sig) <- readTVar v
122122
let sigs' :: Seq.Seq Sig
123123
(resumeTime, sigs') =
124-
foldr (\a (rt, as) -> if sigTTLToPOSIXSeconds (sigTTL a) <= now
124+
foldr (\a (rt, as) -> if getSigTTL (sigTTL a) <= now
125125
then (rt, as)
126-
else (rt `min` sigTTLToPOSIXSeconds (sigTTL a), a Seq.<| as))
126+
else (rt `min` getSigTTL (sigTTL a), a Seq.<| as))
127127
(now, Seq.empty)
128128
sigs
129129
writeTVar v sigs'

decentralized-message-queue/src/DMQ/Protocol/SigSubmission/Codec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ codecSigSubmission =
9898
= CBOR.encodeListLen 5
9999
<> encodeSigId sigId
100100
<> CBOR.encodeBytes (getSigBody sigBody)
101-
<> CBOR.encodeWord32 (getSigTTL sigTTL)
101+
<> CBOR.encodeWord32 (floor $ getSigTTL sigTTL)
102102
<> CBOR.encodeBytes (getSigKesSignature sigKesSignature)
103103
<> CBOR.encodeBytes (getSigOpCertificate sigOpCertificate)
104104

@@ -108,7 +108,7 @@ codecSigSubmission =
108108
when (a /= 5) $ fail (printf "codecSigSubmission: unexpected number of parameters %d" a)
109109
sigId <- decodeSigId
110110
sigBody <- SigBody <$> CBOR.decodeBytes
111-
sigTTL <- SigTTL <$> CBOR.decodeWord32
111+
sigTTL <- SigTTL . realToFrac <$> CBOR.decodeWord32
112112
sigKesSignature <- SigKesSignature <$> CBOR.decodeBytes
113113
sigOpCertificate <- SigOpCertificate <$> CBOR.decodeBytes
114114
return Sig {

decentralized-message-queue/src/DMQ/Protocol/SigSubmission/Type.hs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module DMQ.Protocol.SigSubmission.Type
88
, SigId (..)
99
, SigBody (..)
1010
, SigTTL (..)
11-
, sigTTLToPOSIXSeconds
1211
, SigKesSignature (..)
1312
, SigOpCertificate (..)
1413
, Sig (SigRaw, Sig, sigId, sigBody, sigTTL, sigOpCertificate, sigKesSignature)
@@ -18,7 +17,6 @@ module DMQ.Protocol.SigSubmission.Type
1817
) where
1918

2019
import Data.ByteString (ByteString)
21-
import Data.Word
2220
import Data.Time.Clock.POSIX (POSIXTime)
2321

2422
import Ouroboros.Network.Protocol.TxSubmission2.Type as SigSubmission hiding
@@ -42,12 +40,9 @@ newtype SigBody = SigBody { getSigBody :: ByteString }
4240

4341
-- | POSIX time since epoch in seconds.
4442
--
45-
newtype SigTTL = SigTTL { getSigTTL :: Word32 }
43+
newtype SigTTL = SigTTL { getSigTTL :: POSIXTime }
4644
deriving stock (Show, Eq)
4745

48-
sigTTLToPOSIXSeconds :: SigTTL -> POSIXTime
49-
sigTTLToPOSIXSeconds = fromIntegral . getSigTTL
50-
5146

5247
-- TODO:
5348
-- This type should be something like: `SignedKES (KES crypto) SigPayload`

0 commit comments

Comments
 (0)