-
Notifications
You must be signed in to change notification settings - Fork 63
Move some db ops to DBManager #91
Conversation
src/dbManager.js
Outdated
this._opts = { | ||
keyEncoding: 'binary', | ||
valueEncoding: 'binary' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._opts
can be removed (see suggested changes below for this.get()
)
I made a few minor DRY suggestions above, but otherwise looks great! Regarding browser support for In the meantime, we can just directly use the Also, during the re-factor, one thing to think about is that the current Blockchain implementation uses a Block as the atomic structure for chains. However, this makes it difficult to create chains of just headers, which is useful in the context of the EthereumJS client. Geth and other clients treat the blockchain as a chain of headers that can optionally have bodies (transactions and uncles) attached to them. One of the reasons for the ugly |
@vpulim Thanks for the suggestions, they made the code much cleaner! It seems that node 6 imports its own Injected this manually to |
@s1na Honestly, I think you should just modify I believe EDIT: Actually, I forgot we are building the |
I would be cautiously supportive for dropping From a look a the release table linked above, we should probably currently test against @s1na: can you directly upgrade Travis config here accordingly? |
Updated the travis config, tests run against node 8, 10 and 11, lint and coverage against node 8. There's a problem with coveralls currently (other projects are also failing). I'll rebase after the review. |
For clarification: main reason for |
Yeah exactly, I've noticed that rebasing makes reviewing harder. I'm now trying to keep the entire commit history, and only rebase at the end to get a more concise commit history for merging. |
👍 |
Unless I'm misreading the config files, it looks like |
src/dbManager.js
Outdated
return value | ||
} | ||
|
||
return this._db.get(key, dbOpts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also still operating on this._db
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, its the get
method, so... I didn't know how to avoid using this._db.get
😅 Open to ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, put this somewhere else due to all this comments interrupting the code flow. ARgh. 🤣
|
||
return new Block([header].concat(body), {common: this._common}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add JSDoc comments to the publicly exposed functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(hmm, second thought: or maybe we'll leave it until integrating auto-generated documentation, up to you)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will try to add a bit at least for now. This made me think, should all these methods be public or private? On Blockchain
it makes sense to have them as private, but they're the core functionality of DBManager
🤔 What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I am also getting unsure on various fronts. Wasn't getting aware that DBManager
isn't really prepared to go into the public space (right?). Are all publicly documented API methods from the README still kept in the main Blockchain
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't go public by default, when users do const Blockchain = require('ethereumjs-blockchain')
they'd get the Blockchain
class, and they'd have to explicitly import DBManager
to get access to these methods. Should be fine.
Yeah, the API hasn't changed and the methods in Blockchain
only act as a wrapper for methods in DBManager
.
Just went through the |
@s1na Once you have addressed these latest changes you can probably already do the rebase to ease the process (?). |
Mv _getBlock to DBManager Use get in other DBManager methods Import consts and util fns instead of re-defining Callbackify getHeads in _init Add jsdocs, make dbmanager methods public, re-order them
Added some documentation, removed the |
Thanks! 😄 I have a tendency that we remove the Would it also make sense to expose |
Updated thinking: maybe for now we should stick to the currently exposed API and not prematurely expose whatever stuff and wait till more things have settled (but feel free to express otherwise). |
To me Re exposing: Yeah, I'd agree that maybe at least for now keep it un-exposed, until it solidifies a bit more. |
Thanks, that's a good explanation. Let's stick to this PR "as is" for now, I think it's a solid basis for further work, naming should also be fine. Will approve and merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I started refactoring this by moving some of the (easier) db-related logic to a new class
DBManager
(which works with promises), and usedutil.callbackify
in the same methods inBlockchain
. I'm not sure ifutil.callbackify
works in browser? (I think I remember browserify supports some libraries likeutil
). But honestly, the bigger functions like_putBlockOrHeader
are a piece of work, and I think rewriting it from scratch in typescript might be easier!