-
Notifications
You must be signed in to change notification settings - Fork 221
feature(trie): create rawDB trieDB engine
#3282
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3282 +/- ##
==========================================
+ Coverage 76.07% 76.19% +0.12%
==========================================
Files 326 340 +14
Lines 32468 32611 +143
==========================================
+ Hits 24699 24848 +149
+ Misses 5976 5963 -13
- Partials 1793 1800 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rodrigo-pino
left a comment
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 overall
EgeCaner
left a comment
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! Some nitpicks
core/trie2/triedb/database.go
Outdated
| config *Config | ||
| } | ||
|
|
||
| func New(disk db.KeyValueStore, config *Config) (*Database, error) { |
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 we return Database interface rather than Database struct and then directly interact with underlying db through interface, avoiding switches in other functions to choose which db we are working with?
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.
Yeah, agreed
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.
If we are not doing this at the moment, and decided to plan it for the later, please open an issue so we wont forget.
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.
let me repost the idea here:
As I see Database struct is just a wrapper to handle creation and interaction with different trieDBs. I was wondering what if we return lets say Database interface instead of struct and remove struct all together. I guess all tries implement NodeReader, Update, Close, NewIterator and Commit. This leaves Journal and Scheme, other than that we are just routing call to underlying DB directly. What if we just make Underlying DBs to implement Scheme() which returns pathdb etc.. and Journal. Then New function creates and returns Database interface then from there consumer will directly interact with DB through interface. This allow us to remove Database struct and replace it with interface implemented by the underlying trie then we can avoid switches and remove all the code in that file except New.
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.
I agree with this, we can remove this abstraction layer.
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.
its done, I removed the Database struct and I'm returning the database.TrieDB interface with underlying triedb implementation
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.
thanks!
373032d to
4a7808a
Compare
| func (d *Database) Close() error { | ||
| return nil | ||
| } |
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.
Please add a comment explaining that this is to satisfy the io.Closer interface
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.
added comment
| type Config struct{} | ||
|
|
||
| type Database struct { | ||
| disk db.KeyValueStore | ||
|
|
||
| lock sync.RWMutex | ||
| log utils.SimpleLogger | ||
| } |
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.
Since Database is implementing an interface, I believe it is a good programming practice to add a compilation check for it. It helps because:
- We have a compilation check on this same file
- Everyone reading this code will know that this DB is intentionally following a certain(s) interface(s).
var _ database.TrieDB = (*Database)(nil)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.
added compilation check, thanks
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.
Based on Ege's previous comment, #3282 (comment), shouldn't refactor this logic?
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.
yes I removed the Database structure and return the interface database.TrieDB interface with underlying implementation from the New method
rodrigo-pino
left a comment
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.
I just realized that the code has no tests. If it is something that was done before, it's ok, but we should change it starting from this PR
EgeCaner
left a comment
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.
Some minor comments, rest looks good to me!
| @@ -0,0 +1,274 @@ | |||
| package rawdb | |||
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 be in another PR, but can we use the same test for all 3 implementations?
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.
I'll create a different PR for this, this one covers a lot so far. It's an interesting idea, I'll have to think if its possible, because the underlying triedb implementations don't have the same behavior
infrmtcs
left a comment
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.
I finished my first round, please ping me after you address the comments, thanks
It introduces rawDB engine for the
trie2, which is used by the new state. In this PR:pathdbandhashdbboth in structure and interfaces.Contract,ClassandContract Storagesare written directly to the pebbleDB and read directly from it. The writing is done in theUpdate()method, which takes the nodesets generated bytrie2.Commit(), flattens them and writes them to the DB. For reading, thereadNode()method was introduced.rawdbas atriedbengineNext PR to review: #3283