mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-24 20:53:07 +02:00
etcd+channeldb: fix linter issues, rename receiver
With this commit we address some issues the linter picked up after touching older code.
This commit is contained in:
@@ -25,7 +25,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
dbName = "channel.db"
|
dbName = "channel.db"
|
||||||
dbFilePermission = 0600
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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
|
// 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
|
// the case that no active channels are known to have been created with this
|
||||||
// node, then a zero-length slice is returned.
|
// 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) {
|
nodeID *btcec.PublicKey) ([]*OpenChannel, error) {
|
||||||
|
|
||||||
// Get the bucket dedicated to storing the metadata for open channels.
|
// 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
|
// Finally, we both of the necessary buckets retrieved, fetch
|
||||||
// all the active channels related to this node.
|
// all the active channels related to this node.
|
||||||
nodeChannels, err := db.fetchNodeChannels(chainBucket)
|
nodeChannels, err := d.fetchNodeChannels(chainBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to read channel for "+
|
return fmt.Errorf("unable to read channel for "+
|
||||||
"chain_hash=%x, node_key=%x: %v",
|
"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
|
// fetchNodeChannels retrieves all active channels from the target chainBucket
|
||||||
// which is under a node's dedicated channel bucket. This function is typically
|
// 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.
|
// 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
|
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 "+
|
return fmt.Errorf("unable to read channel data for "+
|
||||||
"chan_point=%v: %v", outPoint, err)
|
"chan_point=%v: %v", outPoint, err)
|
||||||
}
|
}
|
||||||
oChannel.Db = db
|
oChannel.Db = d
|
||||||
|
|
||||||
channels = append(channels, oChannel)
|
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
|
// 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
|
// the database due to no longer having any open channels with it. If there are
|
||||||
// any left, then this acts as a no-op.
|
// any left, then this acts as a no-op.
|
||||||
func (db *DB) pruneLinkNode(tx kvdb.RwTx, remotePub *btcec.PublicKey) error {
|
func (d *DB) pruneLinkNode(tx kvdb.RwTx, remotePub *btcec.PublicKey) error {
|
||||||
openChannels, err := db.fetchOpenChannels(tx, remotePub)
|
openChannels, err := d.fetchOpenChannels(tx, remotePub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to fetch open channels for peer %x: "+
|
return fmt.Errorf("unable to fetch open channels for peer %x: "+
|
||||||
"%v", remotePub.SerializeCompressed(), err)
|
"%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",
|
log.Infof("Pruning link node %x with zero open channels from database",
|
||||||
remotePub.SerializeCompressed())
|
remotePub.SerializeCompressed())
|
||||||
|
|
||||||
return db.deleteLinkNode(tx, remotePub)
|
return d.deleteLinkNode(tx, remotePub)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PruneLinkNodes attempts to prune all link nodes found within the databse with
|
// 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),
|
// 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
|
// then we'll return a nil error. Otherwise, we'll insert a new close summary
|
||||||
// into the database.
|
// 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
|
// 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
|
// channel in the database. If we can't find the channel, then we'll
|
||||||
// return the error back to the caller.
|
// return the error back to the caller.
|
||||||
dbChan, err := db.FetchChannel(*chanPoint)
|
dbChan, err := d.FetchChannel(*chanPoint)
|
||||||
switch {
|
switch {
|
||||||
// If the channel wasn't found, then it's possible that it was already
|
// If the channel wasn't found, then it's possible that it was already
|
||||||
// abandoned from the database.
|
// abandoned from the database.
|
||||||
case err == ErrChannelNotFound:
|
case err == ErrChannelNotFound:
|
||||||
_, closedErr := db.FetchClosedChannel(chanPoint)
|
_, closedErr := d.FetchClosedChannel(chanPoint)
|
||||||
if closedErr != nil {
|
if closedErr != nil {
|
||||||
return closedErr
|
return closedErr
|
||||||
}
|
}
|
||||||
@@ -1271,9 +1270,9 @@ func fetchHistoricalChanBucket(tx kvdb.RTx,
|
|||||||
|
|
||||||
// FetchHistoricalChannel fetches open channel data from the historical channel
|
// FetchHistoricalChannel fetches open channel data from the historical channel
|
||||||
// bucket.
|
// bucket.
|
||||||
func (db *DB) FetchHistoricalChannel(outPoint *wire.OutPoint) (*OpenChannel, error) {
|
func (d *DB) FetchHistoricalChannel(outPoint *wire.OutPoint) (*OpenChannel, error) {
|
||||||
var channel *OpenChannel
|
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)
|
chanBucket, err := fetchHistoricalChanBucket(tx, outPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -61,7 +61,7 @@ type LinkNode struct {
|
|||||||
|
|
||||||
// NewLinkNode creates a new LinkNode from the provided parameters, which is
|
// NewLinkNode creates a new LinkNode from the provided parameters, which is
|
||||||
// backed by an instance of channeldb.
|
// 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 {
|
addrs ...net.Addr) *LinkNode {
|
||||||
|
|
||||||
return &LinkNode{
|
return &LinkNode{
|
||||||
@@ -69,7 +69,7 @@ func (db *DB) NewLinkNode(bitNet wire.BitcoinNet, pub *btcec.PublicKey,
|
|||||||
IdentityPub: pub,
|
IdentityPub: pub,
|
||||||
LastSeen: time.Now(),
|
LastSeen: time.Now(),
|
||||||
Addresses: addrs,
|
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
|
// DeleteLinkNode removes the link node with the given identity from the
|
||||||
// database.
|
// database.
|
||||||
func (db *DB) DeleteLinkNode(identity *btcec.PublicKey) error {
|
func (d *DB) DeleteLinkNode(identity *btcec.PublicKey) error {
|
||||||
return kvdb.Update(db, func(tx kvdb.RwTx) error {
|
return kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||||
return db.deleteLinkNode(tx, identity)
|
return d.deleteLinkNode(tx, identity)
|
||||||
}, func() {})
|
}, 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)
|
nodeMetaBucket := tx.ReadWriteBucket(nodeInfoBucket)
|
||||||
if nodeMetaBucket == nil {
|
if nodeMetaBucket == nil {
|
||||||
return ErrLinkNodesNotFound
|
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
|
// 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
|
// identity public key. If a particular LinkNode for the passed identity public
|
||||||
// key cannot be found, then ErrNodeNotFound if returned.
|
// 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
|
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)
|
node, err := fetchLinkNode(tx, identity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// FetchAllLinkNodes starts a new database transaction to fetch all nodes with
|
||||||
// whom we have active channels with.
|
// whom we have active channels with.
|
||||||
func (db *DB) FetchAllLinkNodes() ([]*LinkNode, error) {
|
func (d *DB) FetchAllLinkNodes() ([]*LinkNode, error) {
|
||||||
var linkNodes []*LinkNode
|
var linkNodes []*LinkNode
|
||||||
err := kvdb.View(db, func(tx kvdb.RTx) error {
|
err := kvdb.View(d, func(tx kvdb.RTx) error {
|
||||||
nodes, err := db.fetchAllLinkNodes(tx)
|
nodes, err := d.fetchAllLinkNodes(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ func (db *DB) FetchAllLinkNodes() ([]*LinkNode, error) {
|
|||||||
|
|
||||||
// fetchAllLinkNodes uses an existing database transaction to fetch all nodes
|
// fetchAllLinkNodes uses an existing database transaction to fetch all nodes
|
||||||
// with whom we have active channels with.
|
// 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)
|
nodeMetaBucket := tx.ReadBucket(nodeInfoBucket)
|
||||||
if nodeMetaBucket == nil {
|
if nodeMetaBucket == nil {
|
||||||
return nil, ErrLinkNodesNotFound
|
return nil, ErrLinkNodesNotFound
|
||||||
|
@@ -233,10 +233,10 @@ type PaymentCreationInfo struct {
|
|||||||
// FetchPayments returns all sent payments found in the DB.
|
// FetchPayments returns all sent payments found in the DB.
|
||||||
//
|
//
|
||||||
// nolint: dupl
|
// nolint: dupl
|
||||||
func (db *DB) FetchPayments() ([]*MPPayment, error) {
|
func (d *DB) FetchPayments() ([]*MPPayment, error) {
|
||||||
var payments []*MPPayment
|
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)
|
paymentsBucket := tx.ReadBucket(paymentsRootBucket)
|
||||||
if paymentsBucket == nil {
|
if paymentsBucket == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -510,10 +510,10 @@ type PaymentsResponse struct {
|
|||||||
// QueryPayments is a query to the payments database which is restricted
|
// QueryPayments is a query to the payments database which is restricted
|
||||||
// to a subset of payments by the payments query, containing an offset
|
// to a subset of payments by the payments query, containing an offset
|
||||||
// index and a maximum number of returned payments.
|
// 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
|
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.
|
// Get the root payments bucket.
|
||||||
paymentsBucket := tx.ReadBucket(paymentsRootBucket)
|
paymentsBucket := tx.ReadBucket(paymentsRootBucket)
|
||||||
if paymentsBucket == nil {
|
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
|
// 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
|
// failedHtlsOnly is set, the payment itself won't be deleted, only failed HTLC
|
||||||
// attempts.
|
// attempts.
|
||||||
func (db *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) error {
|
func (d *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) error {
|
||||||
return kvdb.Update(db, func(tx kvdb.RwTx) error {
|
return kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||||
payments := tx.ReadWriteBucket(paymentsRootBucket)
|
payments := tx.ReadWriteBucket(paymentsRootBucket)
|
||||||
if payments == nil {
|
if payments == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/stretchr/testify/require"
|
"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"
|
"go.etcd.io/etcd/client/v3/namespace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user