htlcswitch: move retransmissionTests var into scope of test

This commit is contained in:
Olaoluwa Osuntokun 2017-11-10 15:20:27 -08:00
parent fceec1306d
commit 5e2b2a5cc8
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1718,21 +1718,31 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
} }
} }
var retransmissionTests = []struct { // TestChannelRetransmission tests the ability of the channel links to
// synchronize theirs states after abrupt disconnect.
func TestChannelRetransmission(t *testing.T) {
t.Parallel()
retransmissionTests := []struct {
name string name string
messages []expectedMessage messages []expectedMessage
}{ }{
{ {
// Tests the ability of the channel links states to be synchronized // Tests the ability of the channel links states to be
// after remote node haven't receive revoke and ack message. // synchronized after remote node haven't receive
// revoke and ack message.
name: "intercept last alice revoke_and_ack", name: "intercept last alice revoke_and_ack",
messages: []expectedMessage{ messages: []expectedMessage{
// First initialization of the channel. // First initialization of the channel.
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
// Send payment from Alice to Bob and intercept the last revocation {"alice", "bob", &lnwire.FundingLocked{}, false},
// message, in this case Bob should not proceed the payment farther. {"bob", "alice", &lnwire.FundingLocked{}, false},
// Send payment from Alice to Bob and intercept
// the last revocation message, in this case
// Bob should not proceed the payment farther.
{"alice", "bob", &lnwire.UpdateAddHTLC{}, false}, {"alice", "bob", &lnwire.UpdateAddHTLC{}, false},
{"alice", "bob", &lnwire.CommitSig{}, false}, {"alice", "bob", &lnwire.CommitSig{}, false},
{"bob", "alice", &lnwire.RevokeAndAck{}, false}, {"bob", "alice", &lnwire.RevokeAndAck{}, false},
@ -1743,12 +1753,14 @@ var retransmissionTests = []struct {
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
// Alice should resend the revoke_and_ack message to Bob because Bob // Alice should resend the revoke_and_ack
// claimed it in the reestbalish message. // message to Bob because Bob claimed it in the
// reestbalish message.
{"alice", "bob", &lnwire.RevokeAndAck{}, false}, {"alice", "bob", &lnwire.RevokeAndAck{}, false},
// Proceed the payment farther by sending the fulfilment message and // Proceed the payment farther by sending the
// trigger the state update. // fulfilment message and trigger the state
// update.
{"bob", "alice", &lnwire.UpdateFufillHTLC{}, false}, {"bob", "alice", &lnwire.UpdateFufillHTLC{}, false},
{"bob", "alice", &lnwire.CommitSig{}, false}, {"bob", "alice", &lnwire.CommitSig{}, false},
{"alice", "bob", &lnwire.RevokeAndAck{}, false}, {"alice", "bob", &lnwire.RevokeAndAck{}, false},
@ -1757,19 +1769,25 @@ var retransmissionTests = []struct {
}, },
}, },
{ {
// Tests the ability of the channel links states to be synchronized // Tests the ability of the channel links states to be
// after remote node haven't receive revoke and ack message. // synchronized after remote node haven't receive
// revoke and ack message.
name: "intercept bob revoke_and_ack commit_sig messages", name: "intercept bob revoke_and_ack commit_sig messages",
messages: []expectedMessage{ messages: []expectedMessage{
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
// Send payment from Alice to Bob and intercept the last revocation {"alice", "bob", &lnwire.FundingLocked{}, false},
// message, in this case Bob should not proceed the payment farther. {"bob", "alice", &lnwire.FundingLocked{}, false},
// Send payment from Alice to Bob and intercept
// the last revocation message, in this case
// Bob should not proceed the payment farther.
{"alice", "bob", &lnwire.UpdateAddHTLC{}, false}, {"alice", "bob", &lnwire.UpdateAddHTLC{}, false},
{"alice", "bob", &lnwire.CommitSig{}, false}, {"alice", "bob", &lnwire.CommitSig{}, false},
// Intercept bob commit sig and revoke and ack messages. // Intercept bob commit sig and revoke and ack
// messages.
{"bob", "alice", &lnwire.RevokeAndAck{}, true}, {"bob", "alice", &lnwire.RevokeAndAck{}, true},
{"bob", "alice", &lnwire.CommitSig{}, true}, {"bob", "alice", &lnwire.CommitSig{}, true},
@ -1781,8 +1799,9 @@ var retransmissionTests = []struct {
{"bob", "alice", &lnwire.RevokeAndAck{}, false}, {"bob", "alice", &lnwire.RevokeAndAck{}, false},
{"bob", "alice", &lnwire.CommitSig{}, false}, {"bob", "alice", &lnwire.CommitSig{}, false},
// Proceed the payment farther by sending the fulfilment message and // Proceed the payment farther by sending the
// trigger the state update. // fulfilment message and trigger the state
// update.
{"alice", "bob", &lnwire.RevokeAndAck{}, false}, {"alice", "bob", &lnwire.RevokeAndAck{}, false},
{"bob", "alice", &lnwire.UpdateFufillHTLC{}, false}, {"bob", "alice", &lnwire.UpdateFufillHTLC{}, false},
{"bob", "alice", &lnwire.CommitSig{}, false}, {"bob", "alice", &lnwire.CommitSig{}, false},
@ -1792,25 +1811,33 @@ var retransmissionTests = []struct {
}, },
}, },
{ {
// Tests the ability of the channel links states to be synchronized // Tests the ability of the channel links states to be
// after remote node haven't receive update and commit sig messages. // synchronized after remote node haven't receive
// update and commit sig messages.
name: "intercept update add htlc and commit sig messages", name: "intercept update add htlc and commit sig messages",
messages: []expectedMessage{ messages: []expectedMessage{
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
// Attempt make a payment from Alice to Bob, which is intercepted, {"alice", "bob", &lnwire.FundingLocked{}, false},
// emulating the Bob server abrupt stop. {"bob", "alice", &lnwire.FundingLocked{}, false},
// Attempt make a payment from Alice to Bob,
// which is intercepted, emulating the Bob
// server abrupt stop.
{"alice", "bob", &lnwire.UpdateAddHTLC{}, true}, {"alice", "bob", &lnwire.UpdateAddHTLC{}, true},
{"alice", "bob", &lnwire.CommitSig{}, true}, {"alice", "bob", &lnwire.CommitSig{}, true},
// Restart of the nodes, and after that nodes should exchange the // Restart of the nodes, and after that nodes
// reestablish messages. // should exchange the reestablish messages.
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
// After Bob has notified Alice that he didn't receive updates Alice {"alice", "bob", &lnwire.FundingLocked{}, false},
// should re-send them. {"bob", "alice", &lnwire.FundingLocked{}, false},
// After Bob has notified Alice that he didn't
// receive updates Alice should re-send them.
{"alice", "bob", &lnwire.UpdateAddHTLC{}, false}, {"alice", "bob", &lnwire.UpdateAddHTLC{}, false},
{"alice", "bob", &lnwire.CommitSig{}, false}, {"alice", "bob", &lnwire.CommitSig{}, false},
@ -1826,12 +1853,6 @@ var retransmissionTests = []struct {
}, },
}, },
} }
// TestChannelRetransmission tests the ability of the channel links to
// synchronize theirs states after abrupt disconnect.
func TestChannelRetransmission(t *testing.T) {
t.Parallel()
paymentWithRestart := func(t *testing.T, messages []expectedMessage) { paymentWithRestart := func(t *testing.T, messages []expectedMessage) {
channels, cleanUp, restoreChannelsFromDb, err := createClusterChannels( channels, cleanUp, restoreChannelsFromDb, err := createClusterChannels(
btcutil.SatoshiPerBitcoin*5, btcutil.SatoshiPerBitcoin*5,