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.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-09 20:24:12 -08:00
parent 4ae0b008ed
commit 2dcd82e779
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 12 additions and 46 deletions

@ -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
}

@ -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,