diff --git a/channeldb/db.go b/channeldb/db.go index 37397b048..e1a29dc1c 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -24,8 +24,7 @@ import ( ) const ( - dbName = "channel.db" - dbFilePermission = 0600 + dbName = "channel.db" ) var ( @@ -408,7 +407,7 @@ func (d *DB) FetchOpenChannels(nodeID *btcec.PublicKey) ([]*OpenChannel, error) // stored currently active/open channels associated with the target nodeID. In // the case that no active channels are known to have been created with this // node, then a zero-length slice is returned. -func (db *DB) fetchOpenChannels(tx kvdb.RTx, +func (d *DB) fetchOpenChannels(tx kvdb.RTx, nodeID *btcec.PublicKey) ([]*OpenChannel, error) { // Get the bucket dedicated to storing the metadata for open channels. @@ -444,7 +443,7 @@ func (db *DB) fetchOpenChannels(tx kvdb.RTx, // Finally, we both of the necessary buckets retrieved, fetch // all the active channels related to this node. - nodeChannels, err := db.fetchNodeChannels(chainBucket) + nodeChannels, err := d.fetchNodeChannels(chainBucket) if err != nil { return fmt.Errorf("unable to read channel for "+ "chain_hash=%x, node_key=%x: %v", @@ -461,7 +460,7 @@ func (db *DB) fetchOpenChannels(tx kvdb.RTx, // fetchNodeChannels retrieves all active channels from the target chainBucket // which is under a node's dedicated channel bucket. This function is typically // used to fetch all the active channels related to a particular node. -func (db *DB) fetchNodeChannels(chainBucket kvdb.RBucket) ([]*OpenChannel, error) { +func (d *DB) fetchNodeChannels(chainBucket kvdb.RBucket) ([]*OpenChannel, error) { var channels []*OpenChannel @@ -487,7 +486,7 @@ func (db *DB) fetchNodeChannels(chainBucket kvdb.RBucket) ([]*OpenChannel, error return fmt.Errorf("unable to read channel data for "+ "chan_point=%v: %v", outPoint, err) } - oChannel.Db = db + oChannel.Db = d channels = append(channels, oChannel) @@ -949,8 +948,8 @@ func (d *DB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error { // pruneLinkNode determines whether we should garbage collect a link node from // the database due to no longer having any open channels with it. If there are // any left, then this acts as a no-op. -func (db *DB) pruneLinkNode(tx kvdb.RwTx, remotePub *btcec.PublicKey) error { - openChannels, err := db.fetchOpenChannels(tx, remotePub) +func (d *DB) pruneLinkNode(tx kvdb.RwTx, remotePub *btcec.PublicKey) error { + openChannels, err := d.fetchOpenChannels(tx, remotePub) if err != nil { return fmt.Errorf("unable to fetch open channels for peer %x: "+ "%v", remotePub.SerializeCompressed(), err) @@ -963,7 +962,7 @@ func (db *DB) pruneLinkNode(tx kvdb.RwTx, remotePub *btcec.PublicKey) error { log.Infof("Pruning link node %x with zero open channels from database", remotePub.SerializeCompressed()) - return db.deleteLinkNode(tx, remotePub) + return d.deleteLinkNode(tx, remotePub) } // PruneLinkNodes attempts to prune all link nodes found within the databse with @@ -1099,16 +1098,16 @@ func (d *DB) AddrsForNode(nodePub *btcec.PublicKey) ([]net.Addr, error) { // database. If the channel was already removed (has a closed channel entry), // then we'll return a nil error. Otherwise, we'll insert a new close summary // into the database. -func (db *DB) AbandonChannel(chanPoint *wire.OutPoint, bestHeight uint32) error { +func (d *DB) AbandonChannel(chanPoint *wire.OutPoint, bestHeight uint32) error { // With the chanPoint constructed, we'll attempt to find the target // channel in the database. If we can't find the channel, then we'll // return the error back to the caller. - dbChan, err := db.FetchChannel(*chanPoint) + dbChan, err := d.FetchChannel(*chanPoint) switch { // If the channel wasn't found, then it's possible that it was already // abandoned from the database. case err == ErrChannelNotFound: - _, closedErr := db.FetchClosedChannel(chanPoint) + _, closedErr := d.FetchClosedChannel(chanPoint) if closedErr != nil { return closedErr } @@ -1271,9 +1270,9 @@ func fetchHistoricalChanBucket(tx kvdb.RTx, // FetchHistoricalChannel fetches open channel data from the historical channel // bucket. -func (db *DB) FetchHistoricalChannel(outPoint *wire.OutPoint) (*OpenChannel, error) { +func (d *DB) FetchHistoricalChannel(outPoint *wire.OutPoint) (*OpenChannel, error) { var channel *OpenChannel - err := kvdb.View(db, func(tx kvdb.RTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { chanBucket, err := fetchHistoricalChanBucket(tx, outPoint) if err != nil { return err diff --git a/channeldb/nodes.go b/channeldb/nodes.go index f17662275..88d98d6ae 100644 --- a/channeldb/nodes.go +++ b/channeldb/nodes.go @@ -61,7 +61,7 @@ type LinkNode struct { // NewLinkNode creates a new LinkNode from the provided parameters, which is // backed by an instance of channeldb. -func (db *DB) NewLinkNode(bitNet wire.BitcoinNet, pub *btcec.PublicKey, +func (d *DB) NewLinkNode(bitNet wire.BitcoinNet, pub *btcec.PublicKey, addrs ...net.Addr) *LinkNode { return &LinkNode{ @@ -69,7 +69,7 @@ func (db *DB) NewLinkNode(bitNet wire.BitcoinNet, pub *btcec.PublicKey, IdentityPub: pub, LastSeen: time.Now(), Addresses: addrs, - db: db, + db: d, } } @@ -129,13 +129,13 @@ func putLinkNode(nodeMetaBucket kvdb.RwBucket, l *LinkNode) error { // DeleteLinkNode removes the link node with the given identity from the // database. -func (db *DB) DeleteLinkNode(identity *btcec.PublicKey) error { - return kvdb.Update(db, func(tx kvdb.RwTx) error { - return db.deleteLinkNode(tx, identity) +func (d *DB) DeleteLinkNode(identity *btcec.PublicKey) error { + return kvdb.Update(d, func(tx kvdb.RwTx) error { + return d.deleteLinkNode(tx, identity) }, func() {}) } -func (db *DB) deleteLinkNode(tx kvdb.RwTx, identity *btcec.PublicKey) error { +func (d *DB) deleteLinkNode(tx kvdb.RwTx, identity *btcec.PublicKey) error { nodeMetaBucket := tx.ReadWriteBucket(nodeInfoBucket) if nodeMetaBucket == nil { return ErrLinkNodesNotFound @@ -148,9 +148,9 @@ func (db *DB) deleteLinkNode(tx kvdb.RwTx, identity *btcec.PublicKey) error { // FetchLinkNode attempts to lookup the data for a LinkNode based on a target // identity public key. If a particular LinkNode for the passed identity public // key cannot be found, then ErrNodeNotFound if returned. -func (db *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) { +func (d *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) { var linkNode *LinkNode - err := kvdb.View(db, func(tx kvdb.RTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { node, err := fetchLinkNode(tx, identity) if err != nil { return err @@ -191,10 +191,10 @@ func fetchLinkNode(tx kvdb.RTx, targetPub *btcec.PublicKey) (*LinkNode, error) { // FetchAllLinkNodes starts a new database transaction to fetch all nodes with // whom we have active channels with. -func (db *DB) FetchAllLinkNodes() ([]*LinkNode, error) { +func (d *DB) FetchAllLinkNodes() ([]*LinkNode, error) { var linkNodes []*LinkNode - err := kvdb.View(db, func(tx kvdb.RTx) error { - nodes, err := db.fetchAllLinkNodes(tx) + err := kvdb.View(d, func(tx kvdb.RTx) error { + nodes, err := d.fetchAllLinkNodes(tx) if err != nil { return err } @@ -213,7 +213,7 @@ func (db *DB) FetchAllLinkNodes() ([]*LinkNode, error) { // fetchAllLinkNodes uses an existing database transaction to fetch all nodes // with whom we have active channels with. -func (db *DB) fetchAllLinkNodes(tx kvdb.RTx) ([]*LinkNode, error) { +func (d *DB) fetchAllLinkNodes(tx kvdb.RTx) ([]*LinkNode, error) { nodeMetaBucket := tx.ReadBucket(nodeInfoBucket) if nodeMetaBucket == nil { return nil, ErrLinkNodesNotFound diff --git a/channeldb/payments.go b/channeldb/payments.go index 1abe54a57..f044d0f1e 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -233,10 +233,10 @@ type PaymentCreationInfo struct { // FetchPayments returns all sent payments found in the DB. // // nolint: dupl -func (db *DB) FetchPayments() ([]*MPPayment, error) { +func (d *DB) FetchPayments() ([]*MPPayment, error) { var payments []*MPPayment - err := kvdb.View(db, func(tx kvdb.RTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { paymentsBucket := tx.ReadBucket(paymentsRootBucket) if paymentsBucket == nil { return nil @@ -510,10 +510,10 @@ type PaymentsResponse struct { // QueryPayments is a query to the payments database which is restricted // to a subset of payments by the payments query, containing an offset // index and a maximum number of returned payments. -func (db *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { +func (d *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { var resp PaymentsResponse - if err := kvdb.View(db, func(tx kvdb.RTx) error { + if err := kvdb.View(d, func(tx kvdb.RTx) error { // Get the root payments bucket. paymentsBucket := tx.ReadBucket(paymentsRootBucket) if paymentsBucket == nil { @@ -681,8 +681,8 @@ func fetchPaymentWithSequenceNumber(tx kvdb.RTx, paymentHash lntypes.Hash, // failedOnly is set, only failed payments will be considered for deletion. If // failedHtlsOnly is set, the payment itself won't be deleted, only failed HTLC // attempts. -func (db *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) error { - return kvdb.Update(db, func(tx kvdb.RwTx) error { +func (d *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) error { + return kvdb.Update(d, func(tx kvdb.RwTx) error { payments := tx.ReadWriteBucket(paymentsRootBucket) if payments == nil { return nil diff --git a/kvdb/etcd/db_test.go b/kvdb/etcd/db_test.go index 357c4ed5c..ebb044f42 100644 --- a/kvdb/etcd/db_test.go +++ b/kvdb/etcd/db_test.go @@ -38,7 +38,7 @@ func TestCopy(t *testing.T) { require.Nil(t, err) expected := map[string]string{ - BucketKey("apple"): BucketVal("apple"), + BucketKey("apple"): BucketVal("apple"), ValueKey("key", "apple"): "val", } require.Equal(t, expected, f.Dump()) diff --git a/kvdb/etcd/fixture.go b/kvdb/etcd/fixture.go index b6404a9f6..8fcfb9f5c 100644 --- a/kvdb/etcd/fixture.go +++ b/kvdb/etcd/fixture.go @@ -11,7 +11,7 @@ import ( "github.com/btcsuite/btcwallet/walletdb" "github.com/stretchr/testify/require" - "go.etcd.io/etcd/client/v3" + clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/client/v3/namespace" ) diff --git a/kvdb/etcd/readwrite_tx_test.go b/kvdb/etcd/readwrite_tx_test.go index c640493ee..7c0c296de 100644 --- a/kvdb/etcd/readwrite_tx_test.go +++ b/kvdb/etcd/readwrite_tx_test.go @@ -85,7 +85,7 @@ func TestChangeDuringUpdate(t *testing.T) { require.Equal(t, count, 2) expected := map[string]string{ - BucketKey("apple"): BucketVal("apple"), + BucketKey("apple"): BucketVal("apple"), ValueKey("key", "apple"): "value", ValueKey("key2", "apple"): "value2", }