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
af2ca5a6
Unverified
Commit
af2ca5a6
authored
3 years ago
by
Péter Szilágyi
Committed by
GitHub
3 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24117 from holiman/db_has
trie, core, eth: use db.has over db.get where possible
parents
0f893109
893502e5
master
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
8 deletions
+20
-8
snapshot.go
cmd/geth/snapshot.go
+1
-2
accessors_state.go
core/rawdb/accessors_state.go
+14
-0
sync.go
eth/protocols/snap/sync.go
+2
-2
sync.go
trie/sync.go
+3
-4
No files found.
cmd/geth/snapshot.go
View file @
af2ca5a6
...
...
@@ -418,8 +418,7 @@ func traverseRawState(ctx *cli.Context) error {
// Check the present for non-empty hash node(embedded node doesn't
// have their own hash).
if
node
!=
(
common
.
Hash
{})
{
blob
:=
rawdb
.
ReadTrieNode
(
chaindb
,
node
)
if
len
(
blob
)
==
0
{
if
!
rawdb
.
HasTrieNode
(
chaindb
,
node
)
{
log
.
Error
(
"Missing trie node(storage)"
,
"hash"
,
node
)
return
errors
.
New
(
"missing storage"
)
}
...
...
This diff is collapsed.
Click to expand it.
core/rawdb/accessors_state.go
View file @
af2ca5a6
...
...
@@ -61,6 +61,14 @@ func ReadCodeWithPrefix(db ethdb.KeyValueReader, hash common.Hash) []byte {
return
data
}
// HasCodeWithPrefix checks if the contract code corresponding to the
// provided code hash is present in the db. This function will only check
// presence using the prefix-scheme.
func
HasCodeWithPrefix
(
db
ethdb
.
KeyValueReader
,
hash
common
.
Hash
)
bool
{
ok
,
_
:=
db
.
Has
(
codeKey
(
hash
))
return
ok
}
// WriteCode writes the provided contract code database.
func
WriteCode
(
db
ethdb
.
KeyValueWriter
,
hash
common
.
Hash
,
code
[]
byte
)
{
if
err
:=
db
.
Put
(
codeKey
(
hash
),
code
);
err
!=
nil
{
...
...
@@ -81,6 +89,12 @@ func ReadTrieNode(db ethdb.KeyValueReader, hash common.Hash) []byte {
return
data
}
// HasTrieNode checks if the trie node with the provided hash is present in db.
func
HasTrieNode
(
db
ethdb
.
KeyValueReader
,
hash
common
.
Hash
)
bool
{
ok
,
_
:=
db
.
Has
(
hash
.
Bytes
())
return
ok
}
// WriteTrieNode writes the provided trie node database.
func
WriteTrieNode
(
db
ethdb
.
KeyValueWriter
,
hash
common
.
Hash
,
node
[]
byte
)
{
if
err
:=
db
.
Put
(
hash
.
Bytes
(),
node
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
eth/protocols/snap/sync.go
View file @
af2ca5a6
...
...
@@ -1781,7 +1781,7 @@ func (s *Syncer) processAccountResponse(res *accountResponse) {
for
i
,
account
:=
range
res
.
accounts
{
// Check if the account is a contract with an unknown code
if
!
bytes
.
Equal
(
account
.
CodeHash
,
emptyCode
[
:
])
{
if
code
:=
rawdb
.
ReadCodeWithPrefix
(
s
.
db
,
common
.
BytesToHash
(
account
.
CodeHash
));
code
==
nil
{
if
!
rawdb
.
HasCodeWithPrefix
(
s
.
db
,
common
.
BytesToHash
(
account
.
CodeHash
))
{
res
.
task
.
codeTasks
[
common
.
BytesToHash
(
account
.
CodeHash
)]
=
struct
{}{}
res
.
task
.
needCode
[
i
]
=
true
res
.
task
.
pend
++
...
...
@@ -1789,7 +1789,7 @@ func (s *Syncer) processAccountResponse(res *accountResponse) {
}
// Check if the account is a contract with an unknown storage trie
if
account
.
Root
!=
emptyRoot
{
if
node
,
err
:=
s
.
db
.
Get
(
account
.
Root
[
:
]);
err
!=
nil
||
node
==
nil
{
if
ok
,
err
:=
s
.
db
.
Has
(
account
.
Root
[
:
]);
err
!=
nil
||
!
ok
{
// If there was a previous large state retrieval in progress,
// don't restart it from scratch. This happens if a sync cycle
// is interrupted and resumed later. However, *do* update the
...
...
This diff is collapsed.
Click to expand it.
trie/sync.go
View file @
af2ca5a6
...
...
@@ -155,8 +155,7 @@ func (s *Sync) AddSubTrie(root common.Hash, path []byte, parent common.Hash, cal
}
// If database says this is a duplicate, then at least the trie node is
// present, and we hold the assumption that it's NOT legacy contract code.
blob
:=
rawdb
.
ReadTrieNode
(
s
.
database
,
root
)
if
len
(
blob
)
>
0
{
if
rawdb
.
HasTrieNode
(
s
.
database
,
root
)
{
return
}
// Assemble the new sub-trie sync request
...
...
@@ -193,7 +192,7 @@ func (s *Sync) AddCodeEntry(hash common.Hash, path []byte, parent common.Hash) {
// sync is expected to run with a fresh new node. Even there
// exists the code with legacy format, fetch and store with
// new scheme anyway.
if
blob
:=
rawdb
.
ReadCodeWithPrefix
(
s
.
database
,
hash
);
len
(
blob
)
>
0
{
if
rawdb
.
HasCodeWithPrefix
(
s
.
database
,
hash
)
{
return
}
// Assemble the new sub-trie sync request
...
...
@@ -401,7 +400,7 @@ func (s *Sync) children(req *request, object node) ([]*request, error) {
}
// If database says duplicate, then at least the trie node is present
// and we hold the assumption that it's NOT legacy contract code.
if
blob
:=
rawdb
.
ReadTrieNode
(
s
.
database
,
hash
);
len
(
blob
)
>
0
{
if
rawdb
.
HasTrieNode
(
s
.
database
,
hash
)
{
continue
}
// Locally unknown node, schedule for retrieval
...
...
This diff is collapsed.
Click to expand it.
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