diff --git a/interceptor/email.go b/interceptor/email.go index 857aacf..8777cac 100644 --- a/interceptor/email.go +++ b/interceptor/email.go @@ -124,7 +124,9 @@ func sendChannelMismatchNotification(nodeID string, notFakeChannels, closedChann func sendOpenChannelEmailNotification( paymentHash []byte, incomingAmountMsat int64, destination []byte, capacity int64, - channelPoint string) error { + channelPoint string, + tag *string, +) error { var html bytes.Buffer tpl := ` @@ -134,6 +136,7 @@ func sendOpenChannelEmailNotification( Destination Node:{{ .Destination }} Channel capacity (sat):{{ .Capacity }} Channel point:{{ .ChannelPoint }} + Tag:{{ .Tag }} ` t, err := template.New("OpenChannelEmail").Parse(tpl) @@ -141,12 +144,17 @@ func sendOpenChannelEmailNotification( return err } + tagStr := "" + if tag != nil { + tagStr = *tag + } if err := t.Execute(&html, map[string]string{ "PaymentHash": hex.EncodeToString(paymentHash), "IncomingAmountMsat": strconv.FormatUint(uint64(incomingAmountMsat), 10), "Destination": hex.EncodeToString(destination), "Capacity": strconv.FormatUint(uint64(capacity), 10), "ChannelPoint": channelPoint, + "Tag": tagStr, }); err != nil { return err } diff --git a/interceptor/intercept.go b/interceptor/intercept.go index 69b8178..351cabe 100644 --- a/interceptor/intercept.go +++ b/interceptor/intercept.go @@ -76,7 +76,7 @@ func NewInterceptor( func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32, reqIncomingExpiry uint32) InterceptResult { reqPaymentHashStr := hex.EncodeToString(reqPaymentHash) resp, _, _ := i.payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) { - params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, err := i.store.PaymentInfo(reqPaymentHash) + params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, tag, err := i.store.PaymentInfo(reqPaymentHash) if err != nil { log.Printf("paymentInfo(%x) error: %v", reqPaymentHash, err) return InterceptResult{ @@ -134,7 +134,7 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi log.Printf("Intercepted expired payment registration. Opening channel anyway, because it's cheaper at the current rate. %+v", params) } - channelPoint, err = i.openChannel(reqPaymentHash, destination, incomingAmountMsat) + channelPoint, err = i.openChannel(reqPaymentHash, destination, incomingAmountMsat, tag) if err != nil { log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err) return InterceptResult{ @@ -297,7 +297,7 @@ func (i *Interceptor) isCurrentChainFeeCheaper(params *OpeningFeeParams) bool { return false } -func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmountMsat int64) (*wire.OutPoint, error) { +func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmountMsat int64, tag *string) (*wire.OutPoint, error) { capacity := incomingAmountMsat/1000 + i.config.AdditionalChannelCapacity if capacity == i.config.PublicChannelAmount { capacity++ @@ -348,6 +348,7 @@ func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmoun destination, capacity, channelPoint.String(), + tag, ) err = i.store.SetFundingTx(paymentHash, channelPoint) return channelPoint, err diff --git a/interceptor/store.go b/interceptor/store.go index 605f9cd..3863139 100644 --- a/interceptor/store.go +++ b/interceptor/store.go @@ -20,7 +20,7 @@ type OpeningFeeParams struct { } type InterceptStore interface { - PaymentInfo(htlcPaymentHash []byte) (*OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, error) + PaymentInfo(htlcPaymentHash []byte) (*OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error RegisterPayment(params *OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error InsertChannel(initialChanID, confirmedChanId uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error diff --git a/postgresql/intercept_store.go b/postgresql/intercept_store.go index 05fe591..31e0acb 100644 --- a/postgresql/intercept_store.go +++ b/postgresql/intercept_store.go @@ -23,24 +23,24 @@ func NewPostgresInterceptStore(pool *pgxpool.Pool) *PostgresInterceptStore { return &PostgresInterceptStore{pool: pool} } -func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (*interceptor.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, error) { +func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (*interceptor.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) { var ( - p *string + p, tag *string paymentHash, paymentSecret, destination []byte incomingAmountMsat, outgoingAmountMsat int64 fundingTxID []byte fundingTxOutnum pgtype.Int4 ) err := s.pool.QueryRow(context.Background(), - `SELECT payment_hash, payment_secret, destination, incoming_amount_msat, outgoing_amount_msat, funding_tx_id, funding_tx_outnum, opening_fee_params + `SELECT payment_hash, payment_secret, destination, incoming_amount_msat, outgoing_amount_msat, funding_tx_id, funding_tx_outnum, opening_fee_params, tag FROM payments WHERE payment_hash=$1 OR sha256('probing-01:' || payment_hash)=$1`, - htlcPaymentHash).Scan(&paymentHash, &paymentSecret, &destination, &incomingAmountMsat, &outgoingAmountMsat, &fundingTxID, &fundingTxOutnum, &p) + htlcPaymentHash).Scan(&paymentHash, &paymentSecret, &destination, &incomingAmountMsat, &outgoingAmountMsat, &fundingTxID, &fundingTxOutnum, &p, &tag) if err != nil { if err == pgx.ErrNoRows { err = nil } - return nil, nil, nil, nil, 0, 0, nil, err + return nil, nil, nil, nil, 0, 0, nil, nil, err } var cp *wire.OutPoint @@ -56,10 +56,10 @@ func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (*intercept err = json.Unmarshal([]byte(*p), ¶ms) if err != nil { log.Printf("Failed to unmarshal OpeningFeeParams '%s': %v", *p, err) - return nil, nil, nil, nil, 0, 0, nil, err + return nil, nil, nil, nil, 0, 0, nil, nil, err } } - return params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, cp, nil + return params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, cp, tag, nil } func (s *PostgresInterceptStore) SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error {