Skip to content

multi: add deadline for first connection of new LNC conn #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
// DefaultMacaroonFilename is the default file name for the
// autogenerated lit macaroon.
DefaultMacaroonFilename = "lit.macaroon"

defaultFirstLNCConnTimeout = 10 * time.Minute
)

var (
Expand Down Expand Up @@ -153,6 +155,8 @@ type Config struct {

MacaroonPath string `long:"macaroonpath" description:"Path to write the macaroon for litd's RPC and REST services if it doesn't exist."`

FirstLNCConnDeadline time.Duration `long:"firstlncconndeadline" description:"The duration after a new LNC session will be revoked if no connection is made with it. This only applies for the first connection which is made using the pairing phrase. "`

// Network is the Bitcoin network we're running on. This will be parsed
// before the configuration is loaded and will set the correct flag on
// `lnd.bitcoin.mainnet|testnet|regtest` and also for the other daemons.
Expand Down Expand Up @@ -302,21 +306,22 @@ func defaultConfig() *Config {
TLSCertPath: poolDefaultConfig.TLSCertPath,
},
},
Network: DefaultNetwork,
LndMode: DefaultLndMode,
Lnd: &lndDefaultConfig,
LitDir: DefaultLitDir,
LetsEncryptListen: defaultLetsEncryptListen,
LetsEncryptDir: defaultLetsEncryptDir,
MacaroonPath: DefaultMacaroonPath,
ConfigFile: defaultConfigFile,
FaradayMode: defaultFaradayMode,
Faraday: &faradayDefaultConfig,
faradayRpcConfig: &frdrpcserver.Config{},
LoopMode: defaultLoopMode,
Loop: &loopDefaultConfig,
PoolMode: defaultPoolMode,
Pool: &poolDefaultConfig,
Network: DefaultNetwork,
LndMode: DefaultLndMode,
Lnd: &lndDefaultConfig,
LitDir: DefaultLitDir,
LetsEncryptListen: defaultLetsEncryptListen,
LetsEncryptDir: defaultLetsEncryptDir,
MacaroonPath: DefaultMacaroonPath,
ConfigFile: defaultConfigFile,
FaradayMode: defaultFaradayMode,
Faraday: &faradayDefaultConfig,
faradayRpcConfig: &frdrpcserver.Config{},
LoopMode: defaultLoopMode,
Loop: &loopDefaultConfig,
PoolMode: defaultPoolMode,
Pool: &poolDefaultConfig,
FirstLNCConnDeadline: defaultFirstLNCConnTimeout,
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/improbable-eng/grpc-web v0.12.0
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/faraday v0.2.8-alpha.0.20220624141723-ddd3cd123e62
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha.0.20220822151854-c072f70315d8
github.com/lightninglabs/lndclient v0.15.0-10
github.com/lightninglabs/loop v0.19.1-beta.0.20220623090540-08209f61e304
github.com/lightninglabs/loop/swapserverrpc v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ github.com/lightninglabs/faraday v0.2.8-alpha.0.20220624141723-ddd3cd123e62 h1:t
github.com/lightninglabs/faraday v0.2.8-alpha.0.20220624141723-ddd3cd123e62/go.mod h1:9kcDuyINNf4RB6vrmPLAMGZmYgN0oPxhdt3IicL9sQY=
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI/f/O0Avg7t8sqkPo78HFzjmeYFl6DPnc=
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk=
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha h1:d+jKyAvCQMLq5O1IL6ONWM/l4C7Q3Q00HkdjDIG9uTg=
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha/go.mod h1:dgyhE+O4GpWBhS7yIzKCm8LqFHX8/QRwJ6OWFrN+WnA=
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha.0.20220822151854-c072f70315d8 h1:FYZ63sERRC2RjVbsAeO55uF7kTIYCClHmd59dZSsyx0=
github.com/lightninglabs/lightning-node-connect v0.1.11-alpha.0.20220822151854-c072f70315d8/go.mod h1:dgyhE+O4GpWBhS7yIzKCm8LqFHX8/QRwJ6OWFrN+WnA=
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
github.com/lightninglabs/lndclient v0.15.0-0/go.mod h1:ORS/YFe9hAXlzN/Uj+gvTmrnXEml6yD6dWwzCjpTJyQ=
Expand Down
4 changes: 4 additions & 0 deletions itest/litd_mode_integrated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ func runLNCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
connectPhrase := strings.Split(
sessResp.Session.PairingSecretMnemonic, " ",
)

ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
defer cancel()

rawLNCConn, err := connectMailbox(ctxt, connectPhrase)
require.NoError(t, err)

Expand Down
30 changes: 30 additions & 0 deletions itest/litd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ import (
"time"

"github.com/btcsuite/btcd/integration/rpctest"
"github.com/lightninglabs/aperture"
"github.com/lightninglabs/lightning-node-connect/gbn"
"github.com/lightninglabs/lightning-node-connect/mailbox"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/signal"
"github.com/stretchr/testify/require"
)

var interceptor *signal.Interceptor

// TestLightningTerminal performs a series of integration tests amongst a
// programmatically driven network of lnd nodes.
func TestLightningTerminal(t *testing.T) {
Expand Down Expand Up @@ -73,6 +81,7 @@ func TestLightningTerminal(t *testing.T) {
// Now we can set up our test harness (LND instance), with the chain
// backend we just created.
ht := newHarnessTest(t, nil)
ht.setupLogging()
binary := getLitdBinary()
litdHarness, err = NewNetworkHarness(miner, chainBackend, binary)
if err != nil {
Expand Down Expand Up @@ -164,3 +173,24 @@ func TestLightningTerminal(t *testing.T) {
}
}
}

func (h *harnessTest) setupLogging() {
logWriter := build.NewRotatingLogWriter()

if interceptor != nil {
return
}

ic, err := signal.Intercept()
require.NoError(h.t, err)
interceptor = &ic

aperture.SetupLoggers(logWriter, *interceptor)
lnd.AddSubLogger(
logWriter, mailbox.Subsystem, *interceptor, mailbox.UseLogger,
)
lnd.AddSubLogger(logWriter, gbn.Subsystem, *interceptor, gbn.UseLogger)

err = build.ParseAndSetDebugLevels("debug", logWriter)
require.NoError(h.t, err)
}
100 changes: 55 additions & 45 deletions litrpc/lit-sessions.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions litrpc/lit-sessions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ message Session {
bytes local_public_key = 9;

bytes remote_public_key = 10;

uint64 created_at = 11 [jstype = JS_STRING];
}

message ListSessionsRequest {
Expand Down
2 changes: 2 additions & 0 deletions session/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Session struct {
State State
Type Type
Expiry time.Time
CreatedAt time.Time
ServerAddr string
DevServer bool
MacaroonRootKey uint64
Expand Down Expand Up @@ -78,6 +79,7 @@ func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
State: StateCreated,
Type: typ,
Expiry: expiry,
CreatedAt: time.Now(),
ServerAddr: serverAddr,
DevServer: devServer,
MacaroonRootKey: macRootKey,
Expand Down
10 changes: 6 additions & 4 deletions session/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func newMailboxSession() *mailboxSession {

func (m *mailboxSession) start(session *Session,
serverCreator GRPCServerCreator, authData []byte,
onUpdate func(sess *Session) error) error {
onUpdate func(sess *Session) error,
onNewStatus func(s mailbox.ServerStatus)) error {

tlsConfig := &tls.Config{}
if session.DevServer {
Expand All @@ -52,7 +53,7 @@ func (m *mailboxSession) start(session *Session,

// Start the mailbox gRPC server.
mailboxServer, err := mailbox.NewServer(
session.ServerAddr, keys,
session.ServerAddr, keys, onNewStatus,
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 2 * time.Minute,
Expand Down Expand Up @@ -104,7 +105,8 @@ func NewServer(serverCreator GRPCServerCreator) *Server {
}

func (s *Server) StartSession(session *Session, authData []byte,
onUpdate func(sess *Session) error) (chan struct{}, error) {
onUpdate func(sess *Session) error,
onNewStatus func(s mailbox.ServerStatus)) (chan struct{}, error) {

s.activeSessionsMtx.Lock()
defer s.activeSessionsMtx.Unlock()
Expand All @@ -121,7 +123,7 @@ func (s *Server) StartSession(session *Session, authData []byte,
s.activeSessions[id] = sess

return sess.quit, sess.start(
session, s.serverCreator, authData, onUpdate,
session, s.serverCreator, authData, onUpdate, onNewStatus,
)
}

Expand Down
Loading