Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

73 inline entry type #79

Merged
merged 14 commits into from
Jul 3, 2018
Merged

73 inline entry type #79

merged 14 commits into from
Jul 3, 2018

Conversation

thedavidmeister
Copy link
Contributor

@thedavidmeister thedavidmeister commented Jun 30, 2018

#73

this diverges from the legacy golang code which has fn signatures looking like this:

func (c *Chain) AddEntry(now time.Time, entryType string, e Entry, privKey ic.PrivKey) (hash Hash, err error) {

which is analogous to our chain.push() trait method in rust.

the limitations of the go version, that i see:

  • fn signature is complex enough to be a code smell, prepareHeader is even worse
  • managing the time and entry type separate to the Entry undermines the benefits of Entry being immutable
  • the private key could come from an agent referenced by the chain itself, i think? i'm not 100% sure if it makes sense to have multiple private keys for a single chain that we select at push() time? @zippy can probably provide more context here.

changes:

  • entry type is set on the entry as part of Entry::new()
    • old: Entry::new("content") new: Entry::new("type", "content")
  • type is no longer provided to Header/Pair/Chain
    • old: chain.push("type", Entry::new("content")) new: chain.push(Entry::new("type", "content"))

pros:

  • no longer possible to make a mistake by providing the wrong type for an entry at push time
    • avoids "hidden mutability" of Entry where the type is only provided after new() call
  • can get the type from the entry
  • much simpler method signatures across Header/Pair/Chain, notably chain.push()
    • can give similar treatment to time as well, locking down time at the actual Entry creation time

cons:

@codecov-io
Copy link

codecov-io commented Jun 30, 2018

Codecov Report

Merging #79 into develop will increase coverage by 0.96%.
The diff coverage is 94.28%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #79      +/-   ##
===========================================
+ Coverage    79.35%   80.32%   +0.96%     
===========================================
  Files           13       13              
  Lines          499      549      +50     
===========================================
+ Hits           396      441      +45     
- Misses         103      108       +5
Impacted Files Coverage Δ
core/src/nucleus/ribosome.rs 67.18% <ø> (-2.17%) ⬇️
core/src/persister.rs 95.65% <100%> (+0.19%) ⬆️
core/src/chain/pair.rs 97.82% <87.5%> (+0.26%) ⬆️
core/src/chain/header.rs 97.45% <95%> (-1.68%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d69e81f...1aec0ef. Read the comment docs.

@thedavidmeister thedavidmeister changed the title WIP: 73 inline entry type 73 inline entry type Jun 30, 2018

// @TODO do NOT serialize entry_type in Entry as it should only be in Header
// @see https://github.com/holochain/holochain-rust/issues/80
entry_type: String,
}

impl _Hash for Entry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the standard Hash trait doesn't clash with anything in this context, could you remove the alias for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it clashes with Entry::hash() doesn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't. Not in this particular context.

Copy link
Contributor Author

@thedavidmeister thedavidmeister Jul 2, 2018

Choose a reason for hiding this comment

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

@sphinxc0re it causes recursion issues if i try self.hash() but i can drop the alias, check out the latest commit

@@ -24,7 +24,7 @@ pub struct Header {
signature: String,
}

impl _Hash for Header {
impl Hash for Header {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just #[derive(Hash)] this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let's continue this in #20

Copy link
Member

@zippy zippy left a comment

Choose a reason for hiding this comment

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

Nice work. You inspire me in the thoroughness of your tests.

// same type different content is not equal
assert_ne!(Entry::new(t1, c1), Entry::new(t1, c2));

// same content different type is equal
Copy link
Member

Choose a reason for hiding this comment

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

This deserves a little bit more in the comment to explain why, because at first glance you might think not. The reason is that what's hashed is JUST the content. i.e. the type is just a convenience value for the implementation, not part of what's getting hashed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh, i'm not even sure if this is desirable behaviour!

part of the reason for writing this test was to highlight something unintuitive about the code :/

i opened up #85 because intuitively the hash of an entry, and also its concept of equality, would contain its type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zippy i added an @see to #85 to provide a pointer to the reasoning

@thedavidmeister thedavidmeister merged commit 14e5c48 into develop Jul 3, 2018
@sphinxc0re sphinxc0re deleted the 73-inline-entry-type branch July 3, 2018 07:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants