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
7633dfdc
Commit
7633dfdc
authored
Jun 21, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1305 from obscuren/database-error-check
core, ethdb, trie: validate database errors
parents
3deded28
a40a91d6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
10 deletions
+26
-10
db.go
common/db.go
+1
-1
chain_manager.go
core/chain_manager.go
+13
-3
database.go
ethdb/database.go
+2
-2
memory_database.go
ethdb/memory_database.go
+3
-1
cache.go
trie/cache.go
+6
-2
trie_test.go
trie/trie_test.go
+1
-1
No files found.
common/db.go
View file @
7633dfdc
...
...
@@ -2,7 +2,7 @@ package common
// Database interface
type
Database
interface
{
Put
(
key
[]
byte
,
value
[]
byte
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
Get
(
key
[]
byte
)
([]
byte
,
error
)
Delete
(
key
[]
byte
)
error
Close
()
...
...
core/chain_manager.go
View file @
7633dfdc
...
...
@@ -377,8 +377,14 @@ func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error
// assumes that the `mu` mutex is held!
func
(
bc
*
ChainManager
)
insert
(
block
*
types
.
Block
)
{
key
:=
append
(
blockNumPre
,
block
.
Number
()
.
Bytes
()
...
)
bc
.
blockDb
.
Put
(
key
,
block
.
Hash
()
.
Bytes
())
bc
.
blockDb
.
Put
([]
byte
(
"LastBlock"
),
block
.
Hash
()
.
Bytes
())
err
:=
bc
.
blockDb
.
Put
(
key
,
block
.
Hash
()
.
Bytes
())
if
err
!=
nil
{
glog
.
Fatal
(
"db write fail:"
,
err
)
}
err
=
bc
.
blockDb
.
Put
([]
byte
(
"LastBlock"
),
block
.
Hash
()
.
Bytes
())
if
err
!=
nil
{
glog
.
Fatal
(
"db write fail:"
,
err
)
}
bc
.
currentBlock
=
block
bc
.
lastBlockHash
=
block
.
Hash
()
...
...
@@ -387,7 +393,11 @@ func (bc *ChainManager) insert(block *types.Block) {
func
(
bc
*
ChainManager
)
write
(
block
*
types
.
Block
)
{
enc
,
_
:=
rlp
.
EncodeToBytes
((
*
types
.
StorageBlock
)(
block
))
key
:=
append
(
blockHashPre
,
block
.
Hash
()
.
Bytes
()
...
)
bc
.
blockDb
.
Put
(
key
,
enc
)
err
:=
bc
.
blockDb
.
Put
(
key
,
enc
)
if
err
!=
nil
{
glog
.
Fatal
(
"db write fail:"
,
err
)
}
// Push block to cache
bc
.
cache
.
Push
(
block
)
}
...
...
ethdb/database.go
View file @
7633dfdc
...
...
@@ -42,8 +42,8 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) {
}
// Put puts the given key / value to the queue
func
(
self
*
LDBDatabase
)
Put
(
key
[]
byte
,
value
[]
byte
)
{
self
.
db
.
Put
(
key
,
rle
.
Compress
(
value
),
nil
)
func
(
self
*
LDBDatabase
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
return
self
.
db
.
Put
(
key
,
rle
.
Compress
(
value
),
nil
)
}
// Get returns the given key if it's present.
...
...
ethdb/memory_database.go
View file @
7633dfdc
...
...
@@ -19,8 +19,10 @@ func NewMemDatabase() (*MemDatabase, error) {
return
db
,
nil
}
func
(
db
*
MemDatabase
)
Put
(
key
[]
byte
,
value
[]
byte
)
{
func
(
db
*
MemDatabase
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
db
.
db
[
string
(
key
)]
=
value
return
nil
}
func
(
db
*
MemDatabase
)
Set
(
key
[]
byte
,
value
[]
byte
)
{
...
...
trie/cache.go
View file @
7633dfdc
package
trie
import
"github.com/ethereum/go-ethereum/logger/glog"
type
Backend
interface
{
Get
([]
byte
)
([]
byte
,
error
)
Put
([]
byte
,
[]
byte
)
Put
([]
byte
,
[]
byte
)
error
}
type
Cache
struct
{
...
...
@@ -29,7 +31,9 @@ func (self *Cache) Put(key []byte, data []byte) {
func
(
self
*
Cache
)
Flush
()
{
for
k
,
v
:=
range
self
.
store
{
self
.
backend
.
Put
([]
byte
(
k
),
v
)
if
err
:=
self
.
backend
.
Put
([]
byte
(
k
),
v
);
err
!=
nil
{
glog
.
Fatal
(
"db write err:"
,
err
)
}
}
// This will eventually grow too large. We'd could
...
...
trie/trie_test.go
View file @
7633dfdc
...
...
@@ -12,7 +12,7 @@ import (
type
Db
map
[
string
][]
byte
func
(
self
Db
)
Get
(
k
[]
byte
)
([]
byte
,
error
)
{
return
self
[
string
(
k
)],
nil
}
func
(
self
Db
)
Put
(
k
,
v
[]
byte
)
{
self
[
string
(
k
)]
=
v
}
func
(
self
Db
)
Put
(
k
,
v
[]
byte
)
error
{
self
[
string
(
k
)]
=
v
;
return
nil
}
// Used for testing
func
NewEmpty
()
*
Trie
{
...
...
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