Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Rewrite baseTrie as an ES6 class. Extract scratchReadStream to its own file from checkpoint-interface #61

Merged
merged 4 commits into from
Dec 11, 2018

Conversation

alextsg
Copy link
Contributor

@alextsg alextsg commented Nov 28, 2018

The ScratchReadStream class was being defined within checkpoint-interface.js. I thought the codebase would be easier to manage if classes were their own separate files, but this is not a necessary change and I'm happy to revert that.

@alextsg alextsg force-pushed the refactor-checkpoint-interface branch from 5755b58 to 89d051e Compare November 28, 2018 04:14
@coveralls
Copy link

coveralls commented Nov 28, 2018

Coverage Status

Coverage decreased (-0.1%) to 94.298% when pulling 96a6325 on refactor-checkpoint-interface into 07c0649 on master.

@holgerd77
Copy link
Member

Hi @alextsg, thanks for the short-term update on this.

Some first note: even if it might be obvious, can you add reasoning for changes like "extract scratchReadStream to its own file"? This generally avoids misunderstandings / misinterpretations on review or generally overlooking stuff by assuming "ah, this will probably make sense if he does it" and at the end it might not for whatever reason. 😄

Just a procedural thing, haven't had any closer look.

@holgerd77
Copy link
Member

Whew, extensive PR. Seems I won't be able to do an in-tram 🚊 review. 😄

@holgerd77
Copy link
Member

(btw: of course this is open for review by everyone else too 😄)

@alextsg
Copy link
Contributor Author

alextsg commented Nov 29, 2018

@holgerd77 Sure, I'll add that in the PR description, though there's not a huge need for it. I just noticed that the ScratchReadStream class was being defined within checkpoint-interface and thought the code would be more manageable as its own file. Thanks!

@holgerd77
Copy link
Member

Can you eventually do a pre-PR to this one - making sure that documentation is actually building - and then we rebase this on top? I wanted to build documentation locally to get an overview on the exposed API (or at least the documented API 😄) and this seems to be broken atm due to the latest changes.

We might generally want to do some changes to the documentation process along with this. Currently this is building to a template file and then this has to be hand-picked to a a final index.md documentation. This is pretty suboptimal and realistically just lead to the situation that it is just not happening in practice. I am also not sure why these internal utility functions have to be exposed to the API docs at all.

Can you have a look here with the goal of having a non-proxied documentation build of what you think what the current externally exposed API actually is? 😄

If it makes sense this might also be done towards separate documentation files to the different trie types - not sure - haven't put much deeper thought into this, just to make this up as an option.

@alextsg
Copy link
Contributor Author

alextsg commented Nov 30, 2018

@holgerd77 Sure I can work on that. And if you want to keep ScratchReadStream private and not import-able, that makes sense too and I can revert that change.

@alextsg
Copy link
Contributor Author

alextsg commented Nov 30, 2018

@holgerd77 What are the requirements for the documentation? Is the handpicking done only to document public methods and remove private methods? If so, I think we can add some things to our JSDoc comments and skip the proxy.

@holgerd77
Copy link
Member

Some meta-note around this: I think this "how is the documentation build" question is some typical example of a case where someone has done something for some reason in some point in time and it is difficult to extract why this is done this way since there is nothing documented around it. I have the impression that I spent far too much time during the year I am working on EthereumJS libraries on cases like that and I would very much encourage you to at least to some extend skip this process and very much trust your intuition and own analysis and not spent too much time on asking yourself this "what the hell was the intent" question! 😄

So if you are confronted with some setup and some current logic and you come to the conclusion that there is a better solution just do the change, since we are doing reviews anyhow I think risk along with this is low (there might be some exception from this rule on security-related changes).

I think in this case we can very safely say that a proxy documentation (I actually invented this word, hehe) simply never really makes too much sense. I would say that an API doc should just collect the public methods and skip the rest, not sure why these internal functions are there as well. So yes, we should very much add every API documentation just to the JSDocs, skip the proxy and target a directly build together documentation.

@alextsg
Copy link
Contributor Author

alextsg commented Nov 30, 2018

