Skip to content

Commit

Permalink
Make fees test-able
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson committed Mar 24, 2023
1 parent 9e77715 commit 88677c9
Show file tree
Hide file tree
Showing 9 changed files with 811 additions and 69 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ Example `fees.service`:

```
[Unit]
Description=Set fees of LND node
Description=Monitor channel fees of LND node
Wants=lnd.service
After=lnd.service
[Service]
User=lightning
Expand All @@ -82,7 +84,11 @@ Environment=RAIJU_MAC_PATH=/home/lightning/.lnd/data/chain/bitcoin/mainnet/admin
Environment=RAIJU_TLS_PATH=/home/lightning/.lnd/tls.cert
Environment=RAIJU_STANDARD_LIQUIDITY_FEE_PPM=200
ExecStart=/usr/local/bin/raiju fees -daemon
[Install]
WantedBy=multi-user.target
```

## rebalance

**Actively manage channel liquidity**
Expand Down
4 changes: 3 additions & 1 deletion cmd/raiju/raiju.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ func main() {
standard = *standardLiquidityFeePPMOverride
}

return r.Fees(ctx, raiju.NewLiquidityFees(standard), *daemon)
_, err = r.Fees(ctx, raiju.NewLiquidityFees(standard), *daemon)

return err
},
}

Expand Down
1 change: 1 addition & 0 deletions lightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type Channel struct {
Edge
ChannelID ChannelID
LocalBalance Satoshi
LocalFee FeePPM
RemoteBalance Satoshi
RemoteNode Node
}
Expand Down
11 changes: 11 additions & 0 deletions lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/nyonson/raiju/lightning"
)

//go:generate moq -stub -skip-ensure -out lnd_mock_test.go . channeler router invoicer

// channeler is the minimum channel requirements from LND.
type channeler interface {
DescribeGraph(ctx context.Context, includeUnannounced bool) (*lndclient.Graph, error)
Expand Down Expand Up @@ -128,9 +130,13 @@ func (l Lnd) GetChannel(ctx context.Context, channelID lightning.ChannelID) (lig
return lightning.Channel{}, err
}

// figure out if which node is local and which is remote
remotePubkey := ce.Node1
// FeeRateMilliMsat is a weird name
localFee := lightning.FeePPM(ce.Node2Policy.FeeRateMilliMsat)
if local.IdentityPubkey == remotePubkey {
remotePubkey = ce.Node2
localFee = lightning.FeePPM(ce.Node1Policy.FeeRateMilliMsat)
}

remote, err := l.c.GetNodeInfo(ctx, remotePubkey, false)
Expand All @@ -145,6 +151,7 @@ func (l Lnd) GetChannel(ctx context.Context, channelID lightning.ChannelID) (lig
Node2: lightning.PubKey(ce.Node2.String()),
},
ChannelID: lightning.ChannelID(ce.ChannelID),
LocalFee: localFee,
RemoteNode: lightning.Node{
PubKey: lightning.PubKey(remote.PubKey.String()),
Alias: remote.Alias,
Expand Down Expand Up @@ -188,9 +195,12 @@ func (l Lnd) ListChannels(ctx context.Context) (lightning.Channels, error) {
return nil, err
}

// figure out if which node is local and which is remote
remotePubkey := ce.Node1
localFee := lightning.FeePPM(ce.Node2Policy.FeeRateMilliMsat)
if local.IdentityPubkey == remotePubkey {
remotePubkey = ce.Node2
localFee = lightning.FeePPM(ce.Node1Policy.FeeRateMilliMsat)
}

remote, err := l.c.GetNodeInfo(ctx, remotePubkey, false)
Expand All @@ -206,6 +216,7 @@ func (l Lnd) ListChannels(ctx context.Context) (lightning.Channels, error) {
},
ChannelID: lightning.ChannelID(ci.ChannelID),
LocalBalance: lightning.Satoshi(ci.LocalBalance.ToUnit(btcutil.AmountSatoshi)),
LocalFee: localFee,
RemoteBalance: lightning.Satoshi(ci.RemoteBalance.ToUnit(btcutil.AmountSatoshi)),
RemoteNode: lightning.Node{
PubKey: lightning.PubKey(remote.PubKey.String()),
Expand Down
Loading

0 comments on commit 88677c9

Please sign in to comment.