channeldb: Open is no longer dependant on a specific set of chain params

This commit is contained in:
Olaoluwa Osuntokun 2016-12-22 12:09:19 -08:00
parent 587bde5636
commit 597b4ee3d3
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
6 changed files with 11 additions and 15 deletions

View File

@ -92,7 +92,7 @@ func makeTestDB() (*DB, func(), error) {
} }
// Next, create channeldb for the first time. // Next, create channeldb for the first time.
cdb, err := Open(tempDirName, netParams) cdb, err := Open(tempDirName)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg"
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
) )
@ -56,13 +55,12 @@ var bufPool = &sync.Pool{
// schedules, and reputation data. // schedules, and reputation data.
type DB struct { type DB struct {
*bolt.DB *bolt.DB
netParams *chaincfg.Params dbPath string
dbPath string
} }
// Open opens an existing channeldb. Any necessary schemas migrations due to // Open opens an existing channeldb. Any necessary schemas migrations due to
// udpates will take plave as necessary. // udpates will take plave as necessary.
func Open(dbPath string, netParams *chaincfg.Params) (*DB, error) { func Open(dbPath string) (*DB, error) {
path := filepath.Join(dbPath, dbName) path := filepath.Join(dbPath, dbName)
if !fileExists(path) { if !fileExists(path) {
@ -77,9 +75,8 @@ func Open(dbPath string, netParams *chaincfg.Params) (*DB, error) {
} }
chanDB := &DB{ chanDB := &DB{
DB: bdb, DB: bdb,
netParams: netParams, dbPath: dbPath,
dbPath: dbPath,
} }
// Synchronize the version of database and apply migrations if needed. // Synchronize the version of database and apply migrations if needed.

View File

@ -18,7 +18,7 @@ func TestOpenWithCreate(t *testing.T) {
// Next, open thereby creating channeldb for the first time. // Next, open thereby creating channeldb for the first time.
dbPath := filepath.Join(tempDirName, "cdb") dbPath := filepath.Join(tempDirName, "cdb")
cdb, err := Open(dbPath, netParams) cdb, err := Open(dbPath)
if err != nil { if err != nil {
t.Fatalf("unable to create channeldb: %v", err) t.Fatalf("unable to create channeldb: %v", err)
} }

2
lnd.go
View File

@ -60,7 +60,7 @@ func lndMain() error {
// Open the channeldb, which is dedicated to storing channel, and // Open the channeldb, which is dedicated to storing channel, and
// network related meta-data. // network related meta-data.
chanDB, err := channeldb.Open(cfg.DataDir, activeNetParams.Params) chanDB, err := channeldb.Open(cfg.DataDir)
if err != nil { if err != nil {
fmt.Println("unable to open channeldb: ", err) fmt.Println("unable to open channeldb: ", err)
return err return err

View File

@ -16,7 +16,6 @@ import (
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/roasbeef/btcd/blockchain" "github.com/roasbeef/btcd/blockchain"
"github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg"
"github.com/roasbeef/btcd/txscript" "github.com/roasbeef/btcd/txscript"
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"
@ -231,13 +230,13 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
} }
alicePath, err := ioutil.TempDir("", "alicedb") alicePath, err := ioutil.TempDir("", "alicedb")
dbAlice, err := channeldb.Open(alicePath, &chaincfg.TestNet3Params) dbAlice, err := channeldb.Open(alicePath)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
bobPath, err := ioutil.TempDir("", "bobdb") bobPath, err := ioutil.TempDir("", "bobdb")
dbBob, err := channeldb.Open(bobPath, &chaincfg.TestNet3Params) dbBob, err := channeldb.Open(bobPath)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
@ -871,7 +870,7 @@ func TestCheckDustLimit(t *testing.T) {
bobDustLimit := bobChannel.channelState.OurDustLimit bobDustLimit := bobChannel.channelState.OurDustLimit
htlcAmount := btcutil.Amount(500) htlcAmount := btcutil.Amount(500)
if !((htlcAmount > aliceDustLimit) && (bobDustLimit > htlcAmount)) { if !((htlcAmount > aliceDustLimit) && (bobDustLimit > htlcAmount)) {
t.Fatal("htlc amount needs to be above Alice's dust limit, but " + t.Fatal("htlc amount needs to be above Alice's dust limit, but " +
"below Bob's dust limit .") "below Bob's dust limit .")
} }

View File

@ -326,7 +326,7 @@ func createTestWallet(tempTestDir string, miningNode *rpctest.Harness,
bio lnwallet.BlockChainIO) (*lnwallet.LightningWallet, error) { bio lnwallet.BlockChainIO) (*lnwallet.LightningWallet, error) {
dbDir := filepath.Join(tempTestDir, "cdb") dbDir := filepath.Join(tempTestDir, "cdb")
cdb, err := channeldb.Open(dbDir, &chaincfg.SegNet4Params) cdb, err := channeldb.Open(dbDir)
if err != nil { if err != nil {
return nil, err return nil, err
} }