lnwallet/chancloser: add fee rate to ClosePending
This'll be useful to communicate what the new fee rate is to an RPC caller.
This commit is contained in:
1 parent
8b2ade7ec9
commit
27b24ab86a
2 files changed
+20
-1
No files matched your search
@@ -663,6 +663,9 @@ type LocalOfferSent struct {
|
|||||||
// ProposedFee is the fee we proposed to the remote party.
|
// ProposedFee is the fee we proposed to the remote party.
|
||||||
ProposedFee btcutil.Amount
|
ProposedFee btcutil.Amount
|
||||||
|
|
||||||
|
// ProposedFeeRate is the fee rate we proposed to the remote party.
|
||||||
|
ProposedFeeRate chainfee.SatPerVByte
|
||||||
|
|
||||||
// LocalSig is the signature we sent to the remote party.
|
// LocalSig is the signature we sent to the remote party.
|
||||||
LocalSig lnwire.Sig
|
LocalSig lnwire.Sig
|
||||||
}
|
}
|
||||||
@@ -706,6 +709,9 @@ func (l *LocalOfferSent) IsTerminal() bool {
|
|||||||
type ClosePending struct {
|
type ClosePending struct {
|
||||||
// CloseTx is the pending close transaction.
|
// CloseTx is the pending close transaction.
|
||||||
CloseTx *wire.MsgTx
|
CloseTx *wire.MsgTx
|
||||||
|
|
||||||
|
// FeeRate is the fee rate of the closing transaction.
|
||||||
|
FeeRate chainfee.SatPerVByte
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the name of the state for ClosePending.
|
// String returns the name of the state for ClosePending.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/mempool"
|
"github.com/btcsuite/btcd/mempool"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
@@ -14,6 +15,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnutils"
|
"github.com/lightningnetwork/lnd/lnutils"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/protofsm"
|
"github.com/lightningnetwork/lnd/protofsm"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
@@ -171,7 +173,7 @@ func (c *ChannelActive) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
}
|
}
|
||||||
|
|
||||||
chancloserLog.Infof("ChannelPoint(%v): sending shutdown msg, "+
|
chancloserLog.Infof("ChannelPoint(%v): sending shutdown msg, "+
|
||||||
"delivery_script=%v", env.ChanPoint, shutdownScript)
|
"delivery_script=%x", env.ChanPoint, shutdownScript)
|
||||||
|
|
||||||
// From here, we'll transition to the shutdown pending state. In
|
// From here, we'll transition to the shutdown pending state. In
|
||||||
// this state we await their shutdown message (self loop), then
|
// this state we await their shutdown message (self loop), then
|
||||||
@@ -730,6 +732,7 @@ func (l *LocalCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
return &CloseStateTransition{
|
return &CloseStateTransition{
|
||||||
NextState: &LocalOfferSent{
|
NextState: &LocalOfferSent{
|
||||||
ProposedFee: absoluteFee,
|
ProposedFee: absoluteFee,
|
||||||
|
ProposedFeeRate: msg.TargetFeeRate,
|
||||||
LocalSig: wireSig,
|
LocalSig: wireSig,
|
||||||
CloseChannelTerms: l.CloseChannelTerms,
|
CloseChannelTerms: l.CloseChannelTerms,
|
||||||
},
|
},
|
||||||
@@ -839,6 +842,7 @@ func (l *LocalOfferSent) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
return &CloseStateTransition{
|
return &CloseStateTransition{
|
||||||
NextState: &ClosePending{
|
NextState: &ClosePending{
|
||||||
CloseTx: closeTx,
|
CloseTx: closeTx,
|
||||||
|
FeeRate: l.ProposedFeeRate,
|
||||||
},
|
},
|
||||||
NewEvents: fn.Some(protofsm.EmittedEvent[ProtocolEvent]{
|
NewEvents: fn.Some(protofsm.EmittedEvent[ProtocolEvent]{
|
||||||
ExternalEvents: broadcastEvent,
|
ExternalEvents: broadcastEvent,
|
||||||
@@ -995,11 +999,20 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
sendEvent, broadcastEvent,
|
sendEvent, broadcastEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We'll also compute the final fee rate that the remote party
|
||||||
|
// paid based off the absolute fee and the size of the closing
|
||||||
|
// transaction.
|
||||||
|
vSize := mempool.GetTxVirtualSize(btcutil.NewTx(closeTx))
|
||||||
|
feeRate := chainfee.SatPerVByte(
|
||||||
|
int64(msg.SigMsg.FeeSatoshis) / vSize,
|
||||||
|
)
|
||||||
|
|
||||||
// Now that we've extracted the signature, we'll transition to
|
// Now that we've extracted the signature, we'll transition to
|
||||||
// the next state where we'll sign+broadcast the sig.
|
// the next state where we'll sign+broadcast the sig.
|
||||||
return &CloseStateTransition{
|
return &CloseStateTransition{
|
||||||
NextState: &ClosePending{
|
NextState: &ClosePending{
|
||||||
CloseTx: closeTx,
|
CloseTx: closeTx,
|
||||||
|
FeeRate: feeRate,
|
||||||
},
|
},
|
||||||
NewEvents: fn.Some(protofsm.EmittedEvent[ProtocolEvent]{
|
NewEvents: fn.Some(protofsm.EmittedEvent[ProtocolEvent]{
|
||||||
ExternalEvents: daemonEvents,
|
ExternalEvents: daemonEvents,
|
||||||
|
|||||||
Reference in new issue
Block a user