Skip to content

Conversation

@MaksymMalicki
Copy link
Contributor

@MaksymMalicki MaksymMalicki commented Nov 20, 2025

It introduces rawDB engine for the trie2, which is used by the new state. In this PR:

  • The new package with rawDB is created. The structure of the package is quite simple and follows the pattern of pathdb and hashdb both in structure and interfaces.
  • Contract, Class and Contract Storages are written directly to the pebbleDB and read directly from it. The writing is done in the Update() method, which takes the nodesets generated by trie2.Commit(), flattens them and writes them to the DB. For reading, the readNode() method was introduced.
  • For the new State, Juno defaults to rawdb as a triedb engine

Next PR to review: #3283

@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 64.10256% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.19%. Comparing base (056cfce) to head (26098c7).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
core/trie2/triedb/rawdb/database.go 68.33% 16 Missing and 3 partials ⚠️
core/trie2/triedb/database.go 28.57% 5 Missing ⚠️
core/trie2/triedb/hashdb/database.go 0.00% 2 Missing ⚠️
core/trie2/triedb/pathdb/database.go 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@rodrigo-pino rodrigo-pino left a comment

Choose a reason for hiding this comment

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

Looks good overall

Copy link
Contributor

@EgeCaner EgeCaner left a 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

config *Config
}

func New(disk db.KeyValueStore, config *Config) (*Database, error) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, agreed

Copy link
Contributor

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.

Copy link
Contributor

@EgeCaner EgeCaner Nov 28, 2025

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

Comment on lines +137 to +139
func (d *Database) Close() error {
return nil
}
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comment

Comment on lines +13 to +20
type Config struct{}

type Database struct {
disk db.KeyValueStore

lock sync.RWMutex
log utils.SimpleLogger
}
Copy link
Collaborator

@rodrigo-pino rodrigo-pino Nov 28, 2025

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:

  1. We have a compilation check on this same file
  2. Everyone reading this code will know that this DB is intentionally following a certain(s) interface(s).
var _ database.TrieDB = (*Database)(nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added compilation check, thanks

Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

@rodrigo-pino rodrigo-pino left a 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

Copy link
Contributor

@EgeCaner EgeCaner left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@infrmtcs infrmtcs left a 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

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.

5 participants