Skip to content

Add leios-late-ib-inclusion to the Haskell simulator #413

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

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

Conversation

nfrisby
Copy link
Collaborator

@nfrisby nfrisby commented Jun 17, 2025

Closes #410.

, leiosLateIbInclusion :: Bool
-- ^ Whether an EB also includes IBs from the two previous iterations.
--
-- TODO Merely one previous iteration if 'pipeline' is 'SingleVote'?
Copy link
Collaborator Author

@nfrisby nfrisby Jun 17, 2025

Choose a reason for hiding this comment

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

The Haskell simulator is configurable to use a single stage for voting (Vote) instead of two stages (VoteSend and VoteRecv).

The Short-to-Full spec only considers the two stage variant, when it specifies to include 3 iterations' IBs in each EB.

Would the Short-to-Full spec only include 2 iterations' IBs if Vote were a single stage? Should the Haskell simulator do that? @pagio @SupernaviX

Copy link
Contributor

Choose a reason for hiding this comment

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

@nfrisby I don't think we care about supporting the behavior when leios-vote-send-recv-stages is false, we've been assuming the uniform leios variant for a long time.

@bwbush bwbush self-requested a review June 17, 2025 17:13
@nfrisby nfrisby force-pushed the nfrisby/issue-410-LateIbs branch 3 times, most recently from e964fed to a1c11f2 Compare June 17, 2025 17:43
@nfrisby
Copy link
Collaborator Author

nfrisby commented Jun 17, 2025

FYI, I did some force pushes that.

  • fixed a bug
  • added tests (very similar to implementation, but that's largely because this first implementation is unoptimized)
  • ran fourmolu locally

@nfrisby nfrisby force-pushed the nfrisby/issue-410-LateIbs branch from a1c11f2 to 18f5c46 Compare June 17, 2025 17:47
Comment on lines +42 to +45
* Extends Leios so that EB producers include IBs directly from previous pipelines.
* Due to casuality, the EB must always include them, even if those IBs end up being
* certified in their own pipeline.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Taking another look at the extension, the behavior you describe looks correct. It's also the behavior that the rust simulation follows. I don't know why I wrote this comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh good .Yeah, I was confident it was nothing more than a typo 👍

Copy link
Collaborator Author

@nfrisby nfrisby Jun 17, 2025

Choose a reason for hiding this comment

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

If it were IBs from more than 3 iterations, then we could start making decisions based on whether we see the EB certificate. However, it's not clear we'd want to do that even though we could.

@nfrisby nfrisby force-pushed the nfrisby/issue-410-LateIbs branch from 18f5c46 to 310070d Compare June 17, 2025 18:29
@nfrisby nfrisby force-pushed the nfrisby/issue-410-LateIbs branch from 305acdb to 1d826bf Compare June 17, 2025 18:52
@nfrisby
Copy link
Collaborator Author

nfrisby commented Jun 17, 2025

I'm now expecting CI to build green.

Copy link
Member

@ch1bo ch1bo left a comment

Choose a reason for hiding this comment

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

Looks good and I love that you added a test for it!

| ibTable' <- shrinkList (const []) testSetup.ibTable
]

test_leiosLateIbInclusion :: Test_leiosLateIbInclusion -> Property
Copy link
Member

Choose a reason for hiding this comment

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

Interesting use of an ad-hoc data type! I would have reached for two functions and forAllShrink, but this is something I see the first time and I think I like it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The "TestSetup data type" approach is something ouroboros-consensus has used since before I joined. I like it a lot.

$ Q.counterexample ("on " <> show (map (.num) on))
$ Q.counterexample
(unlines $ ("off" :) $ map (show . map (.num) . off) $ iterations)
$ on Q.=== concatMap off iterations
Copy link
Member

Choose a reason for hiding this comment

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

This is kind of testing using the implementation. Maybe other interesting properties to write here instead (e.g. using conjoin):

  • When on, equal or more IBs are picked
  • When on, the oldest IB is before stageStart of current - 2 * capL (not sure what functions we can use here)
  • When off, all selected IBs are from the current pipeline

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's true. I was very much thinking of the old behavior being correct, and "code review" being sufficient to establish that new code didn't change the old behavior.

But, to your point, the old behavior wasn't being tested.

On the other hand, I do think "the new behavior is just the union of the old behavior on three pipelines" is essentially the specification of this feature. So I like the test I've written here, but what's missing is a test for the old behavior, in my opinion.

@@ -680,6 +686,26 @@ inputBlocksToEndorse cfg@LeiosConfig{pipeline = _ :: SingPipeline p} current buf
, receivedBy
}

-- | Invokes 'inputBlocksToEndorse1' as many times as 'lateIbInclusion'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO this isn't going to work, since the IBs will have been pruned.

I'll need to relax the pruning logic

pruneExpiredIBs :: (Monad m, MonadDelay m, MonadSTM m, MonadTime m) => Tracer m LeiosNodeEvent -> LeiosNodeConfig -> LeiosNodeState m -> m ()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO also, adoptEB as currently written isn't going to realize the IBs are already available, since it only looks in the relay buffer---and the node will not still be relaying these older IBs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO also shouldVoteOnEB only votes for EBs whose IBs all come from the same iteration.

@nfrisby nfrisby marked this pull request as draft June 18, 2025 17:54
@nfrisby
Copy link
Collaborator Author

nfrisby commented Jun 18, 2025

I converted this to a Draft PR because my study of the whole simulator has turned up at least three reasons this current diff is insufficient (see #413 (comment)).

@@ -9,4 +10,5 @@ main =
defaultMain . testGroup "ouroboros-leios-sim" $
[ Test.Topology.tests
, Test.Config.tests
, Test.ShortToFull.tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hooray for test cases! 🙌

Copy link
Collaborator

@bwbush bwbush left a comment

Choose a reason for hiding this comment

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

I don't have a global enough understanding of the implementation's inclusion logic to fully assess this, but changes seem to have the basics correct.

I'd very much like it if we could cite the specs as comments in the Haskell and Rust code. That direct link would make reviews much easier. Our use of google docs is not aligned very well with this style of commenting/citation.

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.

Add LateIBs to Haskell simulator
4 participants