Update database import paths to new location.
This commit is contained in:
parent
8d7780e0ab
commit
309a9ea31d
18 changed files with 81 additions and 80 deletions
|
@ -14,7 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -1456,13 +1456,13 @@ func warnMultipeDBs() {
|
||||||
// such warning the user if there are multiple databases which consume space on
|
// such warning the user if there are multiple databases which consume space on
|
||||||
// the file system and ensuring the regression test database is clean when in
|
// the file system and ensuring the regression test database is clean when in
|
||||||
// regression test mode.
|
// regression test mode.
|
||||||
func setupBlockDB() (btcdb.Db, error) {
|
func setupBlockDB() (database.Db, error) {
|
||||||
// The memdb backend does not have a file path associated with it, so
|
// The memdb backend does not have a file path associated with it, so
|
||||||
// handle it uniquely. We also don't want to worry about the multiple
|
// handle it uniquely. We also don't want to worry about the multiple
|
||||||
// database type warnings when running with the memory database.
|
// database type warnings when running with the memory database.
|
||||||
if cfg.DbType == "memdb" {
|
if cfg.DbType == "memdb" {
|
||||||
btcdLog.Infof("Creating block database in memory.")
|
btcdLog.Infof("Creating block database in memory.")
|
||||||
db, err := btcdb.CreateDB(cfg.DbType)
|
db, err := database.CreateDB(cfg.DbType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1479,11 +1479,11 @@ func setupBlockDB() (btcdb.Db, error) {
|
||||||
removeRegressionDB(dbPath)
|
removeRegressionDB(dbPath)
|
||||||
|
|
||||||
btcdLog.Infof("Loading block database from '%s'", dbPath)
|
btcdLog.Infof("Loading block database from '%s'", dbPath)
|
||||||
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
|
db, err := database.OpenDB(cfg.DbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Return the error if it's not because the database
|
// Return the error if it's not because the database
|
||||||
// doesn't exist.
|
// doesn't exist.
|
||||||
if err != btcdb.ErrDbDoesNotExist {
|
if err != database.ErrDbDoesNotExist {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1492,7 +1492,7 @@ func setupBlockDB() (btcdb.Db, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
db, err = btcdb.CreateDB(cfg.DbType, dbPath)
|
db, err = database.CreateDB(cfg.DbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1502,7 +1502,7 @@ func setupBlockDB() (btcdb.Db, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadBlockDB opens the block database and returns a handle to it.
|
// loadBlockDB opens the block database and returns a handle to it.
|
||||||
func loadBlockDB() (btcdb.Db, error) {
|
func loadBlockDB() (database.Db, error) {
|
||||||
db, err := setupBlockDB()
|
db, err := setupBlockDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
|
"github.com/btcsuite/btcd/database"
|
||||||
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
"github.com/btcsuite/btcd/limits"
|
"github.com/btcsuite/btcd/limits"
|
||||||
"github.com/btcsuite/btcdb"
|
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
|
||||||
"github.com/btcsuite/btclog"
|
"github.com/btcsuite/btclog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// loadBlockDB opens the block database and returns a handle to it.
|
// loadBlockDB opens the block database and returns a handle to it.
|
||||||
func loadBlockDB() (btcdb.Db, error) {
|
func loadBlockDB() (database.Db, error) {
|
||||||
// The database name is based on the database type.
|
// The database name is based on the database type.
|
||||||
dbName := blockDbNamePrefix + "_" + cfg.DbType
|
dbName := blockDbNamePrefix + "_" + cfg.DbType
|
||||||
if cfg.DbType == "sqlite" {
|
if cfg.DbType == "sqlite" {
|
||||||
|
@ -36,11 +36,11 @@ func loadBlockDB() (btcdb.Db, error) {
|
||||||
dbPath := filepath.Join(cfg.DataDir, dbName)
|
dbPath := filepath.Join(cfg.DataDir, dbName)
|
||||||
|
|
||||||
log.Infof("Loading block database from '%s'", dbPath)
|
log.Infof("Loading block database from '%s'", dbPath)
|
||||||
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
|
db, err := database.OpenDB(cfg.DbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Return the error if it's not because the database doesn't
|
// Return the error if it's not because the database doesn't
|
||||||
// exist.
|
// exist.
|
||||||
if err != btcdb.ErrDbDoesNotExist {
|
if err != database.ErrDbDoesNotExist {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func loadBlockDB() (btcdb.Db, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
db, err = btcdb.CreateDB(cfg.DbType, dbPath)
|
db, err = database.CreateDB(cfg.DbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func realMain() error {
|
||||||
backendLogger := btclog.NewDefaultBackendLogger()
|
backendLogger := btclog.NewDefaultBackendLogger()
|
||||||
defer backendLogger.Flush()
|
defer backendLogger.Flush()
|
||||||
log = btclog.NewSubsystemLogger(backendLogger, "")
|
log = btclog.NewSubsystemLogger(backendLogger, "")
|
||||||
btcdb.UseLogger(btclog.NewSubsystemLogger(backendLogger, "BCDB: "))
|
database.UseLogger(btclog.NewSubsystemLogger(backendLogger, "BCDB: "))
|
||||||
btcchain.UseLogger(btclog.NewSubsystemLogger(backendLogger, "CHAN: "))
|
btcchain.UseLogger(btclog.NewSubsystemLogger(backendLogger, "CHAN: "))
|
||||||
|
|
||||||
// Load the block database.
|
// Load the block database.
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -26,7 +26,7 @@ const (
|
||||||
var (
|
var (
|
||||||
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
||||||
defaultDataDir = filepath.Join(btcdHomeDir, "data")
|
defaultDataDir = filepath.Join(btcdHomeDir, "data")
|
||||||
knownDbTypes = btcdb.SupportedDBs()
|
knownDbTypes = database.SupportedDBs()
|
||||||
activeNetParams = &btcnet.MainNetParams
|
activeNetParams = &btcnet.MainNetParams
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ type importResults struct {
|
||||||
// blockImporter houses information about an ongoing import from a block data
|
// blockImporter houses information about an ongoing import from a block data
|
||||||
// file to the block database.
|
// file to the block database.
|
||||||
type blockImporter struct {
|
type blockImporter struct {
|
||||||
db btcdb.Db
|
db database.Db
|
||||||
chain *btcchain.BlockChain
|
chain *btcchain.BlockChain
|
||||||
medianTime btcchain.MedianTimeSource
|
medianTime btcchain.MedianTimeSource
|
||||||
r io.ReadSeeker
|
r io.ReadSeeker
|
||||||
|
@ -299,7 +299,7 @@ func (bi *blockImporter) Import() chan *importResults {
|
||||||
|
|
||||||
// newBlockImporter returns a new importer for the provided file reader seeker
|
// newBlockImporter returns a new importer for the provided file reader seeker
|
||||||
// and database.
|
// and database.
|
||||||
func newBlockImporter(db btcdb.Db, r io.ReadSeeker) *blockImporter {
|
func newBlockImporter(db database.Db, r io.ReadSeeker) *blockImporter {
|
||||||
return &blockImporter{
|
return &blockImporter{
|
||||||
db: db,
|
db: db,
|
||||||
r: r,
|
r: r,
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
"github.com/btcsuite/btclog"
|
"github.com/btcsuite/btclog"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
@ -78,7 +78,7 @@ func main() {
|
||||||
backendLogger := btclog.NewDefaultBackendLogger()
|
backendLogger := btclog.NewDefaultBackendLogger()
|
||||||
defer backendLogger.Flush()
|
defer backendLogger.Flush()
|
||||||
log = btclog.NewSubsystemLogger(backendLogger, "")
|
log = btclog.NewSubsystemLogger(backendLogger, "")
|
||||||
btcdb.UseLogger(log)
|
database.UseLogger(log)
|
||||||
|
|
||||||
// Multiple networks can't be selected simultaneously.
|
// Multiple networks can't be selected simultaneously.
|
||||||
funcName := "main"
|
funcName := "main"
|
||||||
|
@ -115,7 +115,7 @@ func main() {
|
||||||
dbPath := filepath.Join(cfg.DataDir, dbName)
|
dbPath := filepath.Join(cfg.DataDir, dbName)
|
||||||
|
|
||||||
log.Infof("loading db")
|
log.Infof("loading db")
|
||||||
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
|
db, err := database.OpenDB(cfg.DbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("db open failed: %v", err)
|
log.Warnf("db open failed: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -139,7 +139,7 @@ func main() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSha(db btcdb.Db, str string) (btcwire.ShaHash, error) {
|
func getSha(db database.Db, str string) (btcwire.ShaHash, error) {
|
||||||
argtype, idx, sha, err := parsesha(str)
|
argtype, idx, sha, err := parsesha(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("unable to decode [%v] %v", str, err)
|
log.Warnf("unable to decode [%v] %v", str, err)
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -27,7 +27,7 @@ const (
|
||||||
var (
|
var (
|
||||||
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
||||||
defaultDataDir = filepath.Join(btcdHomeDir, "data")
|
defaultDataDir = filepath.Join(btcdHomeDir, "data")
|
||||||
knownDbTypes = btcdb.SupportedDBs()
|
knownDbTypes = database.SupportedDBs()
|
||||||
activeNetParams = &btcnet.MainNetParams
|
activeNetParams = &btcnet.MainNetParams
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
)
|
)
|
||||||
|
@ -23,7 +23,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// loadBlockDB opens the block database and returns a handle to it.
|
// loadBlockDB opens the block database and returns a handle to it.
|
||||||
func loadBlockDB() (btcdb.Db, error) {
|
func loadBlockDB() (database.Db, error) {
|
||||||
// The database name is based on the database type.
|
// The database name is based on the database type.
|
||||||
dbType := cfg.DbType
|
dbType := cfg.DbType
|
||||||
dbName := blockDbNamePrefix + "_" + dbType
|
dbName := blockDbNamePrefix + "_" + dbType
|
||||||
|
@ -32,7 +32,7 @@ func loadBlockDB() (btcdb.Db, error) {
|
||||||
}
|
}
|
||||||
dbPath := filepath.Join(cfg.DataDir, dbName)
|
dbPath := filepath.Join(cfg.DataDir, dbName)
|
||||||
fmt.Printf("Loading block database from '%s'\n", dbPath)
|
fmt.Printf("Loading block database from '%s'\n", dbPath)
|
||||||
db, err := btcdb.OpenDB(dbType, dbPath)
|
db, err := database.OpenDB(dbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func loadBlockDB() (btcdb.Db, error) {
|
||||||
// candidates at the last checkpoint that is already hard coded into btcchain
|
// candidates at the last checkpoint that is already hard coded into btcchain
|
||||||
// since there is no point in finding candidates before already existing
|
// since there is no point in finding candidates before already existing
|
||||||
// checkpoints.
|
// checkpoints.
|
||||||
func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcnet.Checkpoint, error) {
|
func findCandidates(db database.Db, latestHash *btcwire.ShaHash) ([]*btcnet.Checkpoint, error) {
|
||||||
// Start with the latest block of the main chain.
|
// Start with the latest block of the main chain.
|
||||||
block, err := db.FetchBlockBySha(latestHash)
|
block, err := db.FetchBlockBySha(latestHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,8 +13,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
"github.com/btcsuite/btclog"
|
"github.com/btcsuite/btclog"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
@ -89,7 +89,7 @@ func main() {
|
||||||
backendLogger := btclog.NewDefaultBackendLogger()
|
backendLogger := btclog.NewDefaultBackendLogger()
|
||||||
defer backendLogger.Flush()
|
defer backendLogger.Flush()
|
||||||
log = btclog.NewSubsystemLogger(backendLogger, "")
|
log = btclog.NewSubsystemLogger(backendLogger, "")
|
||||||
btcdb.UseLogger(log)
|
database.UseLogger(log)
|
||||||
|
|
||||||
// Multiple networks can't be selected simultaneously.
|
// Multiple networks can't be selected simultaneously.
|
||||||
funcName := "main"
|
funcName := "main"
|
||||||
|
@ -126,7 +126,7 @@ func main() {
|
||||||
dbPath := filepath.Join(cfg.DataDir, dbName)
|
dbPath := filepath.Join(cfg.DataDir, dbName)
|
||||||
|
|
||||||
log.Infof("loading db %v", cfg.DbType)
|
log.Infof("loading db %v", cfg.DbType)
|
||||||
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
|
db, err := database.OpenDB(cfg.DbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("db open failed: %v", err)
|
log.Warnf("db open failed: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -179,7 +179,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHeight(db btcdb.Db, str string) (int64, error) {
|
func getHeight(db database.Db, str string) (int64, error) {
|
||||||
argtype, idx, sha, err := parsesha(str)
|
argtype, idx, sha, err := parsesha(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("unable to decode [%v] %v", str, err)
|
log.Warnf("unable to decode [%v] %v", str, err)
|
||||||
|
@ -201,7 +201,7 @@ func getHeight(db btcdb.Db, str string) (int64, error) {
|
||||||
return idx, nil
|
return idx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DumpBlock(db btcdb.Db, height int64, fo io.Writer, rflag bool, fflag bool, tflag bool) error {
|
func DumpBlock(db database.Db, height int64, fo io.Writer, rflag bool, fflag bool, tflag bool) error {
|
||||||
sha, err := db.FetchBlockShaByHeight(height)
|
sha, err := db.FetchBlockShaByHeight(height)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,9 +16,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
_ "github.com/btcsuite/btcdb/ldb"
|
_ "github.com/btcsuite/btcd/database/ldb"
|
||||||
_ "github.com/btcsuite/btcdb/memdb"
|
_ "github.com/btcsuite/btcd/database/memdb"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
flags "github.com/btcsuite/go-flags"
|
flags "github.com/btcsuite/go-flags"
|
||||||
|
@ -50,7 +50,7 @@ var (
|
||||||
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
||||||
defaultConfigFile = filepath.Join(btcdHomeDir, defaultConfigFilename)
|
defaultConfigFile = filepath.Join(btcdHomeDir, defaultConfigFilename)
|
||||||
defaultDataDir = filepath.Join(btcdHomeDir, defaultDataDirname)
|
defaultDataDir = filepath.Join(btcdHomeDir, defaultDataDirname)
|
||||||
knownDbTypes = btcdb.SupportedDBs()
|
knownDbTypes = database.SupportedDBs()
|
||||||
defaultRPCKeyFile = filepath.Join(btcdHomeDir, "rpc.key")
|
defaultRPCKeyFile = filepath.Join(btcdHomeDir, "rpc.key")
|
||||||
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
|
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
|
||||||
defaultLogDir = filepath.Join(btcdHomeDir, defaultLogDirname)
|
defaultLogDir = filepath.Join(btcdHomeDir, defaultLogDirname)
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/bzip2"
|
"compress/bzip2"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -36,9 +35,8 @@ type testDb struct {
|
||||||
cleanUpFunc func()
|
cleanUpFunc func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUpTestDb(t *testing.T) (*testDb, error) {
|
func setUpTestDb(t *testing.T, dbname string) (*testDb, error) {
|
||||||
// Ignore db remove errors since it means we didn't have an old one.
|
// Ignore db remove errors since it means we didn't have an old one.
|
||||||
dbname := fmt.Sprintf("tstdbop1")
|
|
||||||
dbnamever := dbname + ".ver"
|
dbnamever := dbname + ".ver"
|
||||||
_ = os.RemoveAll(dbname)
|
_ = os.RemoveAll(dbname)
|
||||||
_ = os.RemoveAll(dbnamever)
|
_ = os.RemoveAll(dbnamever)
|
||||||
|
@ -160,7 +158,7 @@ func testAddrIndexOperations(t *testing.T, db database.Db, newestBlock *btcutil.
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
||||||
// Re-Open, tip still should be updated to current height and sha.
|
// Re-Open, tip still should be updated to current height and sha.
|
||||||
db, err = database.OpenDB("leveldb", "tstdbop1")
|
db, err = database.OpenDB("leveldb", "tstdbopmode")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to re-open created db, err %v", err)
|
t.Fatalf("Unable to re-open created db, err %v", err)
|
||||||
}
|
}
|
||||||
|
@ -209,12 +207,12 @@ func testOperationalMode(t *testing.T) {
|
||||||
// 2) look up all txin (except coinbase in db)
|
// 2) look up all txin (except coinbase in db)
|
||||||
// 3) insert block
|
// 3) insert block
|
||||||
// 4) exercise the optional addridex
|
// 4) exercise the optional addridex
|
||||||
testDb, err := setUpTestDb(t)
|
testDb, err := setUpTestDb(t, "tstdbopmode")
|
||||||
defer testDb.cleanUpFunc()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unable to load blocks from test data: %v", err)
|
t.Errorf("Failed to open test database %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer testDb.cleanUpFunc()
|
||||||
err = nil
|
err = nil
|
||||||
out:
|
out:
|
||||||
for height := int64(0); height < int64(len(testDb.blocks)); height++ {
|
for height := int64(0); height < int64(len(testDb.blocks)); height++ {
|
||||||
|
@ -295,13 +293,12 @@ func testBackout(t *testing.T) {
|
||||||
// 2) look up all txin (except coinbase in db)
|
// 2) look up all txin (except coinbase in db)
|
||||||
// 3) insert block
|
// 3) insert block
|
||||||
|
|
||||||
testDb, err := setUpTestDb(t)
|
testDb, err := setUpTestDb(t, "tstdbbackout")
|
||||||
defer testDb.cleanUpFunc()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to open test database %v", err)
|
t.Errorf("Failed to open test database %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer testDb.cleanUpFunc()
|
||||||
|
|
||||||
if len(testDb.blocks) < 120 {
|
if len(testDb.blocks) < 120 {
|
||||||
t.Errorf("test data too small")
|
t.Errorf("test data too small")
|
||||||
|
@ -516,7 +513,11 @@ func testFetchHeightRange(t *testing.T, db database.Db, blocks []*btcutil.Block)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLimitAndSkipFetchTxsForAddr(t *testing.T) {
|
func TestLimitAndSkipFetchTxsForAddr(t *testing.T) {
|
||||||
testDb, err := setUpTestDb(t)
|
testDb, err := setUpTestDb(t, "tstdbtxaddr")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to open test database %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
defer testDb.cleanUpFunc()
|
defer testDb.cleanUpFunc()
|
||||||
|
|
||||||
// Insert a block with some fake test transactions. The block will have
|
// Insert a block with some fake test transactions. The block will have
|
||||||
|
|
|
@ -202,8 +202,8 @@ information.
|
||||||
* [btcscript](https://github.com/btcsuite/btcscript) - Implements the
|
* [btcscript](https://github.com/btcsuite/btcscript) - Implements the
|
||||||
Bitcoin transaction scripting language
|
Bitcoin transaction scripting language
|
||||||
* [btcec](https://github.com/btcsuite/btcec) - Implements support for the
|
* [btcec](https://github.com/btcsuite/btcec) - Implements support for the
|
||||||
elliptic curve cryptographic functions needed for the Bitcoin scripts
|
* [database](https://github.com/btcsuite/btcd/tree/master/database) -
|
||||||
* [btcdb](https://github.com/btcsuite/btcdb) - Provides a database interface
|
Provides a database interface elliptic curve cryptographic functions
|
||||||
for the Bitcoin block chain
|
needed for the Bitcoin scripts for the Bitcoin block chain
|
||||||
* [btcutil](https://github.com/btcsuite/btcutil) - Provides Bitcoin-specific
|
* [btcutil](https://github.com/btcsuite/btcutil) - Provides Bitcoin-specific
|
||||||
convenience functions and types
|
convenience functions and types
|
4
log.go
4
log.go
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/btcsuite/btcd/addrmgr"
|
"github.com/btcsuite/btcd/addrmgr"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btclog"
|
"github.com/btcsuite/btclog"
|
||||||
"github.com/btcsuite/btcscript"
|
"github.com/btcsuite/btcscript"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -100,7 +100,7 @@ func useLogger(subsystemID string, logger btclog.Logger) {
|
||||||
|
|
||||||
case "BCDB":
|
case "BCDB":
|
||||||
bcdbLog = logger
|
bcdbLog = logger
|
||||||
btcdb.UseLogger(logger)
|
database.UseLogger(logger)
|
||||||
|
|
||||||
case "BMGR":
|
case "BMGR":
|
||||||
bmgrLog = logger
|
bmgrLog = logger
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcscript"
|
"github.com/btcsuite/btcscript"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -764,7 +764,7 @@ func (mp *txMemPool) fetchInputTransactions(tx *btcutil.Tx) (btcchain.TxStore, e
|
||||||
|
|
||||||
// Attempt to populate any missing inputs from the transaction pool.
|
// Attempt to populate any missing inputs from the transaction pool.
|
||||||
for _, txD := range txStore {
|
for _, txD := range txStore {
|
||||||
if txD.Err == btcdb.ErrTxShaMissing || txD.Tx == nil {
|
if txD.Err == database.ErrTxShaMissing || txD.Tx == nil {
|
||||||
if poolTxDesc, exists := mp.pool[*txD.Hash]; exists {
|
if poolTxDesc, exists := mp.pool[*txD.Hash]; exists {
|
||||||
poolTx := poolTxDesc.Tx
|
poolTx := poolTxDesc.Tx
|
||||||
txD.Tx = poolTx
|
txD.Tx = poolTx
|
||||||
|
@ -911,7 +911,7 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit boo
|
||||||
// behavior is desired.
|
// behavior is desired.
|
||||||
var missingParents []*btcwire.ShaHash
|
var missingParents []*btcwire.ShaHash
|
||||||
for _, txD := range txStore {
|
for _, txD := range txStore {
|
||||||
if txD.Err == btcdb.ErrTxShaMissing {
|
if txD.Err == database.ErrTxShaMissing {
|
||||||
missingParents = append(missingParents, txD.Hash)
|
missingParents = append(missingParents, txD.Hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcscript"
|
"github.com/btcsuite/btcscript"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -188,8 +188,8 @@ func minInt(a, b int) int {
|
||||||
func mergeTxStore(txStoreA btcchain.TxStore, txStoreB btcchain.TxStore) {
|
func mergeTxStore(txStoreA btcchain.TxStore, txStoreB btcchain.TxStore) {
|
||||||
for hash, txDataB := range txStoreB {
|
for hash, txDataB := range txStoreB {
|
||||||
if txDataA, exists := txStoreA[hash]; !exists ||
|
if txDataA, exists := txStoreA[hash]; !exists ||
|
||||||
(txDataA.Err == btcdb.ErrTxShaMissing && txDataB.Err !=
|
(txDataA.Err == database.ErrTxShaMissing &&
|
||||||
btcdb.ErrTxShaMissing) {
|
txDataB.Err != database.ErrTxShaMissing) {
|
||||||
|
|
||||||
txStoreA[hash] = txDataB
|
txStoreA[hash] = txDataB
|
||||||
}
|
}
|
||||||
|
|
8
peer.go
8
peer.go
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcd/addrmgr"
|
"github.com/btcsuite/btcd/addrmgr"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcutil/bloom"
|
"github.com/btcsuite/btcutil/bloom"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -890,7 +890,7 @@ func (p *peer) handleGetBlocksMsg(msg *btcwire.MsgGetBlocks) {
|
||||||
// Return all block hashes to the latest one (up to max per message) if
|
// Return all block hashes to the latest one (up to max per message) if
|
||||||
// no stop hash was specified.
|
// no stop hash was specified.
|
||||||
// Attempt to find the ending index of the stop hash if specified.
|
// Attempt to find the ending index of the stop hash if specified.
|
||||||
endIdx := btcdb.AllShas
|
endIdx := database.AllShas
|
||||||
if !msg.HashStop.IsEqual(&zeroHash) {
|
if !msg.HashStop.IsEqual(&zeroHash) {
|
||||||
height, err := p.server.db.FetchBlockHeightBySha(&msg.HashStop)
|
height, err := p.server.db.FetchBlockHeightBySha(&msg.HashStop)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -969,7 +969,7 @@ func (p *peer) handleGetBlocksMsg(msg *btcwire.MsgGetBlocks) {
|
||||||
// message.
|
// message.
|
||||||
func (p *peer) handleGetHeadersMsg(msg *btcwire.MsgGetHeaders) {
|
func (p *peer) handleGetHeadersMsg(msg *btcwire.MsgGetHeaders) {
|
||||||
// Attempt to look up the height of the provided stop hash.
|
// Attempt to look up the height of the provided stop hash.
|
||||||
endIdx := btcdb.AllShas
|
endIdx := database.AllShas
|
||||||
height, err := p.server.db.FetchBlockHeightBySha(&msg.HashStop)
|
height, err := p.server.db.FetchBlockHeightBySha(&msg.HashStop)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
endIdx = height + 1
|
endIdx = height + 1
|
||||||
|
@ -981,7 +981,7 @@ func (p *peer) handleGetHeadersMsg(msg *btcwire.MsgGetHeaders) {
|
||||||
// No blocks with the stop hash were found so there is nothing
|
// No blocks with the stop hash were found so there is nothing
|
||||||
// to do. Just return. This behavior mirrors the reference
|
// to do. Just return. This behavior mirrors the reference
|
||||||
// implementation.
|
// implementation.
|
||||||
if endIdx == btcdb.AllShas {
|
if endIdx == database.AllShas {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcec"
|
"github.com/btcsuite/btcec"
|
||||||
"github.com/btcsuite/btcjson"
|
"github.com/btcsuite/btcjson"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
|
@ -3068,7 +3068,7 @@ func handleSubmitBlock(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{})
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyChain(db btcdb.Db, level, depth int32, timeSource btcchain.MedianTimeSource) error {
|
func verifyChain(db database.Db, level, depth int32, timeSource btcchain.MedianTimeSource) error {
|
||||||
_, curHeight64, err := db.NewestSha()
|
_, curHeight64, err := db.NewestSha()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rpcsLog.Errorf("Verify is unable to fetch current block "+
|
rpcsLog.Errorf("Verify is unable to fetch current block "+
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
|
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
|
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcjson"
|
"github.com/btcsuite/btcjson"
|
||||||
"github.com/btcsuite/btcscript"
|
"github.com/btcsuite/btcscript"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
@ -1607,7 +1607,7 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *btcutil.Block) {
|
||||||
// verifies that the new range of blocks is on the same fork as a previous
|
// verifies that the new range of blocks is on the same fork as a previous
|
||||||
// range of blocks. If this condition does not hold true, the JSON-RPC error
|
// range of blocks. If this condition does not hold true, the JSON-RPC error
|
||||||
// for an unrecoverable reorganize is returned.
|
// for an unrecoverable reorganize is returned.
|
||||||
func recoverFromReorg(db btcdb.Db, minBlock, maxBlock int64,
|
func recoverFromReorg(db database.Db, minBlock, maxBlock int64,
|
||||||
lastBlock *btcutil.Block) ([]btcwire.ShaHash, *btcjson.Error) {
|
lastBlock *btcutil.Block) ([]btcwire.ShaHash, *btcjson.Error) {
|
||||||
|
|
||||||
hashList, err := db.FetchHeightRange(minBlock, maxBlock)
|
hashList, err := db.FetchHeightRange(minBlock, maxBlock)
|
||||||
|
@ -1753,7 +1753,7 @@ func handleRescan(wsc *wsClient, icmd btcjson.Cmd) (interface{}, *btcjson.Error)
|
||||||
return nil, &btcjson.ErrBlockNotFound
|
return nil, &btcjson.ErrBlockNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
maxBlock := btcdb.AllShas
|
maxBlock := database.AllShas
|
||||||
if cmd.EndBlock != "" {
|
if cmd.EndBlock != "" {
|
||||||
maxBlockSha, err := btcwire.NewShaHashFromStr(cmd.EndBlock)
|
maxBlockSha, err := btcwire.NewShaHashFromStr(cmd.EndBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1791,7 +1791,7 @@ fetchRange:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Only handle reorgs if a block could not be
|
// Only handle reorgs if a block could not be
|
||||||
// found for the hash.
|
// found for the hash.
|
||||||
if err != btcdb.ErrBlockShaMissing {
|
if err != database.ErrBlockShaMissing {
|
||||||
rpcsLog.Errorf("Error looking up "+
|
rpcsLog.Errorf("Error looking up "+
|
||||||
"block: %v", err)
|
"block: %v", err)
|
||||||
return nil, &btcjson.ErrDatabase
|
return nil, &btcjson.ErrDatabase
|
||||||
|
@ -1799,7 +1799,7 @@ fetchRange:
|
||||||
|
|
||||||
// If an absolute max block was specified, don't
|
// If an absolute max block was specified, don't
|
||||||
// attempt to handle the reorg.
|
// attempt to handle the reorg.
|
||||||
if maxBlock != btcdb.AllShas {
|
if maxBlock != database.AllShas {
|
||||||
rpcsLog.Errorf("Stopping rescan for "+
|
rpcsLog.Errorf("Stopping rescan for "+
|
||||||
"reorged block %v",
|
"reorged block %v",
|
||||||
cmd.EndBlock)
|
cmd.EndBlock)
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
|
|
||||||
"github.com/btcsuite/btcchain"
|
"github.com/btcsuite/btcchain"
|
||||||
"github.com/btcsuite/btcd/addrmgr"
|
"github.com/btcsuite/btcd/addrmgr"
|
||||||
"github.com/btcsuite/btcdb"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcjson"
|
"github.com/btcsuite/btcjson"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcwire"
|
"github.com/btcsuite/btcwire"
|
||||||
|
@ -90,7 +90,7 @@ type server struct {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
nat NAT
|
nat NAT
|
||||||
db btcdb.Db
|
db database.Db
|
||||||
timeSource btcchain.MedianTimeSource
|
timeSource btcchain.MedianTimeSource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1083,7 +1083,7 @@ out:
|
||||||
// newServer returns a new btcd server configured to listen on addr for the
|
// newServer returns a new btcd server configured to listen on addr for the
|
||||||
// bitcoin network type specified by netParams. Use start to begin accepting
|
// bitcoin network type specified by netParams. Use start to begin accepting
|
||||||
// connections from peers.
|
// connections from peers.
|
||||||
func newServer(listenAddrs []string, db btcdb.Db, netParams *btcnet.Params) (*server, error) {
|
func newServer(listenAddrs []string, db database.Db, netParams *btcnet.Params) (*server, error) {
|
||||||
nonce, err := btcwire.RandomUint64()
|
nonce, err := btcwire.RandomUint64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Add table
Reference in a new issue