Skip to content

Commit

Permalink
chore: update LDK-node dependency to 0.4.2 (#753)
Browse files Browse the repository at this point in the history
* chore: update LDK-node dependency to 0.4.1

* fix: set node alias to open public channels

* chore: update ldk-node-go dependency

* chore: set 100x higher dust exposure for trusted peers

* fix: change dust multiplier for trusted peers to 10x

* fix: do not show pending balance from closed channels for ClaimableAwaitingConfirmations
  • Loading branch information
rolznz authored Nov 5, 2024
1 parent bbf4a17 commit 102f29b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 41 deletions.
2 changes: 1 addition & 1 deletion frontend/src/screens/channels/CurrentChannelOrder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ function PayBitcoinChannelOrderWithSpendableFunds({

const openChannelRequest: OpenChannelRequest = {
pubkey,
amount: +order.amount,
amountSats: +order.amount,
public: order.isPublic,
};
const openChannelResponse = await request<OpenChannelResponse>(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export type CreateInvoiceRequest = {

export type OpenChannelRequest = {
pubkey: string;
amount: number;
amountSats: number;
public: boolean;
};

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/breez/breez-sdk-go v0.5.2
github.com/elnosh/gonuts v0.2.0
github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59
github.com/getAlby/ldk-node-go v0.0.0-20240924080718-27f0fdd2a75d
github.com/getAlby/ldk-node-go v0.0.0-20241105053055-b97a9d042aca
github.com/go-gormigrate/gormigrate/v2 v2.1.3
github.com/labstack/echo/v4 v4.12.0
github.com/nbd-wtf/go-nostr v0.35.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59 h1:fSqdXE9uKhLcO
github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59/go.mod h1:ViyJvjlvv0GCesTJ7mb3fBo4G+/qsujDAFN90xZ7a9U=
github.com/getAlby/ldk-node-go v0.0.0-20240924080718-27f0fdd2a75d h1:scWSwE01B4fKdWmAQClerzSu7Ao691J5HheHdVLI7Tc=
github.com/getAlby/ldk-node-go v0.0.0-20240924080718-27f0fdd2a75d/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
github.com/getAlby/ldk-node-go v0.0.0-20241105053055-b97a9d042aca h1:Jou2O4yUYu9WIBTul/GiqGYcQHhxwll1KTqrXh9zVzU=
github.com/getAlby/ldk-node-go v0.0.0-20241105053055-b97a9d042aca/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
2 changes: 1 addition & 1 deletion lnclient/greenlight/greenlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (gs *GreenlightService) ConnectPeer(ctx context.Context, connectPeerRequest

func (gs *GreenlightService) OpenChannel(ctx context.Context, openChannelRequest *lnclient.OpenChannelRequest) (*lnclient.OpenChannelResponse, error) {

amountMsat := uint64(openChannelRequest.Amount) * 1000
amountMsat := uint64(openChannelRequest.AmountSats) * 1000
// minConf := uint32(0) //
response, err := gs.client.FundChannel(glalby.FundChannelRequest{
Id: openChannelRequest.Pubkey,
Expand Down
85 changes: 55 additions & 30 deletions lnclient/ldk/ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events
ldkConfig.LogLevel = ldk_node.LogLevel(logLevel) + ldk_node.LogLevelGossip
}
builder := ldk_node.BuilderFromConfig(ldkConfig)
builder.SetNodeAlias("Alby Hub") // TODO: allow users to customize
builder.SetEntropyBip39Mnemonic(mnemonic, nil)
builder.SetNetwork(network)
builder.SetEsploraServer(cfg.GetEnv().LDKEsploraServer)
builder.SetChainSourceEsplora(cfg.GetEnv().LDKEsploraServer, nil)
if cfg.GetEnv().LDKGossipSource != "" {
logger.Logger.WithField("gossipSource", cfg.GetEnv().LDKGossipSource).Warn("LDK RGS instance set")
builder.SetGossipSourceRgs(cfg.GetEnv().LDKGossipSource)
Expand All @@ -125,7 +126,6 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events
builder.RestoreEncodedChannelMonitors(getEncodedChannelMonitorsFromStaticChannelsBackup(staticChannelsBackup))
}

//builder.SetLogDirPath (filepath.Join(newpath, "./logs")); // missing?
node, err := builder.Build()

if err != nil {
Expand Down Expand Up @@ -176,7 +176,7 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events
if event == nil {
// if there is no event, wait before polling again to avoid 100% CPU usage
// TODO: remove this and use WaitNextEvent()
time.Sleep(time.Duration(1) * time.Millisecond)
time.Sleep(time.Duration(1000) * time.Millisecond)
continue
}

Expand Down Expand Up @@ -494,7 +494,7 @@ func (ls *LDKService) SendPaymentSync(ctx context.Context, invoice string) (*lnc
ldkEventSubscription := ls.ldkEventBroadcaster.Subscribe()
defer ls.ldkEventBroadcaster.CancelSubscription(ldkEventSubscription)

paymentHash, err := ls.node.Bolt11Payment().Send(invoice)
paymentHash, err := ls.node.Bolt11Payment().Send(invoice, nil)
if err != nil {
logger.Logger.WithError(err).Error("SendPayment failed")
return nil, err
Expand Down Expand Up @@ -535,8 +535,7 @@ func (ls *LDKService) SendPaymentSync(ctx context.Context, invoice string) (*lnc
}
break
}
if isEventPaymentFailedEvent && eventPaymentFailed.PaymentHash == paymentHash {

if isEventPaymentFailedEvent && eventPaymentFailed.PaymentHash != nil && *eventPaymentFailed.PaymentHash == paymentHash {
failureReasonMessage := ls.getPaymentFailReason(&eventPaymentFailed)

logger.Logger.WithFields(logrus.Fields{
Expand Down Expand Up @@ -583,7 +582,7 @@ func (ls *LDKService) SendKeysend(ctx context.Context, amount uint64, destinatio
ldkEventSubscription := ls.ldkEventBroadcaster.Subscribe()
defer ls.ldkEventBroadcaster.CancelSubscription(ldkEventSubscription)

paymentHash, err := ls.node.SpontaneousPayment().Send(amount, destination, customTlvs, &preimage)
paymentHash, err := ls.node.SpontaneousPayment().Send(amount, destination, nil, customTlvs, &preimage)
if err != nil {
logger.Logger.WithError(err).Error("Keysend failed")
return nil, err
Expand All @@ -606,7 +605,7 @@ func (ls *LDKService) SendKeysend(ctx context.Context, amount uint64, destinatio
}
break
}
if isEventPaymentFailedEvent && eventPaymentFailed.PaymentHash == paymentHash {
if isEventPaymentFailedEvent && eventPaymentFailed.PaymentHash != nil && *eventPaymentFailed.PaymentHash == paymentHash {

failureReasonMessage := ls.getPaymentFailReason(&eventPaymentFailed)

Expand Down Expand Up @@ -820,11 +819,12 @@ func (ls *LDKService) ListChannels(ctx context.Context) ([]lnclient.Channel, err
internalChannel := map[string]interface{}{}
internalChannel["channel"] = ldkChannel
internalChannel["config"] = map[string]interface{}{
"AcceptUnderpayingHtlcs": ldkChannel.Config.AcceptUnderpayingHtlcs(),
"CltvExpiryDelta": ldkChannel.Config.CltvExpiryDelta(),
"ForceCloseAvoidanceMaxFeeSatoshis": ldkChannel.Config.ForceCloseAvoidanceMaxFeeSatoshis(),
"ForwardingFeeBaseMsat": ldkChannel.Config.ForwardingFeeBaseMsat(),
"ForwardingFeeProportionalMillionths": ldkChannel.Config.ForwardingFeeProportionalMillionths(),
"AcceptUnderpayingHtlcs": ldkChannel.Config.AcceptUnderpayingHtlcs,
"CltvExpiryDelta": ldkChannel.Config.CltvExpiryDelta,
"ForceCloseAvoidanceMaxFeeSatoshis": ldkChannel.Config.ForceCloseAvoidanceMaxFeeSatoshis,
"ForwardingFeeBaseMsat": ldkChannel.Config.ForwardingFeeBaseMsat,
"ForwardingFeeProportionalMillionths": ldkChannel.Config.ForwardingFeeProportionalMillionths,
"MaxDustHtlcExposure": ldkChannel.Config.MaxDustHtlcExposure,
}

unspendablePunishmentReserve := uint64(0)
Expand Down Expand Up @@ -853,11 +853,11 @@ func (ls *LDKService) ListChannels(ctx context.Context) ([]lnclient.Channel, err
RemotePubkey: ldkChannel.CounterpartyNodeId,
Id: ldkChannel.UserChannelId, // CloseChannel takes the UserChannelId
Active: isActive,
Public: ldkChannel.IsPublic,
Public: ldkChannel.IsAnnounced,
FundingTxId: fundingTxId,
Confirmations: ldkChannel.Confirmations,
ConfirmationsRequired: ldkChannel.ConfirmationsRequired,
ForwardingFeeBaseMsat: ldkChannel.Config.ForwardingFeeBaseMsat(),
ForwardingFeeBaseMsat: ldkChannel.Config.ForwardingFeeBaseMsat,
UnspendablePunishmentReserve: unspendablePunishmentReserve,
CounterpartyUnspendablePunishmentReserve: ldkChannel.CounterpartyUnspendablePunishmentReserve,
Error: channelError,
Expand Down Expand Up @@ -920,7 +920,13 @@ func (ls *LDKService) OpenChannel(ctx context.Context, openChannelRequest *lncli
defer ls.ldkEventBroadcaster.CancelSubscription(ldkEventSubscription)

logger.Logger.WithField("peer_id", foundPeer.NodeId).Info("Opening channel")
userChannelId, err := ls.node.ConnectOpenChannel(foundPeer.NodeId, foundPeer.Address, uint64(openChannelRequest.Amount), nil, nil, openChannelRequest.Public)
var userChannelId string
var err error
if openChannelRequest.Public {
userChannelId, err = ls.node.OpenAnnouncedChannel(foundPeer.NodeId, foundPeer.Address, uint64(openChannelRequest.AmountSats), nil, nil)
} else {
userChannelId, err = ls.node.OpenChannel(foundPeer.NodeId, foundPeer.Address, uint64(openChannelRequest.AmountSats), nil, nil)
}
if err != nil {
logger.Logger.WithError(err).Error("OpenChannel failed")
return nil, err
Expand Down Expand Up @@ -977,7 +983,13 @@ func (ls *LDKService) UpdateChannel(ctx context.Context, updateChannelRequest *l
}

existingConfig := foundChannel.Config
existingConfig.SetForwardingFeeBaseMsat(updateChannelRequest.ForwardingFeeBaseMsat)
existingConfig.ForwardingFeeBaseMsat = updateChannelRequest.ForwardingFeeBaseMsat

if updateChannelRequest.MaxDustHtlcExposureFromFeeRateMultiplier > 0 {
existingConfig.MaxDustHtlcExposure = ldk_node.MaxDustHtlcExposureFeeRateMultiplier{
Multiplier: updateChannelRequest.MaxDustHtlcExposureFromFeeRateMultiplier,
}
}

err := ls.node.UpdateChannelConfig(updateChannelRequest.ChannelId, updateChannelRequest.NodeId, existingConfig)
if err != nil {
Expand All @@ -994,7 +1006,7 @@ func (ls *LDKService) CloseChannel(ctx context.Context, closeChannelRequest *lnc

var err error
if closeChannelRequest.Force {
err = ls.node.ForceCloseChannel(closeChannelRequest.ChannelId, closeChannelRequest.NodeId)
err = ls.node.ForceCloseChannel(closeChannelRequest.ChannelId, closeChannelRequest.NodeId, nil)
} else {
err = ls.node.CloseChannel(closeChannelRequest.ChannelId, closeChannelRequest.NodeId)
}
Expand Down Expand Up @@ -1049,7 +1061,8 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
case ldk_node.LightningBalanceClaimableOnChannelClose:
increasePendingBalance(balanceType.ChannelId, balanceType.AmountSatoshis)
case ldk_node.LightningBalanceClaimableAwaitingConfirmations:
increasePendingBalance(balanceType.ChannelId, balanceType.AmountSatoshis)
// this will show in the total balance (as incoming).
// increasePendingBalance(balanceType.ChannelId, balanceType.AmountSatoshis)
case ldk_node.LightningBalanceContentiousClaimable:
increasePendingBalance(balanceType.ChannelId, balanceType.AmountSatoshis)
case ldk_node.LightningBalanceMaybeTimeoutClaimableHtlc:
Expand Down Expand Up @@ -1117,13 +1130,9 @@ func (ls *LDKService) ResetRouter(key string) error {
}

func (ls *LDKService) SignMessage(ctx context.Context, message string) (string, error) {
sign, err := ls.node.SignMessage([]byte(message))
if err != nil {
logger.Logger.Errorf("SignMessage failed: %v", err)
return "", err
}
signedMessage := ls.node.SignMessage([]byte(message))

return sign, nil
return signedMessage, nil
}

func (ls *LDKService) ldkPaymentToTransaction(payment *ldk_node.PaymentDetails) (*lnclient.Transaction, error) {
Expand Down Expand Up @@ -1350,15 +1359,19 @@ func (ls *LDKService) handleLdkEvent(event *ldk_node.Event) {
logger.Logger.WithField("event", eventType).Error("Failed to find channel by ID")
return
}

isTrusted := eventType.CounterpartyNodeId != nil && slices.Contains(ls.node.Config().AnchorChannelsConfig.TrustedPeersNoReserve, *eventType.CounterpartyNodeId)

channel := channels[channelIndex]
ls.eventPublisher.Publish(&events.Event{
Event: "nwc_channel_ready",
Properties: map[string]interface{}{
"counterparty_node_id": eventType.CounterpartyNodeId,
"node_type": config.LDKBackendType,
"public": channel.IsPublic,
"public": channel.IsAnnounced,
"capacity": channel.ChannelValueSats,
"is_outbound": channel.IsOutbound,
"trusted": isTrusted,
},
})

Expand All @@ -1368,11 +1381,23 @@ func (ls *LDKService) handleLdkEvent(event *ldk_node.Event) {
logger.Logger.WithField("event", eventType).Error("channel ready event has no counterparty node ID")
return
}
// set a super-high forwarding fee of 100K sats by default to disable unwanted routing

// also
maxDustHtlcExposureFromFeeRateMultiplier := uint64(0)
if isTrusted {
// avoid closures like "ProcessingError: Peer sent update_fee with a feerate (62500)
// which may over-expose us to dust-in-flight on our counterparty's transactions (totaling 69348000 msat)"
maxDustHtlcExposureFromFeeRateMultiplier = 100_000 // default * 10
}

// set a super-high forwarding fee of 100K sats by default to disable unwanted routing by default
forwardingFeeBaseMsat := uint32(100_000_000)

err := ls.UpdateChannel(context.Background(), &lnclient.UpdateChannelRequest{
ChannelId: eventType.UserChannelId,
NodeId: *eventType.CounterpartyNodeId,
ForwardingFeeBaseMsat: 100_000_000,
ChannelId: eventType.UserChannelId,
NodeId: *eventType.CounterpartyNodeId,
MaxDustHtlcExposureFromFeeRateMultiplier: maxDustHtlcExposureFromFeeRateMultiplier,
ForwardingFeeBaseMsat: forwardingFeeBaseMsat,
})

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion lnclient/lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func (svc *LNDService) OpenChannel(ctx context.Context, openChannelRequest *lncl
channel, err := svc.client.OpenChannelSync(ctx, &lnrpc.OpenChannelRequest{
NodePubkey: nodePub,
Private: !openChannelRequest.Public,
LocalFundingAmount: openChannelRequest.Amount,
LocalFundingAmount: openChannelRequest.AmountSats,
// set a super-high forwarding fee of 100K sats by default to disable unwanted routing
BaseFee: 100_000_000,
})
Expand Down
13 changes: 7 additions & 6 deletions lnclient/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ type ConnectPeerRequest struct {
}

type OpenChannelRequest struct {
Pubkey string `json:"pubkey"`
Amount int64 `json:"amount"`
Public bool `json:"public"`
Pubkey string `json:"pubkey"`
AmountSats int64 `json:"amountSats"`
Public bool `json:"public"`
}

type OpenChannelResponse struct {
Expand All @@ -125,9 +125,10 @@ type CloseChannelRequest struct {
}

type UpdateChannelRequest struct {
ChannelId string `json:"channelId"`
NodeId string `json:"nodeId"`
ForwardingFeeBaseMsat uint32 `json:"forwardingFeeBaseMsat"`
ChannelId string `json:"channelId"`
NodeId string `json:"nodeId"`
ForwardingFeeBaseMsat uint32 `json:"forwardingFeeBaseMsat"`
MaxDustHtlcExposureFromFeeRateMultiplier uint64 `json:"maxDustHtlcExposureFromFeeRateMultiplier"`
}

type CloseChannelResponse struct {
Expand Down

0 comments on commit 102f29b

Please sign in to comment.