lnwallet: check for nil buckets during fetch in channeldb
This commit is contained in:
parent
3e2a753271
commit
d7a1c5d337
@ -57,21 +57,21 @@ func (c *ChannelDB) PutOpenChannel(channel *OpenChannelState) error {
|
|||||||
// TODO(roasbeef): assumes only 1 active channel per-node
|
// TODO(roasbeef): assumes only 1 active channel per-node
|
||||||
func (c *ChannelDB) FetchOpenChannel(nodeID [32]byte) (*OpenChannelState, error) {
|
func (c *ChannelDB) FetchOpenChannel(nodeID [32]byte) (*OpenChannelState, error) {
|
||||||
var channel *OpenChannelState
|
var channel *OpenChannelState
|
||||||
var err error
|
|
||||||
|
|
||||||
dbErr := c.namespace.View(func(tx walletdb.Tx) error {
|
dbErr := c.namespace.View(func(tx walletdb.Tx) error {
|
||||||
// Get the bucket dedicated to storing the meta-data for open
|
// Get the bucket dedicated to storing the meta-data for open
|
||||||
// channels.
|
// channels.
|
||||||
rootBucket := tx.RootBucket()
|
rootBucket := tx.RootBucket()
|
||||||
openChanBucket, err := rootBucket.CreateBucketIfNotExists(openChannelBucket)
|
openChanBucket := rootBucket.Bucket(openChannelBucket)
|
||||||
if err != nil {
|
if openChannelBucket == nil {
|
||||||
return err
|
return fmt.Errorf("open channel bucket does not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
channel, err = dbGetOpenChannel(openChanBucket, nodeID, c.addrmgr)
|
oChannel, err := dbGetOpenChannel(openChanBucket, nodeID, c.addrmgr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
channel = oChannel
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -102,11 +102,12 @@ func dbPutOpenChannel(activeChanBucket walletdb.Bucket, channel *OpenChannelStat
|
|||||||
// dbPutChannel...
|
// dbPutChannel...
|
||||||
func dbGetOpenChannel(bucket walletdb.Bucket, nodeID [32]byte,
|
func dbGetOpenChannel(bucket walletdb.Bucket, nodeID [32]byte,
|
||||||
addrmgr *waddrmgr.Manager) (*OpenChannelState, error) {
|
addrmgr *waddrmgr.Manager) (*OpenChannelState, error) {
|
||||||
|
|
||||||
// Grab the bucket dedicated to storing data related to this particular
|
// Grab the bucket dedicated to storing data related to this particular
|
||||||
// node.
|
// node.
|
||||||
nodeBucket, err := bucket.CreateBucketIfNotExists(nodeID[:])
|
nodeBucket := bucket.Bucket(nodeID[:])
|
||||||
if err != nil {
|
if nodeBucket == nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("channel bucket for node does not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
serializedChannel := nodeBucket.Get(activeChanKey)
|
serializedChannel := nodeBucket.Get(activeChanKey)
|
||||||
|
Loading…
Reference in New Issue
Block a user