Add saving rebalance results to a CSV file

pull/1/head
rkfg 2 years ago
parent f22cd2574b
commit 4d0cef0ff5

@ -57,6 +57,7 @@ rebalance-lnd](https://github.com/accumulator/rebalance-lnd).
-d, --exclude-node= don't use this node for routing (can be specified multiple times)
--to= try only this channel as target (should satisfy other constraints too)
--from= try only this channel as source (should satisfy other constraints too)
-s, --stat= save successful rebalance information to the specified CSV file
```
Look in `config.json.sample` for corresponding JSON keys, they're not exactly

@ -8,6 +8,7 @@ var (
hiWhiteColorF = color.New(color.FgHiWhite, color.Bold).SprintfFunc()
cyanColor = color.New(color.FgBlue, color.Bold).SprintFunc()
errColor = color.New(color.FgHiRed, color.Bold).SprintFunc()
errColorF = color.New(color.FgHiRed, color.Bold).SprintfFunc()
infoColor = color.New(color.FgHiYellow, color.Bold).SprintFunc()
infoColorF = color.New(color.FgHiYellow, color.Bold).SprintfFunc()
)

@ -10,6 +10,7 @@
"probe_steps": 5,
"pfrom": 10,
"pto": 30,
"stat": "stats.csv",
"exclude_channels_in": [
821913529170526209,
821280210377179136

@ -38,6 +38,7 @@ var params struct {
ExcludeNodes []string `short:"d" long:"exclude-node" description:"don't use this node for routing (can be specified multiple times)" json:"exclude_nodes"`
ToChannel uint64 `long:"to" description:"try only this channel as target (should satisfy other constraints too)" json:"to"`
FromChannel uint64 `long:"from" description:"try only this channel as source (should satisfy other constraints too)" json:"from"`
StatFilename string `short:"s" long:"stat" description:"save successful rebalance information to the specified CSV file" json:"stat"`
}
type regolancer struct {
@ -56,6 +57,7 @@ type regolancer struct {
excludeOut map[uint64]struct{}
excludeBoth map[uint64]struct{}
excludeNodes [][]byte
statFilename string
}
func loadConfig() {
@ -178,6 +180,7 @@ func main() {
nodeCache: map[string]*lnrpc.NodeInfo{},
chanCache: map[uint64]*lnrpc.ChannelEdge{},
failureCache: map[string]*time.Time{},
statFilename: params.StatFilename,
}
r.lnClient = lnrpc.NewLightningClient(conn)
r.routerClient = routerrpc.NewRouterClient(conn)

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/lightningnetwork/lnd/lnrpc"
@ -83,6 +84,20 @@ func (r *regolancer) pay(ctx context.Context, invoice *lnrpc.AddInvoiceResponse,
return fmt.Errorf("error: %s @ %d", result.Failure.Code.String(), result.Failure.FailureSourceIndex)
} else {
log.Printf("Success! Paid %s in fees", hiWhiteColor(result.Route.TotalFeesMsat/1000))
if r.statFilename != "" {
_, err := os.Stat(r.statFilename)
f, ferr := os.OpenFile(r.statFilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if ferr != nil {
log.Print(errColorF("Error saving rebalance stats to %s: %s", r.statFilename, ferr))
return nil
}
defer f.Close()
if os.IsNotExist(err) {
f.WriteString("timestamp,from_channel,to_channel,amount_msat,fees_msat\n")
}
f.Write([]byte(fmt.Sprintf("%d,%d,%d,%d,%d\n", time.Now().Unix(), route.Hops[0].ChanId,
lastHop.ChanId, route.TotalAmtMsat-route.TotalFeesMsat, route.TotalFeesMsat)))
}
return nil
}
}

Loading…
Cancel
Save