OSDN Git Service

replace goleveldb with tendermint db (#1660)
authormuscle_boy <shenao.78@163.com>
Fri, 29 Mar 2019 09:01:29 +0000 (17:01 +0800)
committerPaladz <yzhu101@uottawa.ca>
Fri, 29 Mar 2019 09:01:29 +0000 (17:01 +0800)
* replace goleveldb with tendermint db

* format code

* remove goleveldb

* recover goleveldb

* move db package

* fix ci

* recover .db

* bug fix

* bug fix

55 files changed:
accesstoken/accesstoken.go
accesstoken/accesstoken_test.go
account/accounts.go
account/accounts_test.go
account/utxo_keeper.go
account/utxo_keeper_test.go
api/api_test.go
asset/asset.go
asset/asset_test.go
blockchain/txfeed/txfeed.go
database/cache.go [moved from database/leveldb/cache.go with 98% similarity]
database/cache_test.go [moved from database/leveldb/cache_test.go with 98% similarity]
database/leveldb/LICENSE.md [moved from vendor/github.com/tendermint/tmlibs/db/LICENSE.md with 100% similarity]
database/leveldb/README.md [moved from vendor/github.com/tendermint/tmlibs/db/README.md with 100% similarity]
database/leveldb/db.go [moved from vendor/github.com/tendermint/tmlibs/db/db.go with 98% similarity]
database/leveldb/go_level_db.go [moved from vendor/github.com/tendermint/tmlibs/db/go_level_db.go with 97% similarity]
database/leveldb/go_level_db_test.go [moved from vendor/github.com/tendermint/tmlibs/db/go_level_db_test.go with 100% similarity]
database/leveldb/mem_db.go [moved from vendor/github.com/tendermint/tmlibs/db/mem_db.go with 95% similarity]
database/leveldb/mem_db_test.go [moved from vendor/github.com/tendermint/tmlibs/db/mem_db_test.go with 100% similarity]
database/store.go [moved from database/leveldb/store.go with 99% similarity]
database/store_test.go [moved from database/leveldb/store_test.go with 98% similarity]
database/utxo_view.go [moved from database/leveldb/utxo_view.go with 96% similarity]
database/utxo_view_test.go [moved from database/leveldb/utxo_view_test.go with 98% similarity]
net/http/authn/authn_test.go
node/node.go
p2p/discover/database.go
p2p/discover/database_test.go
p2p/discover/net.go
p2p/discover/udp.go
p2p/switch.go
p2p/switch_test.go
p2p/test_util.go
test/bench_blockchain_test.go
test/block_test.go
test/chain_test_util.go
test/integration/standard_transaction_test.go
test/performance/mining_test.go
test/protocol_test.go
test/protocol_test_util.go
test/tx_test.go
test/tx_test_util.go
test/util.go
test/utxo_view/utxo_view_test.go
test/wallet_test_util.go
vendor/github.com/tendermint/tmlibs/db/c_level_db.go [deleted file]
vendor/github.com/tendermint/tmlibs/db/c_level_db_test.go [deleted file]
wallet/annotated.go
wallet/indexer.go
wallet/recovery.go
wallet/recovery_test.go
wallet/unconfirmed_test.go
wallet/utxo.go
wallet/utxo_test.go
wallet/wallet.go
wallet/wallet_test.go

index b357625..9bdff95 100644 (file)
@@ -10,10 +10,9 @@ import (
        "strings"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/crypto/sha3pool"
        "github.com/bytom/errors"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const tokenSize = 32
index 7b6525d..a588755 100644 (file)
@@ -6,9 +6,8 @@ import (
        "strings"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/errors"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestCreate(t *testing.T) {
index 8e89273..6667888 100644 (file)
@@ -10,7 +10,6 @@ import (
 
        "github.com/golang/groupcache/lru"
        log "github.com/sirupsen/logrus"
-       dbm "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/blockchain/signers"
        "github.com/bytom/blockchain/txbuilder"
@@ -24,6 +23,7 @@ import (
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/vm/vmutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const (
index 7cb23b1..31cd25c 100644 (file)
@@ -7,16 +7,15 @@ import (
        "strings"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/blockchain/pseudohsm"
        "github.com/bytom/blockchain/signers"
        "github.com/bytom/crypto/ed25519/chainkd"
-       "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
        "github.com/bytom/errors"
        "github.com/bytom/event"
        "github.com/bytom/protocol"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestCreateAccountWithUppercase(t *testing.T) {
@@ -215,7 +214,7 @@ func mockAccountManager(t *testing.T) *Manager {
        testDB := dbm.NewDB("testdb", "memdb", dirPath)
        dispatcher := event.NewDispatcher()
 
-       store := leveldb.NewStore(testDB)
+       store := database.NewStore(testDB)
        txPool := protocol.NewTxPool(store, dispatcher)
        chain, err := protocol.NewChain(store, txPool)
        if err != nil {
index 727a354..a984bf9 100644 (file)
@@ -9,10 +9,10 @@ import (
        "time"
 
        log "github.com/sirupsen/logrus"
-       dbm "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const desireUtxoCount = 5
index 066af51..5b4d8a7 100644 (file)
@@ -6,10 +6,9 @@ import (
        "testing"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/protocol/bc"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestAddUnconfirmedUtxo(t *testing.T) {
index 3c15fcd..29df894 100644 (file)
@@ -8,13 +8,12 @@ import (
        "os"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/accesstoken"
        "github.com/bytom/blockchain/rpc"
        "github.com/bytom/blockchain/txbuilder"
        "github.com/bytom/consensus"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestAPIHandler(t *testing.T) {
index 54096ad..c4b9774 100644 (file)
@@ -7,7 +7,6 @@ import (
        "sync"
 
        "github.com/golang/groupcache/lru"
-       dbm "github.com/tendermint/tmlibs/db"
        "golang.org/x/crypto/sha3"
 
        "github.com/bytom/blockchain/signers"
@@ -20,6 +19,7 @@ import (
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/vm/vmutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 // DefaultNativeAsset native BTM asset
index 17096ac..77f983b 100644 (file)
@@ -9,14 +9,13 @@ import (
        "strings"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/consensus"
        "github.com/bytom/crypto/ed25519/chainkd"
-       "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
        "github.com/bytom/event"
        "github.com/bytom/protocol"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestDefineAssetWithLowercase(t *testing.T) {
@@ -152,7 +151,7 @@ func TestListAssets(t *testing.T) {
 }
 
 func mockChain(testDB dbm.DB) (*protocol.Chain, error) {
-       store := leveldb.NewStore(testDB)
+       store := database.NewStore(testDB)
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)
        chain, err := protocol.NewChain(store, txPool)
index d19f7f0..b8e91d4 100644 (file)
@@ -7,7 +7,6 @@ import (
        "strings"
 
        log "github.com/sirupsen/logrus"
-       dbm "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/blockchain/query"
        "github.com/bytom/errors"
@@ -15,6 +14,7 @@ import (
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm/vmutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const (
similarity index 98%
rename from database/leveldb/cache.go
rename to database/cache.go
index 744c05e..41a5525 100644 (file)
@@ -1,4 +1,4 @@
-package leveldb
+package database
 
 import (
        "fmt"
similarity index 98%
rename from database/leveldb/cache_test.go
rename to database/cache_test.go
index 9e47fea..36ea57a 100644 (file)
@@ -1,4 +1,4 @@
-package leveldb
+package database
 
 import (
        "testing"
similarity index 98%
rename from vendor/github.com/tendermint/tmlibs/db/db.go
rename to database/leveldb/db.go
index 8156c1e..38cab5b 100644 (file)
@@ -29,6 +29,7 @@ type Iterator interface {
 
        Key() []byte
        Value() []byte
+       Seek([]byte) bool
 
        Release()
        Error() error
similarity index 97%
rename from vendor/github.com/tendermint/tmlibs/db/go_level_db.go
rename to database/leveldb/go_level_db.go
index 4abd761..e9e8d3d 100644 (file)
@@ -139,6 +139,10 @@ func (it *goLevelDBIterator) Value() []byte {
        return v
 }
 
+func (it *goLevelDBIterator) Seek(point []byte) bool {
+       return it.source.Seek(point)
+}
+
 func (it *goLevelDBIterator) Error() error {
        return it.source.Error()
 }
similarity index 95%
rename from vendor/github.com/tendermint/tmlibs/db/mem_db.go
rename to database/leveldb/mem_db.go
index 2f50732..62f40fc 100644 (file)
@@ -101,6 +101,16 @@ func (it *memDBIterator) Value() []byte {
        return it.db.Get(it.Key())
 }
 
+func (it *memDBIterator) Seek(point []byte) bool {
+       for i, key := range it.keys {
+               if key >= string(point) {
+                       it.last = i
+                       return true
+               }
+       }
+       return false
+}
+
 func (it *memDBIterator) Release() {
        it.db = nil
        it.keys = nil
similarity index 99%
rename from database/leveldb/store.go
rename to database/store.go
index 3f763ba..7e7031b 100644 (file)
@@ -1,4 +1,4 @@
-package leveldb
+package database
 
 import (
        "encoding/binary"
@@ -8,7 +8,6 @@ import (
        "github.com/golang/protobuf/proto"
        log "github.com/sirupsen/logrus"
        "github.com/tendermint/tmlibs/common"
-       dbm "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/database/storage"
        "github.com/bytom/errors"
@@ -16,6 +15,7 @@ import (
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/state"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const logModule = "leveldb"
similarity index 98%
rename from database/leveldb/store_test.go
rename to database/store_test.go
index 668c84c..f0da5ba 100644 (file)
@@ -1,11 +1,9 @@
-package leveldb
+package database
 
 import (
        "os"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/config"
        "github.com/bytom/database/storage"
        "github.com/bytom/protocol"
@@ -13,6 +11,7 @@ import (
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/state"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestLoadBlockIndex(t *testing.T) {
similarity index 96%
rename from database/leveldb/utxo_view.go
rename to database/utxo_view.go
index 2a56613..032a2f8 100644 (file)
@@ -1,13 +1,12 @@
-package leveldb
+package database
 
 import (
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/database/storage"
        "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/state"
        "github.com/golang/protobuf/proto"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const utxoPreFix = "UT:"
similarity index 98%
rename from database/leveldb/utxo_view_test.go
rename to database/utxo_view_test.go
index 8e45606..fa613de 100644 (file)
@@ -1,15 +1,14 @@
-package leveldb
+package database
 
 import (
        "os"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/database/storage"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/state"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestSaveUtxoView(t *testing.T) {
index fc07a04..c6ba995 100644 (file)
@@ -6,10 +6,9 @@ import (
        "strings"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/accesstoken"
        "github.com/bytom/errors"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestAuthenticate(t *testing.T) {
index 332a0f6..fd319f9 100644 (file)
@@ -12,7 +12,6 @@ import (
        "github.com/prometheus/prometheus/util/flock"
        log "github.com/sirupsen/logrus"
        cmn "github.com/tendermint/tmlibs/common"
-       dbm "github.com/tendermint/tmlibs/db"
        browser "github.com/toqueteos/webbrowser"
 
        "github.com/bytom/accesstoken"
@@ -23,7 +22,6 @@ import (
        "github.com/bytom/blockchain/txfeed"
        cfg "github.com/bytom/config"
        "github.com/bytom/consensus"
-       "github.com/bytom/database/leveldb"
        "github.com/bytom/env"
        "github.com/bytom/event"
        "github.com/bytom/mining/cpuminer"
@@ -34,6 +32,8 @@ import (
        "github.com/bytom/p2p"
        "github.com/bytom/protocol"
        w "github.com/bytom/wallet"
+       dbm "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
 )
 
 const (
@@ -75,7 +75,7 @@ func NewNode(config *cfg.Config) *Node {
                cmn.Exit(cmn.Fmt("Param db_backend [%v] is invalid, use leveldb or memdb", config.DBBackend))
        }
        coreDB := dbm.NewDB("core", config.DBBackend, config.DBDir())
-       store := leveldb.NewStore(coreDB)
+       store := database.NewStore(coreDB)
 
        tokenDB := dbm.NewDB("accesstoken", config.DBBackend, config.DBDir())
        accessTokens := accesstoken.NewStore(tokenDB)
index 3f4168c..9d33d1c 100644 (file)
@@ -7,21 +7,17 @@ import (
        "bytes"
        "crypto/rand"
        "encoding/binary"
-       "fmt"
        "os"
+       "path"
        "sync"
        "time"
 
        log "github.com/sirupsen/logrus"
-       "github.com/syndtr/goleveldb/leveldb"
-       "github.com/syndtr/goleveldb/leveldb/errors"
-       "github.com/syndtr/goleveldb/leveldb/iterator"
-       "github.com/syndtr/goleveldb/leveldb/opt"
-       "github.com/syndtr/goleveldb/leveldb/storage"
-       "github.com/syndtr/goleveldb/leveldb/util"
-       "github.com/tendermint/go-wire"
+       wire "github.com/tendermint/go-wire"
 
        "github.com/bytom/crypto"
+       dbm "github.com/bytom/database/leveldb"
+       "github.com/bytom/errors"
 )
 
 var (
@@ -32,7 +28,7 @@ var (
 
 // nodeDB stores all nodes we know about.
 type nodeDB struct {
-       lvl    *leveldb.DB   // Interface to the database itself
+       lvl    dbm.DB        // Interface to the database itself
        self   NodeID        // Own node id to prevent adding it into the database
        runner sync.Once     // Ensures we can start at most one expirer
        quit   chan struct{} // Channel to signal the expiring thread to stop
@@ -55,64 +51,47 @@ var (
 // database is constructed.
 func newNodeDB(path string, version int, self NodeID) (*nodeDB, error) {
        if path == "" {
-               return newMemoryNodeDB(self)
+               return newMemoryNodeDB(self), nil
        }
        return newPersistentNodeDB(path, version, self)
 }
 
 // newMemoryNodeDB creates a new in-memory node database without a persistent
 // backend.
-func newMemoryNodeDB(self NodeID) (*nodeDB, error) {
-       db, err := leveldb.Open(storage.NewMemStorage(), nil)
-       if err != nil {
-               return nil, err
-       }
+func newMemoryNodeDB(self NodeID) *nodeDB {
+       db := dbm.NewMemDB()
        return &nodeDB{
                lvl:  db,
                self: self,
                quit: make(chan struct{}),
-       }, nil
+       }
 }
 
 // newPersistentNodeDB creates/opens a leveldb backed persistent node database,
 // also flushing its contents in case of a version mismatch.
-func newPersistentNodeDB(path string, version int, self NodeID) (*nodeDB, error) {
-       opts := &opt.Options{OpenFilesCacheCapacity: 5}
-       db, err := leveldb.OpenFile(path, opts)
-       if _, iscorrupted := err.(*errors.ErrCorrupted); iscorrupted {
-               db, err = leveldb.RecoverFile(path, nil)
-       }
-       if err != nil {
-               return nil, err
+func newPersistentNodeDB(filePath string, version int, self NodeID) (*nodeDB, error) {
+       dir, file := path.Split(filePath)
+       if file == "" {
+               return nil, errors.New("unspecified db file name")
        }
+       db := dbm.NewDB(file, dbm.GoLevelDBBackendStr, dir)
+
        // The nodes contained in the cache correspond to a certain protocol version.
        // Flush all nodes if the version doesn't match.
        currentVer := make([]byte, binary.MaxVarintLen64)
        currentVer = currentVer[:binary.PutVarint(currentVer, int64(version))]
 
-       blob, err := db.Get(nodeDBVersionKey, nil)
-       switch err {
-       case leveldb.ErrNotFound:
-               // Version not found (i.e. empty cache), insert it
-               if err = db.Put(nodeDBVersionKey, currentVer, nil); err != nil {
-                       if err := db.Close(); err != nil {
-                               log.WithFields(log.Fields{"module": logModule, "error": err}).Warn(fmt.Sprintf("db close err"))
-                       }
+       blob := db.Get(nodeDBVersionKey)
+       if blob == nil {
+               db.Set(nodeDBVersionKey, currentVer)
+       } else if !bytes.Equal(blob, currentVer) {
+               db.Close()
+               if err := os.RemoveAll(filePath + ".db"); err != nil {
                        return nil, err
                }
-
-       case nil:
-               // Version present, flush if different
-               if !bytes.Equal(blob, currentVer) {
-                       if err = db.Close(); err != nil {
-                               log.WithFields(log.Fields{"module": logModule, "error": err}).Warn(fmt.Sprintf("db close err"))
-                       }
-                       if err = os.RemoveAll(path); err != nil {
-                               return nil, err
-                       }
-                       return newPersistentNodeDB(path, version, self)
-               }
+               return newPersistentNodeDB(filePath, version, self)
        }
+
        return &nodeDB{
                lvl:  db,
                self: self,
@@ -146,8 +125,8 @@ func splitKey(key []byte) (id NodeID, field string) {
 // fetchInt64 retrieves an integer instance associated with a particular
 // database key.
 func (db *nodeDB) fetchInt64(key []byte) int64 {
-       blob, err := db.lvl.Get(key, nil)
-       if err != nil {
+       blob := db.lvl.Get(key)
+       if blob == nil {
                return 0
        }
        val, read := binary.Varint(blob)
@@ -159,10 +138,10 @@ func (db *nodeDB) fetchInt64(key []byte) int64 {
 
 // storeInt64 update a specific database entry to the current time instance as a
 // unix timestamp.
-func (db *nodeDB) storeInt64(key []byte, n int64) error {
+func (db *nodeDB) storeInt64(key []byte, n int64) {
        blob := make([]byte, binary.MaxVarintLen64)
        blob = blob[:binary.PutVarint(blob, n)]
-       return db.lvl.Put(key, blob, nil)
+       db.lvl.Set(key, blob)
 }
 
 // node retrieves a node with a given id from the database.
@@ -173,12 +152,9 @@ func (db *nodeDB) node(id NodeID) *Node {
        )
 
        key := makeKey(id, nodeDBDiscoverRoot)
-       rawData, err := db.lvl.Get(key, nil)
-       if err != nil {
-               log.WithFields(log.Fields{"module": logModule, "error": err}).Warn(fmt.Sprintf("get node rawdata err"))
-               return nil
-       }
+       rawData := db.lvl.Get(key)
 
+       var err error
        wire.ReadBinary(node, bytes.NewReader(rawData), 0, &n, &err)
        if err != nil {
                log.WithFields(log.Fields{"module": logModule, "key": key, "node": node, "error": err}).Warn("get node from db err")
@@ -202,18 +178,16 @@ func (db *nodeDB) updateNode(node *Node) error {
                return err
        }
 
-       return db.lvl.Put(makeKey(node.ID, nodeDBDiscoverRoot), blob.Bytes(), nil)
+       db.lvl.Set(makeKey(node.ID, nodeDBDiscoverRoot), blob.Bytes())
+       return nil
 }
 
 // deleteNode deletes all information/keys associated with a node.
-func (db *nodeDB) deleteNode(id NodeID) error {
-       deleter := db.lvl.NewIterator(util.BytesPrefix(makeKey(id, "")), nil)
+func (db *nodeDB) deleteNode(id NodeID) {
+       deleter := db.lvl.IteratorPrefix(makeKey(id, ""))
        for deleter.Next() {
-               if err := db.lvl.Delete(deleter.Key(), nil); err != nil {
-                       return err
-               }
+               db.lvl.Delete(deleter.Key())
        }
-       return nil
 }
 
 // ensureExpirer is a small helper method ensuring that the data expiration
@@ -252,7 +226,7 @@ func (db *nodeDB) expireNodes() error {
        threshold := time.Now().Add(-nodeDBNodeExpiration)
 
        // Find discovered nodes that are older than the allowance
-       it := db.lvl.NewIterator(nil, nil)
+       it := db.lvl.Iterator()
        defer it.Release()
 
        for it.Next() {
@@ -268,9 +242,7 @@ func (db *nodeDB) expireNodes() error {
                        }
                }
                // Otherwise delete all associated information
-               if err := db.deleteNode(id); err != nil {
-                       return err
-               }
+               db.deleteNode(id)
        }
 
        return nil
@@ -283,8 +255,8 @@ func (db *nodeDB) lastPing(id NodeID) time.Time {
 }
 
 // updateLastPing updates the last time we tried contacting a remote node.
-func (db *nodeDB) updateLastPing(id NodeID, instance time.Time) error {
-       return db.storeInt64(makeKey(id, nodeDBDiscoverPing), instance.Unix())
+func (db *nodeDB) updateLastPing(id NodeID, instance time.Time) {
+       db.storeInt64(makeKey(id, nodeDBDiscoverPing), instance.Unix())
 }
 
 // lastPong retrieves the time of the last successful contact from remote node.
@@ -293,8 +265,8 @@ func (db *nodeDB) lastPong(id NodeID) time.Time {
 }
 
 // updateLastPong updates the last time a remote node successfully contacted.
-func (db *nodeDB) updateLastPong(id NodeID, instance time.Time) error {
-       return db.storeInt64(makeKey(id, nodeDBDiscoverPong), instance.Unix())
+func (db *nodeDB) updateLastPong(id NodeID, instance time.Time) {
+       db.storeInt64(makeKey(id, nodeDBDiscoverPong), instance.Unix())
 }
 
 // findFails retrieves the number of findnode failures since bonding.
@@ -303,8 +275,8 @@ func (db *nodeDB) findFails(id NodeID) int {
 }
 
 // updateFindFails updates the number of findnode failures since bonding.
-func (db *nodeDB) updateFindFails(id NodeID, fails int) error {
-       return db.storeInt64(makeKey(id, nodeDBDiscoverFindFails), int64(fails))
+func (db *nodeDB) updateFindFails(id NodeID, fails int) {
+       db.storeInt64(makeKey(id, nodeDBDiscoverFindFails), int64(fails))
 }
 
 // querySeeds retrieves random nodes to be used as potential seed nodes
@@ -313,7 +285,7 @@ func (db *nodeDB) querySeeds(n int, maxAge time.Duration) []*Node {
        var (
                now   = time.Now()
                nodes = make([]*Node, 0, n)
-               it    = db.lvl.NewIterator(nil, nil)
+               it    = db.lvl.Iterator()
                id    NodeID
        )
        defer it.Release()
@@ -353,10 +325,7 @@ seek:
 
 func (db *nodeDB) fetchTopicRegTickets(id NodeID) (issued, used uint32) {
        key := makeKey(id, nodeDBTopicRegTickets)
-       blob, err := db.lvl.Get(key, nil)
-       if err != nil {
-               log.WithFields(log.Fields{"module": logModule, "error": err}).Warn("db get raw data")
-       }
+       blob := db.lvl.Get(key)
 
        if len(blob) != 8 {
                return 0, 0
@@ -366,17 +335,17 @@ func (db *nodeDB) fetchTopicRegTickets(id NodeID) (issued, used uint32) {
        return
 }
 
-func (db *nodeDB) updateTopicRegTickets(id NodeID, issued, used uint32) error {
+func (db *nodeDB) updateTopicRegTickets(id NodeID, issued, used uint32) {
        key := makeKey(id, nodeDBTopicRegTickets)
        blob := make([]byte, 8)
        binary.BigEndian.PutUint32(blob[0:4], issued)
        binary.BigEndian.PutUint32(blob[4:8], used)
-       return db.lvl.Put(key, blob, nil)
+       db.lvl.Set(key, blob)
 }
 
 // reads the next node record from the iterator, skipping over other
 // database entries.
-func nextNode(it iterator.Iterator) *Node {
+func nextNode(it dbm.Iterator) *Node {
        var (
                n    = int(0)
                err  = error(nil)
@@ -403,7 +372,5 @@ func nextNode(it iterator.Iterator) *Node {
 // close flushes and closes the database files.
 func (db *nodeDB) close() {
        close(db.quit)
-       if err := db.lvl.Close(); err != nil {
-               log.WithFields(log.Fields{"module": logModule, "error": err}).Warn("db close err")
-       }
+       db.lvl.Close()
 }
index e20fb51..b98bc1c 100644 (file)
@@ -65,9 +65,8 @@ func TestNodeDBInt64(t *testing.T) {
        tests := nodeDBInt64Tests
        for i := 0; i < len(tests); i++ {
                // Insert the next value
-               if err := db.storeInt64(tests[i].key, tests[i].value); err != nil {
-                       t.Errorf("test %d: failed to store value: %v", i, err)
-               }
+               db.storeInt64(tests[i].key, tests[i].value)
+
                // Check all existing and non existing values
                for j := 0; j < len(tests); j++ {
                        num := db.fetchInt64(tests[j].key)
@@ -98,9 +97,8 @@ func TestNodeDBFetchStore(t *testing.T) {
        if stored := db.lastPing(node.ID); stored.Unix() != 0 {
                t.Errorf("ping: non-existing object: %v", stored)
        }
-       if err := db.updateLastPing(node.ID, inst); err != nil {
-               t.Errorf("ping: failed to update: %v", err)
-       }
+       db.updateLastPing(node.ID, inst)
+
        if stored := db.lastPing(node.ID); stored.Unix() != inst.Unix() {
                t.Errorf("ping: value mismatch: have %v, want %v", stored, inst)
        }
@@ -108,9 +106,8 @@ func TestNodeDBFetchStore(t *testing.T) {
        if stored := db.lastPong(node.ID); stored.Unix() != 0 {
                t.Errorf("pong: non-existing object: %v", stored)
        }
-       if err := db.updateLastPong(node.ID, inst); err != nil {
-               t.Errorf("pong: failed to update: %v", err)
-       }
+       db.updateLastPong(node.ID, inst)
+
        if stored := db.lastPong(node.ID); stored.Unix() != inst.Unix() {
                t.Errorf("pong: value mismatch: have %v, want %v", stored, inst)
        }
@@ -118,9 +115,8 @@ func TestNodeDBFetchStore(t *testing.T) {
        if stored := db.findFails(node.ID); stored != 0 {
                t.Errorf("find-node fails: non-existing object: %v", stored)
        }
-       if err := db.updateFindFails(node.ID, num); err != nil {
-               t.Errorf("find-node fails: failed to update: %v", err)
-       }
+       db.updateFindFails(node.ID, num)
+
        if stored := db.findFails(node.ID); stored != num {
                t.Errorf("find-node fails: value mismatch: have %v, want %v", stored, num)
        }
@@ -204,9 +200,7 @@ func TestNodeDBSeedQuery(t *testing.T) {
                if err := db.updateNode(seed.node); err != nil {
                        t.Fatalf("node %d: failed to insert: %v", i, err)
                }
-               if err := db.updateLastPong(seed.node.ID, seed.pong); err != nil {
-                       t.Fatalf("node %d: failed to insert lastPong: %v", i, err)
-               }
+               db.updateLastPong(seed.node.ID, seed.pong)
        }
 
        // Retrieve the entire batch and check for duplicates
@@ -243,9 +237,7 @@ func TestNodeDBPersistency(t *testing.T) {
        if err != nil {
                t.Fatalf("failed to create persistent database: %v", err)
        }
-       if err = db.storeInt64(testKey, testInt); err != nil {
-               t.Fatalf("failed to store value: %v.", err)
-       }
+       db.storeInt64(testKey, testInt)
        db.close()
 
        // Reopen the database and check the value
@@ -304,9 +296,7 @@ func TestNodeDBExpiration(t *testing.T) {
                if err := db.updateNode(seed.node); err != nil {
                        t.Fatalf("node %d: failed to insert: %v", i, err)
                }
-               if err := db.updateLastPong(seed.node.ID, seed.pong); err != nil {
-                       t.Fatalf("node %d: failed to update pong: %v", i, err)
-               }
+               db.updateLastPong(seed.node.ID, seed.pong)
        }
        // Expire some of them, and check the rest
        if err := db.expireNodes(); err != nil {
@@ -337,9 +327,7 @@ func TestNodeDBSelfExpiration(t *testing.T) {
                if err := db.updateNode(seed.node); err != nil {
                        t.Fatalf("node %d: failed to insert: %v", i, err)
                }
-               if err := db.updateLastPong(seed.node.ID, seed.pong); err != nil {
-                       t.Fatalf("node %d: failed to update pong: %v", i, err)
-               }
+               db.updateLastPong(seed.node.ID, seed.pong)
        }
        // Expire the nodes and make sure self has been evacuated too
        if err := db.expireNodes(); err != nil {
@@ -381,9 +369,7 @@ func TestTopicRegTicketsUpdate(t *testing.T) {
        }
 
        for _, v := range topicRegTicketsTests {
-               if err := db.updateTopicRegTickets(v.id, v.issued, v.used); err != nil {
-                       t.Fatalf("failed to update topic reg ticktes: %v", err)
-               }
+               db.updateTopicRegTickets(v.id, v.issued, v.used)
 
                issued, used := db.fetchTopicRegTickets(v.id)
                if issued != v.issued {
index 7666913..825cded 100644 (file)
@@ -995,9 +995,7 @@ func init() {
                name:     "unresponsive",
                canQuery: true,
                handle: func(net *Network, n *Node, ev nodeEvent, pkt *ingressPacket) (*nodeState, error) {
-                       if err := net.db.deleteNode(n.ID); err != nil {
-                               return known, err
-                       }
+                       net.db.deleteNode(n.ID)
 
                        switch ev {
                        case pingPacket:
@@ -1130,9 +1128,7 @@ func (net *Network) handleKnownPong(n *Node, pkt *ingressPacket) error {
        }
        n.pingEcho = nil
        n.pingTopics = nil
-       if err = net.db.updateLastPong(n.ID, time.Now()); err != nil {
-               return err
-       }
+       net.db.updateLastPong(n.ID, time.Now())
        return err
 }
 
index 000e66f..c0372d7 100644 (file)
@@ -273,7 +273,7 @@ func NewDiscover(config *cfg.Config, priv ed25519.PrivateKey, port uint16) (*Net
        }
 
        realaddr := conn.LocalAddr().(*net.UDPAddr)
-       ntab, err := ListenUDP(priv, conn, realaddr, path.Join(config.DBDir(), "discover.db"), nil)
+       ntab, err := ListenUDP(priv, conn, realaddr, path.Join(config.DBDir(), "discover"), nil)
        if err != nil {
                return nil, err
        }
index 4cc1d3f..e501d30 100644 (file)
@@ -11,7 +11,6 @@ import (
        log "github.com/sirupsen/logrus"
        "github.com/tendermint/go-crypto"
        cmn "github.com/tendermint/tmlibs/common"
-       dbm "github.com/tendermint/tmlibs/db"
 
        cfg "github.com/bytom/config"
        "github.com/bytom/consensus"
@@ -22,6 +21,7 @@ import (
        "github.com/bytom/p2p/netutil"
        "github.com/bytom/p2p/trust"
        "github.com/bytom/version"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const (
index 642a52e..da0db19 100644 (file)
@@ -2,7 +2,6 @@ package p2p
 
 import (
        "github.com/tendermint/go-crypto"
-       dbm "github.com/tendermint/tmlibs/db"
        "io/ioutil"
        "os"
        "sync"
@@ -11,6 +10,7 @@ import (
        cfg "github.com/bytom/config"
        "github.com/bytom/errors"
        conn "github.com/bytom/p2p/connection"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 var (
index 1812843..b8d4cac 100644 (file)
@@ -6,12 +6,12 @@ import (
        log "github.com/sirupsen/logrus"
        "github.com/tendermint/go-crypto"
        cmn "github.com/tendermint/tmlibs/common"
-       dbm "github.com/tendermint/tmlibs/db"
 
        cfg "github.com/bytom/config"
        "github.com/bytom/errors"
        "github.com/bytom/p2p/connection"
        "github.com/bytom/p2p/discover"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 //PanicOnAddPeerErr add peer error
index 307e624..b317f89 100644 (file)
@@ -7,8 +7,6 @@ import (
        "testing"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/blockchain/pseudohsm"
        "github.com/bytom/blockchain/signers"
@@ -16,7 +14,7 @@ import (
        "github.com/bytom/consensus"
        "github.com/bytom/consensus/difficulty"
        "github.com/bytom/crypto/ed25519/chainkd"
-       "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
        "github.com/bytom/database/storage"
        "github.com/bytom/event"
        "github.com/bytom/mining"
@@ -24,6 +22,7 @@ import (
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/state"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func BenchmarkChain_CoinBaseTx_NoAsset(b *testing.B) {
@@ -139,7 +138,7 @@ func GenerateChainData(dirPath string, testDB dbm.DB, txNumber, otherAssetNum in
                return nil, nil, nil, err
        }
 
-       store := leveldb.NewStore(testDB)
+       store := database.NewStore(testDB)
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)
        chain, err := protocol.NewChain(store, txPool)
@@ -381,7 +380,7 @@ func CreateTxbyNum(txNumber, otherAssetNum int) ([]*types.Tx, error) {
 
 func SetUtxoView(db dbm.DB, view *state.UtxoViewpoint) error {
        batch := db.NewBatch()
-       if err := leveldb.SaveUtxoView(batch, view); err != nil {
+       if err := database.SaveUtxoView(batch, view); err != nil {
                return err
        }
        batch.Write()
index 547c34b..8b703f0 100644 (file)
@@ -7,12 +7,11 @@ import (
        "testing"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/consensus"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestBlockHeader(t *testing.T) {
index 67a6971..9e84d20 100644 (file)
@@ -5,17 +5,16 @@ import (
        "os"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/blockchain/txbuilder"
        "github.com/bytom/consensus"
-       "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
        "github.com/bytom/database/storage"
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm"
        "github.com/golang/protobuf/proto"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const utxoPrefix = "UT:"
@@ -23,7 +22,7 @@ const utxoPrefix = "UT:"
 type chainTestContext struct {
        Chain *protocol.Chain
        DB    dbm.DB
-       Store *leveldb.Store
+       Store *database.Store
 }
 
 func (ctx *chainTestContext) validateStatus(block *types.Block) error {
index eda5a11..6db31b6 100644 (file)
@@ -6,8 +6,6 @@ import (
        "os"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/blockchain/pseudohsm"
        "github.com/bytom/blockchain/signers"
@@ -15,6 +13,7 @@ import (
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/validation"
        "github.com/bytom/test"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestP2PKH(t *testing.T) {
index 25364c5..6128f88 100644 (file)
@@ -4,11 +4,10 @@ import (
        "os"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/mining"
        "github.com/bytom/test"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 // Function NewBlockTemplate's benchmark - 0.05s
index 1bc4a86..4fa1a15 100644 (file)
@@ -6,11 +6,10 @@ import (
        "os"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/consensus"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 // case1:           |------c1(height=7)
index 43c3453..3dd6ff3 100644 (file)
@@ -3,10 +3,9 @@ package test
 import (
        "fmt"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc/types"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func declChain(name string, baseChain *protocol.Chain, baseHeight uint64, height uint64) (*protocol.Chain, error) {
index 55cfaab..d951964 100644 (file)
@@ -10,7 +10,6 @@ import (
        "testing"
 
        log "github.com/sirupsen/logrus"
-       dbm "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/account"
        "github.com/bytom/asset"
@@ -20,6 +19,7 @@ import (
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/validation"
        "github.com/bytom/protocol/vm"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func init() {
index 6bf9aa6..4387eba 100644 (file)
@@ -6,8 +6,6 @@ import (
        "fmt"
        "time"
 
-       "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/asset"
        "github.com/bytom/blockchain/pseudohsm"
@@ -22,6 +20,7 @@ import (
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm"
        "github.com/bytom/protocol/vm/vmutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 // TxGenerator used to generate new tx
@@ -293,7 +292,7 @@ func CreateSpendInput(tx *types.Tx, outputIndex uint64) (*types.SpendInput, erro
 }
 
 // SignInstructionFor read CtrlProgram from db, construct SignInstruction for SpendInput
-func SignInstructionFor(input *types.SpendInput, db db.DB, signer *signers.Signer) (*txbuilder.SigningInstruction, error) {
+func SignInstructionFor(input *types.SpendInput, db dbm.DB, signer *signers.Signer) (*txbuilder.SigningInstruction, error) {
        cp := account.CtrlProgram{}
        var hash [32]byte
        sha3pool.Sum256(hash[:], input.ControlProgram)
index e062dc8..5ad897a 100644 (file)
@@ -4,19 +4,18 @@ import (
        "context"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/blockchain/pseudohsm"
        "github.com/bytom/blockchain/txbuilder"
        "github.com/bytom/consensus"
        "github.com/bytom/crypto/ed25519/chainkd"
-       "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
        "github.com/bytom/event"
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const (
@@ -25,8 +24,8 @@ const (
 )
 
 // MockChain mock chain with genesis block
-func MockChain(testDB dbm.DB) (*protocol.Chain, *leveldb.Store, *protocol.TxPool, error) {
-       store := leveldb.NewStore(testDB)
+func MockChain(testDB dbm.DB) (*protocol.Chain, *database.Store, *protocol.TxPool, error) {
+       store := database.NewStore(testDB)
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)
        chain, err := protocol.NewChain(store, txPool)
index 9442d72..6898221 100644 (file)
@@ -7,13 +7,13 @@ import (
        "github.com/bytom/testutil"
 
        "github.com/golang/protobuf/proto"
-       dbm "github.com/tendermint/tmlibs/db"
 
-       "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
        "github.com/bytom/database/storage"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/state"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestAttachOrDetachBlocks(t *testing.T) {
@@ -408,7 +408,7 @@ func TestAttachOrDetachBlocks(t *testing.T) {
        defer os.RemoveAll("temp")
        for index, c := range cases {
                testDB := dbm.NewDB("testdb", "leveldb", "temp")
-               store := leveldb.NewStore(testDB)
+               store := database.NewStore(testDB)
 
                utxoViewpoint := state.NewUtxoViewpoint()
                for k, v := range c.before {
index 6d486a3..abca135 100644 (file)
@@ -7,8 +7,6 @@ import (
        "path"
        "reflect"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/asset"
        "github.com/bytom/blockchain/pseudohsm"
@@ -18,6 +16,7 @@ import (
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc/types"
        w "github.com/bytom/wallet"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 type walletTestConfig struct {
diff --git a/vendor/github.com/tendermint/tmlibs/db/c_level_db.go b/vendor/github.com/tendermint/tmlibs/db/c_level_db.go
deleted file mode 100644 (file)
index b1ae49a..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-// +build gcc
-
-package db
-
-import (
-       "fmt"
-       "path"
-
-       "github.com/jmhodges/levigo"
-
-       . "github.com/tendermint/tmlibs/common"
-)
-
-func init() {
-       dbCreator := func(name string, dir string) (DB, error) {
-               return NewCLevelDB(name, dir)
-       }
-       registerDBCreator(LevelDBBackendStr, dbCreator, true)
-       registerDBCreator(CLevelDBBackendStr, dbCreator, false)
-}
-
-type CLevelDB struct {
-       db     *levigo.DB
-       ro     *levigo.ReadOptions
-       wo     *levigo.WriteOptions
-       woSync *levigo.WriteOptions
-}
-
-func NewCLevelDB(name string, dir string) (*CLevelDB, error) {
-       dbPath := path.Join(dir, name+".db")
-
-       opts := levigo.NewOptions()
-       opts.SetCache(levigo.NewLRUCache(1 << 30))
-       opts.SetCreateIfMissing(true)
-       db, err := levigo.Open(dbPath, opts)
-       if err != nil {
-               return nil, err
-       }
-       ro := levigo.NewReadOptions()
-       wo := levigo.NewWriteOptions()
-       woSync := levigo.NewWriteOptions()
-       woSync.SetSync(true)
-       database := &CLevelDB{
-               db:     db,
-               ro:     ro,
-               wo:     wo,
-               woSync: woSync,
-       }
-       return database, nil
-}
-
-func (db *CLevelDB) Get(key []byte) []byte {
-       res, err := db.db.Get(db.ro, key)
-       if err != nil {
-               PanicCrisis(err)
-       }
-       return res
-}
-
-func (db *CLevelDB) Set(key []byte, value []byte) {
-       err := db.db.Put(db.wo, key, value)
-       if err != nil {
-               PanicCrisis(err)
-       }
-}
-
-func (db *CLevelDB) SetSync(key []byte, value []byte) {
-       err := db.db.Put(db.woSync, key, value)
-       if err != nil {
-               PanicCrisis(err)
-       }
-}
-
-func (db *CLevelDB) Delete(key []byte) {
-       err := db.db.Delete(db.wo, key)
-       if err != nil {
-               PanicCrisis(err)
-       }
-}
-
-func (db *CLevelDB) DeleteSync(key []byte) {
-       err := db.db.Delete(db.woSync, key)
-       if err != nil {
-               PanicCrisis(err)
-       }
-}
-
-func (db *CLevelDB) DB() *levigo.DB {
-       return db.db
-}
-
-func (db *CLevelDB) Close() {
-       db.db.Close()
-       db.ro.Close()
-       db.wo.Close()
-       db.woSync.Close()
-}
-
-func (db *CLevelDB) Print() {
-       iter := db.db.NewIterator(db.ro)
-       defer iter.Close()
-       for iter.Seek(nil); iter.Valid(); iter.Next() {
-               key := iter.Key()
-               value := iter.Value()
-               fmt.Printf("[%X]:\t[%X]\n", key, value)
-       }
-}
-
-func (db *CLevelDB) Stats() map[string]string {
-       // TODO: Find the available properties for the C LevelDB implementation
-       keys := []string{}
-
-       stats := make(map[string]string)
-       for _, key := range keys {
-               str, err := db.db.GetProperty(key)
-               if err == nil {
-                       stats[key] = str
-               }
-       }
-       return stats
-}
-
-func (db *CLevelDB) Iterator() Iterator {
-       return db.db.NewIterator(nil, nil)
-}
-
-func (db *CLevelDB) NewBatch() Batch {
-       batch := levigo.NewWriteBatch()
-       return &cLevelDBBatch{db, batch}
-}
-
-//--------------------------------------------------------------------------------
-
-type cLevelDBBatch struct {
-       db    *CLevelDB
-       batch *levigo.WriteBatch
-}
-
-func (mBatch *cLevelDBBatch) Set(key, value []byte) {
-       mBatch.batch.Put(key, value)
-}
-
-func (mBatch *cLevelDBBatch) Delete(key []byte) {
-       mBatch.batch.Delete(key)
-}
-
-func (mBatch *cLevelDBBatch) Write() {
-       err := mBatch.db.db.Write(mBatch.db.wo, mBatch.batch)
-       if err != nil {
-               PanicCrisis(err)
-       }
-}
diff --git a/vendor/github.com/tendermint/tmlibs/db/c_level_db_test.go b/vendor/github.com/tendermint/tmlibs/db/c_level_db_test.go
deleted file mode 100644 (file)
index e7336cc..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-// +build gcc
-
-package db
-
-import (
-       "bytes"
-       "fmt"
-       "testing"
-
-       . "github.com/tendermint/tmlibs/common"
-)
-
-func BenchmarkRandomReadsWrites2(b *testing.B) {
-       b.StopTimer()
-
-       numItems := int64(1000000)
-       internal := map[int64]int64{}
-       for i := 0; i < int(numItems); i++ {
-               internal[int64(i)] = int64(0)
-       }
-       db, err := NewCLevelDB(Fmt("test_%x", RandStr(12)), "")
-       if err != nil {
-               b.Fatal(err.Error())
-               return
-       }
-
-       fmt.Println("ok, starting")
-       b.StartTimer()
-
-       for i := 0; i < b.N; i++ {
-               // Write something
-               {
-                       idx := (int64(RandInt()) % numItems)
-                       internal[idx] += 1
-                       val := internal[idx]
-                       idxBytes := int642Bytes(int64(idx))
-                       valBytes := int642Bytes(int64(val))
-                       //fmt.Printf("Set %X -> %X\n", idxBytes, valBytes)
-                       db.Set(
-                               idxBytes,
-                               valBytes,
-                       )
-               }
-               // Read something
-               {
-                       idx := (int64(RandInt()) % numItems)
-                       val := internal[idx]
-                       idxBytes := int642Bytes(int64(idx))
-                       valBytes := db.Get(idxBytes)
-                       //fmt.Printf("Get %X -> %X\n", idxBytes, valBytes)
-                       if val == 0 {
-                               if !bytes.Equal(valBytes, nil) {
-                                       b.Errorf("Expected %v for %v, got %X",
-                                               nil, idx, valBytes)
-                                       break
-                               }
-                       } else {
-                               if len(valBytes) != 8 {
-                                       b.Errorf("Expected length 8 for %v, got %X",
-                                               idx, valBytes)
-                                       break
-                               }
-                               valGot := bytes2Int64(valBytes)
-                               if val != valGot {
-                                       b.Errorf("Expected %v for %v, got %v",
-                                               val, idx, valGot)
-                                       break
-                               }
-                       }
-               }
-       }
-
-       db.Close()
-}
-
-/*
-func int642Bytes(i int64) []byte {
-       buf := make([]byte, 8)
-       binary.BigEndian.PutUint64(buf, uint64(i))
-       return buf
-}
-
-func bytes2Int64(buf []byte) int64 {
-       return int64(binary.BigEndian.Uint64(buf))
-}
-*/
index 9ac57c6..263cb6b 100644 (file)
@@ -5,7 +5,6 @@ import (
        "fmt"
 
        log "github.com/sirupsen/logrus"
-       "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/account"
        "github.com/bytom/asset"
@@ -18,6 +17,7 @@ import (
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm/vmutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 // annotateTxs adds asset data to transactions
@@ -85,7 +85,7 @@ func (w *Wallet) getAliasDefinition(assetID bc.AssetID) (string, json.RawMessage
 }
 
 // annotateTxs adds account data to transactions
-func annotateTxsAccount(txs []*query.AnnotatedTx, walletDB db.DB) {
+func annotateTxsAccount(txs []*query.AnnotatedTx, walletDB dbm.DB) {
        for i, tx := range txs {
                for j, input := range tx.Inputs {
                        //issue asset tx input SpentOutputID is nil
@@ -110,7 +110,7 @@ func annotateTxsAccount(txs []*query.AnnotatedTx, walletDB db.DB) {
        }
 }
 
-func getAccountFromACP(program []byte, walletDB db.DB) (*account.Account, error) {
+func getAccountFromACP(program []byte, walletDB dbm.DB) (*account.Account, error) {
        var hash common.Hash
        accountCP := account.CtrlProgram{}
        localAccount := account.Account{}
index 459efad..f7907d3 100644 (file)
@@ -6,7 +6,6 @@ import (
        "sort"
 
        log "github.com/sirupsen/logrus"
-       "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/account"
        "github.com/bytom/asset"
@@ -15,6 +14,7 @@ import (
        chainjson "github.com/bytom/encoding/json"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const (
@@ -51,7 +51,7 @@ func calcGlobalTxIndex(blockHash *bc.Hash, position int) []byte {
 }
 
 // deleteTransaction delete transactions when orphan block rollback
-func (w *Wallet) deleteTransactions(batch db.Batch, height uint64) {
+func (w *Wallet) deleteTransactions(batch dbm.Batch, height uint64) {
        tmpTx := query.AnnotatedTx{}
        txIter := w.DB.IteratorPrefix(calcDeleteKey(height))
        defer txIter.Release()
@@ -67,7 +67,7 @@ func (w *Wallet) deleteTransactions(batch db.Batch, height uint64) {
 // saveExternalAssetDefinition save external and local assets definition,
 // when query ,query local first and if have no then query external
 // details see getAliasDefinition
-func saveExternalAssetDefinition(b *types.Block, walletDB db.DB) {
+func saveExternalAssetDefinition(b *types.Block, walletDB dbm.DB) {
        storeBatch := walletDB.NewBatch()
        defer storeBatch.Write()
 
@@ -105,7 +105,7 @@ type TxSummary struct {
 }
 
 // indexTransactions saves all annotated transactions to the database.
-func (w *Wallet) indexTransactions(batch db.Batch, b *types.Block, txStatus *bc.TransactionStatus) error {
+func (w *Wallet) indexTransactions(batch dbm.Batch, b *types.Block, txStatus *bc.TransactionStatus) error {
        annotatedTxs := w.filterAccountTxs(b, txStatus)
        saveExternalAssetDefinition(b, w.DB)
        annotateTxsAccount(annotatedTxs, w.DB)
index 5f56e6f..b3a0590 100644 (file)
@@ -8,8 +8,6 @@ import (
        "sync/atomic"
        "time"
 
-       "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/blockchain/signers"
        "github.com/bytom/crypto/ed25519/chainkd"
@@ -17,6 +15,7 @@ import (
        "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const (
@@ -171,7 +170,7 @@ func (rs *recoveryState) stateForScope(account *account.Account) {
 type recoveryManager struct {
        mu sync.Mutex
 
-       db         db.DB
+       db         dbm.DB
        accountMgr *account.Manager
 
        locked int32
@@ -188,7 +187,7 @@ type recoveryManager struct {
 }
 
 // newRecoveryManager create recovery manger.
-func newRecoveryManager(db db.DB, accountMgr *account.Manager) *recoveryManager {
+func newRecoveryManager(db dbm.DB, accountMgr *account.Manager) *recoveryManager {
        return &recoveryManager{
                db:         db,
                accountMgr: accountMgr,
index 7fe0ae4..dc5d7ea 100644 (file)
@@ -9,8 +9,6 @@ import (
        "testing"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/blockchain/pseudohsm"
        "github.com/bytom/blockchain/signers"
@@ -20,6 +18,7 @@ import (
        "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 // MockBlock mock a block
index f8f8979..445f4f9 100644 (file)
@@ -5,8 +5,6 @@ import (
        "os"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/asset"
        "github.com/bytom/blockchain/pseudohsm"
@@ -17,6 +15,7 @@ import (
        "github.com/bytom/event"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestWalletUnconfirmedTxs(t *testing.T) {
index 6bb8216..de61c05 100644 (file)
@@ -4,7 +4,6 @@ import (
        "encoding/json"
 
        log "github.com/sirupsen/logrus"
-       "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/account"
        "github.com/bytom/consensus"
@@ -13,6 +12,7 @@ import (
        "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 // GetAccountUtxos return all account unspent outputs
@@ -44,7 +44,7 @@ func (w *Wallet) GetAccountUtxos(accountID string, id string, unconfirmed, isSma
        return accountUtxos
 }
 
-func (w *Wallet) attachUtxos(batch db.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
+func (w *Wallet) attachUtxos(batch dbm.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
        for txIndex, tx := range b.Transactions {
                statusFail, err := txStatus.GetStatus(txIndex)
                if err != nil {
@@ -75,7 +75,7 @@ func (w *Wallet) attachUtxos(batch db.Batch, b *types.Block, txStatus *bc.Transa
        }
 }
 
-func (w *Wallet) detachUtxos(batch db.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
+func (w *Wallet) detachUtxos(batch dbm.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
        for txIndex := len(b.Transactions) - 1; txIndex >= 0; txIndex-- {
                tx := b.Transactions[txIndex]
                for j := range tx.Outputs {
@@ -146,7 +146,7 @@ func (w *Wallet) filterAccountUtxo(utxos []*account.UTXO) []*account.UTXO {
        return result
 }
 
-func batchSaveUtxos(utxos []*account.UTXO, batch db.Batch) error {
+func batchSaveUtxos(utxos []*account.UTXO, batch dbm.Batch) error {
        for _, utxo := range utxos {
                data, err := json.Marshal(utxo)
                if err != nil {
index 85157e3..43d36fa 100644 (file)
@@ -8,13 +8,12 @@ import (
        "sort"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/consensus"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/testutil"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestGetAccountUtxos(t *testing.T) {
index 58d7a67..7ee2f34 100644 (file)
@@ -5,7 +5,6 @@ import (
        "sync"
 
        log "github.com/sirupsen/logrus"
-       "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/account"
        "github.com/bytom/asset"
@@ -15,6 +14,7 @@ import (
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 const (
@@ -42,7 +42,7 @@ type StatusInfo struct {
 
 //Wallet is related to storing account unspent outputs
 type Wallet struct {
-       DB              db.DB
+       DB              dbm.DB
        rw              sync.RWMutex
        status          StatusInfo
        AccountMgr      *account.Manager
@@ -57,7 +57,7 @@ type Wallet struct {
 }
 
 //NewWallet return a new wallet instance
-func NewWallet(walletDB db.DB, account *account.Manager, asset *asset.Registry, hsm *pseudohsm.HSM, chain *protocol.Chain, dispatcher *event.Dispatcher) (*Wallet, error) {
+func NewWallet(walletDB dbm.DB, account *account.Manager, asset *asset.Registry, hsm *pseudohsm.HSM, chain *protocol.Chain, dispatcher *event.Dispatcher) (*Wallet, error) {
        w := &Wallet{
                DB:              walletDB,
                AccountMgr:      account,
@@ -153,7 +153,7 @@ func (w *Wallet) loadWalletInfo() error {
        return w.AttachBlock(block)
 }
 
-func (w *Wallet) commitWalletInfo(batch db.Batch) error {
+func (w *Wallet) commitWalletInfo(batch dbm.Batch) error {
        rawWallet, err := json.Marshal(w.status)
        if err != nil {
                log.WithFields(log.Fields{"module": logModule, "err": err}).Error("save wallet info")
index f3e7153..cb2f2ab 100644 (file)
@@ -8,8 +8,6 @@ import (
        "testing"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/bytom/account"
        "github.com/bytom/asset"
        "github.com/bytom/blockchain/pseudohsm"
@@ -18,11 +16,12 @@ import (
        "github.com/bytom/config"
        "github.com/bytom/consensus"
        "github.com/bytom/crypto/ed25519/chainkd"
-       "github.com/bytom/database/leveldb"
+       "github.com/bytom/database"
        "github.com/bytom/event"
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
+       dbm "github.com/bytom/database/leveldb"
 )
 
 func TestWalletVersion(t *testing.T) {
@@ -97,7 +96,7 @@ func TestWalletUpdate(t *testing.T) {
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
        defer os.RemoveAll("temp")
 
-       store := leveldb.NewStore(testDB)
+       store := database.NewStore(testDB)
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)
 
@@ -191,7 +190,7 @@ func TestMemPoolTxQueryLoop(t *testing.T) {
 
        testDB := dbm.NewDB("testdb", "leveldb", dirPath)
 
-       store := leveldb.NewStore(testDB)
+       store := database.NewStore(testDB)
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)