Skip to content
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

all: introduce trie owner notion #553

Conversation

Francesco4203
Copy link
Collaborator

@Francesco4203 Francesco4203 commented Aug 30, 2024

This PR is to:

  • Add trie owner notion to trie types and prefetcher. Currently, each trie is represented by its root hash. There will be a case when two accounts have exactly the same storage information, and thus the same root hash of storage trie. Adding the owner information helps distinguishing them correctly, and each account has its own storage trie now.
  • Previously, in (t *Trie) Commit(), if the trie is clean (maybe committed earlier) and nothing-dirty-to-commit now, there might still be some resolved nodes (maybe retrieved earlier), but the tracer is Reset(), so it will lose the information regarding those nodes. This PR set the root to its hash to ensure that all nodes are released after Commit().

@huyngopt1994
Copy link
Collaborator

@Francesco4203 Could u put some description about the concept of trie owner here from go-ethereum team ?

* cmd, core/state, light, trie, eth: add trie owner notion

* all: refactor

* tests: fix goimports

* core/state/snapshot: fix ineffasigns

Co-authored-by: Martin Holst Swende <martin@swende.se>
@Francesco4203
Copy link
Collaborator Author

@Francesco4203 Could u put some description about the concept of trie owner here from go-ethereum team ?

@huyngopt1994 Added.

func newTriePrefetcher(db Database, root common.Hash, namespace string) *triePrefetcher {
prefix := triePrefetchMetricsPrefix + namespace
p := &triePrefetcher{
db: db,
root: root,
fetchers: make(map[common.Hash]*subfetcher), // Active prefetchers use the fetchers map
fetchers: make(map[string]*subfetcher), // Active prefetchers use the fetchers map
Copy link
Collaborator

Choose a reason for hiding this comment

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

func (p *triePrefetcher) trieID(owner common.Hash, root common.Hash) string {
	return string(append(owner.Bytes(), root.Bytes()...))
}

so the new key will be changed from the root to string(append(owner.Bytes(), root.Bytes()...))

Copy link
Collaborator

Choose a reason for hiding this comment

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

return &tracer{
insert: insert,
delete: delete,
origin: origin,
Copy link
Collaborator

Choose a reason for hiding this comment

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

then we will have the other PR for tracking this map data ?

@huyngopt1994
Copy link
Collaborator

LGTM, let merge to next Implementing.

@Francesco4203 Francesco4203 merged commit b413887 into axieinfinity:path-base-implementing Sep 4, 2024
1 check passed
Francesco4203 added a commit to Francesco4203/ronin that referenced this pull request Sep 16, 2024
* cmd, core/state, light, trie, eth: add trie owner notion

* all: refactor

* tests: fix goimports

* core/state/snapshot: fix ineffasigns

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
huyngopt1994 pushed a commit that referenced this pull request Sep 17, 2024
* cmd, core/state, light, trie, eth: add trie owner notion

* all: refactor

* tests: fix goimports

* core/state/snapshot: fix ineffasigns

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
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.

3 participants