Skip to content

Commit

Permalink
Merge pull request lightningnetwork#3087 from joostjager/move-itest
Browse files Browse the repository at this point in the history
lntest: move itest into package
  • Loading branch information
cfromknecht authored May 29, 2019
2 parents f8287b0 + dff0387 commit f802ebd
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 177 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ _testmain.go

# Integration test log files
output*.log
/.backendlogs
/.minerlogs
lntest/itest/.backendlogs
lntest/itest/.minerlogs

cmd/cmd
*.key
Expand Down
15 changes: 11 additions & 4 deletions chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ import (
)

const (
defaultBitcoinMinHTLCMSat = lnwire.MilliSatoshi(1000)
defaultBitcoinBaseFeeMSat = lnwire.MilliSatoshi(1000)
defaultBitcoinFeeRate = lnwire.MilliSatoshi(1)
defaultBitcoinTimeLockDelta = 40
defaultBitcoinMinHTLCMSat = lnwire.MilliSatoshi(1000)

// DefaultBitcoinBaseFeeMSat is the default forwarding base fee.
DefaultBitcoinBaseFeeMSat = lnwire.MilliSatoshi(1000)

// DefaultBitcoinFeeRate is the default forwarding fee rate.
DefaultBitcoinFeeRate = lnwire.MilliSatoshi(1)

// DefaultBitcoinTimeLockDelta is the default forwarding time lock
// delta.
DefaultBitcoinTimeLockDelta = 40

defaultLitecoinMinHTLCMSat = lnwire.MilliSatoshi(1000)
defaultLitecoinBaseFeeMSat = lnwire.MilliSatoshi(1000)
Expand Down
72 changes: 38 additions & 34 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,27 @@ import (
)

const (
defaultConfigFilename = "lnd.conf"
defaultDataDirname = "data"
defaultChainSubDirname = "chain"
defaultGraphSubDirname = "graph"
defaultTLSCertFilename = "tls.cert"
defaultTLSKeyFilename = "tls.key"
defaultAdminMacFilename = "admin.macaroon"
defaultReadMacFilename = "readonly.macaroon"
defaultInvoiceMacFilename = "invoice.macaroon"
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "lnd.log"
defaultRPCPort = 10009
defaultRESTPort = 8080
defaultPeerPort = 9735
defaultRPCHost = "localhost"
defaultMaxPendingChannels = 1
defaultConfigFilename = "lnd.conf"
defaultDataDirname = "data"
defaultChainSubDirname = "chain"
defaultGraphSubDirname = "graph"
defaultTLSCertFilename = "tls.cert"
defaultTLSKeyFilename = "tls.key"
defaultAdminMacFilename = "admin.macaroon"
defaultReadMacFilename = "readonly.macaroon"
defaultInvoiceMacFilename = "invoice.macaroon"
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "lnd.log"
defaultRPCPort = 10009
defaultRESTPort = 8080
defaultPeerPort = 9735
defaultRPCHost = "localhost"

// DefaultMaxPendingChannels is the default maximum number of incoming
// pending channels permitted per peer.
DefaultMaxPendingChannels = 1

defaultNoSeedBackup = false
defaultTrickleDelay = 90 * 1000
defaultChanStatusSampleInterval = time.Minute
Expand All @@ -68,14 +72,14 @@ const (
defaultTorV2PrivateKeyFilename = "v2_onion_private_key"
defaultTorV3PrivateKeyFilename = "v3_onion_private_key"

// defaultIncomingBroadcastDelta defines the number of blocks before the
// DefaultIncomingBroadcastDelta defines the number of blocks before the
// expiry of an incoming htlc at which we force close the channel. We
// only go to chain if we also have the preimage to actually pull in the
// htlc. BOLT #2 suggests 7 blocks. We use a few more for extra safety.
// Within this window we need to get our sweep or 2nd level success tx
// confirmed, because after that the remote party is also able to claim
// the htlc using the timeout path.
defaultIncomingBroadcastDelta = 10
DefaultIncomingBroadcastDelta = 10

// defaultFinalCltvRejectDelta defines the number of blocks before the
// expiry of an incoming exit hop htlc at which we cancel it back
Expand All @@ -90,17 +94,17 @@ const (
// window, we may still force close the channel. There is currently no
// way to reject an UpdateAddHtlc of which we already know that it will
// push us in the broadcast window.
defaultFinalCltvRejectDelta = defaultIncomingBroadcastDelta + 3
defaultFinalCltvRejectDelta = DefaultIncomingBroadcastDelta + 3

// defaultOutgoingBroadcastDelta defines the number of blocks before the
// DefaultOutgoingBroadcastDelta defines the number of blocks before the
// expiry of an outgoing htlc at which we force close the channel. We
// are not in a hurry to force close, because there is nothing to claim
// for us. We do need to time the htlc out, because there may be an
// incoming htlc that will time out too (albeit later). Bolt #2 suggests
// a value of -1 here, but we allow one block less to prevent potential
// confusion around the negative value. It means we force close the
// channel at exactly the htlc expiry height.
defaultOutgoingBroadcastDelta = 0
DefaultOutgoingBroadcastDelta = 0

// defaultOutgoingCltvRejectDelta defines the number of blocks before
// the expiry of an outgoing htlc at which we don't want to offer it to
Expand All @@ -111,7 +115,7 @@ const (
// value of 0. We pad it a bit, to prevent a slow round trip to the next
// peer and a block arriving during that round trip to trigger force
// closure.
defaultOutgoingCltvRejectDelta = defaultOutgoingBroadcastDelta + 3
defaultOutgoingCltvRejectDelta = DefaultOutgoingBroadcastDelta + 3

// minTimeLockDelta is the minimum timelock we require for incoming
// HTLCs on our channels.
Expand Down Expand Up @@ -330,9 +334,9 @@ func loadConfig() (*config, error) {
MaxLogFileSize: defaultMaxLogFileSize,
Bitcoin: &chainConfig{
MinHTLC: defaultBitcoinMinHTLCMSat,
BaseFee: defaultBitcoinBaseFeeMSat,
FeeRate: defaultBitcoinFeeRate,
TimeLockDelta: defaultBitcoinTimeLockDelta,
BaseFee: DefaultBitcoinBaseFeeMSat,
FeeRate: DefaultBitcoinFeeRate,
TimeLockDelta: DefaultBitcoinTimeLockDelta,
Node: "btcd",
},
BtcdMode: &btcdConfig{
Expand Down Expand Up @@ -360,7 +364,7 @@ func loadConfig() (*config, error) {
Dir: defaultLitecoindDir,
RPCHost: defaultRPCHost,
},
MaxPendingChannels: defaultMaxPendingChannels,
MaxPendingChannels: DefaultMaxPendingChannels,
NoSeedBackup: defaultNoSeedBackup,
MinBackoff: defaultMinBackoff,
MaxBackoff: defaultMaxBackoff,
Expand All @@ -371,7 +375,7 @@ func loadConfig() (*config, error) {
MaxChannels: 5,
Allocation: 0.6,
MinChannelSize: int64(minChanFundingSize),
MaxChannelSize: int64(maxFundingAmount),
MaxChannelSize: int64(MaxFundingAmount),
Heuristic: map[string]float64{
"preferential": 1.0,
},
Expand Down Expand Up @@ -535,8 +539,8 @@ func loadConfig() (*config, error) {
if cfg.Autopilot.MinChannelSize < int64(minChanFundingSize) {
cfg.Autopilot.MinChannelSize = int64(minChanFundingSize)
}
if cfg.Autopilot.MaxChannelSize > int64(maxFundingAmount) {
cfg.Autopilot.MaxChannelSize = int64(maxFundingAmount)
if cfg.Autopilot.MaxChannelSize > int64(MaxFundingAmount) {
cfg.Autopilot.MaxChannelSize = int64(MaxFundingAmount)
}

if _, err := validateAtplCfg(cfg.Autopilot); err != nil {
Expand Down Expand Up @@ -720,8 +724,8 @@ func loadConfig() (*config, error) {
// Finally we'll register the litecoin chain as our current
// primary chain.
registeredChains.RegisterPrimaryChain(litecoinChain)
maxFundingAmount = maxLtcFundingAmount
maxPaymentMSat = maxLtcPaymentMSat
MaxFundingAmount = maxLtcFundingAmount
MaxPaymentMSat = maxLtcPaymentMSat

case cfg.Bitcoin.Active:
// Multiple networks can't be selected simultaneously. Count
Expand Down Expand Up @@ -855,8 +859,8 @@ func loadConfig() (*config, error) {
if cfg.Autopilot.MinChannelSize < int64(minChanFundingSize) {
cfg.Autopilot.MinChannelSize = int64(minChanFundingSize)
}
if cfg.Autopilot.MaxChannelSize > int64(maxFundingAmount) {
cfg.Autopilot.MaxChannelSize = int64(maxFundingAmount)
if cfg.Autopilot.MaxChannelSize > int64(MaxFundingAmount) {
cfg.Autopilot.MaxChannelSize = int64(MaxFundingAmount)
}

// Validate profile port number.
Expand Down
12 changes: 6 additions & 6 deletions fundingmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ const (
// created over the RPC interface.
minChanFundingSize = btcutil.Amount(20000)

// maxBtcFundingAmount is a soft-limit of the maximum channel size
// MaxBtcFundingAmount is a soft-limit of the maximum channel size
// currently accepted on the Bitcoin chain within the Lightning
// Protocol. This limit is defined in BOLT-0002, and serves as an
// initial precautionary limit while implementations are battle tested
// in the real world.
maxBtcFundingAmount = btcutil.Amount(1<<24) - 1
MaxBtcFundingAmount = btcutil.Amount(1<<24) - 1

// maxLtcFundingAmount is a soft-limit of the maximum channel size
// currently accepted on the Litecoin chain within the Lightning
// Protocol.
maxLtcFundingAmount = maxBtcFundingAmount * btcToLtcConversionRate
maxLtcFundingAmount = MaxBtcFundingAmount * btcToLtcConversionRate
)

var (
// maxFundingAmount is a soft-limit of the maximum channel size
// MaxFundingAmount is a soft-limit of the maximum channel size
// currently accepted within the Lightning Protocol. This limit is
// defined in BOLT-0002, and serves as an initial precautionary limit
// while implementations are battle tested in the real world.
Expand All @@ -80,7 +80,7 @@ var (
// to the value under the Bitcoin chain as default.
//
// TODO(roasbeef): add command line param to modify
maxFundingAmount = maxBtcFundingAmount
MaxFundingAmount = MaxBtcFundingAmount

// ErrFundingManagerShuttingDown is an error returned when attempting to
// process a funding request/message but the funding manager has already
Expand Down Expand Up @@ -1023,7 +1023,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {

// We'll reject any request to create a channel that's above the
// current soft-limit for channel size.
if msg.FundingAmount > maxFundingAmount {
if msg.FundingAmount > MaxFundingAmount {
f.failFundingFlow(
fmsg.peer, fmsg.msg.PendingChannelID,
lnwire.ErrChanTooLarge,
Expand Down
32 changes: 16 additions & 16 deletions fundingmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ func assertHandleFundingLocked(t *testing.T, alice, bob *testNode) {
}

func TestFundingManagerNormalWorkflow(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1101,7 +1101,7 @@ func TestFundingManagerNormalWorkflow(t *testing.T) {
}

func TestFundingManagerRestartBehavior(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// Run through the process of opening the channel, up until the funding
Expand Down Expand Up @@ -1239,7 +1239,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
// server to notify when the peer comes online, in case sending the
// fundingLocked message fails the first time.
func TestFundingManagerOfflinePeer(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// Run through the process of opening the channel, up until the funding
Expand Down Expand Up @@ -1373,7 +1373,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
// will properly clean up a zombie reservation that times out after the
// initFundingMsg has been handled.
func TestFundingManagerPeerTimeoutAfterInitFunding(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1433,7 +1433,7 @@ func TestFundingManagerPeerTimeoutAfterInitFunding(t *testing.T) {
// will properly clean up a zombie reservation that times out after the
// fundingOpenMsg has been handled.
func TestFundingManagerPeerTimeoutAfterFundingOpen(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1502,7 +1502,7 @@ func TestFundingManagerPeerTimeoutAfterFundingOpen(t *testing.T) {
// will properly clean up a zombie reservation that times out after the
// fundingAcceptMsg has been handled.
func TestFundingManagerPeerTimeoutAfterFundingAccept(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1576,7 +1576,7 @@ func TestFundingManagerPeerTimeoutAfterFundingAccept(t *testing.T) {
}

func TestFundingManagerFundingTimeout(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1621,7 +1621,7 @@ func TestFundingManagerFundingTimeout(t *testing.T) {
// the channel initiator, that it does not timeout when the lnd restarts.
func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) {

alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1688,7 +1688,7 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) {
// continues to operate as expected in case we receive a duplicate fundingLocked
// message.
func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1780,7 +1780,7 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) {
// handles receiving a fundingLocked after the its own fundingLocked and channel
// announcement is sent and gets restarted.
func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1857,7 +1857,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
// fundingManager continues to operate as expected after it has received
// fundingLocked and then gets restarted.
func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -1930,7 +1930,7 @@ func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) {
// (a channel not supposed to be announced to the rest of the network),
// the announcementSignatures nor the nodeAnnouncement messages are sent.
func TestFundingManagerPrivateChannel(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -2032,7 +2032,7 @@ func TestFundingManagerPrivateChannel(t *testing.T) {
// announcement signatures nor the node announcement messages are sent upon
// restart.
func TestFundingManagerPrivateRestart(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// We will consume the channel updates as we go, so no buffering is needed.
Expand Down Expand Up @@ -2154,7 +2154,7 @@ func TestFundingManagerPrivateRestart(t *testing.T) {
// TestFundingManagerCustomChannelParameters checks that custom requirements we
// specify during the channel funding flow is preserved correcly on both sides.
func TestFundingManagerCustomChannelParameters(t *testing.T) {
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// This is the custom parameters we'll use.
Expand Down Expand Up @@ -2544,7 +2544,7 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) {
// option, namely that non-zero incoming push amounts are disabled.
func TestFundingManagerRejectPush(t *testing.T) {
// Enable 'rejectpush' option and initialize funding managers.
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
rejectPush := cfg.RejectPush
cfg.RejectPush = true
defer func() {
Expand Down Expand Up @@ -2606,7 +2606,7 @@ func TestFundingManagerRejectPush(t *testing.T) {
func TestFundingManagerMaxConfs(t *testing.T) {
t.Parallel()

alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
alice, bob := setupFundingManagers(t, DefaultMaxPendingChannels)
defer tearDownFundingManagers(t, alice, bob)

// Create a funding request and start the workflow.
Expand Down
Loading

0 comments on commit f802ebd

Please sign in to comment.