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
0abcf03f
Commit
0abcf03f
authored
Nov 22, 2019
by
Felix Lange
Committed by
Péter Szilágyi
Nov 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie: remove unused code (#20366)
parent
58f2ce86
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
63 deletions
+7
-63
database.go
trie/database.go
+7
-52
trie_test.go
trie/trie_test.go
+0
-11
No files found.
trie/database.go
View file @
0abcf03f
...
...
@@ -97,18 +97,16 @@ type Database struct {
// in the same cache fields).
type
rawNode
[]
byte
func
(
n
rawNode
)
canUnload
(
uint16
,
uint16
)
bool
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawNode
)
cache
()
(
hashNode
,
bool
)
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawNode
)
fstring
(
ind
string
)
string
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawNode
)
cache
()
(
hashNode
,
bool
)
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawNode
)
fstring
(
ind
string
)
string
{
panic
(
"this should never end up in a live trie"
)
}
// rawFullNode represents only the useful data content of a full node, with the
// caches and flags stripped out to minimize its data storage. This type honors
// the same RLP encoding as the original parent.
type
rawFullNode
[
17
]
node
func
(
n
rawFullNode
)
canUnload
(
uint16
,
uint16
)
bool
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawFullNode
)
cache
()
(
hashNode
,
bool
)
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawFullNode
)
fstring
(
ind
string
)
string
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawFullNode
)
cache
()
(
hashNode
,
bool
)
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawFullNode
)
fstring
(
ind
string
)
string
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawFullNode
)
EncodeRLP
(
w
io
.
Writer
)
error
{
var
nodes
[
17
]
node
...
...
@@ -131,9 +129,8 @@ type rawShortNode struct {
Val
node
}
func
(
n
rawShortNode
)
canUnload
(
uint16
,
uint16
)
bool
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawShortNode
)
cache
()
(
hashNode
,
bool
)
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawShortNode
)
fstring
(
ind
string
)
string
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawShortNode
)
cache
()
(
hashNode
,
bool
)
{
panic
(
"this should never end up in a live trie"
)
}
func
(
n
rawShortNode
)
fstring
(
ind
string
)
string
{
panic
(
"this should never end up in a live trie"
)
}
// cachedNode is all the information we know about a single cached node in the
// memory database write layer.
...
...
@@ -841,7 +838,7 @@ func (c *cleaner) Put(key []byte, rlp []byte) error {
}
func
(
c
*
cleaner
)
Delete
(
key
[]
byte
)
error
{
panic
(
"
N
ot implemented"
)
panic
(
"
n
ot implemented"
)
}
// Size returns the current storage size of the memory cache in front of the
...
...
@@ -857,45 +854,3 @@ func (db *Database) Size() (common.StorageSize, common.StorageSize) {
var
metarootRefs
=
common
.
StorageSize
(
len
(
db
.
dirties
[
common
.
Hash
{}]
.
children
)
*
(
common
.
HashLength
+
2
))
return
db
.
dirtiesSize
+
db
.
childrenSize
+
metadataSize
-
metarootRefs
,
db
.
preimagesSize
}
// verifyIntegrity is a debug method to iterate over the entire trie stored in
// memory and check whether every node is reachable from the meta root. The goal
// is to find any errors that might cause memory leaks and or trie nodes to go
// missing.
//
// This method is extremely CPU and memory intensive, only use when must.
func
(
db
*
Database
)
verifyIntegrity
()
{
// Iterate over all the cached nodes and accumulate them into a set
reachable
:=
map
[
common
.
Hash
]
struct
{}{{}
:
{}}
for
child
:=
range
db
.
dirties
[
common
.
Hash
{}]
.
children
{
db
.
accumulate
(
child
,
reachable
)
}
// Find any unreachable but cached nodes
var
unreachable
[]
string
for
hash
,
node
:=
range
db
.
dirties
{
if
_
,
ok
:=
reachable
[
hash
];
!
ok
{
unreachable
=
append
(
unreachable
,
fmt
.
Sprintf
(
"%x: {Node: %v, Parents: %d, Prev: %x, Next: %x}"
,
hash
,
node
.
node
,
node
.
parents
,
node
.
flushPrev
,
node
.
flushNext
))
}
}
if
len
(
unreachable
)
!=
0
{
panic
(
fmt
.
Sprintf
(
"trie cache memory leak: %v"
,
unreachable
))
}
}
// accumulate iterates over the trie defined by hash and accumulates all the
// cached children found in memory.
func
(
db
*
Database
)
accumulate
(
hash
common
.
Hash
,
reachable
map
[
common
.
Hash
]
struct
{})
{
// Mark the node reachable if present in the memory cache
node
,
ok
:=
db
.
dirties
[
hash
]
if
!
ok
{
return
}
reachable
[
hash
]
=
struct
{}{}
// Iterate over all the children and accumulate them too
for
_
,
child
:=
range
node
.
childs
()
{
db
.
accumulate
(
child
,
reachable
)
}
}
trie/trie_test.go
View file @
0abcf03f
...
...
@@ -31,7 +31,6 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/leveldb"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/rlp"
...
...
@@ -317,16 +316,6 @@ func TestLargeValue(t *testing.T) {
trie
.
Hash
()
}
type
countingDB
struct
{
ethdb
.
KeyValueStore
gets
map
[
string
]
int
}
func
(
db
*
countingDB
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
{
db
.
gets
[
string
(
key
)]
++
return
db
.
KeyValueStore
.
Get
(
key
)
}
// randTest performs random trie operations.
// Instances of this test are created by Generate.
type
randTest
[]
randTestStep
...
...
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