-
Notifications
You must be signed in to change notification settings - Fork 37
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
base: main
Are you sure you want to change the base?
Conversation
Please make sure the following happened
|
c032bb4
to
f10ecb7
Compare
There was a problem hiding this 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)), |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
consensus/src/creation/creator.rs
Outdated
.control_hash() | ||
.parents() | ||
.nth(5) | ||
.expect("there is a fourth parent") |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
-
We have not enough unit collectors, e.g.
current_round
is 2, butunit.round()
is 6 -
We have enough unit collectors, e.g.
current_round
is 6, butunit.round()
is 2. -
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.
There was a problem hiding this comment.
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.
Also, activated the two tests you mention. (Alsoalso I forgot to |
This should finish the, somewhat unaccurately named, "censorship resistance" project.