-
Notifications
You must be signed in to change notification settings - Fork 197
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
GetAllLeaves On Channel #2081
GetAllLeaves On Channel #2081
Conversation
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.
Yeah, pretty much what I wanted. Minor stuff.
data/interface.go
Outdated
@@ -20,6 +20,12 @@ const ( | |||
// ModifiedHashes is used to memorize all old hashes and new hashes from when a trie is committed | |||
type ModifiedHashes map[string]struct{} | |||
|
|||
// TrieLeaf holds the key to a leaf and the value associated with that leaf |
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.
Exactly at the same pattern I have worked now. We might have a general implementation in core package (keyValueStorage) that will implement a core.KeyValueHolder interface. That interface will be reused in storage package also.
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.
Done.
data/trie/patriciaMerkleTrie.go
Outdated
@@ -602,6 +602,30 @@ func (tr *patriciaMerkleTrie) GetAllLeaves() (map[string][]byte, error) { | |||
return leaves, nil | |||
} | |||
|
|||
// GetAllLeavesOnChannel adds all the trie leaves to the given channel | |||
func (tr *patriciaMerkleTrie) GetAllLeavesOnChannel(leavesChannel chan *data.TrieLeaf) 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.
I would change a little bit this:
func (tr *patriciaMerkleTrie) GetAllLeavesOnChannel() chan *data.TrieLeaf {
ch := make(chan *data.TrieLeaf)
//check nil part (including closing the channel)
go func() {
tr.mutOperation.RLock()
err := tr.root.getAllLeavesOnChannel(leavesChannel, []byte{}, tr.Database(), tr.marshalizer)
if err != nil {
log.Error("could not get all trie leaves: ", "error", err)
}
tr.mutOperation.RUnlock()
close(leavesChannel)
}()
return ch
}
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.
Done.
data/trie/patriciaMerkleTrie_test.go
Outdated
|
||
err := tr.GetAllLeavesOnChannel(leafChannel) | ||
assert.Nil(t, err) | ||
checkLeaves(t, leafChannel, leaves) |
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.
can be changed to this:
recovered := make(map[string][]byte)
for leaf := range leafChannel{
recovered[string(leaf.Key)] = leaf.Value
}
assert.Equal(t, leaves, recovered)
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.
Done.
…Leaves-on-channel # Conflicts: # core/interface.go
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.
a few more minor stuff
data/trie/patriciaMerkleTrie.go
Outdated
tr.mutOperation.RUnlock() | ||
close(leavesChannel) | ||
|
||
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 leavesChannel
in order to not output a nil chan and break down stream code
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.
Done.
dataRetriever/mock/trieStub.go
Outdated
} | ||
|
||
return errNotImplemented | ||
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.
instead of returning nil, just return
ch := make(chan core.KeyValueHolder)
close(ch)
return ch
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.
Done.
epochStart/mock/trieStub.go
Outdated
} | ||
|
||
return errNotImplemented | ||
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.
instead of returning nil, just return
ch := make(chan core.KeyValueHolder)
close(ch)
return ch
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.
Done.
node/mock/trieStub.go
Outdated
} | ||
|
||
return errNotImplemented | ||
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.
instead of returning nil, just return
ch := make(chan core.KeyValueHolder)
close(ch)
return ch
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.
Done.
process/mock/trieStub.go
Outdated
} | ||
|
||
return errNotImplemented | ||
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.
instead of returning nil, just return
ch := make(chan core.KeyValueHolder)
close(ch)
return ch
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.
Done.
update/mock/trieStub.go
Outdated
} | ||
|
||
return errNotImplemented | ||
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.
instead of returning nil, just return
ch := make(chan core.KeyValueHolder)
close(ch)
return ch
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.
Done.
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.
System tests passed.
Add a new trie functionality, getAllLeavesOnChannel, which returns all the trie leaves on a channel. When all the leaves have been sent, the channel closes.