Thanks @holgerd77 . I've created a PR here #63 to address the broken build:docs script and improve the build process.

@holgerd77
Copy link
Member

Cool, thanks!

@holgerd77
Copy link
Member

Did a short try (had a short "is it trie or try" confusion 😛) on rebasing this, but this produces large diffs so I'll leave it to you since you are deeper in the changes.

@alextsg
Copy link
Contributor Author

alextsg commented Dec 7, 2018

Sure, will get this done soon. Thanks.

@alextsg alextsg force-pushed the refactor-checkpoint-interface branch from 89d051e to c2da4c3 Compare December 8, 2018 01:24
@holgerd77
Copy link
Member

Ah, thanks!

Always good to drop another note on rebase, since one is not getting any notification on this. Just stumbled over this accidentally cause I am following you on GitHub. 😄

@holgerd77
Copy link
Member

Just tested, docs is building correctly, looks really nice on first sight.

}, cb2)
/**
* Retrieves a raw value in the underlying db
* @method getRaw
Copy link
Member

Choose a reason for hiding this comment

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

This is missing the @memberof property and it is therefor not included in the docs (unintended I suppose?).

* @param {Buffer} value The value to be stored
* @param {Function} callback A callback `Function`, which is given the argument `err` - for errors that may have occured
*/
this.putRaw = this._putRaw
Copy link
Member

Choose a reason for hiding this comment

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

This move of putRaw to here puts public API methods into a strange/unordered order in the docs and it is also not so good for code readability to have this proxy method.

Do you have an overview how much effort it would be to remove the proxy method and would it eventually be worth the extra effort? An short-run idea for the documentation order would be to move this JSDoc part down to the _putRaw method (and keep the putRaw naming in the JSDoc comment), a bit cheating but maybe ok in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving the JSDoc part down seems to be a good short term solution. I tried rewriting putRaw as

  putRaw (...args) {
    return this._putRaw(...args)
  }

but ran into RangeError: Maximum call stack size exceeded issues in tests due to checkpoint-interface (some methods seem to be getting swapped there). Once I figure out what's going on there we may be able to remove the proxy method.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Two or three things to resolve, otherwise this looks good and can be merged. Thanks Alex! 😄

})
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Definitely makes sense to extract this to its own file once one is having a closer look. We can maybe for now also just leave this like you did, so just have it extracted but not (yet?) add this to the official API documentation.

this._root = value
},
get() {
return this._root
}
})
Copy link
Member

Choose a reason for hiding this comment

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

Constructor is equivalent, ok.

} else {
cb2(null, foundNode)
}
cb(err, value)
})
}
Copy link
Member

Choose a reason for hiding this comment

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

get() method equivalent, ok.

}
})
}
}
Copy link
Member

Choose a reason for hiding this comment

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

put() is equivalent, ok.

} else {
cb()
}
})
})
}
Copy link
Member

Choose a reason for hiding this comment

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

del() method equivalent, ok.


cb(value)
})
}
Copy link
Member

Choose a reason for hiding this comment

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

lookupNode() equivalent, ok.

keyEncoding: 'binary',
valueEncoding: 'binary'
}, cb)
async.each(this._putDBs, dbPut, cb)
}
Copy link
Member

Choose a reason for hiding this comment

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

_putRaw() equivalent, ok.

var stack = []
targetKey = TrieNode.stringToNibbles(targetKey)
async.each(this._putDBs, del, cb)
}
Copy link
Member

Choose a reason for hiding this comment

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

delRaw() equivalent, ok.


stack.push(node)
async.each(this._putDBs, dbBatch, cb)
}
Copy link
Member

Choose a reason for hiding this comment

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

_putNode(), _batchNodes() equivalent, ok.

this._lookupNode(root, value => {
cb(null, !!value)
})
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Remaining functions equivalent as well, done by side-by-side comparison scrolling down editor on left and changes here on the right.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Cool, looks great, thanks for that. So nice to to see these newer-language-features realized.

@holgerd77 holgerd77 merged commit f86961e into master Dec 11, 2018
@holgerd77 holgerd77 deleted the refactor-checkpoint-interface branch December 11, 2018 09:56
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.

None yet

3 participants