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

SyncBucket cleanup #407

Merged
merged 5 commits into from
May 12, 2020
Merged

SyncBucket cleanup #407

merged 5 commits into from
May 12, 2020

Conversation

timvermeulen
Copy link
Contributor

Summary of changes
Changes introduced in this pull request:

Several loosely related changes:

  • A fix for a bug where SyncBucketSet::heaviest wouldn't necessarily return the heaviest tipset
  • Rename same_chain_as -> is_same_chain_as according to Rust's naming conventions
  • Some other minor cleanup of the SyncBucket and SyncBucketSet types
  • The removal of a couple PartialOrd/Ord implementations that weren't useful
  • The removal of Cid's manual PartialEq and Hash implementations in favor of derives that (should) have the same behavior but without allocating

Comment on lines -205 to -216
impl PartialOrd for BlockHeader {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.cached_bytes.partial_cmp(&other.cached_bytes)
}
}

impl Ord for BlockHeader {
fn cmp(&self, other: &Self) -> Ordering {
self.cached_bytes.cmp(&other.cached_bytes)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@dutterbutter Wasn't there a specific need for this? I remember vaguely it being written into the spec

Copy link
Member

Choose a reason for hiding this comment

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

I vaguely remember us needing this at some point as well. Clearly not anymore?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recall the specific need for this, I think its fine to be removed.

@@ -43,7 +42,7 @@ pub struct Prefix {
}

/// Representation of a IPLD CID.
#[derive(Eq, Clone)]
#[derive(PartialEq, Eq, Hash, Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

It was intentional to keep those separate before (this was a fork of existing implementations initially) and the specific details of comparing and hashing bytes was necessary. I can't see at this point for that specific comparison (cids aren't used as Hamt keys and that was going to be the only potential need to be specific).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, could two CIDs ever be considered equal in one way but not in the other?

Copy link
Contributor

Choose a reason for hiding this comment

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

Equality, no, but ordering potentially yes because of the variant encoding. Just something to keep in mind in the future, that would be a very nuanced bug to find if there was an inconsistency (I mean, even without varints because the bytes are lexicographically sorted and not all codes are the same byte length)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So are you talking about ordering and not about Eq and Hash? I agree that changing the ordering can change behavior but here I'm getting rid of Cid's Ord implementation altogether, rather than changing it. Deriving Eq and Hash should not result in observable changes as long as the implementation is correct

Copy link
Contributor

Choose a reason for hiding this comment

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

hash will be different too, only PartialEq/Eq would be the same (sorry for bringing up order, was just looking on my phone)

Copy link
Contributor

Choose a reason for hiding this comment

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

But I don't think we use the cid hash for any consensus related things so should be fine. (Might be safe to keep that one until we have those specifics tested more in detail)

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 yeah, the hash will be different, but as far as I understand you would never look at the resulting hash value anyway, or somehow rely on what it is – i.e. previously the hash of a cid was the hash of its bytes which as far as we're concerned could be anything

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I mean it could matter if you use a cid as the key to a hamt, but that shouldn't be a need in the near future because the go implementation statically uses bytes for their keys.

I double checked, doesn't seem like there is an actual use for a consistent hash here, so good on my end sorry to sidetrack with this. I just wanted to make sure it didn't go quietly unconsidered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will definitely keep this in mind for if we're ever going to use the CID as the key to a hamt

@timvermeulen timvermeulen merged commit f47b757 into master May 12, 2020
@timvermeulen timvermeulen deleted the tim/syncbucket-cleanup branch May 12, 2020 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants