-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
trie/pathdb: decode verkle node in loadLayers #30870
Conversation
if !isVerkle { | ||
if len(blob) == 0 { | ||
return types.EmptyRootHash, nil | ||
} | ||
return crypto.Keccak256Hash(blob), nil | ||
} | ||
// Compute the node hash in verkle tree manner | ||
if len(blob) == 0 { | ||
return types.EmptyVerkleHash, nil | ||
} | ||
n, err := verkle.ParseNode(blob, 0) | ||
if err != nil { | ||
return common.Hash{}, err | ||
} | ||
return n.Commit().Bytes(), 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.
I think the "default" code path should be non-verkle. So instead of having a if !isVerkle
special case, make it if isVerkle
into the special case
if !isVerkle { | |
if len(blob) == 0 { | |
return types.EmptyRootHash, nil | |
} | |
return crypto.Keccak256Hash(blob), nil | |
} | |
// Compute the node hash in verkle tree manner | |
if len(blob) == 0 { | |
return types.EmptyVerkleHash, nil | |
} | |
n, err := verkle.ParseNode(blob, 0) | |
if err != nil { | |
return common.Hash{}, err | |
} | |
return n.Commit().Bytes(), nil | |
if isVerkle { // Compute the node hash in verkle tree manner | |
if len(blob) == 0 { | |
return types.EmptyVerkleHash, nil | |
} | |
if n, err := verkle.ParseNode(blob, 0); err != nil { | |
return common.Hash{}, err | |
} else { | |
return n.Commit().Bytes(), nil | |
} | |
} | |
if len(blob) == 0 { | |
return types.EmptyRootHash, nil | |
} | |
return crypto.Keccak256Hash(blob), 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.
Another way to do this would be to define two hashers:
func mptHash(blob []byte) (common.Hash, error) {
if len(blob) == 0 {
return types.EmptyRootHash, nil
}
return crypto.Keccak256Hash(blob), nil
}
func verkleHash(blob []byte) (common.Hash, error) {
if len(blob) == 0 {
return types.EmptyVerkleHash, nil
}
n, err := verkle.ParseNode(blob, 0)
if err != nil {
return common.Hash{}, err
}
return n.Commit().Bytes(), nil
}
And then, in e.g Enalbe
, you do
stored = hasher(rawdb.ReadAccountTrieNode(db.diskdb, nil))
you'd just configure the hasher
to use, to be one of either mptHash
or verkleHash
. So whenever you set db.isVerkle
, you can also set db.hasher
to use the correct one.
Just an idea...
Yep, I encounter another big issue, is about the EmptyRootHash. The empty root hash is different in Merkle Tree and Verkle Tree. We use EmptyRootHash (the root of empty Merkle Tree) everywhere. We should fix it first. |
Please check #30896 instead |
In
loadLayers
, the root is computed by hashing (keccak) the node. This is not going to work for a verkle node, so make sure the correct root node derivation is used.