Merge branch 'master' into params-per-token

This commit is contained in:
Yaacov Akiba Slama
2023-06-05 15:37:37 +03:00
7 changed files with 36 additions and 15 deletions

View File

@@ -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(
<tr><td>Destination Node:</td><td>{{ .Destination }}</td></tr>
<tr><td>Channel capacity (sat):</td><td>{{ .Capacity }}</td></tr>
<tr><td>Channel point:</td><td>{{ .ChannelPoint }}</td></tr>
<tr><td>Tag:</td><td>{{ .Tag }}</td></tr>
</table>
`
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
}

View File

@@ -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) {
token, params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, err := i.store.PaymentInfo(reqPaymentHash)
token, 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(token string, params *OpeningFeeP
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

View File

@@ -20,7 +20,7 @@ type OpeningFeeParams struct {
}
type InterceptStore interface {
PaymentInfo(htlcPaymentHash []byte) (string, *OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, error)
PaymentInfo(htlcPaymentHash []byte) (string, *OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error)
SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error
RegisterPayment(token string, params *OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error
InsertChannel(initialChanID, confirmedChanId uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error