Skip to content

Commit 47d72bd

Browse files
authored
Merge pull request #175 from Roasbeef/skip-invoice-load
multi: add new strict-verify CLI option to control invoice usage
2 parents ab83de2 + ea63781 commit 47d72bd

File tree

6 files changed

+79
-8
lines changed

6 files changed

+79
-8
lines changed

aperture.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (a *Aperture) Start(errChan chan error) error {
337337

338338
a.challenger, err = challenger.NewLNCChallenger(
339339
session, lncStore, a.cfg.InvoiceBatchSize,
340-
genInvoiceReq, errChan,
340+
genInvoiceReq, errChan, a.cfg.StrictVerify,
341341
)
342342
if err != nil {
343343
return fmt.Errorf("unable to start lnc "+
@@ -361,7 +361,7 @@ func (a *Aperture) Start(errChan chan error) error {
361361

362362
a.challenger, err = challenger.NewLndChallenger(
363363
client, a.cfg.InvoiceBatchSize, genInvoiceReq,
364-
context.Background, errChan,
364+
context.Background, errChan, a.cfg.StrictVerify,
365365
)
366366
if err != nil {
367367
return err

challenger/lnc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type LNCChallenger struct {
2020
// connect to an lnd backend to create payment challenges.
2121
func NewLNCChallenger(session *lnc.Session, lncStore lnc.Store,
2222
invoiceBatchSize int, genInvoiceReq InvoiceRequestGenerator,
23-
errChan chan<- error) (*LNCChallenger, error) {
23+
errChan chan<- error, strictVerify bool) (*LNCChallenger, error) {
2424

2525
nodeConn, err := lnc.NewNodeConn(session, lncStore)
2626
if err != nil {
@@ -35,7 +35,7 @@ func NewLNCChallenger(session *lnc.Session, lncStore lnc.Store,
3535

3636
lndChallenger, err := NewLndChallenger(
3737
client, invoiceBatchSize, genInvoiceReq, nodeConn.CtxFunc,
38-
errChan,
38+
errChan, strictVerify,
3939
)
4040
if err != nil {
4141
return nil, err

challenger/lnd.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ type LndChallenger struct {
2525
invoicesCancel func()
2626
invoicesCond *sync.Cond
2727

28+
// strictVerify indicates whether we should verify the invoice states,
29+
// or rely on the higher level preimage verification.
30+
strictVerify bool
31+
2832
errChan chan<- error
2933

3034
quit chan struct{}
@@ -38,9 +42,8 @@ var _ Challenger = (*LndChallenger)(nil)
3842
// NewLndChallenger creates a new challenger that uses the given connection to
3943
// an lnd backend to create payment challenges.
4044
func NewLndChallenger(client InvoiceClient, batchSize int,
41-
genInvoiceReq InvoiceRequestGenerator,
42-
ctxFunc func() context.Context,
43-
errChan chan<- error) (*LndChallenger, error) {
45+
genInvoiceReq InvoiceRequestGenerator, ctxFunc func() context.Context,
46+
errChan chan<- error, strictVerification bool) (*LndChallenger, error) {
4447

4548
// Make sure we have a valid context function. This will be called to
4649
// create a new context for each call to the lnd client.
@@ -63,6 +66,7 @@ func NewLndChallenger(client InvoiceClient, batchSize int,
6366
invoicesCond: sync.NewCond(invoicesMtx),
6467
quit: make(chan struct{}),
6568
errChan: errChan,
69+
strictVerify: strictVerification,
6670
}
6771

6872
err := challenger.Start()
@@ -78,6 +82,14 @@ func NewLndChallenger(client InvoiceClient, batchSize int,
7882
// invoices on startup and a subscription to all subsequent invoice updates
7983
// is created.
8084
func (l *LndChallenger) Start() error {
85+
// If we aren't doing strict verification, then we can just exit here as
86+
// we don't need the invoice state.
87+
if !l.strictVerify {
88+
log.Infof("Skipping invoice state tracking strict_verify=%v",
89+
l.strictVerify)
90+
return nil
91+
}
92+
8193
// These are the default values for the subscription. In case there are
8294
// no invoices yet, this will instruct lnd to just send us all updates.
8395
// If there are existing invoices, these indices will be updated to
@@ -303,6 +315,12 @@ func (l *LndChallenger) NewChallenge(price int64) (string, lntypes.Hash,
303315
func (l *LndChallenger) VerifyInvoiceStatus(hash lntypes.Hash,
304316
state lnrpc.Invoice_InvoiceState, timeout time.Duration) error {
305317

318+
// If we're not doing strict verification, we can skip this check.
319+
if !l.strictVerify {
320+
log.Tracef("Skipping invoice state check, pay_hash=%v", hash)
321+
return nil
322+
}
323+
306324
// Prevent the challenger to be shut down while we're still waiting for
307325
// status updates.
308326
l.wg.Add(1)

challenger/lnd_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func newChallenger() (*LndChallenger, *mockInvoiceClient, chan error) {
120120
invoicesMtx: invoicesMtx,
121121
invoicesCond: sync.NewCond(invoicesMtx),
122122
errChan: mainErrChan,
123+
strictVerify: true,
123124
}, mockClient, mainErrChan
124125
}
125126

@@ -142,7 +143,7 @@ func TestLndChallenger(t *testing.T) {
142143
// First of all, test that the NewLndChallenger doesn't allow a nil
143144
// invoice generator function.
144145
errChan := make(chan error)
145-
_, err := NewLndChallenger(nil, 1, nil, nil, errChan)
146+
_, err := NewLndChallenger(nil, 1, nil, nil, errChan, true)
146147
require.Error(t, err)
147148

148149
// Now mock the lnd backend and create a challenger instance that we can

config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var (
2020
defaultLogLevel = "info"
2121
defaultLogFilename = "aperture.log"
2222
defaultInvoiceBatchSize = 100000
23+
defaultStrictVerify = false
2324

2425
defaultSqliteDatabaseFileName = "aperture.db"
2526

@@ -224,6 +225,11 @@ type Config struct {
224225
// request.
225226
InvoiceBatchSize int `long:"invoicebatchsize" description:"The number of invoices to fetch in a single request."`
226227

228+
// StrictVerify is a flag that indicates whether we should verify the
229+
// invoice status strictly or not. If set to true, then this requires
230+
// all invoices to be read from disk at start up.
231+
StrictVerify bool `long:"strictverify" description:"Whether to verify the invoice status strictly or not."`
232+
227233
// Logging controls various aspects of aperture logging.
228234
Logging *build.LogConfig `group:"logging" namespace:"logging"`
229235

@@ -274,5 +280,6 @@ func NewConfig() *Config {
274280
InvoiceBatchSize: defaultInvoiceBatchSize,
275281
Logging: build.DefaultLogConfig(),
276282
Blocklist: []string{},
283+
StrictVerify: defaultStrictVerify,
277284
}
278285
}

sample-conf.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,42 @@ servestatic: false
1414
# Valid options include: trace, debug, info, warn, error, critical, off.
1515
debuglevel: "debug"
1616

17+
# Custom path to a config file.
18+
configfile: "/path/to/your/aperture.yaml"
19+
20+
# Directory to place all of aperture's files in.
21+
basedir: "/path/to/.aperture"
22+
1723
# Whether the proxy should create a valid certificate through Let's Encrypt for
1824
# the fully qualifying domain name.
1925
autocert: false
2026
servername: aperture.example.com
2127

28+
# Whether to listen on an insecure connection, disabling TLS for incoming
29+
# connections.
30+
insecure: false
31+
32+
# Whether we should verify the invoice status strictly or not. If set to true,
33+
# then this requires all invoices to be read from disk at start up.
34+
strictverify: false
35+
36+
# The number of invoices to fetch in a single request when interacting with LND.
37+
invoicebatchsize: 100000
38+
2239
# The port on which the pprof profile will be served. If no port is provided,
2340
# the profile will not be served.
2441
profile: 9999
2542

43+
# The maximum amount of time a connection may be idle before being closed.
44+
# Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
45+
idletimeout: 2m
46+
47+
# The maximum amount of time to wait for a request to be fully read.
48+
readtimeout: 15s
49+
50+
# The maximum amount of time to wait for a response to be fully written.
51+
writetimeout: 30s
52+
2653
# Settings for the lnd node used to generate payment requests. All of these
2754
# options are required.
2855
authenticator:
@@ -76,6 +103,9 @@ sqlite:
76103
# The full path to the database.
77104
dbfile: "/path/to/.aperture/aperture.db"
78105

106+
# Skip applying migrations on startup.
107+
skipmigrations: false
108+
79109
# Settings for the postgres instance which the proxy will use to reliably store
80110
# and retrieve token information.
81111
postgres:
@@ -93,6 +123,9 @@ postgres:
93123
# server.
94124
requireSSL: true
95125

126+
# Skip applying migrations on startup.
127+
skipmigrations: false
128+
96129
# Settings for the etcd instance which the proxy will use to reliably store and
97130
# retrieve token information.
98131
etcd:
@@ -224,6 +257,10 @@ hashmail:
224257
enabled: true
225258
messagerate: 20ms
226259
messageburstallowance: 1000
260+
261+
# The time after the last activity that a mailbox should be removed.
262+
# Set to -1s to disable. Valid time units are "ns", "us", "ms", "s", "m", "h".
263+
staletimeout: -1s # Example: 5m for 5 minutes, or -1s to disable
227264

228265
# Enable the prometheus metrics exporter so that a prometheus server can scrape
229266
# the metrics.
@@ -238,6 +275,14 @@ logging:
238275
disable: false
239276
callsite: off
240277
notimestamps: true
278+
279+
# Log level for console output.
280+
# Valid options include: trace, debug, info, warn, error, critical, off.
281+
level: "info"
241282
file:
242283
disable: false
243284
callsite: long
285+
286+
# Log level for file output.
287+
# Valid options include: trace, debug, info, warn, error, critical, off.
288+
level: "info"

0 commit comments

Comments
 (0)