Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce configured routing policy on channel open #239

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cln/cln_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ func (c *ClnClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoi
return nil, err
}

if req.RoutingPolicy != nil {
var delay uint32 = 0

_, err = c.client.SetChannel(context.Background(), &rpc.SetchannelRequest{
Id: hex.EncodeToString(fundResult.ChannelId),
Feebase: &rpc.Amount{Msat: req.RoutingPolicy.BaseMsat},
Feeppm: &req.RoutingPolicy.Ppm,
Enforcedelay: &delay,
})
if err != nil {
log.Printf("CLN: client.SetChannel error: %v. Ignoring error and continue funding flow.", err)
}
}

return channelPoint, nil
}

Expand Down
4 changes: 4 additions & 0 deletions interceptor/intercept_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmoun
MinConfs: i.config.MinConfs,
FeeSatPerVByte: fee.SatPerVByte,
TargetConf: fee.TargetConf,
RoutingPolicy: &lightning.RoutingPolicy{
Ppm: uint32(i.config.FeeRate * 1_000_000),
BaseMsat: i.config.BaseFeeMsat,
},
})
if err != nil {
log.Printf("paymenthash %x, client.OpenChannelSync(%x, %v) error: %v", paymentHash, destination, capacity, err)
Expand Down
6 changes: 6 additions & 0 deletions lightning/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ type GetChannelResult struct {
HtlcMinimumMsat uint64
}

type RoutingPolicy struct {
Ppm uint32
BaseMsat uint64
}

type OpenChannelRequest struct {
Destination []byte
CapacitySat uint64
MinConfs *uint32
FeeSatPerVByte *float64
TargetConf *uint32
RoutingPolicy *RoutingPolicy
}

type Channel struct {
Expand Down
12 changes: 12 additions & 0 deletions lnd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,25 @@ func (c *LndClient) IsConnected(destination []byte) (bool, error) {
}

func (c *LndClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoint, error) {
var baseFee uint64
var feeRate uint64
useFees := false
if req.RoutingPolicy != nil {
useFees = true
baseFee = req.RoutingPolicy.BaseMsat
feeRate = uint64(req.RoutingPolicy.Ppm)
}
lnReq := &lnrpc.OpenChannelRequest{
NodePubkey: req.Destination,
LocalFundingAmount: int64(req.CapacitySat),
PushSat: 0,
Private: true,
CommitmentType: lnrpc.CommitmentType_ANCHORS,
ZeroConf: true,
BaseFee: baseFee,
UseBaseFee: useFees,
FeeRate: feeRate,
UseFeeRate: useFees,
}

if req.MinConfs != nil {
Expand Down
Loading