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

View File

@@ -191,6 +191,15 @@ func (l *lspBase) Initialize() error {
}
defer pgxPool.Close()
_, err = pgxPool.Exec(
l.harness.Ctx,
`DELETE FROM new_channel_params`,
)
if err != nil {
lntest.PerformCleanup(cleanups)
return fmt.Errorf("failed to delete new_channel_params: %w", err)
}
_, err = pgxPool.Exec(
l.harness.Ctx,
`INSERT INTO new_channel_params (validity, params)

View File

@@ -28,24 +28,24 @@ func NewPostgresInterceptStore(pool *pgxpool.Pool) *PostgresInterceptStore {
return &PostgresInterceptStore{pool: pool}
}
func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *interceptor.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, error) {
func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *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
@@ -61,10 +61,10 @@ func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *i
err = json.Unmarshal([]byte(*p), &extParams)
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 extParams.Token, &extParams.Params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, cp, nil
return extParams.Token, &extParams.Params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, cp, tag, nil
}
func (s *PostgresInterceptStore) SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error {

View File

@@ -1,2 +1,3 @@
ALTER TABLE public.new_channel_params
DROP COLUMN token;
ALTER TABLE public.new_channel_params DROP COLUMN token;
DROP INDEX new_channel_params_token_validity_idx;
CREATE UNIQUE INDEX new_channel_params_validity_idx ON public.new_channel_params (validity);

View File

@@ -1 +1,3 @@
ALTER TABLE public.new_channel_params ADD token varchar;
ALTER TABLE public.new_channel_params ADD token varchar;
DROP INDEX public.new_channel_params_validity_idx;
CREATE UNIQUE INDEX new_channel_params_token_validity_idx ON public.new_channel_params (token, validity);