mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-27 18:16:18 +02:00
Merge branch 'refresh-chan-id'
This commit is contained in:
@@ -594,13 +594,16 @@ func (c *OpenChannel) hasChanStatus(status ChannelStatus) bool {
|
||||
return c.chanStatus&status == status
|
||||
}
|
||||
|
||||
// RefreshShortChanID updates the in-memory short channel ID using the latest
|
||||
// RefreshShortChanID updates the in-memory channel state using the latest
|
||||
// value observed on disk.
|
||||
//
|
||||
// TODO: the name of this function should be changed to reflect the fact that
|
||||
// it is not only refreshing the short channel id but all the channel state.
|
||||
// maybe Refresh/Reload?
|
||||
func (c *OpenChannel) RefreshShortChanID() error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
var sid lnwire.ShortChannelID
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
@@ -609,22 +612,18 @@ func (c *OpenChannel) RefreshShortChanID() error {
|
||||
return err
|
||||
}
|
||||
|
||||
channel, err := fetchOpenChannel(chanBucket, &c.FundingOutpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
// We'll re-populating the in-memory channel with the info
|
||||
// fetched from disk.
|
||||
if err := fetchChanInfo(chanBucket, c); err != nil {
|
||||
return fmt.Errorf("unable to fetch chan info: %v", err)
|
||||
}
|
||||
|
||||
sid = channel.ShortChannelID
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.ShortChannelID = sid
|
||||
c.Packager = NewChannelPackager(sid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -939,8 +939,8 @@ func TestFetchWaitingCloseChannels(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestRefreshShortChanID asserts that RefreshShortChanID updates the in-memory
|
||||
// short channel ID of another OpenChannel to reflect a preceding call to
|
||||
// MarkOpen on a different OpenChannel.
|
||||
// state of another OpenChannel to reflect a preceding call to MarkOpen on a
|
||||
// different OpenChannel.
|
||||
func TestRefreshShortChanID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -1038,4 +1038,10 @@ func TestRefreshShortChanID(t *testing.T) {
|
||||
"got %v", chanOpenLoc,
|
||||
pendingChannel.Packager.(*ChannelPackager).source)
|
||||
}
|
||||
|
||||
// Check to ensure that this channel is no longer pending and this field
|
||||
// is up to date.
|
||||
if pendingChannel.IsPending {
|
||||
t.Fatalf("channel pending state wasn't updated: want false got true")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user