Skip to content

Commit ba60e40

Browse files
committed
dmq: replaced sigTTL with sigExpiresAt
1 parent 117db8b commit ba60e40

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

decentralized-message-queue/decentralized-message-queue.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ test-suite dmq-test
114114
quickcheck-instances,
115115
tasty,
116116
tasty-quickcheck,
117+
time,
117118
typed-protocols,
118119
with-utf8,
119120

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 sigTTL a <= now
124+
foldr (\a (rt, as) -> if sigExpiresAt a <= now
125125
then (rt, as)
126-
else (rt `min` sigTTL a, a Seq.<| as))
126+
else (rt `min` sigExpiresAt 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ codecSigSubmission =
9292
encodeSig :: Sig -> CBOR.Encoding
9393
encodeSig Sig { sigId,
9494
sigBody,
95-
sigTTL,
95+
sigExpiresAt,
9696
sigKesSignature,
9797
sigOpCertificate
9898
}
9999
= CBOR.encodeListLen 5
100100
<> encodeSigId sigId
101101
<> CBOR.encodeBytes (getSigBody sigBody)
102-
<> CBOR.encodeWord32 (floor sigTTL)
102+
<> CBOR.encodeWord32 (floor sigExpiresAt)
103103
<> CBOR.encodeBytes (getSigKesSignature sigKesSignature)
104104
<> CBOR.encodeBytes (getSigOpCertificate sigOpCertificate)
105105

@@ -109,13 +109,13 @@ codecSigSubmission =
109109
when (a /= 5) $ fail (printf "codecSigSubmission: unexpected number of parameters %d" a)
110110
sigId <- decodeSigId
111111
sigBody <- SigBody <$> CBOR.decodeBytes
112-
sigTTL <- realToFrac <$> CBOR.decodeWord32
112+
sigExpiresAt <- realToFrac <$> CBOR.decodeWord32
113113
sigKesSignature <- SigKesSignature <$> CBOR.decodeBytes
114114
sigOpCertificate <- SigOpCertificate <$> CBOR.decodeBytes
115115
return Sig {
116116
sigId,
117117
sigBody,
118-
sigTTL,
118+
sigExpiresAt,
119119
sigKesSignature,
120120
sigOpCertificate
121121
}

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ module DMQ.Protocol.SigSubmission.Type
77
SigHash (..)
88
, SigId (..)
99
, SigBody (..)
10-
, SigTTL (..)
1110
, SigKesSignature (..)
1211
, SigOpCertificate (..)
13-
, Sig (SigRaw, Sig, sigId, sigBody, sigTTL, sigOpCertificate, sigKesSignature)
12+
, Sig (SigRaw, Sig, sigId, sigBody, sigExpiresAt, sigOpCertificate, sigKesSignature)
1413
-- * `TxSubmission` mini-protocol
1514
, SigSubmission
1615
, module SigSubmission
@@ -38,12 +37,6 @@ newtype SigBody = SigBody { getSigBody :: ByteString }
3837
deriving stock (Show, Eq)
3938

4039

41-
-- | POSIX time since epoch in seconds.
42-
--
43-
newtype SigTTL = SigTTL { getSigTTL :: POSIXTime }
44-
deriving stock (Show, Eq)
45-
46-
4740
-- TODO:
4841
-- This type should be something like: `SignedKES (KES crypto) SigPayload`
4942
newtype SigKesSignature = SigKesSignature { getSigKesSignature :: ByteString }
@@ -63,7 +56,7 @@ data Sig = SigRaw {
6356
data SigPayload = SigPayload {
6457
sigPayloadId :: SigId,
6558
sigPayloadBody :: SigBody,
66-
sigPayloadTTL :: SigTTL,
59+
sigPayloadExpiresAt :: POSIXTime,
6760
sigPayloadOpCertificate :: SigOpCertificate
6861
}
6962
deriving stock (Show, Eq)
@@ -80,7 +73,7 @@ pattern Sig
8073
pattern
8174
Sig { sigId,
8275
sigBody,
83-
sigTTL,
76+
sigExpiresAt,
8477
sigOpCertificate,
8578
sigKesSignature
8679
}
@@ -90,15 +83,15 @@ pattern
9083
SigPayload {
9184
sigPayloadId = sigId,
9285
sigPayloadBody = sigBody,
93-
sigPayloadTTL = SigTTL sigTTL,
86+
sigPayloadExpiresAt = sigExpiresAt,
9487
sigPayloadOpCertificate = sigOpCertificate
9588
},
9689
sigRawKesSignature = sigKesSignature
9790
}
9891
where
9992
Sig sigPayloadId
10093
sigPayloadBody
101-
sigTTL
94+
sigPayloadExpiresAt
10295
sigPayloadOpCertificate
10396
sigRawKesSignature
10497
=
@@ -107,7 +100,7 @@ pattern
107100
SigPayload {
108101
sigPayloadId,
109102
sigPayloadBody,
110-
sigPayloadTTL = SigTTL sigTTL,
103+
sigPayloadExpiresAt,
111104
sigPayloadOpCertificate
112105
},
113106
sigRawKesSignature

decentralized-message-queue/test/Test/DMQ/Protocol/SigSubmission.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Test.DMQ.Protocol.SigSubmission where
99
import Control.Monad.ST (runST)
1010
import Data.Bifunctor (second)
1111
import Data.List.NonEmpty qualified as NonEmpty
12+
import Data.Time.Clock.POSIX (POSIXTime)
1213
import Data.Word (Word32)
1314

1415
import Network.TypedProtocol.Codec hiding (prop_codec)
@@ -55,12 +56,11 @@ instance Arbitrary SigBody where
5556
arbitrary = SigBody <$> arbitrary
5657
shrink = map SigBody . shrink . getSigBody
5758

58-
instance Arbitrary SigTTL where
59+
instance Arbitrary POSIXTime where
5960
-- generate only whole seconds (this is what we receive on the wire)
60-
arbitrary = SigTTL . realToFrac @Word32 <$> arbitrary
61+
arbitrary = realToFrac @Word32 <$> arbitrary
6162
-- shrink via Word32 (e.g. in seconds)
62-
shrink (SigTTL posix) = SigTTL . realToFrac
63-
<$> shrink (floor @_ @Word32 posix)
63+
shrink posix = realToFrac <$> shrink (floor @_ @Word32 posix)
6464

6565
instance Arbitrary SigKesSignature where
6666
arbitrary = SigKesSignature <$> arbitrary
@@ -73,10 +73,10 @@ instance Arbitrary SigOpCertificate where
7373
instance Arbitrary Sig where
7474
arbitrary = Sig <$> arbitrary
7575
<*> arbitrary
76-
<*> (getSigTTL <$> arbitrary)
7776
<*> arbitrary
7877
<*> arbitrary
79-
shrink sig@Sig { sigId, sigBody, sigTTL, sigOpCertificate, sigKesSignature } =
78+
<*> arbitrary
79+
shrink sig@Sig { sigId, sigBody, sigExpiresAt, sigOpCertificate, sigKesSignature } =
8080
[ sig { sigId = sigId' }
8181
| sigId' <- shrink sigId
8282
]
@@ -85,8 +85,8 @@ instance Arbitrary Sig where
8585
| sigBody' <- shrink sigBody
8686
]
8787
++
88-
[ sig { sigTTL = sigTTL' }
89-
| SigTTL sigTTL' <- shrink (SigTTL sigTTL)
88+
[ sig { sigExpiresAt = sigExpiresAt' }
89+
| sigExpiresAt' <- shrink sigExpiresAt
9090
]
9191
++
9292
[ sig { sigOpCertificate = sigOpCertificate' }

0 commit comments

Comments
 (0)