channeldb: fix commit key state corruption bug

This commit fixes a bug caused by overriding the prefix key for storing
commitment keys with the first few bytes of a channel’s channel point.

Once a channel was deleted, then all future channels would result in a
panic due to a nil pointer deference since the prefix key was mutated,
causing all future stores/gets to fail.
This commit is contained in:
Olaoluwa Osuntokun 2016-07-12 16:59:50 -07:00
parent 4548e4497d
commit 48491a7fee
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -171,6 +171,7 @@ type OpenChannel struct {
// order to encrypt sensitive information.
func (c *OpenChannel) FullSync() error {
return c.Db.store.Update(func(tx *bolt.Tx) error {
// TODO(roasbeef): add helper funcs to create scoped update
// First fetch the top level bucket which stores all data related to
// current, active channels.
chanBucket, err := tx.CreateBucketIfNotExists(openChannelBucket)
@ -773,7 +774,7 @@ func putChanCommitKeys(nodeChanBucket *bolt.Bucket, channel *OpenChannel,
}
commitKey := make([]byte, len(commitKeys)+bc.Len())
copy(commitKey[:3], commitKeys)
copy(commitKeys[3:], bc.Bytes())
copy(commitKey[3:], bc.Bytes())
var b bytes.Buffer
@ -796,7 +797,7 @@ func putChanCommitKeys(nodeChanBucket *bolt.Bucket, channel *OpenChannel,
func deleteChanCommitKeys(nodeChanBucket *bolt.Bucket, chanID []byte) error {
commitKey := make([]byte, len(commitKeys)+len(chanID))
copy(commitKey[:3], commitKeys)
copy(commitKeys[3:], chanID)
copy(commitKey[3:], chanID)
return nodeChanBucket.Delete(commitKey)
}
@ -811,7 +812,7 @@ func fetchChanCommitKeys(nodeChanBucket *bolt.Bucket, channel *OpenChannel,
}
commitKey := make([]byte, len(commitKeys)+bc.Len())
copy(commitKey[:3], commitKeys)
copy(commitKeys[3:], bc.Bytes())
copy(commitKey[3:], bc.Bytes())
var err error
keyBytes := nodeChanBucket.Get(commitKey)