-
Notifications
You must be signed in to change notification settings - Fork 58
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
[feature] Use LNC to connect to the LND node #98
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8dde304
config: support config for LNC connections
positiveblue baec262
lnc: add lnc session package
positiveblue ea2fb83
sqlc: add table+queries for sessions
positiveblue 0e02476
aperturedb: implement lnc sessions store
positiveblue 3d53f20
multi: use `InvoiceClient` in `NewLndChallenger`
positiveblue a04f3b1
challenger: custom context for LightningClient methods
positiveblue 4e81f5d
challenger: move challenger logic to its own package
positiveblue a6ff4a9
challenger: add `LNCChallenger`
positiveblue aa9ca46
aperture: initialize server with the configured authenticator
positiveblue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package challenger | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/lightninglabs/aperture/auth" | ||
"github.com/lightninglabs/aperture/mint" | ||
"github.com/lightningnetwork/lnd/lnrpc" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// InvoiceRequestGenerator is a function type that returns a new request for the | ||
// lnrpc.AddInvoice call. | ||
type InvoiceRequestGenerator func(price int64) (*lnrpc.Invoice, error) | ||
|
||
// InvoiceClient is an interface that only implements part of a full lnd client, | ||
// namely the part around the invoices we need for the challenger to work. | ||
type InvoiceClient interface { | ||
// ListInvoices returns a paginated list of all invoices known to lnd. | ||
ListInvoices(ctx context.Context, in *lnrpc.ListInvoiceRequest, | ||
opts ...grpc.CallOption) (*lnrpc.ListInvoiceResponse, error) | ||
|
||
// SubscribeInvoices subscribes to updates on invoices. | ||
SubscribeInvoices(ctx context.Context, in *lnrpc.InvoiceSubscription, | ||
opts ...grpc.CallOption) ( | ||
lnrpc.Lightning_SubscribeInvoicesClient, error) | ||
|
||
// AddInvoice adds a new invoice to lnd. | ||
AddInvoice(ctx context.Context, in *lnrpc.Invoice, | ||
opts ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error) | ||
} | ||
|
||
// Challenger is an interface that combines the mint.Challenger and the | ||
// auth.InvoiceChecker interfaces. | ||
type Challenger interface { | ||
mint.Challenger | ||
auth.InvoiceChecker | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package aperture | ||
package challenger | ||
|
||
import ( | ||
"context" | ||
|
@@ -9,34 +9,10 @@ import ( | |
"sync" | ||
"time" | ||
|
||
"github.com/lightninglabs/aperture/auth" | ||
"github.com/lightninglabs/aperture/mint" | ||
"github.com/lightningnetwork/lnd/lnrpc" | ||
"github.com/lightningnetwork/lnd/lntypes" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// InvoiceRequestGenerator is a function type that returns a new request for the | ||
// lnrpc.AddInvoice call. | ||
type InvoiceRequestGenerator func(price int64) (*lnrpc.Invoice, error) | ||
|
||
// InvoiceClient is an interface that only implements part of a full lnd client, | ||
// namely the part around the invoices we need for the challenger to work. | ||
type InvoiceClient interface { | ||
// ListInvoices returns a paginated list of all invoices known to lnd. | ||
ListInvoices(ctx context.Context, in *lnrpc.ListInvoiceRequest, | ||
opts ...grpc.CallOption) (*lnrpc.ListInvoiceResponse, error) | ||
|
||
// SubscribeInvoices subscribes to updates on invoices. | ||
SubscribeInvoices(ctx context.Context, in *lnrpc.InvoiceSubscription, | ||
opts ...grpc.CallOption) ( | ||
lnrpc.Lightning_SubscribeInvoicesClient, error) | ||
|
||
// AddInvoice adds a new invoice to lnd. | ||
AddInvoice(ctx context.Context, in *lnrpc.Invoice, | ||
opts ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error) | ||
} | ||
|
||
// LndChallenger is a challenger that uses an lnd backend to create new LSAT | ||
// payment challenges. | ||
type LndChallenger struct { | ||
|
@@ -55,16 +31,9 @@ type LndChallenger struct { | |
wg sync.WaitGroup | ||
} | ||
|
||
// A compile time flag to ensure the LndChallenger satisfies the | ||
// mint.Challenger and auth.InvoiceChecker interface. | ||
var _ mint.Challenger = (*LndChallenger)(nil) | ||
var _ auth.InvoiceChecker = (*LndChallenger)(nil) | ||
|
||
const ( | ||
// invoiceMacaroonName is the name of the invoice macaroon belonging | ||
// to the target lnd node. | ||
invoiceMacaroonName = "invoice.macaroon" | ||
) | ||
// A compile time flag to ensure the LndChallenger satisfies the Challenger | ||
// interface. | ||
var _ Challenger = (*LndChallenger)(nil) | ||
|
||
// NewLndChallenger creates a new challenger that uses the given connection to | ||
// an lnd backend to create payment challenges. | ||
|
@@ -84,7 +53,7 @@ func NewLndChallenger(client InvoiceClient, | |
} | ||
|
||
invoicesMtx := &sync.Mutex{} | ||
return &LndChallenger{ | ||
challenger := &LndChallenger{ | ||
client: client, | ||
clientCtx: ctxFunc, | ||
genInvoiceReq: genInvoiceReq, | ||
|
@@ -93,7 +62,14 @@ func NewLndChallenger(client InvoiceClient, | |
invoicesCond: sync.NewCond(invoicesMtx), | ||
quit: make(chan struct{}), | ||
errChan: errChan, | ||
}, nil | ||
} | ||
|
||
err := challenger.Start() | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to start challenger: %w", err) | ||
} | ||
|
||
return challenger, nil | ||
} | ||
|
||
// Start starts the challenger's main work which is to keep track of all | ||
|
@@ -263,7 +239,9 @@ func (l *LndChallenger) Stop() { | |
// request (invoice) and the corresponding payment hash. | ||
// | ||
// NOTE: This is part of the mint.Challenger interface. | ||
func (l *LndChallenger) NewChallenge(price int64) (string, lntypes.Hash, error) { | ||
func (l *LndChallenger) NewChallenge(price int64) (string, lntypes.Hash, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re the above comment, we could pass in the additional context here as an optional argument. Then the invoice creation has a chance to tag any extra details. |
||
error) { | ||
|
||
// Obtain a new invoice from lnd first. We need to know the payment hash | ||
// so we can add it as a caveat to the macaroon. | ||
invoice, err := l.genInvoiceReq(price) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package aperture | ||
package challenger | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package challenger | ||
|
||
import ( | ||
"github.com/btcsuite/btclog" | ||
"github.com/lightningnetwork/lnd/build" | ||
) | ||
|
||
// Subsystem defines the sub system name of this package. | ||
const Subsystem = "CHLL" | ||
|
||
// log is a logger that is initialized with no output filters. This | ||
// means the package will not perform any logging by default until the caller | ||
// requests it. | ||
var log btclog.Logger | ||
|
||
// The default amount of logging is none. | ||
func init() { | ||
UseLogger(build.NewSubLogger(Subsystem, nil)) | ||
} | ||
|
||
// UseLogger uses a specified Logger to output package logging info. | ||
// This should be used in preference to SetLogWriter if the caller is also | ||
// using btclog. | ||
func UseLogger(logger btclog.Logger) { | ||
log = logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking, but in the future we can insert relevant endpoint/context information here so someone can build a UI/dashboard on top of lnd/aperture to do things like track the amount earned from a given endpoint, etc.
To do this, we'd need to expose the memo as part of the challenger interface, as only much later in the pipeline do we have the full request context information.