From 48491a7fee7ae74cba8b170447f8961dd9cce693 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 12 Jul 2016 16:59:50 -0700 Subject: [PATCH] channeldb: fix commit key state corruption bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- channeldb/channel.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index 2613269c3..982fe46de 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -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)