2020-06-17 02:33:06 +02:00
|
|
|
package chancloser
|
2019-12-03 10:38:29 +01:00
|
|
|
|
|
|
|
import (
|
2022-06-10 20:17:20 +02:00
|
|
|
"bytes"
|
2022-07-27 01:39:36 +02:00
|
|
|
"fmt"
|
2019-12-03 10:38:29 +01:00
|
|
|
"testing"
|
|
|
|
|
2022-07-27 01:39:36 +02:00
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
2022-06-10 20:17:20 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
2022-07-27 01:39:36 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2022-06-10 20:17:20 +02:00
|
|
|
"github.com/btcsuite/btcd/txscript"
|
2022-07-27 01:39:36 +02:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
2022-07-27 01:39:36 +02:00
|
|
|
"github.com/lightningnetwork/lnd/input"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
2019-12-03 10:38:29 +01:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2022-05-05 22:11:50 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-12-03 10:38:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestMaybeMatchScript tests that the maybeMatchScript errors appropriately
|
|
|
|
// when an upfront shutdown script is set and the script provided does not
|
|
|
|
// match, and does not error in any other case.
|
|
|
|
func TestMaybeMatchScript(t *testing.T) {
|
2022-07-27 01:39:36 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-06-10 20:17:20 +02:00
|
|
|
pubHash := bytes.Repeat([]byte{0x0}, 20)
|
|
|
|
scriptHash := bytes.Repeat([]byte{0x0}, 32)
|
|
|
|
|
|
|
|
p2wkh, err := txscript.NewScriptBuilder().AddOp(txscript.OP_0).
|
|
|
|
AddData(pubHash).Script()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
p2wsh, err := txscript.NewScriptBuilder().AddOp(txscript.OP_0).
|
|
|
|
AddData(scriptHash).Script()
|
|
|
|
require.NoError(t, err)
|
2019-12-03 10:38:29 +01:00
|
|
|
|
2022-06-10 20:17:20 +02:00
|
|
|
p2tr, err := txscript.NewScriptBuilder().AddOp(txscript.OP_1).
|
|
|
|
AddData(scriptHash).Script()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
p2OtherV1, err := txscript.NewScriptBuilder().AddOp(txscript.OP_1).
|
|
|
|
AddData(pubHash).Script()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
invalidFork, err := txscript.NewScriptBuilder().AddOp(txscript.OP_NOP).
|
|
|
|
AddData(scriptHash).Script()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
type testCase struct {
|
2019-12-03 10:38:29 +01:00
|
|
|
name string
|
|
|
|
shutdownScript lnwire.DeliveryAddress
|
|
|
|
upfrontScript lnwire.DeliveryAddress
|
|
|
|
expectedErr error
|
2022-06-10 20:17:20 +02:00
|
|
|
}
|
|
|
|
tests := []testCase{
|
2019-12-03 10:38:29 +01:00
|
|
|
{
|
|
|
|
name: "no upfront shutdown set, script ok",
|
2022-06-10 20:17:20 +02:00
|
|
|
shutdownScript: p2wkh,
|
2019-12-03 10:38:29 +01:00
|
|
|
upfrontScript: []byte{},
|
|
|
|
expectedErr: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "upfront shutdown set, script ok",
|
2022-06-10 20:17:20 +02:00
|
|
|
shutdownScript: p2wkh,
|
|
|
|
upfrontScript: p2wkh,
|
2019-12-03 10:38:29 +01:00
|
|
|
expectedErr: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "upfront shutdown set, script not ok",
|
2022-06-10 20:17:20 +02:00
|
|
|
shutdownScript: p2wkh,
|
|
|
|
upfrontScript: p2wsh,
|
2020-06-11 21:25:05 +02:00
|
|
|
expectedErr: ErrUpfrontShutdownScriptMismatch,
|
2019-12-03 10:38:29 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "nil shutdown and empty upfront",
|
|
|
|
shutdownScript: nil,
|
|
|
|
upfrontScript: []byte{},
|
|
|
|
expectedErr: nil,
|
|
|
|
},
|
2022-06-10 20:17:20 +02:00
|
|
|
{
|
|
|
|
name: "p2tr is ok",
|
|
|
|
shutdownScript: p2tr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit v1 is ok",
|
|
|
|
shutdownScript: p2OtherV1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid script not allowed",
|
|
|
|
shutdownScript: invalidFork,
|
|
|
|
expectedErr: ErrInvalidShutdownScript,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// All future segwit softforks should also be ok.
|
|
|
|
futureForks := []byte{
|
|
|
|
txscript.OP_1, txscript.OP_2, txscript.OP_3, txscript.OP_4,
|
|
|
|
txscript.OP_5, txscript.OP_6, txscript.OP_7, txscript.OP_8,
|
|
|
|
txscript.OP_9, txscript.OP_10, txscript.OP_11, txscript.OP_12,
|
|
|
|
txscript.OP_13, txscript.OP_14, txscript.OP_15, txscript.OP_16,
|
|
|
|
}
|
|
|
|
for _, witnessVersion := range futureForks {
|
|
|
|
p2FutureFork, err := txscript.NewScriptBuilder().AddOp(witnessVersion).
|
|
|
|
AddData(scriptHash).Script()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
opString, err := txscript.DisasmString([]byte{witnessVersion})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tests = append(tests, testCase{
|
|
|
|
name: fmt.Sprintf("witness_version=%v", opString),
|
|
|
|
shutdownScript: p2FutureFork,
|
|
|
|
})
|
2019-12-03 10:38:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2022-07-27 01:39:36 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-06-10 20:17:20 +02:00
|
|
|
err := validateShutdownScript(
|
2019-12-03 10:38:29 +01:00
|
|
|
func() error { return nil }, test.upfrontScript,
|
2022-06-10 20:17:20 +02:00
|
|
|
test.shutdownScript, &chaincfg.SimNetParams,
|
2019-12-03 10:38:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != test.expectedErr {
|
|
|
|
t.Fatalf("Error: %v, expected error: %v", err, test.expectedErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-27 01:39:36 +02:00
|
|
|
|
|
|
|
type mockChannel struct {
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
chanPoint wire.OutPoint
|
|
|
|
initiator bool
|
|
|
|
scid lnwire.ShortChannelID
|
2022-07-27 01:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) ChannelPoint() *wire.OutPoint {
|
|
|
|
return &m.chanPoint
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) MarkCoopBroadcasted(*wire.MsgTx, bool) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) IsInitiator() bool {
|
|
|
|
return m.initiator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) ShortChanID() lnwire.ShortChannelID {
|
|
|
|
return m.scid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) AbsoluteThawHeight() (uint32, error) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) RemoteUpfrontShutdownScript() lnwire.DeliveryAddress {
|
|
|
|
return lnwire.DeliveryAddress{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) CreateCloseProposal(fee btcutil.Amount,
|
|
|
|
localScript, remoteScript []byte,
|
|
|
|
) (input.Signature, *chainhash.Hash, btcutil.Amount, error) {
|
|
|
|
|
|
|
|
return nil, nil, 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) CompleteCooperativeClose(localSig,
|
|
|
|
remoteSig input.Signature, localScript, remoteScript []byte,
|
|
|
|
proposedFee btcutil.Amount) (*wire.MsgTx, btcutil.Amount, error) {
|
|
|
|
|
|
|
|
return nil, 0, nil
|
|
|
|
}
|
|
|
|
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
func (m *mockChannel) LocalBalanceDust() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockChannel) RemoteBalanceDust() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockCoopFeeEstimator struct {
|
|
|
|
targetFee btcutil.Amount
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockCoopFeeEstimator) EstimateFee(chanType channeldb.ChannelType,
|
|
|
|
localTxOut, remoteTxOut *wire.TxOut,
|
|
|
|
idealFeeRate chainfee.SatPerKWeight) btcutil.Amount {
|
|
|
|
|
|
|
|
return m.targetFee
|
|
|
|
}
|
|
|
|
|
2022-07-27 01:39:36 +02:00
|
|
|
// TestMaxFeeClamp tests that if a max fee is specified, then it's used instead
|
|
|
|
// of the default max fee multiplier.
|
|
|
|
func TestMaxFeeClamp(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
const (
|
|
|
|
absoluteFeeOneSatByte = 126
|
|
|
|
absoluteFeeTenSatByte = 1265
|
|
|
|
)
|
2022-07-27 01:39:36 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
|
|
|
|
idealFee chainfee.SatPerKWeight
|
|
|
|
inputMaxFee chainfee.SatPerKWeight
|
|
|
|
|
|
|
|
maxFee btcutil.Amount
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
// No max fee specified, we should see 3x the ideal fee.
|
|
|
|
name: "no max fee",
|
|
|
|
|
|
|
|
idealFee: chainfee.SatPerKWeight(253),
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
maxFee: absoluteFeeOneSatByte * defaultMaxFeeMultiplier,
|
|
|
|
},
|
|
|
|
{
|
2022-07-27 01:39:36 +02:00
|
|
|
// Max fee specified, this should be used in place.
|
|
|
|
name: "max fee clamp",
|
|
|
|
|
|
|
|
idealFee: chainfee.SatPerKWeight(253),
|
|
|
|
inputMaxFee: chainfee.SatPerKWeight(2530),
|
|
|
|
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
// We should get the resulting absolute fee based on a
|
|
|
|
// factor of 10 sat/byte (our new max fee).
|
|
|
|
maxFee: absoluteFeeTenSatByte,
|
2022-07-27 01:39:36 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
test := test
|
|
|
|
|
2022-07-27 01:39:36 +02:00
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
channel := mockChannel{}
|
2022-07-27 01:39:36 +02:00
|
|
|
|
|
|
|
chanCloser := NewChanCloser(
|
|
|
|
ChanCloseCfg{
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
Channel: &channel,
|
|
|
|
MaxFee: test.inputMaxFee,
|
|
|
|
FeeEstimator: &SimpleCoopFeeEstimator{},
|
2022-07-27 01:39:36 +02:00
|
|
|
}, nil, test.idealFee, 0, nil, false,
|
|
|
|
)
|
|
|
|
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
// We'll call initFeeBaseline early here since we need
|
|
|
|
// the populate these internal variables.
|
|
|
|
chanCloser.initFeeBaseline()
|
|
|
|
|
2022-07-27 01:39:36 +02:00
|
|
|
require.Equal(t, test.maxFee, chanCloser.maxFee)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestMaxFeeBailOut tests that once the negotiated fee rate rises above our
|
|
|
|
// maximum fee, we'll return an error and refuse to process a co-op close
|
|
|
|
// message.
|
|
|
|
func TestMaxFeeBailOut(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
const (
|
|
|
|
absoluteFee = btcutil.Amount(1000)
|
|
|
|
idealFee = chainfee.SatPerKWeight(253)
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, isInitiator := range []bool{true, false} {
|
2022-10-07 02:42:06 +02:00
|
|
|
isInitiator := isInitiator
|
|
|
|
|
2022-07-27 01:39:36 +02:00
|
|
|
t.Run(fmt.Sprintf("initiator=%v", isInitiator), func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
// First, we'll make our mock channel, and use that to
|
|
|
|
// instantiate our channel closer.
|
|
|
|
closeCfg := ChanCloseCfg{
|
|
|
|
Channel: &mockChannel{
|
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.
To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.
We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.
The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.
Fixes #6953
2022-09-30 04:49:44 +02:00
|
|
|
initiator: isInitiator,
|
|
|
|
},
|
|
|
|
FeeEstimator: &mockCoopFeeEstimator{
|
|
|
|
targetFee: absoluteFee,
|
2022-07-27 01:39:36 +02:00
|
|
|
},
|
|
|
|
MaxFee: idealFee * 2,
|
|
|
|
}
|
|
|
|
chanCloser := NewChanCloser(
|
|
|
|
closeCfg, nil, idealFee, 0, nil, false,
|
|
|
|
)
|
|
|
|
|
|
|
|
// We'll now force the channel state into the
|
|
|
|
// closeFeeNegotiation state so we can skip straight to
|
|
|
|
// the juicy part. We'll also set our last fee sent so
|
|
|
|
// we'll attempt to actually "negotiate" here.
|
|
|
|
chanCloser.state = closeFeeNegotiation
|
|
|
|
chanCloser.lastFeeProposal = absoluteFee
|
|
|
|
|
|
|
|
// Next, we'll make a ClosingSigned message that
|
|
|
|
// proposes a fee that's above the specified max fee.
|
|
|
|
//
|
|
|
|
// NOTE: We use the absoluteFee here since our mock
|
|
|
|
// always returns this fee for the CalcFee method which
|
|
|
|
// is used to translate a fee rate
|
|
|
|
// into an absolute fee amount in sats.
|
|
|
|
closeMsg := &lnwire.ClosingSigned{
|
|
|
|
FeeSatoshis: absoluteFee * 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err := chanCloser.ProcessCloseMsg(closeMsg)
|
|
|
|
|
|
|
|
switch isInitiator {
|
|
|
|
// If we're the initiator, then we expect an error at
|
|
|
|
// this point.
|
|
|
|
case true:
|
|
|
|
require.ErrorIs(t, err, ErrProposalExeceedsMaxFee)
|
|
|
|
|
|
|
|
// Otherwise, we expect things to fail for some other
|
|
|
|
// reason (invalid sig, etc).
|
|
|
|
case false:
|
|
|
|
require.NotErrorIs(t, err, ErrProposalExeceedsMaxFee)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-12-23 12:26:55 +01:00
|
|
|
|
|
|
|
// TestParseUpfrontShutdownAddress tests the we are able to parse the upfront
|
|
|
|
// shutdown address properly.
|
|
|
|
func TestParseUpfrontShutdownAddress(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var (
|
|
|
|
testnetAddress = "tb1qdfkmwwgdaa5dnezrlhtftvmj5qn2kwgp7n0z6r"
|
|
|
|
regtestAddress = "bcrt1q09crvvuj95x5nk64wsxf5n6ky0kr8358vpx4d8"
|
|
|
|
)
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
address string
|
|
|
|
params chaincfg.Params
|
|
|
|
expectedErr string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid closing address",
|
|
|
|
address: "non-valid-address",
|
|
|
|
params: chaincfg.RegressionNetParams,
|
|
|
|
expectedErr: "invalid address",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "closing address from another net",
|
|
|
|
address: testnetAddress,
|
|
|
|
params: chaincfg.RegressionNetParams,
|
|
|
|
expectedErr: "not a regtest address",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "valid p2wkh closing address",
|
|
|
|
address: regtestAddress,
|
|
|
|
params: chaincfg.RegressionNetParams,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
tc := tc
|
|
|
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
_, err := ParseUpfrontShutdownAddress(
|
|
|
|
tc.address, &tc.params,
|
|
|
|
)
|
|
|
|
|
|
|
|
if tc.expectedErr != "" {
|
|
|
|
require.ErrorContains(t, err, tc.expectedErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|