aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-06-21 02:31:11 +0800
committerobscuren <geffobscura@gmail.com>2015-06-21 22:59:15 +0800
commitc590b505ed92957baf2ab4baa1788c6b0ec862cc (patch)
tree473ddb052798c30a21c05abef4764bccf4ab4e0a
parent3deded28a50398b8ce108c72f27ea861c1bce178 (diff)
downloadgo-tangerine-c590b505ed92957baf2ab4baa1788c6b0ec862cc.tar
go-tangerine-c590b505ed92957baf2ab4baa1788c6b0ec862cc.tar.gz
go-tangerine-c590b505ed92957baf2ab4baa1788c6b0ec862cc.tar.bz2
go-tangerine-c590b505ed92957baf2ab4baa1788c6b0ec862cc.tar.lz
go-tangerine-c590b505ed92957baf2ab4baa1788c6b0ec862cc.tar.xz
go-tangerine-c590b505ed92957baf2ab4baa1788c6b0ec862cc.tar.zst
go-tangerine-c590b505ed92957baf2ab4baa1788c6b0ec862cc.zip
core, ethdb, trie: validate database errors
-rw-r--r--common/db.go2
-rw-r--r--core/chain_manager.go16
-rw-r--r--ethdb/database.go4
-rw-r--r--ethdb/memory_database.go4
-rw-r--r--trie/cache.go8
5 files changed, 25 insertions, 9 deletions
diff --git a/common/db.go b/common/db.go
index c12a2cfb0..7f3becd5a 100644
--- a/common/db.go
+++ b/common/db.go
@@ -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()
diff --git a/core/chain_manager.go b/core/chain_manager.go
index c3b7273c2..e3795f561 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -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)
}
diff --git a/ethdb/database.go b/ethdb/database.go
index 019645ced..5faf8c4e0 100644
--- a/ethdb/database.go
+++ b/ethdb/database.go
@@ -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.
diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go
index f5d5faee7..c15c56bfb 100644
--- a/ethdb/memory_database.go
+++ b/ethdb/memory_database.go
@@ -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) {
diff --git a/trie/cache.go b/trie/cache.go
index 2143785fa..4c76c6cba 100644
--- a/trie/cache.go
+++ b/trie/cache.go
@@ -1,8 +1,10 @@
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