mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-17 04:11:42 +02:00
peer_test.go: fixes to coop close tests, modifying variable names
to either be alice or bob-prefixed. This helps an observer understand what the test is actually doing.
This commit is contained in:
parent
ac72479b10
commit
ac3d416b04
400
peer_test.go
400
peer_test.go
@ -7,13 +7,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
|
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
@ -40,7 +40,7 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
broadcastTxChan := make(chan *wire.MsgTx)
|
broadcastTxChan := make(chan *wire.MsgTx)
|
||||||
|
|
||||||
responder, responderChan, initiatorChan, cleanUp, err := createTestPeer(
|
alicePeer, _, bobChan, cleanUp, err := createTestPeer(
|
||||||
notifier, broadcastTxChan, noUpdate,
|
notifier, broadcastTxChan, noUpdate,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,19 +48,19 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
chanID := lnwire.NewChanIDFromOutPoint(responderChan.ChannelPoint())
|
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
|
||||||
|
|
||||||
// We send a shutdown request to Alice. She will now be the responding
|
// We send a shutdown request to Alice. She will now be the responding
|
||||||
// node in this shutdown procedure. We first expect Alice to answer
|
// node in this shutdown procedure. We first expect Alice to answer
|
||||||
// this shutdown request with a Shutdown message.
|
// this shutdown request with a Shutdown message.
|
||||||
responder.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: lnwire.NewShutdown(chanID, dummyDeliveryScript),
|
msg: lnwire.NewShutdown(chanID, dummyDeliveryScript),
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg lnwire.Message
|
var msg lnwire.Message
|
||||||
select {
|
select {
|
||||||
case outMsg := <-responder.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive shutdown message")
|
t.Fatalf("did not receive shutdown message")
|
||||||
@ -77,33 +77,33 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
|||||||
// closing transaction fee. Alice sends the ClosingSigned message as she is
|
// closing transaction fee. Alice sends the ClosingSigned message as she is
|
||||||
// the initiator of the channel.
|
// the initiator of the channel.
|
||||||
select {
|
select {
|
||||||
case outMsg := <-responder.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive ClosingSigned message")
|
t.Fatalf("did not receive ClosingSigned message")
|
||||||
}
|
}
|
||||||
|
|
||||||
responderClosingSigned, ok := msg.(*lnwire.ClosingSigned)
|
respClosingSigned, ok := msg.(*lnwire.ClosingSigned)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We accept the fee, and send a ClosingSigned with the same fee back,
|
// We accept the fee, and send a ClosingSigned with the same fee back,
|
||||||
// so she knows we agreed.
|
// so she knows we agreed.
|
||||||
peerFee := responderClosingSigned.FeeSatoshis
|
aliceFee := respClosingSigned.FeeSatoshis
|
||||||
initiatorSig, _, _, err := initiatorChan.CreateCloseProposal(
|
bobSig, _, _, err := bobChan.CreateCloseProposal(
|
||||||
peerFee, dummyDeliveryScript, respDeliveryScript,
|
aliceFee, dummyDeliveryScript, respDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating close proposal: %v", err)
|
t.Fatalf("error creating close proposal: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedSig, err := lnwire.NewSigFromSignature(initiatorSig)
|
parsedSig, err := lnwire.NewSigFromSignature(bobSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing signature: %v", err)
|
t.Fatalf("error parsing signature: %v", err)
|
||||||
}
|
}
|
||||||
closingSigned := lnwire.NewClosingSigned(chanID, peerFee, parsedSig)
|
closingSigned := lnwire.NewClosingSigned(chanID, aliceFee, parsedSig)
|
||||||
responder.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: closingSigned,
|
msg: closingSigned,
|
||||||
}
|
}
|
||||||
@ -116,7 +116,18 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
|||||||
t.Fatalf("closing tx not broadcast")
|
t.Fatalf("closing tx not broadcast")
|
||||||
}
|
}
|
||||||
|
|
||||||
// And the initiator should be waiting for a confirmation notification.
|
// Need to pull the remaining message off of Alice's outgoing queue.
|
||||||
|
select {
|
||||||
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
|
msg = outMsg.msg
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatalf("did not receive ClosingSigned message")
|
||||||
|
}
|
||||||
|
if _, ok := msg.(*lnwire.ClosingSigned); !ok {
|
||||||
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alice should be waiting in a goroutine for a confirmation.
|
||||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +141,7 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
broadcastTxChan := make(chan *wire.MsgTx)
|
broadcastTxChan := make(chan *wire.MsgTx)
|
||||||
|
|
||||||
initiator, initiatorChan, responderChan, cleanUp, err := createTestPeer(
|
alicePeer, _, bobChan, cleanUp, err := createTestPeer(
|
||||||
notifier, broadcastTxChan, noUpdate,
|
notifier, broadcastTxChan, noUpdate,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -143,17 +154,17 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
|||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
closeCommand := &htlcswitch.ChanClose{
|
closeCommand := &htlcswitch.ChanClose{
|
||||||
CloseType: htlcswitch.CloseRegular,
|
CloseType: htlcswitch.CloseRegular,
|
||||||
ChanPoint: initiatorChan.ChannelPoint(),
|
ChanPoint: bobChan.ChannelPoint(),
|
||||||
Updates: updateChan,
|
Updates: updateChan,
|
||||||
TargetFeePerKw: 12500,
|
TargetFeePerKw: 12500,
|
||||||
Err: errChan,
|
Err: errChan,
|
||||||
}
|
}
|
||||||
initiator.localCloseChanReqs <- closeCommand
|
alicePeer.localCloseChanReqs <- closeCommand
|
||||||
|
|
||||||
// We can now pull a Shutdown message off of Alice's outgoingQueue.
|
// We can now pull a Shutdown message off of Alice's outgoingQueue.
|
||||||
var msg lnwire.Message
|
var msg lnwire.Message
|
||||||
select {
|
select {
|
||||||
case outMsg := <-initiator.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive shutdown request")
|
t.Fatalf("did not receive shutdown request")
|
||||||
@ -164,35 +175,45 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
|||||||
t.Fatalf("expected Shutdown message, got %T", msg)
|
t.Fatalf("expected Shutdown message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
initiatorDeliveryScript := shutdownMsg.Address
|
aliceDeliveryScript := shutdownMsg.Address
|
||||||
|
|
||||||
// Bob will respond with his own Shutdown message.
|
// Bob will respond with his own Shutdown message.
|
||||||
chanID := shutdownMsg.ChannelID
|
chanID := shutdownMsg.ChannelID
|
||||||
initiator.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: lnwire.NewShutdown(chanID,
|
msg: lnwire.NewShutdown(chanID,
|
||||||
dummyDeliveryScript),
|
dummyDeliveryScript),
|
||||||
}
|
}
|
||||||
|
|
||||||
estimator := chainfee.NewStaticEstimator(12500, 0)
|
// Alice will reply with a ClosingSigned here.
|
||||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
select {
|
||||||
if err != nil {
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
t.Fatalf("unable to query fee estimator: %v", err)
|
msg = outMsg.msg
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatalf("did not receive closing signed message")
|
||||||
}
|
}
|
||||||
fee := responderChan.CalcFee(feePerKw)
|
closingSignedMsg, ok := msg.(*lnwire.ClosingSigned)
|
||||||
closeSig, _, _, err := responderChan.CreateCloseProposal(fee,
|
if !ok {
|
||||||
dummyDeliveryScript, initiatorDeliveryScript)
|
t.Fatalf("expected to receive closing signed message, got %T", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bob should reply with the exact same fee in his next ClosingSigned
|
||||||
|
// message.
|
||||||
|
bobFee := closingSignedMsg.FeeSatoshis
|
||||||
|
bobSig, _, _, err := bobChan.CreateCloseProposal(
|
||||||
|
bobFee, dummyDeliveryScript, aliceDeliveryScript,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create close proposal: %v", err)
|
t.Fatalf("unable to create close proposal: %v", err)
|
||||||
}
|
}
|
||||||
parsedSig, err := lnwire.NewSigFromSignature(closeSig)
|
parsedSig, err := lnwire.NewSigFromSignature(bobSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to parse signature: %v", err)
|
t.Fatalf("unable to parse signature: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
closingSigned := lnwire.NewClosingSigned(shutdownMsg.ChannelID,
|
closingSigned := lnwire.NewClosingSigned(shutdownMsg.ChannelID,
|
||||||
fee, parsedSig)
|
bobFee, parsedSig)
|
||||||
initiator.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: closingSigned,
|
msg: closingSigned,
|
||||||
}
|
}
|
||||||
@ -202,31 +223,31 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
|||||||
|
|
||||||
// Alice should now broadcast the closing transaction.
|
// Alice should now broadcast the closing transaction.
|
||||||
select {
|
select {
|
||||||
case outMsg := <-initiator.outgoingQueue:
|
|
||||||
msg = outMsg.msg
|
|
||||||
case <-time.After(timeout):
|
|
||||||
t.Fatalf("did not receive closing signed message")
|
|
||||||
}
|
|
||||||
|
|
||||||
closingSignedMsg, ok := msg.(*lnwire.ClosingSigned)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if closingSignedMsg.FeeSatoshis != fee {
|
|
||||||
t.Fatalf("expected ClosingSigned fee to be %v, instead got %v",
|
|
||||||
fee, closingSignedMsg.FeeSatoshis)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The initiator will now see that we agreed on the fee, and broadcast
|
|
||||||
// the closing transaction.
|
|
||||||
select {
|
|
||||||
case <-broadcastTxChan:
|
case <-broadcastTxChan:
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("closing tx not broadcast")
|
t.Fatalf("closing tx not broadcast")
|
||||||
}
|
}
|
||||||
|
|
||||||
// And the initiator should be waiting for a confirmation notification.
|
// Alice should respond with the ClosingSigned they both agreed upon.
|
||||||
|
|
||||||
|
select {
|
||||||
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
|
msg = outMsg.msg
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatalf("did not receive closing signed message")
|
||||||
|
}
|
||||||
|
|
||||||
|
closingSignedMsg, ok = msg.(*lnwire.ClosingSigned)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if closingSignedMsg.FeeSatoshis != bobFee {
|
||||||
|
t.Fatalf("expected ClosingSigned fee to be %v, instead got %v",
|
||||||
|
bobFee, closingSignedMsg.FeeSatoshis)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alice should be waiting on a single confirmation for the coop close tx.
|
||||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +262,7 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
broadcastTxChan := make(chan *wire.MsgTx)
|
broadcastTxChan := make(chan *wire.MsgTx)
|
||||||
|
|
||||||
responder, responderChan, initiatorChan, cleanUp, err := createTestPeer(
|
alicePeer, _, bobChan, cleanUp, err := createTestPeer(
|
||||||
notifier, broadcastTxChan, noUpdate,
|
notifier, broadcastTxChan, noUpdate,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -249,12 +270,12 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
chanID := lnwire.NewChanIDFromOutPoint(responderChan.ChannelPoint())
|
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
|
||||||
|
|
||||||
// We send a shutdown request to Alice. She will now be the responding
|
// Bob sends a shutdown request to Alice. She will now be the responding
|
||||||
// node in this shutdown procedure. We first expect Alice to answer
|
// node in this shutdown procedure. We first expect Alice to answer this
|
||||||
// this shutdown request with a Shutdown message.
|
// Shutdown request with a Shutdown message.
|
||||||
responder.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: lnwire.NewShutdown(chanID,
|
msg: lnwire.NewShutdown(chanID,
|
||||||
dummyDeliveryScript),
|
dummyDeliveryScript),
|
||||||
@ -262,7 +283,7 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
|
|
||||||
var msg lnwire.Message
|
var msg lnwire.Message
|
||||||
select {
|
select {
|
||||||
case outMsg := <-responder.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive shutdown message")
|
t.Fatalf("did not receive shutdown message")
|
||||||
@ -273,38 +294,38 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
t.Fatalf("expected Shutdown message, got %T", msg)
|
t.Fatalf("expected Shutdown message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
respDeliveryScript := shutdownMsg.Address
|
aliceDeliveryScript := shutdownMsg.Address
|
||||||
|
|
||||||
// As Alice is the channel initiator, she will send her ClosingSigned
|
// As Alice is the channel initiator, she will send her ClosingSigned
|
||||||
// message.
|
// message.
|
||||||
select {
|
select {
|
||||||
case outMsg := <-responder.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive closing signed message")
|
t.Fatalf("did not receive closing signed message")
|
||||||
}
|
}
|
||||||
|
|
||||||
responderClosingSigned, ok := msg.(*lnwire.ClosingSigned)
|
aliceClosingSigned, ok := msg.(*lnwire.ClosingSigned)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bob doesn't agree with the fee and will send one back that's 2.5x.
|
// Bob doesn't agree with the fee and will send one back that's 2.5x.
|
||||||
preferredRespFee := responderClosingSigned.FeeSatoshis
|
preferredRespFee := aliceClosingSigned.FeeSatoshis
|
||||||
increasedFee := btcutil.Amount(float64(preferredRespFee) * 2.5)
|
increasedFee := btcutil.Amount(float64(preferredRespFee) * 2.5)
|
||||||
initiatorSig, _, _, err := initiatorChan.CreateCloseProposal(
|
bobSig, _, _, err := bobChan.CreateCloseProposal(
|
||||||
increasedFee, dummyDeliveryScript, respDeliveryScript,
|
increasedFee, dummyDeliveryScript, aliceDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating close proposal: %v", err)
|
t.Fatalf("error creating close proposal: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedSig, err := lnwire.NewSigFromSignature(initiatorSig)
|
parsedSig, err := lnwire.NewSigFromSignature(bobSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing signature: %v", err)
|
t.Fatalf("error parsing signature: %v", err)
|
||||||
}
|
}
|
||||||
closingSigned := lnwire.NewClosingSigned(chanID, increasedFee, parsedSig)
|
closingSigned := lnwire.NewClosingSigned(chanID, increasedFee, parsedSig)
|
||||||
responder.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: closingSigned,
|
msg: closingSigned,
|
||||||
}
|
}
|
||||||
@ -314,41 +335,41 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
// should get a new proposal back, which should have the average fee rate
|
// should get a new proposal back, which should have the average fee rate
|
||||||
// proposed.
|
// proposed.
|
||||||
select {
|
select {
|
||||||
case outMsg := <-responder.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive closing signed message")
|
t.Fatalf("did not receive closing signed message")
|
||||||
}
|
}
|
||||||
|
|
||||||
responderClosingSigned, ok = msg.(*lnwire.ClosingSigned)
|
aliceClosingSigned, ok = msg.(*lnwire.ClosingSigned)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The fee sent by the responder should be less than the fee we just
|
// The fee sent by Alice should be less than the fee Bob just sent as Alice
|
||||||
// sent as it should attempt to compromise.
|
// should attempt to compromise.
|
||||||
peerFee := responderClosingSigned.FeeSatoshis
|
aliceFee := aliceClosingSigned.FeeSatoshis
|
||||||
if peerFee > increasedFee {
|
if aliceFee > increasedFee {
|
||||||
t.Fatalf("new fee should be less than our fee: new=%v, "+
|
t.Fatalf("new fee should be less than our fee: new=%v, "+
|
||||||
"prior=%v", peerFee, increasedFee)
|
"prior=%v", aliceFee, increasedFee)
|
||||||
}
|
}
|
||||||
lastFeeResponder := peerFee
|
lastFeeResponder := aliceFee
|
||||||
|
|
||||||
// We try negotiating a 2.1x fee, which should also be rejected.
|
// We try negotiating a 2.1x fee, which should also be rejected.
|
||||||
increasedFee = btcutil.Amount(float64(preferredRespFee) * 2.1)
|
increasedFee = btcutil.Amount(float64(preferredRespFee) * 2.1)
|
||||||
initiatorSig, _, _, err = initiatorChan.CreateCloseProposal(
|
bobSig, _, _, err = bobChan.CreateCloseProposal(
|
||||||
increasedFee, dummyDeliveryScript, respDeliveryScript,
|
increasedFee, dummyDeliveryScript, aliceDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating close proposal: %v", err)
|
t.Fatalf("error creating close proposal: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedSig, err = lnwire.NewSigFromSignature(initiatorSig)
|
parsedSig, err = lnwire.NewSigFromSignature(bobSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing signature: %v", err)
|
t.Fatalf("error parsing signature: %v", err)
|
||||||
}
|
}
|
||||||
closingSigned = lnwire.NewClosingSigned(chanID, increasedFee, parsedSig)
|
closingSigned = lnwire.NewClosingSigned(chanID, increasedFee, parsedSig)
|
||||||
responder.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: closingSigned,
|
msg: closingSigned,
|
||||||
}
|
}
|
||||||
@ -357,44 +378,44 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
// a new ClosingSigned message. It should be the average of what Bob and
|
// a new ClosingSigned message. It should be the average of what Bob and
|
||||||
// Alice each proposed last time.
|
// Alice each proposed last time.
|
||||||
select {
|
select {
|
||||||
case outMsg := <-responder.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive closing signed message")
|
t.Fatalf("did not receive closing signed message")
|
||||||
}
|
}
|
||||||
|
|
||||||
responderClosingSigned, ok = msg.(*lnwire.ClosingSigned)
|
aliceClosingSigned, ok = msg.(*lnwire.ClosingSigned)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The peer should inch towards our fee, in order to compromise.
|
// Alice should inch towards Bob's fee, in order to compromise.
|
||||||
// Additionally, this fee should be less than the fee we sent prior.
|
// Additionally, this fee should be less than the fee Bob sent before.
|
||||||
peerFee = responderClosingSigned.FeeSatoshis
|
aliceFee = aliceClosingSigned.FeeSatoshis
|
||||||
if peerFee < lastFeeResponder {
|
if aliceFee < lastFeeResponder {
|
||||||
t.Fatalf("new fee should be greater than prior: new=%v, "+
|
t.Fatalf("new fee should be greater than prior: new=%v, "+
|
||||||
"prior=%v", peerFee, lastFeeResponder)
|
"prior=%v", aliceFee, lastFeeResponder)
|
||||||
}
|
}
|
||||||
if peerFee > increasedFee {
|
if aliceFee > increasedFee {
|
||||||
t.Fatalf("new fee should be less than our fee: new=%v, "+
|
t.Fatalf("new fee should be less than Bob's fee: new=%v, "+
|
||||||
"prior=%v", peerFee, increasedFee)
|
"prior=%v", aliceFee, increasedFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, we'll accept the fee by echoing back the same fee that they
|
// Finally, Bob will accept the fee by echoing back the same fee that Alice
|
||||||
// sent to us.
|
// just sent over.
|
||||||
initiatorSig, _, _, err = initiatorChan.CreateCloseProposal(
|
bobSig, _, _, err = bobChan.CreateCloseProposal(
|
||||||
peerFee, dummyDeliveryScript, respDeliveryScript,
|
aliceFee, dummyDeliveryScript, aliceDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating close proposal: %v", err)
|
t.Fatalf("error creating close proposal: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedSig, err = lnwire.NewSigFromSignature(initiatorSig)
|
parsedSig, err = lnwire.NewSigFromSignature(bobSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing signature: %v", err)
|
t.Fatalf("error parsing signature: %v", err)
|
||||||
}
|
}
|
||||||
closingSigned = lnwire.NewClosingSigned(chanID, peerFee, parsedSig)
|
closingSigned = lnwire.NewClosingSigned(chanID, aliceFee, parsedSig)
|
||||||
responder.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: closingSigned,
|
msg: closingSigned,
|
||||||
}
|
}
|
||||||
@ -407,7 +428,18 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
t.Fatalf("closing tx not broadcast")
|
t.Fatalf("closing tx not broadcast")
|
||||||
}
|
}
|
||||||
|
|
||||||
// And the responder should be waiting for a confirmation notification.
|
// Alice should respond with the ClosingSigned they both agreed upon.
|
||||||
|
select {
|
||||||
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
|
msg = outMsg.msg
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatalf("did not receive closing signed message")
|
||||||
|
}
|
||||||
|
if _, ok := msg.(*lnwire.ClosingSigned); !ok {
|
||||||
|
t.Fatalf("expected to receive closing signed message, got %T", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alice should be waiting on a single confirmation for the coop close tx.
|
||||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,7 +454,7 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
broadcastTxChan := make(chan *wire.MsgTx)
|
broadcastTxChan := make(chan *wire.MsgTx)
|
||||||
|
|
||||||
initiator, initiatorChan, responderChan, cleanUp, err := createTestPeer(
|
alicePeer, _, bobChan, cleanUp, err := createTestPeer(
|
||||||
notifier, broadcastTxChan, noUpdate,
|
notifier, broadcastTxChan, noUpdate,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -435,18 +467,18 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
closeCommand := &htlcswitch.ChanClose{
|
closeCommand := &htlcswitch.ChanClose{
|
||||||
CloseType: htlcswitch.CloseRegular,
|
CloseType: htlcswitch.CloseRegular,
|
||||||
ChanPoint: initiatorChan.ChannelPoint(),
|
ChanPoint: bobChan.ChannelPoint(),
|
||||||
Updates: updateChan,
|
Updates: updateChan,
|
||||||
TargetFeePerKw: 12500,
|
TargetFeePerKw: 12500,
|
||||||
Err: errChan,
|
Err: errChan,
|
||||||
}
|
}
|
||||||
|
|
||||||
initiator.localCloseChanReqs <- closeCommand
|
alicePeer.localCloseChanReqs <- closeCommand
|
||||||
|
|
||||||
// We should now be getting the shutdown request.
|
// Alice should now send a Shutdown request to Bob.
|
||||||
var msg lnwire.Message
|
var msg lnwire.Message
|
||||||
select {
|
select {
|
||||||
case outMsg := <-initiator.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive shutdown request")
|
t.Fatalf("did not receive shutdown request")
|
||||||
@ -457,47 +489,20 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
t.Fatalf("expected Shutdown message, got %T", msg)
|
t.Fatalf("expected Shutdown message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
initiatorDeliveryScript := shutdownMsg.Address
|
aliceDeliveryScript := shutdownMsg.Address
|
||||||
|
|
||||||
// We'll answer the shutdown message with our own Shutdown, and then a
|
// Bob will answer the Shutdown message with his own Shutdown.
|
||||||
// ClosingSigned message.
|
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
|
||||||
chanID := lnwire.NewChanIDFromOutPoint(initiatorChan.ChannelPoint())
|
|
||||||
respShutdown := lnwire.NewShutdown(chanID, dummyDeliveryScript)
|
respShutdown := lnwire.NewShutdown(chanID, dummyDeliveryScript)
|
||||||
initiator.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: respShutdown,
|
msg: respShutdown,
|
||||||
}
|
}
|
||||||
|
|
||||||
estimator := chainfee.NewStaticEstimator(12500, 0)
|
// Alice should now respond with a ClosingSigned message with her ideal
|
||||||
initiatorIdealFeeRate, err := estimator.EstimateFeePerKW(1)
|
// fee rate.
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to query fee estimator: %v", err)
|
|
||||||
}
|
|
||||||
initiatorIdealFee := responderChan.CalcFee(initiatorIdealFeeRate)
|
|
||||||
increasedFee := btcutil.Amount(float64(initiatorIdealFee) * 2.5)
|
|
||||||
closeSig, _, _, err := responderChan.CreateCloseProposal(
|
|
||||||
increasedFee, dummyDeliveryScript, initiatorDeliveryScript,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("error creating close proposal: %v", err)
|
|
||||||
}
|
|
||||||
parsedSig, err := lnwire.NewSigFromSignature(closeSig)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to parse signature: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
closingSigned := lnwire.NewClosingSigned(
|
|
||||||
shutdownMsg.ChannelID, increasedFee, parsedSig,
|
|
||||||
)
|
|
||||||
initiator.chanCloseMsgs <- &closeMsg{
|
|
||||||
cid: chanID,
|
|
||||||
msg: closingSigned,
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should get two closing signed messages, the first will be the
|
|
||||||
// ideal fee sent by the initiator in response to our shutdown request.
|
|
||||||
select {
|
select {
|
||||||
case outMsg := <-initiator.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive closing signed")
|
t.Fatalf("did not receive closing signed")
|
||||||
@ -506,16 +511,35 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
}
|
}
|
||||||
if closingSignedMsg.FeeSatoshis != initiatorIdealFee {
|
|
||||||
t.Fatalf("expected ClosingSigned fee to be %v, instead got %v",
|
|
||||||
initiatorIdealFee, closingSignedMsg.FeeSatoshis)
|
|
||||||
}
|
|
||||||
lastFeeSent := closingSignedMsg.FeeSatoshis
|
|
||||||
|
|
||||||
// The second message should be the compromise fee sent in response to
|
idealFeeRate := closingSignedMsg.FeeSatoshis
|
||||||
// them receiving our fee proposal.
|
lastReceivedFee := idealFeeRate
|
||||||
|
|
||||||
|
increasedFee := btcutil.Amount(float64(idealFeeRate) * 2.1)
|
||||||
|
lastSentFee := increasedFee
|
||||||
|
|
||||||
|
bobSig, _, _, err := bobChan.CreateCloseProposal(
|
||||||
|
increasedFee, dummyDeliveryScript, aliceDeliveryScript,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating close proposal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
parsedSig, err := lnwire.NewSigFromSignature(bobSig)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to parse signature: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
closingSigned := lnwire.NewClosingSigned(chanID, increasedFee, parsedSig)
|
||||||
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
|
cid: chanID,
|
||||||
|
msg: closingSigned,
|
||||||
|
}
|
||||||
|
|
||||||
|
// It still won't be accepted, and we should get a new proposal, the
|
||||||
|
// average of what we proposed, and what they proposed last time.
|
||||||
select {
|
select {
|
||||||
case outMsg := <-initiator.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive closing signed")
|
t.Fatalf("did not receive closing signed")
|
||||||
@ -525,35 +549,36 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The peer should inch towards our fee, in order to compromise.
|
aliceFee := closingSignedMsg.FeeSatoshis
|
||||||
// Additionally, this fee should be less than the fee we sent prior.
|
if aliceFee < lastReceivedFee {
|
||||||
peerFee := closingSignedMsg.FeeSatoshis
|
t.Fatalf("new fee should be greater than prior: new=%v, old=%v",
|
||||||
if peerFee < lastFeeSent {
|
aliceFee, lastReceivedFee)
|
||||||
t.Fatalf("new fee should be greater than prior: new=%v, "+
|
|
||||||
"prior=%v", peerFee, lastFeeSent)
|
|
||||||
}
|
}
|
||||||
if peerFee > increasedFee {
|
if aliceFee > lastSentFee {
|
||||||
t.Fatalf("new fee should be less than our fee: new=%v, "+
|
t.Fatalf("new fee should be less than our fee: new=%v, old=%v",
|
||||||
"prior=%v", peerFee, increasedFee)
|
aliceFee, lastSentFee)
|
||||||
}
|
}
|
||||||
lastFeeSent = closingSignedMsg.FeeSatoshis
|
|
||||||
|
|
||||||
// We try negotiating a 2.1x fee, which should also be rejected.
|
lastReceivedFee = aliceFee
|
||||||
increasedFee = btcutil.Amount(float64(initiatorIdealFee) * 2.1)
|
|
||||||
responderSig, _, _, err := responderChan.CreateCloseProposal(
|
// We'll try negotiating a 1.5x fee, which should also be rejected.
|
||||||
increasedFee, dummyDeliveryScript, initiatorDeliveryScript,
|
increasedFee = btcutil.Amount(float64(idealFeeRate) * 1.5)
|
||||||
|
lastSentFee = increasedFee
|
||||||
|
|
||||||
|
bobSig, _, _, err = bobChan.CreateCloseProposal(
|
||||||
|
increasedFee, dummyDeliveryScript, aliceDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating close proposal: %v", err)
|
t.Fatalf("error creating close proposal: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedSig, err = lnwire.NewSigFromSignature(responderSig)
|
parsedSig, err = lnwire.NewSigFromSignature(bobSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing signature: %v", err)
|
t.Fatalf("error parsing signature: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
closingSigned = lnwire.NewClosingSigned(chanID, increasedFee, parsedSig)
|
closingSigned = lnwire.NewClosingSigned(chanID, increasedFee, parsedSig)
|
||||||
initiator.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: closingSigned,
|
msg: closingSigned,
|
||||||
}
|
}
|
||||||
@ -562,44 +587,41 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
// proposal which is the average of what Bob proposed and Alice proposed
|
// proposal which is the average of what Bob proposed and Alice proposed
|
||||||
// last time.
|
// last time.
|
||||||
select {
|
select {
|
||||||
case outMsg := <-initiator.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive closing signed")
|
t.Fatalf("did not receive closing signed")
|
||||||
}
|
}
|
||||||
|
closingSignedMsg, ok = msg.(*lnwire.ClosingSigned)
|
||||||
initiatorClosingSigned, ok := msg.(*lnwire.ClosingSigned)
|
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
t.Fatalf("expected ClosingSigned message, got %T", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once again, the fee sent by the initiator should be greater than the
|
aliceFee = closingSignedMsg.FeeSatoshis
|
||||||
// last fee they sent, but less than the last fee we sent.
|
if aliceFee < lastReceivedFee {
|
||||||
peerFee = initiatorClosingSigned.FeeSatoshis
|
t.Fatalf("new fee should be greater than prior: new=%v, old=%v",
|
||||||
if peerFee < lastFeeSent {
|
aliceFee, lastReceivedFee)
|
||||||
t.Fatalf("new fee should be greater than prior: new=%v, "+
|
|
||||||
"prior=%v", peerFee, lastFeeSent)
|
|
||||||
}
|
}
|
||||||
if peerFee > increasedFee {
|
if aliceFee > lastSentFee {
|
||||||
t.Fatalf("new fee should be less than our fee: new=%v, "+
|
t.Fatalf("new fee should be less than Bob's fee: new=%v, old=%v",
|
||||||
"prior=%v", peerFee, increasedFee)
|
aliceFee, lastSentFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, we'll accept their fee by sending back a CloseSigned
|
// Bob will now accept their fee by sending back a ClosingSigned message
|
||||||
// message with an identical fee.
|
// with an identical fee.
|
||||||
responderSig, _, _, err = responderChan.CreateCloseProposal(
|
bobSig, _, _, err = bobChan.CreateCloseProposal(
|
||||||
peerFee, dummyDeliveryScript, initiatorDeliveryScript,
|
aliceFee, dummyDeliveryScript, aliceDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating close proposal: %v", err)
|
t.Fatalf("error creating close proposal: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedSig, err = lnwire.NewSigFromSignature(responderSig)
|
parsedSig, err = lnwire.NewSigFromSignature(bobSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing signature: %v", err)
|
t.Fatalf("error parsing signature: %v", err)
|
||||||
}
|
}
|
||||||
closingSigned = lnwire.NewClosingSigned(chanID, peerFee, parsedSig)
|
closingSigned = lnwire.NewClosingSigned(chanID, aliceFee, parsedSig)
|
||||||
initiator.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: closingSigned,
|
msg: closingSigned,
|
||||||
}
|
}
|
||||||
@ -610,6 +632,20 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("closing tx not broadcast")
|
t.Fatalf("closing tx not broadcast")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Alice should respond with the ClosingSigned they both agreed upon.
|
||||||
|
select {
|
||||||
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
|
msg = outMsg.msg
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatalf("did not receive closing signed message")
|
||||||
|
}
|
||||||
|
if _, ok := msg.(*lnwire.ClosingSigned); !ok {
|
||||||
|
t.Fatalf("expected to receive closing signed message, got %T", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alice should be waiting on a single confirmation for the coop close tx.
|
||||||
|
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestChooseDeliveryScript tests that chooseDeliveryScript correctly errors
|
// TestChooseDeliveryScript tests that chooseDeliveryScript correctly errors
|
||||||
@ -752,7 +788,7 @@ func TestCustomShutdownScript(t *testing.T) {
|
|||||||
broadcastTxChan := make(chan *wire.MsgTx)
|
broadcastTxChan := make(chan *wire.MsgTx)
|
||||||
|
|
||||||
// Open a channel.
|
// Open a channel.
|
||||||
initiator, initiatorChan, _, cleanUp, err := createTestPeer(
|
alicePeer, _, bobChan, cleanUp, err := createTestPeer(
|
||||||
notifier, broadcastTxChan, test.update,
|
notifier, broadcastTxChan, test.update,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -764,7 +800,7 @@ func TestCustomShutdownScript(t *testing.T) {
|
|||||||
// a specified delivery address.
|
// a specified delivery address.
|
||||||
updateChan := make(chan interface{}, 1)
|
updateChan := make(chan interface{}, 1)
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
chanPoint := initiatorChan.ChannelPoint()
|
chanPoint := bobChan.ChannelPoint()
|
||||||
closeCommand := htlcswitch.ChanClose{
|
closeCommand := htlcswitch.ChanClose{
|
||||||
CloseType: htlcswitch.CloseRegular,
|
CloseType: htlcswitch.CloseRegular,
|
||||||
ChanPoint: chanPoint,
|
ChanPoint: chanPoint,
|
||||||
@ -776,11 +812,11 @@ func TestCustomShutdownScript(t *testing.T) {
|
|||||||
|
|
||||||
// Send the close command for the correct channel and check that a
|
// Send the close command for the correct channel and check that a
|
||||||
// shutdown message is sent.
|
// shutdown message is sent.
|
||||||
initiator.localCloseChanReqs <- &closeCommand
|
alicePeer.localCloseChanReqs <- &closeCommand
|
||||||
|
|
||||||
var msg lnwire.Message
|
var msg lnwire.Message
|
||||||
select {
|
select {
|
||||||
case outMsg := <-initiator.outgoingQueue:
|
case outMsg := <-alicePeer.outgoingQueue:
|
||||||
msg = outMsg.msg
|
msg = outMsg.msg
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
t.Fatalf("did not receive shutdown message")
|
t.Fatalf("did not receive shutdown message")
|
||||||
@ -824,7 +860,7 @@ func genScript(t *testing.T, address string) lnwire.DeliveryAddress {
|
|||||||
// Generate an address which can be used for testing.
|
// Generate an address which can be used for testing.
|
||||||
deliveryAddr, err := btcutil.DecodeAddress(
|
deliveryAddr, err := btcutil.DecodeAddress(
|
||||||
address,
|
address,
|
||||||
activeNetParams.Params,
|
&chaincfg.TestNet3Params,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("invalid delivery address: %v", err)
|
t.Fatalf("invalid delivery address: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user