Skip to content

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiidb committed Aug 9, 2023
1 parent b915fdb commit 6d30bec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func main() {
sentry.CaptureException(err)
logrus.Fatal(err)
}
//create buffered channels to handle publisher confirms
//so we don't block publishing if there is a peak in traffic
cci := make(chan InvoiceConfirmation, 100)
ccp := make(chan PaymentConfirmation, 100)
svc := &Service{
Expand Down
21 changes: 13 additions & 8 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type InvoiceConfirmation struct {
}
type PaymentConfirmation struct {
confirmation *amqp.DeferredConfirmation
invoice *lnrpc.Payment
payment *lnrpc.Payment
tx *gorm.DB
}

Expand Down Expand Up @@ -332,7 +332,7 @@ func (svc *Service) ProcessPayment(ctx context.Context, payment *lnrpc.Payment)
}).Info("published payment")
svc.confirmChannelPayments <- PaymentConfirmation{
confirmation: conf,
invoice: payment,
payment: payment,
tx: tx,
}
}
Expand Down Expand Up @@ -369,7 +369,6 @@ func (svc *Service) StartInvoiceConfirmationLoop(ctx context.Context) error {
case <-ctx.Done():
return context.Canceled
case ic := <-svc.confirmChannelInvoices:
logrus.Infof("invoice chan length %d", len(svc.confirmChannelInvoices))
ok, err := ic.confirmation.WaitContext(ctx)
if !ok {
return fmt.Errorf("publisher confirm failed %v", err)
Expand All @@ -378,6 +377,11 @@ func (svc *Service) StartInvoiceConfirmationLoop(ctx context.Context) error {
if err != nil {
return err
}
logrus.WithFields(
logrus.Fields{
"invoice_chan_lenght": len(svc.confirmChannelInvoices),
"payment_hash": hex.EncodeToString(ic.invoice.RHash),
}).Info("handled invoice confirmation")
}
}
}
Expand All @@ -388,7 +392,6 @@ func (svc *Service) StartPaymentConfirmationLoop(ctx context.Context) error {
case <-ctx.Done():
return context.Canceled
case ic := <-svc.confirmChannelPayments:
logrus.Infof("payment chan length %d", len(svc.confirmChannelPayments))
ok, err := ic.confirmation.WaitContext(ctx)
if !ok {
//rollback transaction
Expand All @@ -399,6 +402,11 @@ func (svc *Service) StartPaymentConfirmationLoop(ctx context.Context) error {
if err != nil {
return err
}
logrus.WithFields(
logrus.Fields{
"payment_chan_length": len(svc.confirmChannelPayments),
"payment_hash": hex.EncodeToString([]byte(ic.payment.PaymentHash)),
}).Info("handled payment confirmation")
}
}
}
Expand All @@ -410,11 +418,8 @@ func (svc *Service) PublishPayload(ctx context.Context, payload interface{}, exc
return nil, err
}

timeoutCtx, cancel := context.WithTimeout(ctx, time.Duration(svc.cfg.RabbitMQTimeoutSeconds)*time.Second)
defer cancel()
logrus.Info("Publishing message")
return svc.rabbitChannel.PublishWithDeferredConfirmWithContext(
timeoutCtx,
ctx,
exchange, key, false, false, amqp.Publishing{
ContentType: "application/json",
Body: payloadBytes.Bytes(),
Expand Down

0 comments on commit 6d30bec

Please sign in to comment.