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

Optimize traceBlock with fastCache/Persistent DB #546

Merged
merged 5 commits into from
Jun 24, 2020

Conversation

KimKyungup
Copy link
Contributor

@KimKyungup KimKyungup commented Jun 16, 2020

Proposed changes

This PR optimizes traceBlock feature like below.

  • Support state database with exist fast cache for trace block
  • Support to get stateDB with a root trie on persistent DB or its cache

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@KimKyungup
Copy link
Contributor Author

Dear reviewers, I will separate this PR and fix the unit test.

@KimKyungup KimKyungup changed the title Optimize traceBlock with fastCache/Persistent DB, and warming up API Optimize traceBlock with fastCache/Persistent DB Jun 17, 2020
@KimKyungup KimKyungup mentioned this pull request Jun 17, 2020
9 tasks
@KimKyungup
Copy link
Contributor Author

PTAL :) @jeongkyun-oh

jeongkyun-oh
jeongkyun-oh previously approved these changes Jun 18, 2020
Support state database with exist fast cache for trace block
Support to get stateDB with a root trie on persistent DB or its cache
@@ -357,6 +369,11 @@ func (db *Database) DiskDB() database.DBManager {
return db.diskDB
}

// TrieNodeCache retrieves the trieNodeCache of the trie database.
func (db *Database) TrieNodeCache() *fastcache.Cache {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR, however, it would be better if returning an interface, not a pointer of struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. We don't have an interface for trieNodeCache now.
Let's make a cache interface for trieNodeCache later. :)

// DoesExistNodeInPersistent returns if the node exists on the persistent database or its cache.
func (db *Database) DoesExistNodeInPersistent(hash common.Hash) bool {
// Retrieve the node from DB cache if available
if enc := db.getCachedNode(hash); enc != nil {
Copy link
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 strange since the function name. According to its name, I think it should directly call db.diskDB.ReadCachedTrieNode, shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, without state migration, if the trie is in fastCache, it means the trie is already in level DB. So I added the check routine like this. :)

return nil, emptyFn, err
}
logger.Debug("Get stateDB by computeStateDB", "block", block.NumberU64())
emptyFn := func() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about declaring this as a static variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean a static variable?
It means to declare a global variable? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, a package variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is only used in this function. So I think we don't need to declare it as a package variable. :)

joowon-byun
joowon-byun previously approved these changes Jun 23, 2020
@KimKyungup
Copy link
Contributor Author

PTAL. :)

Copy link
Contributor

@ehnuje ehnuje left a comment

Choose a reason for hiding this comment

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

LGTM, however, this seems to conflict with #548

@KimKyungup KimKyungup closed this Jun 24, 2020
@KimKyungup KimKyungup reopened this Jun 24, 2020
@KimKyungup KimKyungup merged commit 5cebdb9 into klaytn:dev Jun 24, 2020
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

5 participants