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
d86fe26f
Unverified
Commit
d86fe26f
authored
Oct 19, 2022
by
s7v7nislands
Committed by
GitHub
Oct 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/rawdb: refactor db key prefix (#26000)
Co-authored-by:
seven
<
seven@nodereal.io
>
parent
6069d829
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
30 deletions
+34
-30
snapshot.go
consensus/clique/snapshot.go
+3
-2
database.go
core/rawdb/database.go
+7
-7
schema.go
core/rawdb/schema.go
+10
-0
handler_test.go
les/handler_test.go
+2
-2
server_handler.go
les/server_handler.go
+2
-2
postprocess.go
light/postprocess.go
+10
-17
No files found.
consensus/clique/snapshot.go
View file @
d86fe26f
...
...
@@ -23,6 +23,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
...
...
@@ -87,7 +88,7 @@ func newSnapshot(config *params.CliqueConfig, sigcache *lru.ARCCache, number uin
// loadSnapshot loads an existing snapshot from the database.
func
loadSnapshot
(
config
*
params
.
CliqueConfig
,
sigcache
*
lru
.
ARCCache
,
db
ethdb
.
Database
,
hash
common
.
Hash
)
(
*
Snapshot
,
error
)
{
blob
,
err
:=
db
.
Get
(
append
(
[]
byte
(
"clique-"
)
,
hash
[
:
]
...
))
blob
,
err
:=
db
.
Get
(
append
(
rawdb
.
CliqueSnapshotPrefix
,
hash
[
:
]
...
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -107,7 +108,7 @@ func (s *Snapshot) store(db ethdb.Database) error {
if
err
!=
nil
{
return
err
}
return
db
.
Put
(
append
(
[]
byte
(
"clique-"
)
,
s
.
Hash
[
:
]
...
),
blob
)
return
db
.
Put
(
append
(
rawdb
.
CliqueSnapshotPrefix
,
s
.
Hash
[
:
]
...
),
blob
)
}
// copy creates a deep copy of the snapshot, though not the individual votes.
...
...
core/rawdb/database.go
View file @
d86fe26f
...
...
@@ -439,15 +439,15 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
bloomBits
.
Add
(
size
)
case
bytes
.
HasPrefix
(
key
,
skeletonHeaderPrefix
)
&&
len
(
key
)
==
(
len
(
skeletonHeaderPrefix
)
+
8
)
:
beaconHeaders
.
Add
(
size
)
case
bytes
.
HasPrefix
(
key
,
[]
byte
(
"clique-"
)
)
&&
len
(
key
)
==
7
+
common
.
HashLength
:
case
bytes
.
HasPrefix
(
key
,
CliqueSnapshotPrefix
)
&&
len
(
key
)
==
7
+
common
.
HashLength
:
cliqueSnaps
.
Add
(
size
)
case
bytes
.
HasPrefix
(
key
,
[]
byte
(
"cht-"
)
)
||
bytes
.
HasPrefix
(
key
,
[]
byte
(
"chtIndexV2-"
)
)
||
bytes
.
HasPrefix
(
key
,
[]
byte
(
"chtRootV2-"
)
)
:
// Canonical hash trie
case
bytes
.
HasPrefix
(
key
,
ChtTablePrefix
)
||
bytes
.
HasPrefix
(
key
,
ChtIndexTablePrefix
)
||
bytes
.
HasPrefix
(
key
,
ChtPrefix
)
:
// Canonical hash trie
chtTrieNodes
.
Add
(
size
)
case
bytes
.
HasPrefix
(
key
,
[]
byte
(
"blt-"
)
)
||
bytes
.
HasPrefix
(
key
,
[]
byte
(
"bltIndex-"
)
)
||
bytes
.
HasPrefix
(
key
,
[]
byte
(
"bltRoot-"
)
)
:
// Bloomtrie sub
case
bytes
.
HasPrefix
(
key
,
BloomTrieTablePrefix
)
||
bytes
.
HasPrefix
(
key
,
BloomTrieIndexPrefix
)
||
bytes
.
HasPrefix
(
key
,
BloomTriePrefix
)
:
// Bloomtrie sub
bloomTrieNodes
.
Add
(
size
)
default
:
var
accounted
bool
...
...
core/rawdb/schema.go
View file @
d86fe26f
...
...
@@ -109,6 +109,16 @@ var (
// BloomBitsIndexPrefix is the data table of a chain indexer to track its progress
BloomBitsIndexPrefix
=
[]
byte
(
"iB"
)
ChtPrefix
=
[]
byte
(
"chtRootV2-"
)
// ChtPrefix + chtNum (uint64 big endian) -> trie root hash
ChtTablePrefix
=
[]
byte
(
"cht-"
)
ChtIndexTablePrefix
=
[]
byte
(
"chtIndexV2-"
)
BloomTriePrefix
=
[]
byte
(
"bltRoot-"
)
// BloomTriePrefix + bloomTrieNum (uint64 big endian) -> trie root hash
BloomTrieTablePrefix
=
[]
byte
(
"blt-"
)
BloomTrieIndexPrefix
=
[]
byte
(
"bltIndex-"
)
CliqueSnapshotPrefix
=
[]
byte
(
"clique-"
)
preimageCounter
=
metrics
.
NewRegisteredCounter
(
"db/preimage/total"
,
nil
)
preimageHitCounter
=
metrics
.
NewRegisteredCounter
(
"db/preimage/hits"
,
nil
)
)
...
...
les/handler_test.go
View file @
d86fe26f
...
...
@@ -512,7 +512,7 @@ func testGetCHTProofs(t *testing.T, protocol int) {
AuxData
:
[][]
byte
{
rlp
},
}
root
:=
light
.
GetChtRoot
(
server
.
db
,
0
,
bc
.
GetHeaderByNumber
(
config
.
ChtSize
-
1
)
.
Hash
())
trie
,
_
:=
trie
.
New
(
trie
.
TrieID
(
root
),
trie
.
NewDatabase
(
rawdb
.
NewTable
(
server
.
db
,
light
.
ChtTablePrefix
)))
trie
,
_
:=
trie
.
New
(
trie
.
TrieID
(
root
),
trie
.
NewDatabase
(
rawdb
.
NewTable
(
server
.
db
,
string
(
rawdb
.
ChtTablePrefix
)
)))
trie
.
Prove
(
key
,
0
,
&
proofsV2
.
Proofs
)
// Assemble the requests for the different protocols
requestsV2
:=
[]
HelperTrieReq
{{
...
...
@@ -577,7 +577,7 @@ func testGetBloombitsProofs(t *testing.T, protocol int) {
var
proofs
HelperTrieResps
root
:=
light
.
GetBloomTrieRoot
(
server
.
db
,
0
,
bc
.
GetHeaderByNumber
(
config
.
BloomTrieSize
-
1
)
.
Hash
())
trie
,
_
:=
trie
.
New
(
trie
.
TrieID
(
root
),
trie
.
NewDatabase
(
rawdb
.
NewTable
(
server
.
db
,
light
.
BloomTrieTablePrefix
)))
trie
,
_
:=
trie
.
New
(
trie
.
TrieID
(
root
),
trie
.
NewDatabase
(
rawdb
.
NewTable
(
server
.
db
,
string
(
rawdb
.
BloomTrieTablePrefix
)
)))
trie
.
Prove
(
key
,
0
,
&
proofs
.
Proofs
)
// Send the proof request and verify the response
...
...
les/server_handler.go
View file @
d86fe26f
...
...
@@ -383,10 +383,10 @@ func (h *serverHandler) GetHelperTrie(typ uint, index uint64) *trie.Trie {
switch
typ
{
case
htCanonical
:
sectionHead
:=
rawdb
.
ReadCanonicalHash
(
h
.
chainDb
,
(
index
+
1
)
*
h
.
server
.
iConfig
.
ChtSize
-
1
)
root
,
prefix
=
light
.
GetChtRoot
(
h
.
chainDb
,
index
,
sectionHead
),
light
.
ChtTablePrefix
root
,
prefix
=
light
.
GetChtRoot
(
h
.
chainDb
,
index
,
sectionHead
),
string
(
rawdb
.
ChtTablePrefix
)
case
htBloomBits
:
sectionHead
:=
rawdb
.
ReadCanonicalHash
(
h
.
chainDb
,
(
index
+
1
)
*
h
.
server
.
iConfig
.
BloomTrieSize
-
1
)
root
,
prefix
=
light
.
GetBloomTrieRoot
(
h
.
chainDb
,
index
,
sectionHead
),
light
.
BloomTrieTablePrefix
root
,
prefix
=
light
.
GetBloomTrieRoot
(
h
.
chainDb
,
index
,
sectionHead
),
string
(
rawdb
.
BloomTrieTablePrefix
)
}
if
root
==
(
common
.
Hash
{})
{
return
nil
...
...
light/postprocess.go
View file @
d86fe26f
...
...
@@ -102,8 +102,6 @@ var (
errNoTrustedCht
=
errors
.
New
(
"no trusted canonical hash trie"
)
errNoTrustedBloomTrie
=
errors
.
New
(
"no trusted bloom trie"
)
errNoHeader
=
errors
.
New
(
"header not found"
)
chtPrefix
=
[]
byte
(
"chtRootV2-"
)
// chtPrefix + chtNum (uint64 big endian) -> trie root hash
ChtTablePrefix
=
"cht-"
)
// ChtNode structures are stored in the Canonical Hash Trie in an RLP encoded format
...
...
@@ -116,7 +114,7 @@ type ChtNode struct {
func
GetChtRoot
(
db
ethdb
.
Database
,
sectionIdx
uint64
,
sectionHead
common
.
Hash
)
common
.
Hash
{
var
encNumber
[
8
]
byte
binary
.
BigEndian
.
PutUint64
(
encNumber
[
:
],
sectionIdx
)
data
,
_
:=
db
.
Get
(
append
(
append
(
c
htPrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
))
data
,
_
:=
db
.
Get
(
append
(
append
(
rawdb
.
C
htPrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
))
return
common
.
BytesToHash
(
data
)
}
...
...
@@ -124,7 +122,7 @@ func GetChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) c
func
StoreChtRoot
(
db
ethdb
.
Database
,
sectionIdx
uint64
,
sectionHead
,
root
common
.
Hash
)
{
var
encNumber
[
8
]
byte
binary
.
BigEndian
.
PutUint64
(
encNumber
[
:
],
sectionIdx
)
db
.
Put
(
append
(
append
(
c
htPrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
),
root
.
Bytes
())
db
.
Put
(
append
(
append
(
rawdb
.
C
htPrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
),
root
.
Bytes
())
}
// ChtIndexerBackend implements core.ChainIndexerBackend.
...
...
@@ -140,7 +138,7 @@ type ChtIndexerBackend struct {
// NewChtIndexer creates a Cht chain indexer
func
NewChtIndexer
(
db
ethdb
.
Database
,
odr
OdrBackend
,
size
,
confirms
uint64
,
disablePruning
bool
)
*
core
.
ChainIndexer
{
trieTable
:=
rawdb
.
NewTable
(
db
,
ChtTablePrefix
)
trieTable
:=
rawdb
.
NewTable
(
db
,
string
(
rawdb
.
ChtTablePrefix
)
)
backend
:=
&
ChtIndexerBackend
{
diskdb
:
db
,
odr
:
odr
,
...
...
@@ -149,7 +147,7 @@ func NewChtIndexer(db ethdb.Database, odr OdrBackend, size, confirms uint64, dis
sectionSize
:
size
,
disablePruning
:
disablePruning
,
}
return
core
.
NewChainIndexer
(
db
,
rawdb
.
NewTable
(
db
,
"chtIndexV2-"
),
backend
,
size
,
confirms
,
time
.
Millisecond
*
100
,
"cht"
)
return
core
.
NewChainIndexer
(
db
,
rawdb
.
NewTable
(
db
,
string
(
rawdb
.
ChtIndexTablePrefix
)
),
backend
,
size
,
confirms
,
time
.
Millisecond
*
100
,
"cht"
)
}
// fetchMissingNodes tries to retrieve the last entry of the latest trusted CHT from the
...
...
@@ -249,7 +247,7 @@ func (c *ChtIndexerBackend) Commit() error {
}
}
for
it
.
Next
()
{
trimmed
:=
bytes
.
TrimPrefix
(
it
.
Key
(),
[]
byte
(
ChtTablePrefix
)
)
trimmed
:=
bytes
.
TrimPrefix
(
it
.
Key
(),
rawdb
.
ChtTablePrefix
)
if
len
(
trimmed
)
==
common
.
HashLength
{
if
_
,
ok
:=
hashes
[
common
.
BytesToHash
(
trimmed
)];
!
ok
{
batch
.
Delete
(
trimmed
)
...
...
@@ -311,16 +309,11 @@ func (c *ChtIndexerBackend) Prune(threshold uint64) error {
return
nil
}
var
(
bloomTriePrefix
=
[]
byte
(
"bltRoot-"
)
// bloomTriePrefix + bloomTrieNum (uint64 big endian) -> trie root hash
BloomTrieTablePrefix
=
"blt-"
)
// GetBloomTrieRoot reads the BloomTrie root associated to the given section from the database
func
GetBloomTrieRoot
(
db
ethdb
.
Database
,
sectionIdx
uint64
,
sectionHead
common
.
Hash
)
common
.
Hash
{
var
encNumber
[
8
]
byte
binary
.
BigEndian
.
PutUint64
(
encNumber
[
:
],
sectionIdx
)
data
,
_
:=
db
.
Get
(
append
(
append
(
b
loomTriePrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
))
data
,
_
:=
db
.
Get
(
append
(
append
(
rawdb
.
B
loomTriePrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
))
return
common
.
BytesToHash
(
data
)
}
...
...
@@ -328,7 +321,7 @@ func GetBloomTrieRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.H
func
StoreBloomTrieRoot
(
db
ethdb
.
Database
,
sectionIdx
uint64
,
sectionHead
,
root
common
.
Hash
)
{
var
encNumber
[
8
]
byte
binary
.
BigEndian
.
PutUint64
(
encNumber
[
:
],
sectionIdx
)
db
.
Put
(
append
(
append
(
b
loomTriePrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
),
root
.
Bytes
())
db
.
Put
(
append
(
append
(
rawdb
.
B
loomTriePrefix
,
encNumber
[
:
]
...
),
sectionHead
.
Bytes
()
...
),
root
.
Bytes
())
}
// BloomTrieIndexerBackend implements core.ChainIndexerBackend
...
...
@@ -347,7 +340,7 @@ type BloomTrieIndexerBackend struct {
// NewBloomTrieIndexer creates a BloomTrie chain indexer
func
NewBloomTrieIndexer
(
db
ethdb
.
Database
,
odr
OdrBackend
,
parentSize
,
size
uint64
,
disablePruning
bool
)
*
core
.
ChainIndexer
{
trieTable
:=
rawdb
.
NewTable
(
db
,
BloomTrieTablePrefix
)
trieTable
:=
rawdb
.
NewTable
(
db
,
string
(
rawdb
.
BloomTrieTablePrefix
)
)
backend
:=
&
BloomTrieIndexerBackend
{
diskdb
:
db
,
odr
:
odr
,
...
...
@@ -359,7 +352,7 @@ func NewBloomTrieIndexer(db ethdb.Database, odr OdrBackend, parentSize, size uin
}
backend
.
bloomTrieRatio
=
size
/
parentSize
backend
.
sectionHeads
=
make
([]
common
.
Hash
,
backend
.
bloomTrieRatio
)
return
core
.
NewChainIndexer
(
db
,
rawdb
.
NewTable
(
db
,
"bltIndex-"
),
backend
,
size
,
0
,
time
.
Millisecond
*
100
,
"bloomtrie"
)
return
core
.
NewChainIndexer
(
db
,
rawdb
.
NewTable
(
db
,
string
(
rawdb
.
BloomTrieIndexPrefix
)
),
backend
,
size
,
0
,
time
.
Millisecond
*
100
,
"bloomtrie"
)
}
// fetchMissingNodes tries to retrieve the last entries of the latest trusted bloom trie from the
...
...
@@ -500,7 +493,7 @@ func (b *BloomTrieIndexerBackend) Commit() error {
}
}
for
it
.
Next
()
{
trimmed
:=
bytes
.
TrimPrefix
(
it
.
Key
(),
[]
byte
(
BloomTrieTablePrefix
)
)
trimmed
:=
bytes
.
TrimPrefix
(
it
.
Key
(),
rawdb
.
BloomTrieTablePrefix
)
if
len
(
trimmed
)
==
common
.
HashLength
{
if
_
,
ok
:=
hashes
[
common
.
BytesToHash
(
trimmed
)];
!
ok
{
batch
.
Delete
(
trimmed
)
...
...
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