mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 06:44:23 +01:00
Check the amounts when using RegisterPayments
This commit is contained in:
11
intercept.go
11
intercept.go
@@ -24,6 +24,17 @@ import (
|
|||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkPayment(incomingAmountMsat, outgoingAmountMsat int64) error {
|
||||||
|
var fees int64 = 0
|
||||||
|
if incomingAmountMsat > channelFeeStartAmount {
|
||||||
|
fees += (incomingAmountMsat - channelFeeStartAmount) * channelFeeAmountNumerator / channelFeeAmountDenominator
|
||||||
|
}
|
||||||
|
if incomingAmountMsat-outgoingAmountMsat < fees {
|
||||||
|
return fmt.Errorf("not enough fees")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func openChannel(ctx context.Context, client lnrpc.LightningClient, paymentHash, destination []byte, incomingAmountMsat int64) ([]byte, uint32, error) {
|
func openChannel(ctx context.Context, client lnrpc.LightningClient, paymentHash, destination []byte, incomingAmountMsat int64) ([]byte, uint32, error) {
|
||||||
capacity := incomingAmountMsat/1000 + channelFeeStartAmount
|
capacity := incomingAmountMsat/1000 + channelFeeStartAmount
|
||||||
channelPoint, err := client.OpenChannelSync(ctx, &lnrpc.OpenChannelRequest{
|
channelPoint, err := client.OpenChannelSync(ctx, &lnrpc.OpenChannelRequest{
|
||||||
|
|||||||
24
server.go
24
server.go
@@ -29,14 +29,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
channelAmount = 1_000_000
|
channelAmount = 1_000_000
|
||||||
targetConf = 1
|
targetConf = 1
|
||||||
minHtlcMsat = 600
|
minHtlcMsat = 600
|
||||||
baseFeeMsat = 1000
|
baseFeeMsat = 1000
|
||||||
feeRate = 0.000001
|
feeRate = 0.000001
|
||||||
timeLockDelta = 144
|
timeLockDelta = 144
|
||||||
channelFeeStartAmount = 100_000
|
channelFeeStartAmount = 100_000
|
||||||
channelFeeAmount = 0.001
|
channelFeeAmountNumerator = 1
|
||||||
|
channelFeeAmountDenominator = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
type server struct{}
|
type server struct{}
|
||||||
@@ -63,7 +64,7 @@ func (s *server) ChannelInformation(ctx context.Context, in *lspdrpc.ChannelInfo
|
|||||||
FeeRate: feeRate,
|
FeeRate: feeRate,
|
||||||
TimeLockDelta: timeLockDelta,
|
TimeLockDelta: timeLockDelta,
|
||||||
ChannelFeeStartAmount: channelFeeStartAmount,
|
ChannelFeeStartAmount: channelFeeStartAmount,
|
||||||
ChannelFeeRate: channelFeeAmount,
|
ChannelFeeRate: 1.0 * channelFeeAmountNumerator / channelFeeAmountDenominator,
|
||||||
LspPubkey: publicKey.SerializeCompressed(),
|
LspPubkey: publicKey.SerializeCompressed(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -82,6 +83,11 @@ func (s *server) RegisterPayment(ctx context.Context, in *lspdrpc.RegisterPaymen
|
|||||||
}
|
}
|
||||||
log.Printf("RegisterPayment - Destination: %x, pi.PaymentHash: %x, pi.PaymentSecret: %x, pi.IncomingAmountMsat: %v, pi.OutgoingAmountMsat: %v",
|
log.Printf("RegisterPayment - Destination: %x, pi.PaymentHash: %x, pi.PaymentSecret: %x, pi.IncomingAmountMsat: %v, pi.OutgoingAmountMsat: %v",
|
||||||
pi.Destination, pi.PaymentHash, pi.PaymentSecret, pi.IncomingAmountMsat, pi.OutgoingAmountMsat)
|
pi.Destination, pi.PaymentHash, pi.PaymentSecret, pi.IncomingAmountMsat, pi.OutgoingAmountMsat)
|
||||||
|
err = checkPayment(pi.IncomingAmountMsat, pi.OutgoingAmountMsat)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("checkPayment(%v, %v) error: %v", pi.IncomingAmountMsat, pi.OutgoingAmountMsat, err)
|
||||||
|
return nil, fmt.Errorf("checkPayment(%v, %v) error: %v", pi.IncomingAmountMsat, pi.OutgoingAmountMsat, err)
|
||||||
|
}
|
||||||
err = registerPayment(pi.Destination, pi.PaymentHash, pi.PaymentSecret, pi.IncomingAmountMsat, pi.OutgoingAmountMsat)
|
err = registerPayment(pi.Destination, pi.PaymentHash, pi.PaymentSecret, pi.IncomingAmountMsat, pi.OutgoingAmountMsat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("RegisterPayment() error: %v", err)
|
log.Printf("RegisterPayment() error: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user