Skip to content

Commit c95c6e7

Browse files
authored
Small refactor of drift (#2505)
So that it's more clear that we want an error when it's less than zero. -- Edit: In the end we think it's best to drop the `Natural` representation entirely; as it seems like it may be fine to have negative "drift". Todo: - [x] Remove the `Natural` rep entirely - [x] Go back to merely `NominalDiffTime`
2 parents 5e58107 + 576b240 commit c95c6e7

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

hydra-node/json-schemas/api.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ components:
15221522
- $ref: "api.yaml#/components/messages/Fanout/payload"
15231523
- $ref: "api.yaml#/components/messages/SideLoadSnapshot/payload"
15241524
drift:
1525-
$ref: "api.yaml#/components/schemas/Natural"
1525+
$ref: "api.yaml#/components/schemas/NominalDiffTime"
15261526

15271527
SideLoadSnapshotRejected:
15281528
type: object
@@ -2061,7 +2061,7 @@ components:
20612061
description: |
20622062
Difference between the current system wall-clock time and the chain time
20632063
of the latest observed chain point (now − chainTime).
2064-
$ref: "api.yaml#/components/schemas/Natural"
2064+
$ref: "api.yaml#/components/schemas/NominalDiffTime"
20652065
seq:
20662066
$ref: "api.yaml#/components/schemas/SequenceNumber"
20672067
timestamp:
@@ -2099,7 +2099,7 @@ components:
20992099
description: |
21002100
Difference between the current system wall-clock time and the chain time
21012101
of the latest observed chain point (now − chainTime).
2102-
$ref: "api.yaml#/components/schemas/Natural"
2102+
$ref: "api.yaml#/components/schemas/NominalDiffTime"
21032103
seq:
21042104
$ref: "api.yaml#/components/schemas/SequenceNumber"
21052105
timestamp:
@@ -3275,11 +3275,12 @@ components:
32753275
description: |
32763276
A length of time, measured in whole seconds, to be used in deposit validity.
32773277
example: 60
3278-
3279-
Natural:
3280-
# XXX: UInt64 in cardanonical, but Natural in cardano-api
3281-
type: integer
3282-
minimum: 0
3278+
3279+
NominalDiffTime:
3280+
type: number
3281+
description: |
3282+
A unit of time, measured in seconds.
3283+
example: 5
32833284

32843285
UnsyncedPeriod:
32853286
type: number
@@ -3777,7 +3778,7 @@ components:
37773778
currentChainTime:
37783779
$ref: "api.yaml#/components/schemas/UTCTime"
37793780
drift:
3780-
$ref: "api.yaml#/components/schemas/Natural"
3781+
$ref: "api.yaml#/components/schemas/NominalDiffTime"
37813782

37823783
NodeState:
37833784
oneOf:

hydra-node/src/Hydra/API/ServerOutput.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ instance (FromJSON (TxIdType tx), FromJSON (UTxOType tx)) => FromJSON (DecommitI
6767
data ClientMessage tx
6868
= CommandFailed {clientInput :: ClientInput tx, state :: HeadState tx}
6969
| PostTxOnChainFailed {postChainTx :: PostChainTx tx, postTxError :: PostTxError tx}
70-
| RejectedInputBecauseUnsynced {clientInput :: ClientInput tx, drift :: Natural}
70+
| RejectedInputBecauseUnsynced {clientInput :: ClientInput tx, drift :: NominalDiffTime}
7171
| SideLoadSnapshotRejected {clientInput :: ClientInput tx, requirementFailure :: SideLoadRequirementFailure tx}
7272
deriving (Eq, Show, Generic)
7373

@@ -204,8 +204,8 @@ data ServerOutput tx
204204
-- Any signing round has been discarded, and the snapshot leader has changed accordingly.
205205
SnapshotSideLoaded {headId :: HeadId, snapshotNumber :: SnapshotNumber}
206206
| EventLogRotated {checkpoint :: NodeState tx}
207-
| NodeUnsynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: Natural}
208-
| NodeSynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: Natural}
207+
| NodeUnsynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: NominalDiffTime}
208+
| NodeSynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: NominalDiffTime}
209209
deriving stock (Generic)
210210

211211
deriving stock instance IsChainState tx => Eq (ServerOutput tx)

hydra-node/src/Hydra/HeadLogic.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,7 @@ handleOutOfSync Environment{unsyncedPeriod} now chainPoint chainTime syncStatus
14081408
where
14091409
plus = flip addUTCTime
14101410
chainSlot = chainPointSlot chainPoint
1411-
delta = now `diffUTCTime` chainTime
1412-
drift = fromInteger (floor delta)
1411+
drift = now `diffUTCTime` chainTime
14131412

14141413
-- | Validate whether a current deposit in the local state actually exists
14151414
-- in the map of pending deposits.

hydra-node/src/Hydra/HeadLogic/Outcome.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ data StateChanged tx
142142
| TxInvalid {headId :: HeadId, utxo :: UTxOType tx, transaction :: tx, validationError :: ValidationError}
143143
| LocalStateCleared {headId :: HeadId, snapshotNumber :: SnapshotNumber}
144144
| Checkpoint {state :: NodeState tx}
145-
| NodeUnsynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: Natural}
146-
| NodeSynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: Natural}
145+
| NodeUnsynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: NominalDiffTime}
146+
| NodeSynced {chainSlot :: ChainSlot, chainTime :: UTCTime, drift :: NominalDiffTime}
147147
deriving stock (Generic)
148148

149149
deriving stock instance (IsChainState tx, IsTx tx, Eq (NodeState tx), Eq (ChainStateType tx)) => Eq (StateChanged tx)

hydra-node/src/Hydra/Node/State.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data ChainPointTime = ChainPointTime
2020
-- ^ Latest chain slot as observed on chain.
2121
, currentChainTime :: UTCTime
2222
-- ^ Time corresponding to `currentSlot`.
23-
, drift :: Natural
23+
, drift :: NominalDiffTime
2424
-- ^ Time difference with current system wall-clock measured in seconds
2525
}
2626
deriving stock (Eq, Show, Generic)

0 commit comments

Comments
 (0)