From 2dcd82e77957d1f7eabd54f96bea4fd6f38e9d7e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 9 Nov 2017 20:24:12 -0800 Subject: [PATCH] channeldb: add new MarkAsOpen method to OpenChannel struct In this commit we add a new MarkAsOpen method to the OpenChannel struct. This method replaces the existing MarkChannelAsOpen method which targeted the database struct itself. --- channeldb/channel.go | 12 ++++++++++++ channeldb/db.go | 46 -------------------------------------------- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index cae5ae12..65a37dbb 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -487,6 +487,18 @@ func (c *OpenChannel) fullSync(tx *bolt.Tx) error { return putOpenChannel(chanBucket, c) } +// MarkAsOpen marks a channel as fully open given a locator that uniquely +// describes its location within the chain. +func (c *OpenChannel) MarkAsOpen(openLoc lnwire.ShortChannelID) error { + return c.Db.Update(func(tx *bolt.Tx) error { + chanBucket, err := updateChanBucket(tx, c.IdentityPub, + &c.FundingOutpoint, c.ChainHash) + if err != nil { + return err + } + + channel, err := fetchOpenChannel(chanBucket, &c.FundingOutpoint) + if err != nil { return err } diff --git a/channeldb/db.go b/channeldb/db.go index 59c77f04..2f5d7bc5 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -358,52 +358,6 @@ func fetchChannels(d *DB, pendingOnly bool) ([]*OpenChannel, error) { return channels, err } -// MarkChannelAsOpen records the finalization of the funding process and marks -// a channel as available for use. Additionally the height in which this -// channel as opened will also be recorded within the database. -func (d *DB) MarkChannelAsOpen(outpoint *wire.OutPoint, - openLoc lnwire.ShortChannelID) error { - - return d.Update(func(tx *bolt.Tx) error { - openChanBucket := tx.Bucket(openChannelBucket) - if openChanBucket == nil { - return ErrNoActiveChannels - } - - // Generate the database key, which will consist of the - // IsPending prefix followed by the channel's outpoint. - var b bytes.Buffer - if err := writeOutpoint(&b, outpoint); err != nil { - return err - } - keyPrefix := make([]byte, 3+b.Len()) - copy(keyPrefix[3:], b.Bytes()) - copy(keyPrefix[:3], isPendingPrefix) - - // For the database value, store a zero, since the channel is - // no longer pending. - scratch := make([]byte, 4) - byteOrder.PutUint16(scratch[:2], uint16(0)) - if err := openChanBucket.Put(keyPrefix, scratch[:2]); err != nil { - return err - } - - // Finally, we'll also store the opening height for this - // channel as well. - confInfoKey := make([]byte, len(confInfoPrefix)+len(b.Bytes())) - copy(confInfoKey[:len(confInfoPrefix)], confInfoPrefix) - copy(confInfoKey[len(confInfoPrefix):], b.Bytes()) - - confInfoBytes := openChanBucket.Get(confInfoKey) - infoCopy := make([]byte, len(confInfoBytes)) - copy(infoCopy[:], confInfoBytes) - - byteOrder.PutUint64(infoCopy[4:], openLoc.ToUint64()) - - return openChanBucket.Put(confInfoKey, infoCopy) - }) -} - // FetchClosedChannels attempts to fetch all closed channels from the database. // The pendingOnly bool toggles if channels that aren't yet fully closed should // be returned int he response or not. When a channel was cooperatively closed,