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

common ancestor should return the youngest ancestor instead of the oldest one #2056

Merged
merged 11 commits into from Mar 29, 2019

Conversation

Projects
None yet
4 participants
@ghost-not-in-the-shell
Copy link
Contributor

ghost-not-in-the-shell commented Mar 28, 2019

In this PR, I fixed a bug in Transition_frontier.get_path_diff. Namely when we try to find the ancestor for two blocks, we should always try to find the youngest ancestor.

@ghost-not-in-the-shell ghost-not-in-the-shell requested a review from cmr Mar 28, 2019

@johnwu93

This comment has been minimized.

Copy link
Contributor

johnwu93 commented Mar 28, 2019

I think it would be useful to have a unit test of this. Can you write one in test_transition_frontier.ml? Shouldn't be tricky. Just create a transition_frontier with a fork of unequal length. Get the breadcrumbs at both ends. Then apply the breadcrumbs to get_path_diff

@@ -770,6 +770,13 @@ struct
let new_root_node = move_root t heir_node in
(* 4.V *)
let garbage = List.bind bad_hashes ~f:(successor_hashes_rec t) in
Logger.info t.logger ~module_:__MODULE__ ~location:__LOC__

This comment has been minimized.

Copy link
@cmr

cmr Mar 28, 2019

Contributor

can you also change this to a Logger.trace?

ghost-not-in-the-shell added some commits Mar 28, 2019

Transition_frontier.add_breadcrumb_exn frontier ancestor )
in
let%bind branch1 =
create_breadcrumbs ~logger ~size:(max_length / 2) youngest_ancestor

This comment has been minimized.

Copy link
@johnwu93

johnwu93 Mar 28, 2019

Contributor

Small nit, can you randomly generate a size between 1 and max_legnth/2 for both branches? I want to show in the test that we can retrieve the breadcrumbs successfully even with two uneven branches.

This comment has been minimized.

Copy link
@ghost-not-in-the-shell

ghost-not-in-the-shell Mar 28, 2019

Author Contributor

Sure, I would do that.

@enolan

This comment has been minimized.

Copy link
Contributor

enolan commented Mar 28, 2019

I don't understand what you're saying here. The oldest common ancestor of two breadcrumbs will always be the root of the transition frontier, which is definitely not what it used to return. What is the change? Given this diagram

           -->6-->7-->8
          /
         /
1-->2-->3
         \
          \-->4-->5

What did common_ancestor return when called on 8 and 5 before and what does it return now?

ghost-not-in-the-shell added some commits Mar 28, 2019

@enolan
Copy link
Contributor

enolan left a comment

Good work finding this bug!

in
let%bind branch1 =
create_breadcrumbs ~logger
~size:(1 + Random.int ((max_length / 2) - 1))

This comment has been minimized.

Copy link
@enolan

enolan Mar 28, 2019

Contributor

Use QuickCheck to make this try a bunch of possibilities every time you run the test, rather than picking one each time. Also I think the probability of randomly getting two paths of the same length is very low, so add a test that explicitly checks that situation, since that's where the bug was.

This comment has been minimized.

Copy link
@johnwu93

johnwu93 Mar 28, 2019

Contributor

It's quite slow to generate breadcrumbs. As a result, we only generate one instance of it. I think it would be a good idea to have a test where the forks have even lengths and where the forks don't have even lengths.

@cmr

This comment has been minimized.

Copy link
Contributor

cmr commented Mar 28, 2019

@enolan is right, the bug only happens on branches of the same length. So instead of chosing randomly, I would just make 2 ancestors and 1 child on each path.

@cmr

cmr approved these changes Mar 29, 2019

previously it returned the root if the branches were the same length, but you seem to have figured that out.

@cmr cmr added the ready-to-merge label Mar 29, 2019

@mergify mergify bot merged commit ed8e28c into master Mar 29, 2019

18 checks passed

ci/circleci: build-artifacts--testnet_postake Your tests passed on CircleCI!
Details
ci/circleci: build-artifacts--testnet_postake_snarkless_fake_hash Your tests passed on CircleCI!
Details
ci/circleci: build-wallet Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: test--fake_hash Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_bootstrap Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_catchup Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_five_even_snarkless Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_five_even_txns Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_snarkless Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_split Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_split_snarkless Your tests passed on CircleCI!
Details
ci/circleci: test--test_postake_txns Your tests passed on CircleCI!
Details
ci/circleci: test-unit--dev Your tests passed on CircleCI!
Details
ci/circleci: test-unit--test_posig_snarkless Your tests passed on CircleCI!
Details
ci/circleci: test-unit--test_postake_snarkless Your tests passed on CircleCI!
Details
ci/circleci: tracetool Your tests passed on CircleCI!
Details

@mergify mergify bot deleted the fix/common-ancestor branch Mar 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.