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

A0-4559: Create units with ancient parents #528

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

timorleph
Copy link
Contributor

This should finish the, somewhat unaccurately named, "censorship resistance" project.

Copy link

Please make sure the following happened

  • Appropriate tests created
  • Infrastructure updated accordingly
  • Updated existing documentation
  • New documentation created
  • Version bumped if breaking changes

Copy link
Contributor

@Marcin-Radecki Marcin-Radecki left a comment

Choose a reason for hiding this comment

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

Changes looks good.

There are two disabled tests, I tried to enable them on this branch, they pass but unfortunately I wrote them down in a way they do not test what they should be testing. I'll create ticket for fixing this


let to_insert = match self.candidates.get(node_id) {
None => Some((hash, round)),
Some((_, r)) if *r < round => Some((hash, round)),
Copy link
Contributor

Choose a reason for hiding this comment

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

The unit test coverage in this module is neat already, however we can consider adding a test to cover this line as well, e.g. add this code to existing following_inherits_units test (at the end):

        units_collector.add_unit(&units[1][3]);
        let parents = units_collector
            .prospective_parents(NodeIndex(0))
            .expect("we should be able to retrieve parents");
        assert_eq!(parents.item_count(), 4);
        let new_units: Vec<_> = units[1]
            .iter()
            .map(|unit| (unit.hash(), unit.round()))
            .collect();
        let selected_parents: Vec<_> = parents.values().cloned().collect();
        assert_eq!(new_units, selected_parents);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already tested by the units produced by 0-2 being inserted already though, no?

let hash = unit.hash();
let round = unit.round();

if round >= self.for_round {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this flow is not tested in this module - maybe some simple test which tries to add unit with round == self.for_round, which does not change state of UnitsCollector?

Just realized it is tested in creator module in creates_unit_with_ancient_parents_weird_order when we try to add round 1 unit to UnitCollector which has round_for == 0. So this comment becomes very minor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an explicit test for that. Also, I think the test in creator doesn't do that, the lowest round_for we can get is 1?

.control_hash()
.parents()
.nth(5)
.expect("there is a fourth parent")
Copy link
Contributor

Choose a reason for hiding this comment

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

You mean here there is sixth parent? Or there are ancient parents?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point, too much copypasting, fixed.

.add_unit(unit);
let start_round = unit.round();
let end_round = cmp::max(start_round, self.current_round());
for round in start_round..=end_round {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only piece of the code I thinkied longer if it's required, but I think now it is, we just need to have various scenarios covered in tests. As we do two loops now right, first one iterates by rounds and second one creates UnitCollectors if necessary

  1. We have not enough unit collectors, e.g. current_round is 2, but unit.round() is 6

  2. We have enough unit collectors, e.g. current_round is 6, but unit.round() is 2.

  3. I think is covered already, but 2 is not? E.g. we can have minimal dag up to 6 rounds, and then call this add_unit method for round 2 unit for NodeIndex which was not in the dag yet, and then create round 7 unit and then check parents etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Point 1 cannot really happen, we are missing at most one round, because the units come in order to the creator. I did add one slightly better test anyway, to ensure this loop works properly though.

@timorleph
Copy link
Contributor Author

Also, activated the two tests you mention.

(Alsoalso I forgot to fmt, but I'm fixing that. :p)

@timorleph timorleph deployed to Autobump version January 24, 2025 13:28 — with GitHub Actions Active
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