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

ChainSync client: simplify a correctness argument #222

Merged
merged 1 commit into from
Jul 13, 2023

Conversation

amesgen
Copy link
Member

@amesgen amesgen commented Jul 11, 2023

This is a single-commit PR; see its message.

Migrated from IntersectMBO/ouroboros-network#4313

@amesgen
Copy link
Member Author

amesgen commented Jul 11, 2023

For direct reference, the comments from IntersectMBO/ouroboros-network#4313:


@nfrisby:

Hmm. Actually: does "average-case = worst-case" apply here, meaning that we don't want to share the selection's prefix amongst all the ChainSync clients' theirFrag prefixes?


@amesgen

I think this is a nice change, I could even see defining an abstract function like

cross ::
     forall blk. HasHeader blk
  => AnchoredFragment blk
  -> AnchoredFragment blk
  -> Maybe (Point blk, AnchoredFragment blk)
cross c1 c2 = do
    (p1, _p2, _s1, s2) <- AF.intersect c1 c2
    let crossed = fromMaybe (error "impossible") $ AF.join p1 s2
    pure (AF.anchorPoint s2, crossed)

to make it more clear that we don't rely on any domain-specific properties of the ChainSync fragments here. Of course, we should keep the fairbairn threshold in mind.

W.r.t. performance, this new implementation should have the same worst-case performance; and I don't immediately see how it might have a better average-case performance (splitAfterPoint and join both perform sharing with previous fragments). In any case, it should be easy to write a small benchmark (and if we use the cross function above, it is easy to swap out the implementation if we intentionally want to make the average case slower again).


@nfrisby

splitAfterPoint and join both perform sharing with previous fragments

cross causes all clients to share the selection's prefix. join causes each client to reuse its own copy of that prefix. So splitAfterPoint causes the clients to share less, right?

We introduce a small generic helper function `cross` whose correctness follows
immediately from the guarantees of `AF.intersect`; removing the need for ad-hoc
inline justifications.

Note that this change improves sharing when multiple ChainSync clients maintain
candidate fragments that are (small) extensions of our selection. A priori, this
is contrary to our design principle of "average case = worst case", but we think
the effect is sufficiently small compared to the overall resource usage of a
node in order to influence an SPO to downgrade their node due to this.

Concretely, a Cardano header has a maximum size of `1.1 kB`, and `ourPre`
contains at most `k = 2160` headers, so we get a maximum size decrease of

    1.1 kB × 2160 × 100 = 237.6 MB

very conservatively assuming 100 ChainSync clients.

Co-authored-by: Alexander Esgen <alexander.esgen@iohk.io>
@amesgen amesgen force-pushed the nfrisby/potential-tiny-ChainSync-refactor branch from 4645ec4 to 5be9544 Compare July 13, 2023 09:14
@amesgen amesgen changed the title WIP: possible improvement in ChainSync client? ChainSync client: simplify a correctness argument Jul 13, 2023
@amesgen amesgen marked this pull request as ready for review July 13, 2023 09:18
@amesgen amesgen requested a review from a team as a code owner July 13, 2023 09:18
Copy link
Collaborator

@nc6 nc6 left a comment

Choose a reason for hiding this comment

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

We reviewed this in a call, and agree that it makes sense, and that the increased sharing in a good case is unlikely to be significant, especially compared to the ledger state.

Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

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

The local definition is a good balance 👍

@amesgen amesgen added this pull request to the merge queue Jul 13, 2023
Merged via the queue into main with commit a535aed Jul 13, 2023
7 checks passed
@amesgen amesgen deleted the nfrisby/potential-tiny-ChainSync-refactor branch July 13, 2023 14:05
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.

3 participants