Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
86dd0055
Unverified
Commit
86dd0055
authored
Oct 12, 2020
by
gary rong
Committed by
GitHub
Oct 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie: polish commit function (#21692)
* trie: polish commit function * trie: fix typo
parent
706f5e3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
9 deletions
+19
-9
stacktrie.go
trie/stacktrie.go
+15
-8
trie_test.go
trie/trie_test.go
+4
-1
No files found.
trie/stacktrie.go
View file @
86dd0055
...
...
@@ -17,6 +17,7 @@
package
trie
import
(
"errors"
"fmt"
"sync"
...
...
@@ -26,6 +27,8 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
var
ErrCommitDisabled
=
errors
.
New
(
"no database for committing"
)
var
stPool
=
sync
.
Pool
{
New
:
func
()
interface
{}
{
return
NewStackTrie
(
nil
)
...
...
@@ -391,14 +394,18 @@ func (st *StackTrie) Hash() (h common.Hash) {
return
common
.
BytesToHash
(
st
.
val
)
}
// Commit will commit the current node to database db
func
(
st
*
StackTrie
)
Commit
(
db
ethdb
.
KeyValueStore
)
common
.
Hash
{
oldDb
:=
st
.
db
st
.
db
=
db
defer
func
()
{
st
.
db
=
oldDb
}()
// Commit will firstly hash the entrie trie if it's still not hashed
// and then commit all nodes to the associated database. Actually most
// of the trie nodes MAY have been committed already. The main purpose
// here is to commit the root node.
//
// The associated database is expected, otherwise the whole commit
// functionality should be disabled.
func
(
st
*
StackTrie
)
Commit
()
(
common
.
Hash
,
error
)
{
if
st
.
db
==
nil
{
return
common
.
Hash
{},
ErrCommitDisabled
}
st
.
hash
()
h
:=
common
.
BytesToHash
(
st
.
val
)
return
h
return
h
,
nil
}
trie/trie_test.go
View file @
86dd0055
...
...
@@ -831,7 +831,10 @@ func TestCommitSequenceStackTrie(t *testing.T) {
// Flush memdb -> disk (sponge)
db
.
Commit
(
root
,
false
,
nil
)
// And flush stacktrie -> disk
stRoot
:=
stTrie
.
Commit
(
stTrie
.
db
)
stRoot
,
err
:=
stTrie
.
Commit
()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to commit stack trie %v"
,
err
)
}
if
stRoot
!=
root
{
t
.
Fatalf
(
"root wrong, got %x exp %x"
,
stRoot
,
root
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment