hydra icon indicating copy to clipboard operation
hydra copied to clipboard

Clarify what is a seen snapshot

Open pgrange opened this issue 2 years ago • 1 comments

What is a seenSnapshot? In particular, for the RequestedSnapshot case, shouldn't the seenSnapshot be the last snapshot that we know of, which would be the requested?

On master, the seenSnapshot function does not do that but returns the lastSeen in the case of a RequestedSnapshot:

-- | Get the last seen snapshot number given a 'SeenSnapshot'.
seenSnapshotNumber :: SeenSnapshot tx -> SnapshotNumber
seenSnapshotNumber = \case
  NoSeenSnapshot -> 0
  LastSeenSnapshot{lastSeen} -> lastSeen
  RequestedSnapshot{lastSeen} -> lastSeen
  SeenSnapshot{snapshot = Snapshot{number}} -> number

Looking at this code, we feel that we have to change to that for it to make sense:

-- | Get the last seen snapshot number given a 'SeenSnapshot'.
seenSnapshotNumber :: SeenSnapshot tx -> SnapshotNumber
seenSnapshotNumber = \case
  NoSeenSnapshot -> 0
  LastSeenSnapshot{lastSeen} -> lastSeen
  RequestedSnapshot{requested} -> requested
  SeenSnapshot{snapshot = Snapshot{number}} -> number

But of course this breaks the code because we use this function in onOpenNetworkReqSn where we really want the master's way of computing the seenSnapshot number for some reason. For instance, we can see that the following test becomes red:

  test/Hydra/NodeSpec.hs:69:7: 
  1) Hydra.Node emits a single ReqSn and AckSn as leader, even after multiple ReqTxs
       expected: [ReqSn {snapshotNumber = UnsafeSnapshotNumber 1, transactionIds = [1]},AckSn {signed = HydraSignature "4d5e417b001974f93c8932ec29efb0c93c75de211c5413d78b806e6dbc41606d10c1c64735bb384b8b3ff2165ed46dbba9d9593a80f102285a8d9892e3ffe609", snapshotNumber = UnsafeSnapshotNumber 1}]
        but got: [ReqSn {snapshotNumber = UnsafeSnapshotNumber 1, transactionIds = [1]}]

We should clarify what is a seenSnapshot here and adapt the code that we don't question it anymore in the future.

Originally posted by @pgrange in https://github.com/input-output-hk/hydra/pull/980#discussion_r1267004316

pgrange avatar Jul 18 '23 16:07 pgrange

Furthermore to this: The spec does not mention the need for recording the fact that we requested a snapshot, but we introduced this via the RequestedSnapshot case of SeenSnapshot in the past.

Within this item we could also clarify whether we really need this?

ch1bo avatar Jul 21 '23 09:07 ch1bo