-
Notifications
You must be signed in to change notification settings - Fork 324
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
Return new node on modification #3193
Conversation
0c93b9e
to
260b0d9
Compare
260b0d9
to
3e5b098
Compare
Codecov Report
@@ Coverage Diff @@
## master #3193 +/- ##
==========================================
- Coverage 74.95% 74.77% -0.18%
==========================================
Files 269 269
Lines 23819 23880 +61
==========================================
+ Hits 17854 17857 +3
- Misses 5039 5095 +56
- Partials 926 928 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Could an new pr be created to introduce |
is it hard to understand client interface? |
db/trie/mptrie/hashnode.go
Outdated
hashVal []byte | ||
} | ||
|
||
func newHashNode(mpt *merklePatriciaTrie, ha []byte) *hashNode { | ||
return &hashNode{mpt: mpt, hashVal: ha} | ||
func newHashNode(_ client, ha []byte) *hashNode { |
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.
why leave client
here if it's not used?
li []uint8 | ||
isSorted bool // lazy-initilization | ||
li []uint8 | ||
sorted bool |
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.
does not hurt to leave the comment
@@ -17,20 +17,28 @@ var ErrNoData = errors.New("no data in hash node") | |||
type ( | |||
keyType []byte | |||
|
|||
client interface { |
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.
seems to me merklePatriciaTrie
implements this interface, is there more purpose/use of this interface?
if that's the case, name it like trieOps
? the name client
is not clear in this context
Delete(client, keyType, uint8) (node, error) | ||
Upsert(client, keyType, uint8, []byte) (node, error) | ||
Hash(client) ([]byte, error) | ||
Flush(client) error |
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.
is it possible not add client
to the func's input, if the node struct (leaf, extension, branch) contains the client
interface?
feel it's a bit heavy/clumsy with this extra input
hash(client, bool) ([]byte, error) | ||
proto(client, bool) (proto.Message, error) | ||
delete(client) error | ||
store(client) error |
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.
same here
} | ||
} | ||
li := make([]uint8, 0, len(children)) | ||
for k := range children { | ||
li = append(li, k) | ||
} | ||
return &SortedList{ | ||
li: li, | ||
isSorted: false, | ||
li: li, |
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.
add sorted: false
db/trie/mptrie/cachenode.go
Outdated
hashVal []byte | ||
ser []byte | ||
} | ||
|
||
func (cn *cacheNode) Hash() ([]byte, error) { | ||
return cn.hash(false) | ||
func (cn *cacheNode) Hash(c client) ([]byte, error) { |
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.
cli
db/trie/mptrie/branchnode.go
Outdated
ser: ser, | ||
}, | ||
children: children, | ||
indices: b.indices, |
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.
Is b.indices.Clone()
needed?
db/trie/mptrie/branchnode.go
Outdated
return nil, err | ||
} | ||
var indices *SortedList | ||
var children map[byte]node |
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.
the creation of children
could be moved before if condition
children := make(map[byte]node, len(b.children))
for k, v := range b.children {
children[k] = v
}
if child == nil {
delete(b.children, key)
.......
} else {
children[key] = child
}
} | ||
} | ||
|
||
func (sl *SortedList) sort() { |
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.
let's keep private func below public func
Other things seems good for me apart from two things: 1. how is the performance of new |
db/trie/mptrie/merklepatriciatrie.go
Outdated
mpt.resetRoot(emptyRoot, mpt.emptyRootHash) | ||
return 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.
return mpt.resetRoot
because error unhandled
db/trie/mptrie/branchnode.go
Outdated
} | ||
|
||
func (b *branchNode) updateChild(key byte, child node, hashnode bool) (node, error) { | ||
if err := b.delete(); err != nil { | ||
func (b *branchNode) updateChild(cli client, key byte, child node, hashnode bool) (node, error) { |
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.
hashnode
is not used
db/trie/mptrie/extensionnode.go
Outdated
} | ||
|
||
func (e *extensionNode) updateChild(newChild node, hashnode bool) (node, error) { | ||
err := e.delete() | ||
func (e *extensionNode) updateChild(cli client, newChild node, hashnode bool) (node, error) { |
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.
hashnode
is not used
db/trie/mptrie/extensionnode.go
Outdated
} | ||
|
||
func (e *extensionNode) updatePath(path []byte, hashnode bool) (node, error) { | ||
if err := e.delete(); err != nil { | ||
func (e *extensionNode) updatePath(cli client, path []byte, hashnode bool) (node, error) { |
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.
hashnode
is not used
PTAL @dustinxie @Liuhaai @huof6829 |
Except from |
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
Return a new node on any modification. With this change, it is possible to reuse the nodes and minimize the spending in constructing a trie.
#2847