forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 15
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
[PoC] Snapshot to bintrie #12
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2d92754
trie: binary trie + snapbin command
gballet 93375a1
Update trie/binary.go
gballet d40815b
Update trie/binary.go
gballet 2a1629d
Fix bintrie command
gballet 62370f0
Fix a couple bugs in insert and add a corresponding test
gballet 60cdf15
Fix tests broken after rebase
gballet 4936cc3
fix a fix in tryGet tests
gballet cbe3620
Prune the left subtree when inserting into the right subtree
gballet b8c27d5
Benchmarking code for bintrie
gballet 96d4e08
trie: introduce extension nodes in search
gballet 15e9a10
trie: cleanup and one more extension read test
gballet e954eb7
trie: Add helper to represent bintries in dot format
gballet 0369446
trie: extension support in binary trie
gballet 65ff453
Change the node hash format to something hexary-like
gballet 3691a07
trie: offload db writes to goroutine + remove dependency on DB in Bin…
gballet 50505ee
trie: refactor binary node creation
gballet 8f092fd
trie: store binary trie in datadir
gballet cf0990f
bugfixes and helpers needed to read from the bintrie
gballet 309e0ad
Code to read back from the binary trie DB
gballet b8c749d
fix: bit overflow in binary prefix's first byte
gballet c695344
fix: move value to left of node if right is inserted
gballet 9d88014
bug: values were overwritten before it hit the DB
gballet 684f5fb
Increase count for report on number of read keys
gballet 50e6855
trie: change bintrie structure to keep keys at the bottom
gballet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ | |
package snapshot | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/ethdb/memorydb" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/trie" | ||
"github.com/syndtr/goleveldb/leveldb" | ||
) | ||
|
||
type leaf struct { | ||
|
@@ -33,6 +35,48 @@ type leaf struct { | |
|
||
type trieGeneratorFn func(in chan (leaf), out chan (common.Hash)) | ||
|
||
func GenerateBinaryTree(path string, it AccountIterator) common.Hash { | ||
db, err := leveldb.OpenFile(path+"/bintrie", nil) | ||
if err != nil { | ||
panic(fmt.Sprintf("error opening bintrie db, err=%v", err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa, please don't . You have a live iterator on the original trie db, please back out carefully and close it nicely |
||
} | ||
defer db.Close() | ||
btrie := new(trie.BinaryTrie) | ||
btrie.CommitCh = make(chan trie.BinaryHashPreimage) | ||
|
||
var nodeCount uint64 | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for kv := range btrie.CommitCh { | ||
nodeCount++ | ||
log.Debug("inserting key", "count", nodeCount, "key", common.ToHex(kv.Key), "value", common.ToHex(kv.Value)) | ||
db.Put(kv.Key, kv.Value, nil) | ||
} | ||
}() | ||
counter := 0 | ||
for it.Next() { | ||
counter++ | ||
// Don't get the entire expanded account at this | ||
// stage - NOTE | ||
btrie.TryUpdate(it.Hash().Bytes(), it.Account()) | ||
} | ||
log.Info("Inserted all leaves", "count", counter) | ||
|
||
err = btrie.Commit() | ||
if err != nil { | ||
panic(fmt.Sprintf("error committing trie, err=%v", err)) | ||
} | ||
close(btrie.CommitCh) | ||
wg.Wait() | ||
btrie.CommitCh = nil | ||
log.Info("Done writing nodes to the DB", "count", nodeCount) | ||
log.Info("Calculated binary hash", "hash", common.ToHex(btrie.Hash())) | ||
|
||
return common.BytesToHash(btrie.Hash()) | ||
} | ||
|
||
// GenerateTrieRoot takes an account iterator and reproduces the root hash. | ||
func GenerateTrieRoot(it AccountIterator) common.Hash { | ||
//return generateTrieRoot(it, StackGenerate) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 that resolve itself correctly? Like, what if
--goerli
is specified, is theGlobalString (utils.DataDir...
really correct?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.
While you're at it above, doing
log.Info
, maybe add