From 597b4ee3d3d2bc4d8c66b28b1e664120d93d12fa Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 22 Dec 2016 12:09:19 -0800 Subject: [PATCH] channeldb: Open is no longer dependant on a specific set of chain params --- channeldb/channel_test.go | 2 +- channeldb/db.go | 11 ++++------- channeldb/db_test.go | 2 +- lnd.go | 2 +- lnwallet/channel_test.go | 7 +++---- lnwallet/interface_test.go | 2 +- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index aa63fdcc..49d823a7 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -92,7 +92,7 @@ func makeTestDB() (*DB, func(), error) { } // Next, create channeldb for the first time. - cdb, err := Open(tempDirName, netParams) + cdb, err := Open(tempDirName) if err != nil { return nil, nil, err } diff --git a/channeldb/db.go b/channeldb/db.go index aa4bbc3a..39fd7987 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -10,7 +10,6 @@ import ( "github.com/boltdb/bolt" "github.com/roasbeef/btcd/btcec" - "github.com/roasbeef/btcd/chaincfg" "github.com/roasbeef/btcd/wire" ) @@ -56,13 +55,12 @@ var bufPool = &sync.Pool{ // schedules, and reputation data. type DB struct { *bolt.DB - netParams *chaincfg.Params - dbPath string + dbPath string } // Open opens an existing channeldb. Any necessary schemas migrations due to // 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) if !fileExists(path) { @@ -77,9 +75,8 @@ func Open(dbPath string, netParams *chaincfg.Params) (*DB, error) { } chanDB := &DB{ - DB: bdb, - netParams: netParams, - dbPath: dbPath, + DB: bdb, + dbPath: dbPath, } // Synchronize the version of database and apply migrations if needed. diff --git a/channeldb/db_test.go b/channeldb/db_test.go index 47122ce3..69c2d3b5 100644 --- a/channeldb/db_test.go +++ b/channeldb/db_test.go @@ -18,7 +18,7 @@ func TestOpenWithCreate(t *testing.T) { // Next, open thereby creating channeldb for the first time. dbPath := filepath.Join(tempDirName, "cdb") - cdb, err := Open(dbPath, netParams) + cdb, err := Open(dbPath) if err != nil { t.Fatalf("unable to create channeldb: %v", err) } diff --git a/lnd.go b/lnd.go index 4e7b18b2..02772df0 100644 --- a/lnd.go +++ b/lnd.go @@ -60,7 +60,7 @@ func lndMain() error { // Open the channeldb, which is dedicated to storing channel, and // network related meta-data. - chanDB, err := channeldb.Open(cfg.DataDir, activeNetParams.Params) + chanDB, err := channeldb.Open(cfg.DataDir) if err != nil { fmt.Println("unable to open channeldb: ", err) return err diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index ef14b01c..61314333 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -16,7 +16,6 @@ import ( "github.com/lightningnetwork/lnd/lnwire" "github.com/roasbeef/btcd/blockchain" "github.com/roasbeef/btcd/btcec" - "github.com/roasbeef/btcd/chaincfg" "github.com/roasbeef/btcd/txscript" "github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcutil" @@ -231,13 +230,13 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan } alicePath, err := ioutil.TempDir("", "alicedb") - dbAlice, err := channeldb.Open(alicePath, &chaincfg.TestNet3Params) + dbAlice, err := channeldb.Open(alicePath) if err != nil { return nil, nil, nil, err } bobPath, err := ioutil.TempDir("", "bobdb") - dbBob, err := channeldb.Open(bobPath, &chaincfg.TestNet3Params) + dbBob, err := channeldb.Open(bobPath) if err != nil { return nil, nil, nil, err } @@ -871,7 +870,7 @@ func TestCheckDustLimit(t *testing.T) { bobDustLimit := bobChannel.channelState.OurDustLimit 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 " + "below Bob's dust limit .") } diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index b4341ced..8ad7b50e 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -326,7 +326,7 @@ func createTestWallet(tempTestDir string, miningNode *rpctest.Harness, bio lnwallet.BlockChainIO) (*lnwallet.LightningWallet, error) { dbDir := filepath.Join(tempTestDir, "cdb") - cdb, err := channeldb.Open(dbDir, &chaincfg.SegNet4Params) + cdb, err := channeldb.Open(dbDir) if err != nil { return nil, err }