Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Annotate headers with time #1288

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

dnadales
Copy link
Member

Introduce a new HeaderWithTime data type, which associates the relative slot time the chain sync client mini-protocol received the header.

Introduce a new `HeaderWithTime` data type which associates the
relative slot time the header was received by the chain sync client
mini-protocol.
Comment on lines +320 to +321
-- REVIEW: is it ok to drop time here?
= peerSimStateDiagramSTMTracerDebug gtBlockTree getCurrentChain (undefined getCandidates) getPoints
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so; only performance could theoretically be a concern here, but I don't think so.

Comment on lines 230 to 231
-- REVIEW: we should avoid this linear computation, but I don't see an alternative to changing the type of the LoE fragment.
pure $ dropTime loeFrag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the approach here would be to make the logic work on AnchoredFragment (HeaderWithTime blk) (or even AnchoredFragment a where a is suitably constrained). This will e.g. also require changing the type of cdbLoE in the ChainDB.

@@ -349,7 +359,9 @@ densityDisconnect (GenesisWindow sgen) (SecurityParam k) states candidateSuffixe
-- If not, it is not qualified to compete by density (yet).
offersMoreThanK = totalBlockCount > k

pure (peer, DensityBounds {clippedFragment, offersMoreThanK, lowerBound, upperBound, hasBlockAfter, latestSlot, idling})
pure (peer, DensityBounds {
clippedFragment = (dropTime clippedFragment), -- REVIEW: should we change the type of the clipped fragment?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍

Comment on lines +313 to +314
-> [(peer, AnchoredFragment (HeaderWithTime blk))] -- REVIEW: add a comment here? (in addition to the haddock above)
-> AnchoredFragment (HeaderWithTime blk) -- REVIEW: add a comment here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, moving the Haddocks to the individual parameters from the docs above sounds good, but seems orthogonal to this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed; however, I don't think we'll ever do if we don't improve the haddocks while working on other tasks. I can use a separate commit for this, of course :)

Comment on lines 192 to 193
readCandidateChains = undefined getCandidates
-- REVIWE: Should we change the 'BlockFetchConsensusInterface' s that 'readCandidateChains' return 'HeaderWithTime'?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly the idea of step 3b) in the corresponding draft issue 👍 As BlockFetchConsensusInterface is polymorphic in what type header is used for headers, it doesn't even require changing BlockFetchConsensusInterface for this purpose. Concretely, mkBlockFetchConsensusInterface would return BlockFetchConsensusInterface peer (HeaderWithTime blk) blk m.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. This would change the type of readCurrentChain, which I'm unsure it is intended (since now the current chain will need to incorporate the times).

Comment on lines +516 to +518
-- 'ValidatedHeader' however this seems to be a misnomer since the
-- header is not validated at the point at which we construct this
-- value in 'Ouroboros.Consensus.MiniProtocol.ChainSync.Client'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that depends on where you construct HeaderWithTime/ValidatedHeader.

(Generally, HeaderWithTime sounds good though 👍)

$ ( case isPipeliningEnabled version of
ReceivingTentativeBlocks -> drop 1
ReceivingTentativeBlocks -> drop 1 -- REVIEW: we could also use this opportunity to explain this.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the comment above clear it up?

-- As of block diffusion pipelining, their tip header might be
-- tentative. Since they do not yet have a way to explicitly say
-- whether it is tentative, we assume it is and therefore skip their
-- tip here. TODO once it's explicit, only skip it if it's annotated as
-- tentative

Maybe we could move the comment directly above the drop 1?

@@ -281,7 +281,7 @@ runBlockFetchTest BlockFetchClientTestSetup{..} = withRegistry \registry -> do
BlockFetchClientInterface.mkBlockFetchConsensusInterface
(TestBlockConfig numCoreNodes)
chainDbView
getCandidates
(undefined getCandidates) -- TODO: adapt 'getCandidates' if the change to 'mkBlockFetchConsensusInterface' is correct.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this test, the annotated times should be irrelevant.

Comment on lines +592 to +593
-- TODO: this should be a library function if the idea of dropping time on the candidate fragment makes sense.
dropTime = undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping time here seems fine 👍

From

```
BlockFetchConsensusInterface (ConnectionId addrNTN) (Header blk) blk m
```

to

```
BlockFetchConsensusInterface (ConnectionId addrNTN) (HeaderWithTime blk) blk m
```

The next commits will start implementing the `undefined` in the code.
dnadales and others added 5 commits November 14, 2024 12:13
This is semantically identical (as the LoE fragment is anchored in a recent
immutable tip), but it is nice to use a more familiar function, and it is also
potentially useful for a planned change.
... from `AnchoredFragment (Header blk)` to
`AnchoredFragment (HeaderWithTime blk)`.
... which contains an `AddBogusTime` type class, which allows to add
bogus times to headers. This type class and its instances are meant to
be used in test code.
@dnadales dnadales force-pushed the dnadales/annotate-headers-with-time branch from b76d77c to 2b11f09 Compare November 19, 2024 13:11
... from `AnchoredFragment (Header TestBlock))` to `AnchoredFragment (HeaderWithTime TestBlock))`.
... from `AnchoredFragment (Header TestBlock))` to `AnchoredFragment (HeaderWithTime TestBlock))`.
... in the density disconnect tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants