multi: extract new DeriveHeightHint() function, use for new rbf closer
With this commit, we make sure we set the right height hint, even if the channel is a zero conf channel.
This commit is contained in:
1 parent
b2794b07cb
commit
8432e706d3
3 files changed
+37
-29
No files matched your search
@@ -4104,6 +4104,34 @@ func (c *OpenChannel) AbsoluteThawHeight() (uint32, error) {
|
|||||||
return c.ThawHeight, nil
|
return c.ThawHeight, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeriveHeightHint derives the block height for the channel opening.
|
||||||
|
func (c *OpenChannel) DeriveHeightHint() uint32 {
|
||||||
|
// As a height hint, we'll try to use the opening height, but if the
|
||||||
|
// channel isn't yet open, then we'll use the height it was broadcast
|
||||||
|
// at. This may be an unconfirmed zero-conf channel.
|
||||||
|
heightHint := c.ShortChanID().BlockHeight
|
||||||
|
if heightHint == 0 {
|
||||||
|
heightHint = c.BroadcastHeight()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since no zero-conf state is stored in a channel backup, the below
|
||||||
|
// logic will not be triggered for restored, zero-conf channels. Set
|
||||||
|
// the height hint for zero-conf channels.
|
||||||
|
if c.IsZeroConf() {
|
||||||
|
if c.ZeroConfConfirmed() {
|
||||||
|
// If the zero-conf channel is confirmed, we'll use the
|
||||||
|
// confirmed SCID's block height.
|
||||||
|
heightHint = c.ZeroConfRealScid().BlockHeight
|
||||||
|
} else {
|
||||||
|
// The zero-conf channel is unconfirmed. We'll need to
|
||||||
|
// use the FundingBroadcastHeight.
|
||||||
|
heightHint = c.BroadcastHeight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return heightHint
|
||||||
|
}
|
||||||
|
|
||||||
func putChannelCloseSummary(tx kvdb.RwTx, chanID []byte,
|
func putChannelCloseSummary(tx kvdb.RwTx, chanID []byte,
|
||||||
summary *ChannelCloseSummary, lastChanState *OpenChannel) error {
|
summary *ChannelCloseSummary, lastChanState *OpenChannel) error {
|
||||||
|
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ func newChainWatcher(cfg chainWatcherConfig) (*chainWatcher, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the channel opening block height.
|
// Get the channel opening block height.
|
||||||
heightHint := deriveHeightHint(chanState)
|
heightHint := chanState.DeriveHeightHint()
|
||||||
|
|
||||||
// We'll register for a notification to be dispatched if the funding
|
// We'll register for a notification to be dispatched if the funding
|
||||||
// output is spent.
|
// output is spent.
|
||||||
@@ -1328,34 +1328,6 @@ func deriveFundingPkScript(chanState *channeldb.OpenChannel) ([]byte, error) {
|
|||||||
return fundingPkScript, nil
|
return fundingPkScript, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deriveHeightHint derives the block height for the channel opening.
|
|
||||||
func deriveHeightHint(chanState *channeldb.OpenChannel) uint32 {
|
|
||||||
// As a height hint, we'll try to use the opening height, but if the
|
|
||||||
// channel isn't yet open, then we'll use the height it was broadcast
|
|
||||||
// at. This may be an unconfirmed zero-conf channel.
|
|
||||||
heightHint := chanState.ShortChanID().BlockHeight
|
|
||||||
if heightHint == 0 {
|
|
||||||
heightHint = chanState.BroadcastHeight()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since no zero-conf state is stored in a channel backup, the below
|
|
||||||
// logic will not be triggered for restored, zero-conf channels. Set
|
|
||||||
// the height hint for zero-conf channels.
|
|
||||||
if chanState.IsZeroConf() {
|
|
||||||
if chanState.ZeroConfConfirmed() {
|
|
||||||
// If the zero-conf channel is confirmed, we'll use the
|
|
||||||
// confirmed SCID's block height.
|
|
||||||
heightHint = chanState.ZeroConfRealScid().BlockHeight
|
|
||||||
} else {
|
|
||||||
// The zero-conf channel is unconfirmed. We'll need to
|
|
||||||
// use the FundingBroadcastHeight.
|
|
||||||
heightHint = chanState.BroadcastHeight()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return heightHint
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleCommitSpend takes a spending tx of the funding output and handles the
|
// handleCommitSpend takes a spending tx of the funding output and handles the
|
||||||
// channel close based on the closure type.
|
// channel close based on the closure type.
|
||||||
func (c *chainWatcher) handleCommitSpend(
|
func (c *chainWatcher) handleCommitSpend(
|
||||||
|
|||||||
@@ -9874,6 +9874,14 @@ func (lc *LightningChannel) FundingTxOut() *wire.TxOut {
|
|||||||
return &lc.fundingOutput
|
return &lc.fundingOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeriveHeightHint derives the block height for the channel opening.
|
||||||
|
func (lc *LightningChannel) DeriveHeightHint() uint32 {
|
||||||
|
lc.RLock()
|
||||||
|
defer lc.RUnlock()
|
||||||
|
|
||||||
|
return lc.channelState.DeriveHeightHint()
|
||||||
|
}
|
||||||
|
|
||||||
// MultiSigKeys returns the set of multi-sig keys for an channel.
|
// MultiSigKeys returns the set of multi-sig keys for an channel.
|
||||||
func (lc *LightningChannel) MultiSigKeys() (keychain.KeyDescriptor,
|
func (lc *LightningChannel) MultiSigKeys() (keychain.KeyDescriptor,
|
||||||
keychain.KeyDescriptor) {
|
keychain.KeyDescriptor) {
|
||||||
|
|||||||
Reference in new issue
Block a user