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

core, trie: rework trie commiter #560

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

huyngopt1994
Copy link
Collaborator

Reference in ethereum/go-ethereum#25320.
It's implementing PR prepare for next implementing Path based.

this PR is submitted to adjust the commit procedure. Now all the dirty nodes of a trie will be encapsulated in a struct called nodeSet for return. Multiple nodeSets can be merged together as a MergedNodeSet. Eventually the MergedNodeSet will be submitted to in-memory database as a whole to represent the state transition from block to block.

changed the commit procedure, introduce new struct called nodeSet for
returning including all dirty nodes of a trie. Multiple nodeset will be
merged to MergedNodeSet struct. then be submitted to in-memory database
from block to block
trie/iterator.go Outdated Show resolved Hide resolved
// Merge merges the provided dirty nodes of a trie into the set. The assumption
// is held that no duplicated set belonging to the same trie will be merged twice.
func (set *MergedNodeSet) Merge(other *NodeSet) error {
_, present := set.sets[other.owner]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just concerning, account trie does not have owner (owner is empty), will this still work as expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I understood, The account trie will have the empty hash for the owner, but the StorageTrie will use the addrHash for it

// OpenStorageTrie opens the storage trie of an account.
func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) {
	tr, err := trie.NewSecure(addrHash, root, db.db)

For account owner, the mergednodeset will be initiated and merged one time when comitting so it's safe for case duplicated.

	// Write the account trie changes, measuing the amount of wasted time
	var start time.Time
	if metrics.EnabledExpensive {
		start = time.Now()
	}
	root, nodeSet, err := s.trie.Commit(true)
	if err != nil {
		return common.Hash{}, err
	}

@huyngopt1994 huyngopt1994 merged commit 5a33878 into path-base-implementing Sep 6, 2024
1 check passed
@huyngopt1994 huyngopt1994 deleted the rework-trie-commiter branch September 9, 2024 04:39
Francesco4203 pushed a commit to Francesco4203/ronin that referenced this pull request Sep 16, 2024
* core, trie: rework trie commiter

changed the commit procedure, introduce new struct called nodeSet for
returning including all dirty nodes of a trie. Multiple nodeset will be
merged to MergedNodeSet struct. then be submitted to in-memory database
from block to block

* trie,core: fix comments
huyngopt1994 added a commit that referenced this pull request Sep 17, 2024
* core, trie: rework trie commiter

changed the commit procedure, introduce new struct called nodeSet for
returning including all dirty nodes of a trie. Multiple nodeset will be
merged to MergedNodeSet struct. then be submitted to in-memory database
from block to block

* trie,core: fix comments
huyngopt1994 added a commit that referenced this pull request Oct 25, 2024
* core, trie: rework trie commiter

changed the commit procedure, introduce new struct called nodeSet for
returning including all dirty nodes of a trie. Multiple nodeset will be
merged to MergedNodeSet struct. then be submitted to in-memory database
from block to block

* trie,core: fix comments
huyngopt1994 added a commit that referenced this pull request Nov 21, 2024
* core, trie: rework trie commiter

changed the commit procedure, introduce new struct called nodeSet for
returning including all dirty nodes of a trie. Multiple nodeset will be
merged to MergedNodeSet struct. then be submitted to in-memory database
from block to block

* trie,core: fix comments
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.

2 participants