fundingmanager_test: verify max HTLC in ChannelUpdates

In this commit, we verify that ChannelUpdates for newly
funded channels contain the max HTLC that we expect.
We expect the max HTLC value of each ChannelUpdate to
equal the maximum pending msats in HTLCs required by
the remote peer.

Co-authored-by: Johan T. Halseth <johanth@gmail.com>
This commit is contained in:
Valentine Wallace 2019-01-12 18:59:46 +01:00 committed by Johan T. Halseth
parent a66a1e113f
commit 4fb1536f54
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -433,6 +433,7 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) {
FeeRate: 1000,
TimeLockDelta: 10,
},
RequiredRemoteMaxValue: oldCfg.RequiredRemoteMaxValue,
PublishTransaction: func(txn *wire.MsgTx) error {
publishChan <- txn
return nil
@ -819,7 +820,8 @@ func assertAddedToRouterGraph(t *testing.T, alice, bob *testNode,
// advertised value will be checked against the other node's default min_htlc
// value.
func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
customMinHtlc ...lnwire.MilliSatoshi) {
capacity btcutil.Amount, customMinHtlc ...lnwire.MilliSatoshi) {
t.Helper()
// After the FundingLocked message is sent, Alice and Bob will each
// send the following messages to their gossiper:
@ -871,6 +873,24 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
minHtlc, m.HtlcMinimumMsat)
}
// The MaxHTLC value should at this point
// _always_ be the same as the
// maxValueInFlight capacity.
if m.MessageFlags != 1 {
t.Fatalf("expected message flags to "+
"be 1, was %v", m.MessageFlags)
}
maxPendingMsat := alice.fundingMgr.cfg.RequiredRemoteMaxValue(
capacity,
)
if maxPendingMsat != m.HtlcMaximumMsat {
t.Fatalf("expected ChannelUpdate to "+
"advertise max HTLC %v, had %v",
maxPendingMsat,
m.HtlcMaximumMsat)
}
gotChannelUpdate = true
}
}
@ -1005,8 +1025,11 @@ func TestFundingManagerNormalWorkflow(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
true)
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, true)
// Check that neither Alice nor Bob sent an error message.
assertErrorNotSent(t, alice.msgChan)
@ -1037,7 +1060,7 @@ func TestFundingManagerNormalWorkflow(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// Check that the state machine is updated accordingly
assertAddedToRouterGraph(t, alice, bob, fundingOutPoint)
@ -1072,9 +1095,12 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
updateChan := make(chan *lnrpc.OpenStatusUpdate)
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
true)
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, true)
// After the funding transaction gets mined, both nodes will send the
// fundingLocked message to the other peer. If the funding node fails
@ -1175,7 +1201,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// Check that the state machine is updated accordingly
assertAddedToRouterGraph(t, alice, bob, fundingOutPoint)
@ -1207,9 +1233,12 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
updateChan := make(chan *lnrpc.OpenStatusUpdate)
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
true)
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, true)
// After the funding transaction gets mined, both nodes will send the
// fundingLocked message to the other peer. If the funding node fails
@ -1299,7 +1328,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// Check that the state machine is updated accordingly
assertAddedToRouterGraph(t, alice, bob, fundingOutPoint)
@ -1656,8 +1685,11 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
true)
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, true)
// Notify that transaction was mined
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{}
@ -1684,7 +1716,7 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// Check that the state machine is updated accordingly
assertAddedToRouterGraph(t, alice, bob, fundingOutPoint)
@ -1745,8 +1777,11 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
true)
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, true)
// Notify that transaction was mined
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{}
@ -1773,7 +1808,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// Check that the state machine is updated accordingly
assertAddedToRouterGraph(t, alice, bob, fundingOutPoint)
@ -1819,8 +1854,11 @@ func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
true)
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, true)
// Notify that transaction was mined
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{}
@ -1860,7 +1898,7 @@ func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// Check that the state machine is updated accordingly
assertAddedToRouterGraph(t, alice, bob, fundingOutPoint)
@ -1889,8 +1927,11 @@ func TestFundingManagerPrivateChannel(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
false)
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, false)
// Notify that transaction was mined
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{}
@ -1917,7 +1958,7 @@ func TestFundingManagerPrivateChannel(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// The funding transaction is now confirmed, wait for the
// OpenStatusUpdate_ChanOpen update
@ -1988,8 +2029,11 @@ func TestFundingManagerPrivateRestart(t *testing.T) {
// Run through the process of opening the channel, up until the funding
// transaction is broadcasted.
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
false)
localAmt := btcutil.Amount(500000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
fundingOutPoint := openChannel(t, alice, bob, localAmt, pushAmt, 1,
updateChan, false)
// Notify that transaction was mined
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{}
@ -2016,7 +2060,7 @@ func TestFundingManagerPrivateRestart(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
assertChannelAnnouncements(t, alice, bob)
assertChannelAnnouncements(t, alice, bob, capacity)
// Note: We don't check for the addedToRouterGraph state because in
// the private channel mode, the state is quickly changed from
@ -2110,14 +2154,18 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
// needed.
updateChan := make(chan *lnrpc.OpenStatusUpdate)
localAmt := btcutil.Amount(5000000)
pushAmt := btcutil.Amount(0)
capacity := localAmt + pushAmt
// Create a funding request with the custom parameters and start the
// workflow.
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
localFundingAmt: 5000000,
pushAmt: lnwire.NewMSatFromSatoshis(0),
localFundingAmt: localAmt,
pushAmt: lnwire.NewMSatFromSatoshis(pushAmt),
private: false,
minHtlc: minHtlc,
remoteCsvDelay: csvDelay,
@ -2313,7 +2361,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
// announcements. Alice should advertise the default MinHTLC value of
// 5, while bob should advertise the value minHtlc, since Alice
// required him to use it.
assertChannelAnnouncements(t, alice, bob, 5, minHtlc)
assertChannelAnnouncements(t, alice, bob, capacity, 5, minHtlc)
// The funding transaction is now confirmed, wait for the
// OpenStatusUpdate_ChanOpen update