circular is a high-performance Core Lightning plugin designed for routing nodes to rebalance channels efficiently and cost-effectively.
It features a custom edge-based backwards Dijkstra pathfinding algorithm that accounts for channel liquidity, bLIP-18 inbound fee policies (discounts and surcharges), and feedback from failed payment attempts.
- bLIP-18 Inbound Fee Aware: Parses gossip TLV type 55555 for inbound fees, computing exact net fees (
max(0, outbound + inbound)) to discover routes with negative fee discounts. - Success-Aware Routes: Weighs each route's fees against its chance of success, from what circular knows of each channel's liquidity, so it prefers routes likely to carry the payment over slightly cheaper ones that are not (
circular-risk-ppm). - Failure-Informed Pathfinding: Automatically excludes failing channels across retry attempts, bypassing bottlenecks without getting stuck on dead routes.
- Parallel Multi-Channel Rebalancing: Simultaneously pull into or push out of target channels across multiple peers (
circular-pullandcircular-push). - In-Flight Payment Tracking: Real-time visibility into active parallel rebalancing operations via
circular-active. - Fee-Aware Selection: Prioritizes lowest-cost outgoing routes rather than blindly picking the largest balance channel.
- Safe Self-Payments: Each attempt pays a short-lived invoice (label
circular-…) that circular deletes once the attempt ends. lightningd checks the incoming HTLC's payment secret, amount and CLTV before it settles, so circular needs nohtlc_acceptedhook.
Earlier versions settled rebalances from an htlc_accepted hook that released the preimage for any HTLC carrying a known payment hash, including forwarded HTLCs and HTLCs paying less than the rebalance amount. A node on a rebalance route could use that to obtain the preimage and keep the payment. If you run an older build, update before rebalancing again.
circular-pull: Pull liquidity into a channel using multiple peer channels as sources in parallelcircular-push: Push liquidity out of a channel using multiple peer channels as destinations in parallelcircular: Rebalance between two specific channels by Short Channel ID (inscid/outscid)circular-node: Rebalance between two specific peers by Node ID (innode/outnode)circular-quote: Show what acircular-pull,circular-pushorcircularrun would try first, without paying anything; withmeasure=true, probe what its routes carry now (payments nobody can settle: nothing is paid)circular-active: List currently active in-flight rebalancing paymentscircular-stats: Get usage statistics and historical performance datacircular-delete-stats: Reset and delete saved rebalancing statisticscircular-stop: Stopcircularfrom firing new HTLCs (active ones will complete)circular-resume: Resume normal rebalancing activity after acircular-stopcircular-nodes [limit]: The nodes remembered for failing rebalances' payments (circular-node-memory), most first: their score and what it adds to routes through them, in ppmcircular-results [target]: Thecircular-pull/circular-pushruns circular knows - the running ones and the last 20 finished, in memory since the plugin started - newest first:kind,target,amount,maxppm,started,ended,status(running / done / failed) and theresultthe call returned (orerror). A caller whose connection was cut meanwhile (alightning-clikilled with the program that started it) reads the result here; the run itself goes on inside the plugin either waycircular-candidates [scid] [limit]: How each of your channels did as acircular-pullorcircular-pushcandidate, in the order runs rank them (see below)
Detailed explanation of the endpoints follows in the Usage section.
You need Go 1.18 or higher to build this plugin.
git clone https://github.com/btweenthebars/CLN-circular.git
cd CLN-circular
go build -o circular ./cmd/circular
chmod +x circularAlternatively, you can run:
make buildThis plugin is dynamic, meaning that you can start and stop it via the CLI. For general plugin installation instructions see How to install a plugin.
The executable that you have just built is called circular.
The startup options are:
-
circular-graph-refresh(minutes): How often the graph is refreshed. Default is 10. At each refresh and at shutdown, what rebalances have learned about channels' liquidity is saved tocircular/learned.json(a few hundred KB), and loaded at the next start. Earlier versions saved the whole graph tograph.jsoninstead; its beliefs are migrated at the first start, then the file is removed. -
circular-peer-refresh(seconds): How often the list of peers is refreshed . Default is 30. -
circular-liquidity-refresh(minutes): Period of time after which we consider a liquidity belief not valid anymore. Default is 300. -
circular-liquidity-halflife(minutes): How fast a liquidity belief fades back toward the default (half the capacity): half of the way every this many minutes. Default is 60; 0 turns fading off, so beliefs hold in full untilcircular-liquidity-refresh. -
circular-risk-ppm(ppm): How much a route's chance of success weighs against its fees. Default is 200; 0 (or less) chooses routes as before: the fewest hops withinmaxppm, then the cheapest. Each channel between your two peers gets a chance of carrying the payment: circular takes what it believes the channel holds (half its capacity until payments teach it otherwise) as the middle of an even spread of possible balances. The search then takes the route with the least fees plus, for each channel, -ln(its chance) times this many ppm of the amount: a channel with an even chance adds about 0.69 × 200 = 139 ppm, one with a 99% chance about 2 ppm.maxppmstill bounds the fees themselves. If no route fits this way, the search falls back to the one used with 0, so it never finds fewer routes. Higher values favour likely routes more. With it on, the number of hops is no longer kept to the least: a route may use up tomaxhopschannels when the extra ones are likely to carry the payment, so setmaxhopsto the longest route you accept. A channel no payment has told circular about, whose proportional fee (ppm) is at least twice, and 50 ppm above, the median over its node's active channels (for nodes with at least 3 channels; recomputed at each graph refresh), is taken to hold about 30% of its capacity rather than half: automatic fee managers raise a channel's fee as it drains, and among one node's 140 channels with known balances, those priced that way held a median of about 20% on the peer's side, the others about 40%. This only lowers its chance in the search; it does not change what the channel may carry. When a payment fails on a channel, circular knows it holds less than that amount: from then on any balance below it is taken as equally likely, so a split of 90% of the failed amount gets about a 10% chance there, and later splits and runs go elsewhere. The bound is kept inlearned.jsonand loosens toward the capacity withcircular-liquidity-halflife, the chance it gives rising back to what an unknown channel gets; a payment larger than the bound ends it, and smaller ones it carries lower it by what they moved. -
circular-attempts,circular-max-hops,circular-max-node-fails,circular-max-fail-streak,circular-max-time(seconds) andcircular-max-fee(sats): what the rebalance commands use forattempts,maxhops,maxnodefails,maxfailstreak,maxtimeandmaxfeewhen a call leaves them out. Defaults are the commands' own: 1, 8, 5, 300, 0 (no time limit) and 0 (no fee budget). A value a call gives always wins; a call can turn off a node-wide time limit or fee budget withmaxtime=-1ormaxfee=-1, and a fail-streak limit withmaxfailstreak=-1. Setcircular-max-fail-streakto -1 to turn the limit off for every run. -
circular-fee-ratio(e.g. 0.8) andcircular-earn-days(days): whatcircular-pullandcircular-pushuse forfeeratiowhen a call leaves it out (default 0, off), and how many days of forwards count for what a channel earns (default 30). -
circular-save-stats(boolean): Whether to save stats about the usage of the plugin. Default is true. Save this to false if you are not interested in stats, as this data can grow big if you are running a lot of rebalances. You can delete the stats with the methodcircular-delete-stats. -
circular-node-memory(hours): How long nodes that keep failing rebalances' payments are remembered. Default is 24; 0 turns it off. Each payment a node fails in the middle of a route (past your out-peer and before your in-peer: it could not forward for lack of liquidity, a channel down, or a failure of its own; not a fee, CLTV or amount error, which only shows that your copy of its policy was out of date) adds 1 to its score; each payment it forwards halves it; and the score halves every this many hours. Withcircular-risk-ppm, the route search treats a node's score as a lower chance for every channel out of it: 50 failed payments cost as much as a channel with a chance of 1/e,circular-risk-ppmppm of the amount (200 by default), up to 1000 ppm at 250 failures. A node that failed a hundred payments in a run costs routes through it about 400 ppm right after, 200 ppm a day later, so they go elsewhere while a way that costs less exists; one that failed a few barely moves. Scores are kept inlearned.json;circular-nodeslists them. Routes chosen by fees alone (riskppm=-1,circular-risk-ppm=0) ignore them: the scores are still kept, but no search uses them (circular-nodesthen shows apenalty_ppmof 0).
Some failures say nothing about liquidity, so circular avoids what caused them in every rebalance for the next 30 minutes, not only in the one that hit them: a node that failed the payment itself, an erring node that was not on the route, a channel whose fee or CLTV error persists after refreshing its policy, and channels failing with other codes. A newer channel_update, from gossip or listchannels, lifts a channel early. Your own peers are only avoided for the rebalance that hit them. The list is saved in learned.json. A channel found disabled or closed is not faded back by circular-liquidity-halflife; it waits for the hard reset or a newer policy.
You can also set a preferred logging level. For example, with this startup command you would refresh the graph every 5 minutes, peers every 60 seconds, and reset liquidity on channels every 120 minutes. You would also not save stats and set the logging level to DEBUG.
⚠ This command is meant to be an example of how to use startup options. You should probably use a configuration file for CLN instead of starting it in this way.️
lightningd --plugin=/path/to/circularexecutable --circular-graph-refresh=5 --circular-peer-refresh=60 --circular-liquidity-refresh=120 --circular-save-stats=false --log-level=debug:plugin-circularThe params that mean something below 0 (riskppm, maxfailstreak, maxtime, maxfee, feeratio, maxidlerounds, probefailstreak) also take a number written as a string: lightning-cli -k leaves a value unquoted only when it is all digits and dots, so feeratio=-1 reaches the plugin as "-1". (Before, such a call failed with Incompatible types or Expecting float64 input.) All but feeratio take whole numbers only: maxfee=1.5 is refused, where it used to be cut to 1.
via Short Channel ID:
lightning-cli circular -k inscid=123456x1x1 outscid=345678x1x1 amount=200000 maxppm=10 attempts=1via Node ID:
lightning-cli circular-node -k outnode=123abc innode=345def amount=200000 maxppm=10 attempts=1Required parameters:
outnodeoroutscid: the node/scid that you want to use to send the paymentinnodeorinscid: the node/scid where you want to receive the payment
Optional parameters:
amount(sats, default=200000) is the amount that you want to rebalancemaxppm(default=10) is the maximum ppm that you are willing to payattempts(default=1, orcircular-attempts) is the number of payments that may be made once a path is found (one more in the parallel commands when a split's reused route fails). Theattemptsa rebalance reports are the payments it made; searches that found no route are not counted.maxnodefails(default=5, orcircular-max-node-fails) is how many of a rebalance's payments one node may fail to forward for lack of liquidity. Each failure only rules out the channel that failed, so a drained node with many channels would otherwise cost one payment per channel. After that many, the rest of the rebalance routes around the node; if it is the peer of the out channel, which every route goes through, the rebalance stops:circular-pullthen leaves that channel out for the rest of the run, andcircular-push, whose every split goes out through that peer, starts no more splits. Set it aboveattempts+ 1 to turn it off.riskppmsetscircular-risk-ppmfor this call only: above 0, that rate; -1, routes chosen by fees and hops alone; left out, the startup option.maxhops(default=8, orcircular-max-hops) is the maximum number of hops that a path is allowed to have
lightning-cli circular-pull -k inscid=123456x1x1 amount=500000 splits=5 splitamount=20000 maxppm=10 maxoutppm=50 attempts=1 maxhops=8 depleteuptopercent=0.5 depleteuptoamount=2000000Required parameters:
inscid: the Short Channel Id where you want to pull liquidity.
Optional parameters:
amount(sats, default=400000) is the total amount that you want to rebalancesplits(default=4) is the maximum number of rebalances that will happen in parallelsplitamount(sats, default=100000) is the amount that each rebalance will carryminsplit(sats, default=splitamount, which turns it off) is the smallest amount a split may shrink to. By default a split always asks for its full amount. With a lowerminsplit, a split whose route fails because a channel along it lacks liquidity still searches for another route first; only if none is left does it send half the amount over the route that was short, down tominsplit, and later searches look for the smaller amount. Each payment with less uses one of theattempts, so this also needsattemptsof 2 or more.maxoutppm(default=50) is the maximum ppm of the outgoing channels thatcircularis allowed to use to rebalanceinscid. Useful to avoid rebalancing a channel from channels where you can profitmaxppm(default=10),attempts(default=1),maxnodefails(default=5),riskppmandmaxhops(default=8) are the same as for thecircularcommandmaxfailstreak(default=300, orcircular-max-fail-streak): once this many payments in a row have failed, across all splits, without a split succeeding in between, no more splits are started; splits already in flight stop before their next payment, and the result'sstoppedsays why (it also says so when the target channel takes no more). A later success does not start firing again. It counts payments, so withattempts=100the default amounts to about 3 failed splits in a row. A run whose target nothing can reach withinmaxppmotherwise goes through every candidate'sattempts. Set it to -1 to turn this off.maxtime(default=0, no limit, orcircular-max-time; -1 for none whatever the node's default): once the run has taken this many seconds, it stops as formaxfailstreak: no more splits are started, splits already in flight stop before their next payment (a payment already sent still completes), andstoppedsays so. What moved until then counts.maxfee(default=0, no budget, orcircular-max-fee; -1 for none whatever the node's default): the most the whole run may pay in fees, in sats. A split is started only if what the run has paid, plus the most the splits in flight can still cost, plus the most this split can cost (its amount atmaxppm), fits; so the run never pays more thanmaxfee(barring a payment that settles after its timeout because its invoice could not be deleted). When the next split doesn't fit, the run waits for the splits in flight (they usually cost less than their most), and once none is left in flight, it stops andstoppedsays what was paid. A budget below one split atmaxppmstarts nothing: raise it, or lowermaxppmorsplitamount.retryevery(seconds, default 0, off): slow mode. When a run falls short (no candidate left,maxfailstreakreached, or the target took no more), it waits this long (at least 60 s), finds the candidates again and runs another round, until the target is reached,maxtime(6 hours if the call and the node give none;maxtime=-1doesn't turn the limit off in slow mode),maxfee, orcircular-stop. Fees and liquidity change through the day: a route that costs more thanmaxppmnow may not in an hour. Totals add up over the rounds; the result says how many there were (rounds) and why the last one that fell short did (last_round), and the progress lines go on while it waits.stepppm,capppmandprobe(sats): slow mode that steps the price up to find one that flows. After a round that moved nothing because of its price (every route found cost more thanmaxppm, the in-peer alone did, or payments failed in the middle of the routes within it, past our own peers; splits with a lowerfeeratiolimit of their own don't count, as a highermaxppmdoesn't raise it), the next round, at once, triesstepppmmore than the lastmaxppm(never abovecapppm, which is required and at leastmaxppm) for a small amount:probesats, by default 20% of what is left (at least a split). Once a probe moves something, the rest goes, at once, at the highest rate the probe paid plus half a step (never abovecapppm): what the network actually took, not the step. A round that moved nothing atcapppmwaitsretryevery(10 minutes if not given) and probes again; a round that could try nothing (channels depleted, peers offline, the target refusing: no sign of the price), or a full round that moved some, waits, and tries again at the same limit. A probe at a higher limit keeps more ofmaxfeeaside for its splits in flight (their worst case at that limit), so a budget that is nearly spent can end the run sooner.maxfeeandfeeratiostill hold on every round. Withfeeratio, a split can never pay more than its own limit, ratio × what the filled channel earned less your fee on the drained one, whatevermaxppmis; so stepping goes no higher than the most any split of the round could pay, and waits there as atcapppm(the log says "the most its splits can pay at feeratio"). A round whose splitsfeeratioall held below itsmaxppmshows the highest of their limits aslimit_ppminround_history, and says so in the log and inlast_round("feeratio held its splits to at most N ppm"); passfeeratio=-1to step past it. The result'sround_historylists each round'smaxppm, what it asked for and moved, the rate it paid (paid_ppmon average,max_paid_ppmat most) and, whenfeeratioheld its splits lower,limit_ppm. For example, 5M at 1100 withstepppm=300 capppm=1700: 1100 for 5M moves nothing; 1400 for 1M moves it, paying at most 1250; the other 4M then go at 1400.probefailstreak(default 100 withstepppm, otherwise none; -1 for none): a probe round stops after this many failed payments in a row, asmaxfailstreakdoes for the run, when that is lower, and each of its splits makes at most that many payments (the streak is counted as splits finish, so withsplits=2a probe can make up to about twice as many): a probe only tests a price, and on a busy network a full streak of 300 payments costs your peers' channels more than it tells.last_roundthen names it (probefailstreak 100).avoid: nodes and channels this run never routes through, besides the saved list (see avoid list): node ids, short channel ids (both directions) orscid/direction, as a JSON list (avoid='["03ab...","812345x12x0"]') or one string with commas or spaces. A candidate channel on it, or whose peer is, is skipped ("avoided: ..." instopped). Naming the target channel (any direction) or its peer is refused: the run goes through them, so they cannot be avoided (the same for the pair quote's two channels). Short channel ids are written without leading zeros, as CLN writes them.softavoid,softavoidscore,softavoidstreak: what the run's routes leave out at first, and when it lets them back (see soft avoid).maxrunnodefails(default 10; -1 for never): a node in the middle of the routes that fails this many of the run's payments for lack of liquidity, counted across all its splits, is routed around for the rest of the run (in slow mode, of the round: its liquidity may be back by the next).maxnodefailscounts per split and starts over with each one, so a drained hub could otherwise fail dozens of a run's payments. A failure counts against a node in the middle of a route, never against the split's own two peers (its candidate's and the target's); a candidate's peer can still be dropped for failing in the middle of other splits' routes, and is then routed around there, while its own split still goes through it. The result lists them indropped_nodes(node id, alias,failed_payments).probeonly(default false): pay nothing. Every payment of the run is a probe instead, a payment nobody can settle, and the run tells what its probes found the routes to carry: see a probe-only run. Not withretryeveryorstepppm.maxidlerounds(default 3 withstepppm, otherwise off; -1 for never): slow mode gives up after this many rounds in a row that moved nothing at the most the run can pay, when the price is what held them back (routes cost more, or payments failed on the routes within it, orfeeratioheld the splits lower), instead of retrying untilmaxtime. The most it can pay ismaxppmwithout stepping; with it,capppm, or withfeeratiothe most any split can pay if lower. Rounds that could try nothing (channels depleted, peers offline) neither count nor start the count over; a round that moves something, or that ran below a top that has since risen (the filled channel earned more), starts it over. Incircular-push, a candidate left out because its peer charges more thanmaxppmkeeps the top atcapppm: what it could pay is not known.stoppedthen says so, with that rate and the cheapest route found, e.g.gave up: 3 rounds in a row at the most this run can pay (1274 ppm, feeratio) moved nothing; the cheapest route found cost 1715 ppm;last_roundkeeps why the last round fell short.feeratio(default=0, off, orcircular-fee-ratio; -1 for off whatever the node's default): pay only what the rebalance is worth. Each split may pay at mostfeeratio× what the filled channel earns, less your fee on the drained channel, and never more thanmaxppm. What a channel earns is what its forwards out paid, as ppm of what they carried, over the lastcircular-earn-days(default 30); with less than 100,000 sats of such forwards, your current fee on it stands in. Incircular-pullthe target is filled and each candidate drained; incircular-pushthe target is drained and each candidate filled. Withfeeratio=0.8, a target whose forwards earned 500 ppm and a candidate on which you charge 100 ppm give that candidate's splits a limit of 0.8 × 500 − 100 = 300 ppm. A candidate whose limit comes to nothing, or whose in-peer alone charges more than that limit, is skipped (not worth it at feeratioinstopped, and in the log with its numbers). The forwards are read before the run starts, several channels at once, and kept for 10 minutes, so runs started meanwhile don't read them again. At 1, a rebalance breaks even if the liquidity sells again at the rate it earned; below 1 keeps a margin.maxfeestill holds each split tomaxppmin its reckoning.outlistis a JSON array of node ids that you want to use as sources. If this is specified,maxoutppmis ignored. An example of how to use this parameter is the following:
cli circular-pull -k inscid=123456x1x1 outlist='["03700917a25f79a3e427fe86e49b5041b583c73dd223cfa9a87cd6be5076b7b7a5", "025614be3600e9899bc044d331ab58a9fe1ccf30e75ae35943cdd11218a0a55dba"]' amount=800000 splitamount=80000 splits=4 maxppm=5000depleteuptopercent and depleteuptoamount are a bit special:
depleteuptopercent(default=0.2) is a threshold percentage for the amount to leave in the outgoing channels. This must be between 0 and 1.depleteuptoamount(sats, default=1000000) is a value in sats for the amount to leave in the outgoing channels. The actual amount that is going to be left in the outgoing channels is the minimum ofdepleteuptopercentanddepleteuptoamount.
Example: you have a 10M channel and you set depleteuptopercent to 0.2 (20%) and depleteuptoamount to 1000000. The actual amount that will be left in that channel will be the minimum of 0.2 and 1000000. So in this case, at least 1000000 sats will be left in that channel.
A channel is only used for a split if its balance, less the HTLCs in flight, stays above the threshold after sending that split and its fees.
The result of circular-pull (and circular-push) looks like this:
{
"rebalance_target": 2926336,
"rebalanced_amount": 640136,
"attempts": 2073,
"time": "4877.893s",
"fees_paid_msat": 483943,
"avg_ppm": 756,
"splits_succeeded": 32,
"splits_failed": 311,
"successes": {
"123456x1x0": {
"alias": "BCash_Is_Trash",
"node_id": "02...",
"756": 640136,
"involving": ["03...", "02..."]
}
},
"worst_nodes": [
{"alias": "Garlic", "node_id": "03...", "failed_payments": 14},
{"node_id": "02...", "failed_payments": 6}
]
}Each entry in successes is a candidate channel: its peer, the sats moved at each fee rate (ppm), and under involving the other nodes its successful routes went through, each once, in the order first seen (without your node and that peer; the target channel's peer is in every entry). attempts is the total of payments the splits made. fees_paid_msat and avg_ppm are what the successful splits paid, in all and as a rate of what they moved; splits_succeeded and splits_failed count the splits (leaving out those a stop ended). When splits failed because every route cost more than maxppm, cheapest_ppm_over_max is the lowest rate of the cheapest routes they found: the maxppm their search would have needed. Splits stopped before any search because the peer sending to you charges more than maxppm on its own are not counted there; their message says what that peer charges. With feeratio, feeratio_skipped counts the candidates left out before trying (not worth it), and feeratio_held the splits that failed on their own limit where maxppm would have let them go on: a route cost more than their limit but no more than maxppm, or their in-peer alone charged more than their limit but no more than maxppm. When a run with feeratio moves too little, a feeratio_held or feeratio_skipped above 0 means the ratio held it back (raise it, or pass feeratio=-1 to pay up to maxppm); a cheapest_ppm_over_max above maxppm means maxppm would have held it back too (with feeratio it can also be below maxppm: it is measured against each split's own limit). A split that feeratio held below maxppm says so in its message, with how its limit came about: route too expensive. Cheapest route found was 1519 ppm, but this split's own limit is 1170 ppm (feeratio 0.9 × 1300 ppm earned by the filled channel − 0 ppm our fee on the drained one; maxppm 1600) (our fee on the filled channel (too few forwards to go by) when its forwards carried too little), and the same for an in-peer that charges more than that limit. When no candidate was left and feeratio held every split of the run's last round below maxppm, with some failing where maxppm would have let them go on, stopped ends with ; feeratio held its splits to at most 1170 ppm, and the cheapest route found cost 1519 ppm: raise feeratio, or pass feeratio=-1 to pay up to maxppm 1600. worst_nodes lists the 5 nodes that failed the most of the run's payments (for any reason, in any split, including those that succeeded in the end), most first; failures on your own channels are not counted, so a busy target channel doesn't show up there, but the peers at either end do when their channels onward fail (in circular-push, often the target's peer, when it has little outbound liquidity left). last_error, when present, is the last failed split's message, prefixed with that split's channel and peer (last failed split, via 123456x1x0 (alias): ...); its count of payments is that split's alone. stopped, when the run fell short of its target, says why it started no more splits: the target channel took no more, maxfailstreak, maxtime or maxfee was reached, or no candidate was left, as in no candidates left: 4 failed, 1 refused by the target, 3 skipped (channel is depleted). A candidate counts for the last thing that happened to it: its last split failed (on its channel, along the route, or for a reason neither channel is to blame for, such as a timeout), the target refused it, or it was skipped because it could no longer be used, with the reason (channel is depleted: down to depleteuptopercent/depleteuptoamount in circular-pull; channel is filled: up to filluptopercent/filluptoamount in circular-push; its peer is disconnected; the channel is not in normal state, or no longer found). After circular-stop, stopped says so instead, and no more splits are started.
While a circular-pull or circular-push runs for longer than 30 seconds, it logs how it is going every 30 seconds, at the INFO level:
circular-pull 965538x2935x4: 1200000/3000000 sats moved in 312s, 143 payments, avg 280 ppm, 2 splits in flight, 23 payments failed in a row
The payments include those of the splits still in flight; the average fee rate appears once a split has succeeded, and the count of failures in a row (of the splits that have finished) once the last ones failed.
Candidates are tried best first, by how they did in earlier splits (kept across runs in learned.json): a channel that failed in the last 30 minutes, and hasn't succeeded since, goes last; the others by success rate; then those that have moved liquidity before those that have not; then by the fee rate their splits paid (for those that have not, your own fee alone), adjusted by your own fee on the channel: circular-pull adds it, since draining a channel gives up what it earns you, and circular-push subtracts it, since filling a channel gives it more to earn. Channels never tried count as an even chance.
lightning-cli circular-candidates lists those records, in that order (before your own fee on each, which depends on the run's split amount), at most limit (default 50), or one channel's with scid=. Each has scid, as (pull: your channel to the peer, which circular-pull drains; push: the peer's to you, which circular-push fills; empty once the channel is no longer known), peer_id, alias, successes, failures, success_rate ((successes+1)/(successes+failures+2), what the ranking orders by), moved_sat and paid_ppm (what the counted successes moved and paid), last_success and last_failure (UTC), failing (its last split failed) and ranked_last_until (after a failure, runs try it after all the others until then). Past 50 results the counts are halved, so recent ones weigh more; count is how many records matched.
A failed split counts against its candidate only if it failed on the candidate's channel or along the route. If the target channel refuses a split because the other splits hold its HTLC slots or balance, the run keeps no more splits in flight than the target took, and the refused candidate is tried again once one finishes. That limit grows back by one once as many splits succeed, in case the refusal had another cause; each time growing it is refused, the run waits twice as long before trying again, and half as long once a growth holds. A candidate the target refuses as busy more than 3 times, beyond what the target's limit explains, is tried after the others. If the target refuses with nothing else in flight because our copy of its balance is too low, its channel is read again from lightningd and the split tried once more, since that copy may have been read while other splits held it. If it refuses that candidate again, or lightningd or the peer refused it, the candidate is left out for the run, as the target may refuse it alone (for the fees its route adds); if it then refuses another candidate alone too, or refuses for good (disabled, disconnected, its own fee above maxppm even with its inbound discounts), no more splits are started. A stale-fee failure on a channel of ours gets one more try, only if reading the channel again shows a new fee.
Once a split succeeds, the next split through the same channel first tries the same route again, with current fees, and only searches if that route is no longer usable or now costs more than maxppm. Splits that shrank count for what they delivered, and the following splits ask for what is left.
successes is keyed by the short channel id of each channel that was used: the outgoing channel drained by circular-pull, or the incoming channel filled by circular-push. Each entry has the peer's alias (when known) and node id, then the sats rebalanced at each fee rate paid, in ppm.
Symmetrical to circular-pull, but for pushing liquidity out of a channel.
lightning-cli circular-push -k outscid=123456x1x1 amount=500000 splits=5 splitamount=20000 maxppm=10 minoutppm=50 attempts=1 maxhops=8 filluptopercent=0.5 filluptoamount=2000000Required parameters:
outscid: the Short Channel Id from which you want to push out liquidity.
Optional parameters:
amount,splits,splitamount,minsplit,maxppm,attempts,maxnodefails,maxfailstreak,maxtime,maxfee,feeratio,retryevery,stepppm,capppm,probe,maxidlerounds,probefailstreak,probeonly,riskppmandmaxhopsare the same as for thecircular-pullcommand.minoutppm(default=50) is the minimum ppm charged by your node that a channel has to charge to be selected bycircular-push. Useful to avoid rebalancing a channel to channels where you can't profit from.inlistis a JSON array of node ids that you want to use as destinations. If this is specified,minoutppmis ignored. An example of how to use this parameter is the following:
cli circular-push -k outscid=123456x1x1 inlist='["03700917a25f79a3e427fe86e49b5041b583c73dd223cfa9a87cd6be5076b7b7a5", "025614be3600e9899bc044d331ab58a9fe1ccf30e75ae35943cdd11218a0a55dba"]' amount=800000 splitamount=80000 splits=4 maxppm=5000filluptopercent and filluptoamount are a bit special:
filluptopercent(default=0.8) is a threshold percentage for the minimum amount that is allowed to stay as remote liquidity in the incoming channels. This must be between 0 and 1.filluptoamount(sats, default=10000000) is a value in sats for the minimum amount that is allowed to stay as remote liquidity in the incoming channels. The actual amount that is going to be left in the incoming channels is the minimum offilluptopercentandfilluptoamount.
Example: you have a 10M channel and you set filluptopercent to 0.2 (20%) and filluptoamount to 1000000. The minimum amount of remote liquidity that will be left in that channel will be the minimum of 0.2 and 1000000. So in this case, at least 1000000 sats will be left in that channel.
As for circular-pull, the threshold is checked after the split, against the remote balance less the HTLCs in flight.
lightning-cli circular-quote -k inscid=123456x1x1 splitamount=20000 maxppm=500 maxoutppm=50 maxhops=6circular-quote takes the parameters of circular-pull (with inscid), circular-push (with outscid) or circular (with both), so you can swap the command name in a call you already make with named parameters (-k or key=value). Name them: positional arguments fill its fields in an order of its own, not that of the command you copied. It picks the candidates the same way and runs the same route search as a run, and pays nothing. For each candidate, in the order a run would try them, it shows the route of its first payment: fee rate, fee, hops and the path from your out-peer to your in-peer. A candidate without one shows why (error), and when every route costs more than maxppm, the cheapest rate found (cheapest_ppm). A candidate a run would not use, because of depleteuptopercent/depleteuptoamount or filluptopercent/filluptoamount, or because it is not worth it at feeratio, shows why under skipped. With feeratio, each candidate also shows its own limit (maxppm) and how it came to it (economics), and its route is quoted at that limit. Candidates a run leaves out before trying anything are not listed: those over maxoutppm (pull) or not over minoutppm (push), and in a push, peers whose fee to send to you is above maxppm even with their inbound discounts.
For a pull or a push it also answers for the whole amount, not just the first split: each candidate shows its room_sat (what a run may drain from it, or fill into it, by its balance and the deplete / fill limits, in whole splits: a pull's each with its fee at maxppm), and whole fills the amount from the candidates with a route, cheapest route first, each up to its room: covered (sats), how many candidates it takes, the cheapest and dearest route used (min_ppm, top_ppm), avg_ppm, fee_sat and a verdict ("the whole 2400000 sat: 3 candidates, routes 410-590 ppm (avg 480), about 1152 sat in fees, if their routes carry more than the first split", or "only 900000 of 2400000 sat: ..."). A route's liquidity beyond its first split is not known, so it is an upper bound at those prices, not a promise.
{
"mode": "pull",
"target": "123456x1x1",
"target_peer": "Target",
"amount": 20000,
"maxppm": 500,
"summary": "1 of 2 candidates have a route within 500 ppm (cheapest 412 ppm); 1 would fail (the cheapest route above maxppm is 518 ppm)",
"candidates": [
{
"scid": "234567x1x1",
"alias": "Zero",
"node_id": "02...",
"ppm": 412,
"fee_msat": 8240,
"hops": 5,
"path": ["Zero", "Hub", "Other", "Target"],
"estimate": 0.83,
"guessed_hops": 2
},
{
"scid": "345678x1x1",
"alias": "One",
"node_id": "03...",
"cheapest_ppm": 518,
"error": "route too expensive. Cheapest route found was 518 ppm, but maxppm is 500"
}
]
}estimate is a rough chance that the route can carry the payment: the product of each channel's chance, as circular-risk-ppm describes. guessed_hops counts the channels no payment has told circular about, for which any balance up to the capacity is taken as equally likely. It is a guide for comparing routes, not a promise. A quote reflects what circular knows at that moment: what earlier payments taught it and the nodes it is avoiding. remembered lists the nodes on the route remembered for failing payments (circular-node-memory), with their score and what each adds to the route in the search (penalty_ppm); the summary counts the routes through any.
lightning-cli circular-quote -k inscid=123456x1x1 amount=2000000 splitamount=100000 maxppm=900 measure=trueWith measure=true the quote no longer guesses: it sends the routes probes, payments that nobody can settle (a random payment hash, with no invoice and no preimage anywhere), so they can only fail: at your own node, which knows no such payment, once every channel along the route carried the amount; or where a channel could not. Nothing is paid, nothing moves, and each probe's record is deleted from listsendpays once it failed (one still in flight after 30 s when it fails). The candidates with a route are measured cheapest first, until the run's amount is covered: each searches up to 3 routes until one carries a split (each search avoids what the probes before found short), then probes that route up to 3 more times for how much more it carries, up to what is left of the amount and the candidate's room_sat (the whole of it first, then halfway: a binary search, in whole splits). Each candidate measured shows measured: carried_sat (the most its route carried), that route's ppm, hops and path, probes, and error when no route carried a split. whole then comes from what was carried, cheapest measured route first, with measured: true, probes, and a verdict that says so ("measured: routes carry the whole 2000000 sat now: 3 candidates, routes 410-760 ppm (avg 560), about 1120 sat in fees (11 probes, nothing paid)", or "measured: routes carry only 600000 of 2000000 sat now ...", or "measured: none of the few routes it tried carried a split (9 probes, nothing paid); this does not show that none can: ..."). Measuring stops at 40 probes or 100 seconds from the call's start, or at circular-stop, and the verdict says so when that left part of the amount unmeasured. For a firmer answer, measureprobes (up to 1000) and measuretime (seconds from the call's start, up to 1800) raise those limits, and either one turns measure on: measureprobes=150 measuretime=300 tries far more routes on a hard target, where 40 probes can run out after about ten candidates. Each multiple of 40 in measureprobes also searches each candidate harder: 150 probes give each candidate 9 route searches and up to 8 sizing probes instead of 3 and 3, so a deep measure rests on more routes per candidate, not only more candidates (measuretime alone only gives more time). Even so, a measure that finds nothing is weak evidence: it gives up on a candidate after a few routes, where a run tries up to attempts on each split. A run has moved a whole amount minutes after a deep measure found nothing, through the first candidate the measure had given up on: the route that worked came after some 180 that did not. A measure's "carried" can be relied on; for a "nothing carries" that can, use a probe-only run, below. A probe started just before the time is up can take up to 30 s more, so wait measuretime + 30 s for the answer (lightning-cli waits as long as it takes). With inscid and outscid (a pair), the one payment is measured. Nothing is measured while a circular-pull or circular-push is running: probes would hold liquidity on the channels its splits use and make them fail; not_measured says so, and the quote is as without measure. A run that starts while it measures stops it before the next probe. When nothing could be probed at all (no time left after the quote itself, circular-stop, no candidate with a route), the quote is also left as it was, and not_measured says why.
What the probes find is learned like a payment's outcome: a channel that carried a probe holds at least its amount; one that could not holds less, and the nodes that failed it are remembered (circular-node-memory). So a run started after a measure avoids what it found short. A probe holds an HTLC on each channel along its route for a second or two, like a failed payment; a measure sends at most 40. It measures one route per candidate, alone, so a run that also uses other routes can move more than carried_sat, while routes through different candidates that share channels may carry less together than their sum (the verdict says which way it can be off); and liquidity changes, so it is what the routes carried at that moment, not a promise.
lightning-cli circular-pull -k inscid=123456x1x1 amount=2000000 splitamount=100000 splits=2 attempts=100 maxppm=900 probeonly=truecircular-pull and circular-push with probeonly=true run as they always do, except that every payment is a probe: a payment nobody can settle (see above), so nothing is paid and nothing moves. The search is the run's own: the candidates in their order, splits at once, each split with its attempts, what fails learned and avoided, maxnodefails, feeratio, and maxfailstreak or maxtime to end it. So it takes as long as a run that moves nothing (some 300 probes with the defaults, a few seconds each, splits at a time), and its "nothing carried" means what a run moving nothing means.
A split succeeds when its probe arrives. Up to 6 more probes over that route then find how much of what is left of the amount it carries, in whole splits and up to the candidate's room. Those probes grow while they arrive: the first is one HTLC of at most 10 splits, each one that arrives lets the next be twice as large, and once one fails the rest search between what arrived and what failed. (A probe that got stuck would hold its whole amount on your channel until it failed, so the large ones go only over a route that just carried half as much without delay.) Nothing moved, so the same route would carry the same again: what a route carried counts once toward amount, and the run's later searches leave its channels out (all but your own two), so that whatever they find next is on top of it. The candidate is fired again, as in a run, to look for another route, while it has room and the amount is not covered. Two splits at once that find routes sharing a channel count one of them; the other searches again. The run ends once the amount is covered, like a run that moved it.
The result is circular-pull's, with probe_only: true. Nothing moved and nothing was paid, so rebalanced_amount, fees_paid_msat and avg_ppm are 0 and successes is empty: a reader that does not know probe_only sees a run that moved nothing. What the probes found has its own names: carried_amount (sats), carried (as successes: per candidate, the sats its routes carried at each rate), carried_fee_msat and carried_avg_ppm (what moving that over those routes would cost). splits_succeeded counts the routes counted; stopped, worst_nodes and the rest are as for a run ("every candidate was probed: 2 carried a part; 5 failed" when the candidates ran out). circular-results marks it probe_only too. There is no fee budget (maxfee is ignored: nothing is paid), and it does not go with retryevery or stepppm (a second round would find the same routes and count them again).
What it leaves for the run that pays: the failures of its searches are learned (beliefs, circular-node-memory, candidates that carried nothing rank last for 30 minutes), and for each pair of channels the first route that carried is kept for an hour (in memory). The next circular-pull or circular-push between the two fires that candidate first and sends its first split over the proven route, so it should move at once instead of searching again; a route that no longer carries costs that split one failed payment before it searches. The probes that size a route teach only the channels' bounds: a node that just carried a split is not marked for failing a larger amount.
What it cannot tell: carried_amount is a floor, not the most a run can move. A route is sized with single HTLCs, which a channel's htlc_maximum_msat and your own channel's single-HTLC limit cap, though a run would pass them in splits; the search for a route's size stops after 7 probes; and each channel counts for one route only, since two routes sharing a channel might not carry their sum. And liquidity changes: it is what the routes carried then. Each probe holds an HTLC on every channel along its route for a second or two, as a failed payment does: a probe-only run loads the network like a run that fails.
lightning-cli circular-pull -k inscid=... amount=2000000 maxppm=900 softavoidscore=5 softavoid=03ab...,812345x12x0Nodes known to fail can be left out of a run's routes at first, without ruling them out: softavoid (node ids, short channel ids, scid/direction) and, with softavoidscore, every node circular-nodes scores at least that (failed payments in the middle of routes, fading with circular-node-memory). A split searches without them; when that finds no route, or none within its maxppm, the same search goes on through them (they still cost their circular-risk-ppm penalty there), and so do that split's later searches. And once the run's payments have failed softavoidstreak times in a row in the middle of their routes (default 60; -1 for never), routes without them are not working either, and they are let back for the rest of the run. Only those failures count: past the out-peer and not on our in channel; failures of our own channels or node, the in-peer's, timeouts and errors before a payment went out neither count nor end the streak. At most 50 nodes come from the score, the most failing. Unlike avoid and the saved list, they never skip a candidate, and a split's own two peers are always used. A route that worked before (reused within the run, or found by a probe-only run in the last hour) is taken as it is. Probes count like payments. The result's soft_avoid lists them (with memory_score for those the score put there), let_back says when and why they were let back, and splits_through_them how many splits found no route without them. circular-quote takes the same parameters and quotes the routes a run would take: through_soft_avoided marks a candidate whose route needs them. A quote shows how a run starts: what its measure's probes find failing lets no node back.
lightning-cli circular-avoid -k add=0242a4ae0c5bef18048fbecf995094b74bfb0f7391418d71ed394784373f41e4f3 note="drained hub"
lightning-cli circular-avoid -k add=812345x12x0 # a channel, both directions; 812345x12x0/1 for one
lightning-cli circular-avoid -k remove=812345x12x0
lightning-cli circular-avoid # the listA saved list of nodes and channels that no rebalance routes through: circular, circular-pull, circular-push and circular-quote (its measures too) leave them out of every search, and a candidate channel on it, or whose peer is, is skipped. The target channel and its peer are never avoided. What is added while a run is going is left out from each split's next attempt on (a split already out keeps its own candidate channel and peer to the end; the next split skips them). It is kept in circular/avoid.json (with a note and when each was added) until removed; unlike the avoid list rebalances learn from failures (30 minutes), it never expires. A list that cannot be read refuses rebalances until it is fixed or removed and circular restarted: what it holds could not be avoided; listing it then shows error and only the entries that could be read. A run can add its own with avoid.
lightning-cli circular-stats > stats.jsonThis command will return the following stats:
graph_stats: stats about the graph thatcircularhas learnedrebalanced_msat: the total amount the successful rebalances below movedsuccesses: successful rebalances done bycircularfailures: failed rebalances done bycircularroutes: routes taken bycircularversion: the running build:commit(asgit log --onelineshows it), itstime,modifiedwhen built from files changed since that commit, andgo. The plugin also logs it when it starts:circular 14f4b66 (2026-10-31T12:06:07Z, go1.22.1) starting. To check a deploy:lightning-cli circular-stats | jq .version. It comes from whatgo build ./cmd/circular(ormake build) stamps into the binary in a git checkout;unknownwhen the build had no git information.
It's a good idea to pipe the output into a file, since it can be quite big.
⚠ To limit the size, circular will only keep the last 14 days of stats.
Panics and other output to stderr go to circular/stderr.log in the lightning directory. It is moved to stderr.log.old when it passes 10 MB.
lightning-cli circular-activeThis returns a JSON list of all currently active, in-flight rebalancing payments (useful to monitor what parallel commands like circular-pull or circular-push are waiting on):
active_payments: JSON array containing the payment hash, amount (msat), creation time, and routing hops of each active payment.
Here is the performance of the pathfinding algorithm on the mainnet lightning network graph as of August 2022 (about 16000 nodes and 80000 channels). The benchmarks consist in finding a route between two random nodes and measuring the time it takes to find the route. Different values of maxhops are tested to show that shorter routes take less time to compute. Those routes are preferred by circular, since the longer the route, the most likely it is to fail.
On a laptop:
goos: linux
goarch: amd64
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
30 runs sampled
name time/op
Graph_GetRoute/dijkstra_3_maxhops-8 2.44ms ± 2%
Graph_GetRoute/dijkstra_4_maxhops-8 3.25ms ± 5%
Graph_GetRoute/dijkstra_5_maxhops-8 6.57ms ± 5%
Graph_GetRoute/dijkstra_6_maxhops-8 10.6ms ± 5%
Graph_GetRoute/dijkstra_7_maxhops-8 14.6ms ±10%
Graph_GetRoute/dijkstra_8_maxhops-8 17.6ms ± 7%On a Raspberry Pi 4:
goos: linux
goarch: arm64
30 runs sampled
name time/op
Graph_GetRoute/dijkstra_3_maxhops-4 20.4ms ± 1%
Graph_GetRoute/dijkstra_4_maxhops-4 23.3ms ± 2%
Graph_GetRoute/dijkstra_5_maxhops-4 36.0ms ± 3%
Graph_GetRoute/dijkstra_6_maxhops-4 52.3ms ± 6%
Graph_GetRoute/dijkstra_7_maxhops-4 67.3ms ± 7%
Graph_GetRoute/dijkstra_8_maxhops-4 78.0ms ± 8%To replicate these benchmarks on your own machine, you can use the following command:
cd graph
go test -bench=. -timeout 0 -count 30 | tee bench.txt
benchstat bench.txt(you need benchstat installed)
If you have any problems feel free to open an issue or join our Telegram group. Pull requests are welcome as well.
Special thanks to devzorLN🐸 for helping me test the plugin.