fundingmanager test: test that MinHtlc is preserved during flow
This commit is contained in:
parent
3d55767838
commit
ed2cfd74c1
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
@ -282,6 +283,12 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
|||||||
|
|
||||||
return nil, fmt.Errorf("unable to find channel")
|
return nil, fmt.Errorf("unable to find channel")
|
||||||
},
|
},
|
||||||
|
DefaultRoutingPolicy: htlcswitch.ForwardingPolicy{
|
||||||
|
MinHTLC: 5,
|
||||||
|
BaseFee: 100,
|
||||||
|
FeeRate: 1000,
|
||||||
|
TimeLockDelta: 10,
|
||||||
|
},
|
||||||
NumRequiredConfs: func(chanAmt btcutil.Amount,
|
NumRequiredConfs: func(chanAmt btcutil.Amount,
|
||||||
pushAmt lnwire.MilliSatoshi) uint16 {
|
pushAmt lnwire.MilliSatoshi) uint16 {
|
||||||
return 3
|
return 3
|
||||||
@ -1941,8 +1948,9 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
|
|||||||
alice, bob := setupFundingManagers(t)
|
alice, bob := setupFundingManagers(t)
|
||||||
defer tearDownFundingManagers(t, alice, bob)
|
defer tearDownFundingManagers(t, alice, bob)
|
||||||
|
|
||||||
// This is the custom CSV delay we'll use.
|
// This is the custom parameters we'll use.
|
||||||
const csvDelay = 67
|
const csvDelay = 67
|
||||||
|
const minHtlc = 1234
|
||||||
|
|
||||||
// We will consume the channel updates as we go, so no buffering is
|
// We will consume the channel updates as we go, so no buffering is
|
||||||
// needed.
|
// needed.
|
||||||
@ -1957,6 +1965,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
|
|||||||
localFundingAmt: 5000000,
|
localFundingAmt: 5000000,
|
||||||
pushAmt: lnwire.NewMSatFromSatoshis(0),
|
pushAmt: lnwire.NewMSatFromSatoshis(0),
|
||||||
private: false,
|
private: false,
|
||||||
|
minHtlc: minHtlc,
|
||||||
remoteCsvDelay: csvDelay,
|
remoteCsvDelay: csvDelay,
|
||||||
updates: updateChan,
|
updates: updateChan,
|
||||||
err: errChan,
|
err: errChan,
|
||||||
@ -1992,6 +2001,12 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
|
|||||||
csvDelay, openChannelReq.CsvDelay)
|
csvDelay, openChannelReq.CsvDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the custom minHTLC value is sent.
|
||||||
|
if openChannelReq.HtlcMinimum != minHtlc {
|
||||||
|
t.Fatalf("expected OpenChannel to have minHtlc %v, got %v",
|
||||||
|
minHtlc, openChannelReq.HtlcMinimum)
|
||||||
|
}
|
||||||
|
|
||||||
chanID := openChannelReq.PendingChannelID
|
chanID := openChannelReq.PendingChannelID
|
||||||
|
|
||||||
// Let Bob handle the init message.
|
// Let Bob handle the init message.
|
||||||
@ -2008,6 +2023,12 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
|
|||||||
4, acceptChannelResponse.CsvDelay)
|
4, acceptChannelResponse.CsvDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// And the default MinHTLC value of 5.
|
||||||
|
if acceptChannelResponse.HtlcMinimum != 5 {
|
||||||
|
t.Fatalf("expected AcceptChannel to have minHtlc %v, got %v",
|
||||||
|
5, acceptChannelResponse.HtlcMinimum)
|
||||||
|
}
|
||||||
|
|
||||||
// Forward the response to Alice.
|
// Forward the response to Alice.
|
||||||
alice.fundingMgr.processFundingAccept(acceptChannelResponse, bobAddr)
|
alice.fundingMgr.processFundingAccept(acceptChannelResponse, bobAddr)
|
||||||
|
|
||||||
@ -2067,6 +2088,25 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper method for checking the MinHtlc value stored for a
|
||||||
|
// reservation.
|
||||||
|
assertMinHtlc := func(resCtx *reservationWithCtx,
|
||||||
|
expOurMinHtlc, expTheirMinHtlc lnwire.MilliSatoshi) error {
|
||||||
|
|
||||||
|
ourMinHtlc := resCtx.reservation.OurContribution().MinHTLC
|
||||||
|
if ourMinHtlc != expOurMinHtlc {
|
||||||
|
return fmt.Errorf("expected our minHtlc to be %v, "+
|
||||||
|
"was %v", expOurMinHtlc, ourMinHtlc)
|
||||||
|
}
|
||||||
|
|
||||||
|
theirMinHtlc := resCtx.reservation.TheirContribution().MinHTLC
|
||||||
|
if theirMinHtlc != expTheirMinHtlc {
|
||||||
|
return fmt.Errorf("expected their minHtlc to be %v, "+
|
||||||
|
"was %v", expTheirMinHtlc, theirMinHtlc)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Check that the custom channel parameters were properly set in the
|
// Check that the custom channel parameters were properly set in the
|
||||||
// channel reservation.
|
// channel reservation.
|
||||||
resCtx, err := alice.fundingMgr.getReservationCtx(bobPubKey, chanID)
|
resCtx, err := alice.fundingMgr.getReservationCtx(bobPubKey, chanID)
|
||||||
@ -2080,6 +2120,12 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The minimum HTLC value Alice can offer should be 5, and the minimum
|
||||||
|
// Bob can offer should be 1234.
|
||||||
|
if err := assertMinHtlc(resCtx, 5, minHtlc); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Also make sure the parameters are properly set on Bob's end.
|
// Also make sure the parameters are properly set on Bob's end.
|
||||||
resCtx, err = bob.fundingMgr.getReservationCtx(alicePubKey, chanID)
|
resCtx, err = bob.fundingMgr.getReservationCtx(alicePubKey, chanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2089,4 +2135,8 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
|
|||||||
if err := assertDelay(resCtx, csvDelay, 4); err != nil {
|
if err := assertDelay(resCtx, csvDelay, 4); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := assertMinHtlc(resCtx, minHtlc, 5); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user