Skip to content

Enable access to root hashes#151

Merged
mafintosh merged 1 commit intomasterfrom
unknown repository
May 2, 2018
Merged

Enable access to root hashes#151
mafintosh merged 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Apr 25, 2018

Root hashes can be accessed via Feed::rootHashes; fixes #142

@ghost ghost mentioned this pull request Apr 27, 2018
@mafintosh
Copy link
Copy Markdown
Contributor

Since this is very different than the other verify method I'd much prefer to add thing under a new method called feed.rootHashes fx (naming up to you)

@mafintosh
Copy link
Copy Markdown
Contributor

Looks great otherwise

@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 29, 2018

@mafintosh it's done

test/basic.js Outdated

tape('verify', function (t) {
t.plan(9)
t.plan(4)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hey @denim2x this change looks like a leftover error from previous work ^_^ I think this should say 9 here?

I noticed this because it's me who wrote the old code that got changed.


evilfeed.commend(0, function (err, roots) {
t.ok(err === null, 'no error')
t.ok(roots instanceof Array)
Copy link
Copy Markdown
Contributor

@xloem xloem May 1, 2018

Choose a reason for hiding this comment

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

This is good test coverage. A nitpick would be that the test doesn't check that evilfeed and feed have different root hashes (the point of getting root hashes is to ensure matching content is the same and differing content is different without having to compare all the content).

It would be good to check evilfeed after the roots of feed are returned, and assert that the two have the same number of hashes but that those hashes are different.

This is so that if somebody accidentally changes the code such that the function no longer has the proper behavior, the test suite will catch them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 on @xloem comments

README.md Outdated
Callback is called with `(err, success)` where success is true only if the signature is
correct.

#### `feed.commend(index, callback)`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure what 'commend' means personally =S I might call the function 'rootHashes' if nobody else cares !

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes I was just about to comment that, rootHashes is better. I had to lookup commend in the dictionary.

@xloem
Copy link
Copy Markdown
Contributor

xloem commented May 1, 2018

@denim2x I noticed a bug on line 57
Not sure why mafintosh hasn't replied; he seems pretty busy and I had to ask him a lot on irc last time.

@mafintosh
Copy link
Copy Markdown
Contributor

@denim2x LGTM on @xloem's comments, sorry for being busy.

@ghost
Copy link
Copy Markdown
Author

ghost commented May 1, 2018

thanks for the feedback
working on it...

index.js Outdated
}

Feed.prototype.rootHashes = function (index, cb) {
this._withRoots(index, function (err, roots) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

quick question, why is this not just passing index, cb directly?

index.js Outdated

Feed.prototype.rootHashes = function (index, cb) {
this._withRoots(index, function (err, roots) {
if (err) { cb(err) } else { cb(null, roots) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if (err) return cb(err)
cb(null, roots)

instead, assuming this closure is necessary (see above q)

test/basic.js Outdated
t.equal(result[0].length, result[1].length)
t.notEqual(Buffer.compare(result[0][0].hash, result[1][0].hash), 0)
}
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is a bit confusing to read. why not just name the function (ev) here and call it after doing result.push below? also removes the need to an additional dep.

var results = []

feed.rootHashes(0, onroot)
evilfeed.rootHashes(0, onroot)

function onroots (err, roots) {
  t.error(err, 'no error')
  t.ok(roots instanceof Array)
  result.push(roots)
  if (result.length < 2) return
  t.notEqual(result[0], result[1])
  t.equal(result[0].length, result[1].length)
  t.notEqual(Buffer.compare(result[0][0].hash, result[1][0].hash), 0)
}

@ghost
Copy link
Copy Markdown
Author

ghost commented May 2, 2018

fixed it

@mafintosh
Copy link
Copy Markdown
Contributor

mafintosh commented May 2, 2018

Nice! @denim2x is this an issue? https://github.com/mafintosh/hypercore/pull/151/files#r185249278 other than that LGTM from me 🎉

@ghost
Copy link
Copy Markdown
Author

ghost commented May 2, 2018

@mafintosh doubtful - since the number assertions in verify has increased + it's tested and works

@mafintosh
Copy link
Copy Markdown
Contributor

@denim2x hmm, you sure? I count 9 assertions in verify still

@xloem
Copy link
Copy Markdown
Contributor

xloem commented May 2, 2018

i’d imagine the test could be terminating early because 4 assertions are planned for in verify, even though 9 are present. it would still appear to pass but should be fixed.

@ghost
Copy link
Copy Markdown
Author

ghost commented May 2, 2018

@mafintosh that's right (I misunderstood @xloem's comment)

index.js Outdated
var self = this

this._getRootsToVerify(index * 2 + 2, {}, [], function (err, roots) {
this._withRoots(function (err, roots) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this missing index? a bit confused actually

@xloem
Copy link
Copy Markdown
Contributor

xloem commented May 2, 2018

@denim2x I'm sorry but that failure indicates your changes have broken the verify function. It's important to keep the tests all active; they indicate when something is broken !

Root hashes are accessible via Feed::rootHashes

Signed-off-by: denim2x <denim2x@cyberdude.com>
@ghost
Copy link
Copy Markdown
Author

ghost commented May 2, 2018

the call to _withRoots was missing the index argument - that's fixed now

@mafintosh mafintosh merged commit 51093b5 into holepunchto:master May 2, 2018
@mafintosh
Copy link
Copy Markdown
Contributor

merrrrged

mafintosh added a commit that referenced this pull request May 2, 2018
@mafintosh
Copy link
Copy Markdown
Contributor

6.14.0 🎉

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.

Expose access to root hashes

2 participants