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
a7842c9c
Unverified
Commit
a7842c9c
authored
Sep 07, 2023
by
rjl493456442
Committed by
GitHub
Sep 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, trie: cleanup trie database (#28062)
parent
a8d7201e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
26 deletions
+20
-26
statedb.go
core/state/statedb.go
+8
-1
statedb_fuzz_test.go
core/state/statedb_fuzz_test.go
+3
-1
database.go
trie/database.go
+0
-20
database_test.go
trie/database_test.go
+9
-4
No files found.
core/state/statedb.go
View file @
a7842c9c
...
...
@@ -135,6 +135,9 @@ type StateDB struct {
StorageUpdated
int
AccountDeleted
int
StorageDeleted
int
// Testing hooks
onCommit
func
(
states
*
triestate
.
Set
)
// Hook invoked when commit is performed
}
// New creates a new state from a given trie.
...
...
@@ -1276,13 +1279,17 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
}
if
root
!=
origin
{
start
:=
time
.
Now
()
if
err
:=
s
.
db
.
TrieDB
()
.
Update
(
root
,
origin
,
block
,
nodes
,
triestate
.
New
(
s
.
accountsOrigin
,
s
.
storagesOrigin
,
incomplete
));
err
!=
nil
{
set
:=
triestate
.
New
(
s
.
accountsOrigin
,
s
.
storagesOrigin
,
incomplete
)
if
err
:=
s
.
db
.
TrieDB
()
.
Update
(
root
,
origin
,
block
,
nodes
,
set
);
err
!=
nil
{
return
common
.
Hash
{},
err
}
s
.
originalRoot
=
root
if
metrics
.
EnabledExpensive
{
s
.
TrieDBCommits
+=
time
.
Since
(
start
)
}
if
s
.
onCommit
!=
nil
{
s
.
onCommit
(
set
)
}
}
// Clear all internal flags at the end of commit operation.
s
.
accounts
=
make
(
map
[
common
.
Hash
][]
byte
)
...
...
core/state/statedb_fuzz_test.go
View file @
a7842c9c
...
...
@@ -181,7 +181,7 @@ func (test *stateTest) run() bool {
storageList
=
append
(
storageList
,
copy2DSet
(
states
.
Storages
))
}
disk
=
rawdb
.
NewMemoryDatabase
()
tdb
=
trie
.
NewDatabase
(
disk
,
&
trie
.
Config
{
OnCommit
:
onCommit
,
PathDB
:
pathdb
.
Defaults
})
tdb
=
trie
.
NewDatabase
(
disk
,
&
trie
.
Config
{
PathDB
:
pathdb
.
Defaults
})
sdb
=
NewDatabaseWithNodeDB
(
disk
,
tdb
)
byzantium
=
rand
.
Intn
(
2
)
==
0
)
...
...
@@ -206,6 +206,8 @@ func (test *stateTest) run() bool {
if
err
!=
nil
{
panic
(
err
)
}
state
.
onCommit
=
onCommit
for
i
,
action
:=
range
actions
{
if
i
%
test
.
chunk
==
0
&&
i
!=
0
{
if
byzantium
{
...
...
trie/database.go
View file @
a7842c9c
...
...
@@ -33,9 +33,6 @@ type Config struct {
Preimages
bool
// Flag whether the preimage of node key is recorded
HashDB
*
hashdb
.
Config
// Configs for hash-based scheme
PathDB
*
pathdb
.
Config
// Configs for experimental path-based scheme
// Testing hooks
OnCommit
func
(
states
*
triestate
.
Set
)
// Hook invoked when commit is performed
}
// HashDefaults represents a config for using hash-based scheme with
...
...
@@ -88,20 +85,6 @@ type Database struct {
backend
backend
// The backend for managing trie nodes
}
// prepare initializes the database with provided configs, but the
// database backend is still left as nil.
func
prepare
(
diskdb
ethdb
.
Database
,
config
*
Config
)
*
Database
{
var
preimages
*
preimageStore
if
config
!=
nil
&&
config
.
Preimages
{
preimages
=
newPreimageStore
(
diskdb
)
}
return
&
Database
{
config
:
config
,
diskdb
:
diskdb
,
preimages
:
preimages
,
}
}
// NewDatabase initializes the trie database with default settings, note
// the legacy hash-based scheme is used by default.
func
NewDatabase
(
diskdb
ethdb
.
Database
,
config
*
Config
)
*
Database
{
...
...
@@ -149,9 +132,6 @@ func (db *Database) Reader(blockRoot common.Hash) (Reader, error) {
// The passed in maps(nodes, states) will be retained to avoid copying everything.
// Therefore, these maps must not be changed afterwards.
func
(
db
*
Database
)
Update
(
root
common
.
Hash
,
parent
common
.
Hash
,
block
uint64
,
nodes
*
trienode
.
MergedNodeSet
,
states
*
triestate
.
Set
)
error
{
if
db
.
config
!=
nil
&&
db
.
config
.
OnCommit
!=
nil
{
db
.
config
.
OnCommit
(
states
)
}
if
db
.
preimages
!=
nil
{
db
.
preimages
.
commit
(
false
)
}
...
...
trie/database_test.go
View file @
a7842c9c
...
...
@@ -25,11 +25,16 @@ import (
// newTestDatabase initializes the trie database with specified scheme.
func
newTestDatabase
(
diskdb
ethdb
.
Database
,
scheme
string
)
*
Database
{
db
:=
prepare
(
diskdb
,
nil
)
config
:=
&
Config
{
Preimages
:
false
}
if
scheme
==
rawdb
.
HashScheme
{
db
.
backend
=
hashdb
.
New
(
diskdb
,
&
hashdb
.
Config
{},
mptResolver
{})
config
.
HashDB
=
&
hashdb
.
Config
{
CleanCacheSize
:
0
,
}
// disable clean cache
}
else
{
db
.
backend
=
pathdb
.
New
(
diskdb
,
&
pathdb
.
Config
{})
// disable clean/dirty cache
config
.
PathDB
=
&
pathdb
.
Config
{
CleanCacheSize
:
0
,
DirtyCacheSize
:
0
,
}
// disable clean/dirty cache
}
return
db
return
NewDatabase
(
diskdb
,
config
)
}
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