Skip to content

chanevents: exclude unobserved time from forwarding uptime - #260

Open
bitromortac wants to merge 5 commits into
lightninglabs:masterfrom
bitromortac:20261030-5d52-dispatch
Open

bitromortac wants to merge 5 commits into
lightninglabs:masterfrom
bitromortac:20261030-5d52-dispatch

Conversation

@bitromortac

Copy link
Copy Markdown
Contributor

Forwarding-ability uptime no longer counts the time faraday did not observe lnd, so a node outage stops counting as uptime for pairs that were routable before it. The RPC reports this time as unobserved_s, so clients can divide by the observed window.

Between events the analyzer replays the last known channel state, so an outage of faraday or lnd counted as uptime. An unobserved interval now starts at the last live event before a sync batch and ends at that batch, and one restart gives one interval. EffectiveUptimeS keeps its meaning, but the uptime threshold and the node-down guard apply to the observed window. We do not write synthetic offline events, because the channels of a remote lnd can stay up while faraday is down.

The monitor also runs the initial sync on each reconnect, so a broken subscription is marked the same way as a restart. An outage that still goes on counts as observed time until the next sync.

Breaking for scripts: frcli forwardingability now prints an object with unobserved_s and pairs, and pairs holds the array it printed before.

An unobserved interval is the time faraday did not observe lnd. It ends
at the last event of a sync batch and starts at the last live event of
any channel before that batch. Sync events that share the same preceding
live event form one batch, so one restart gives one interval.

The store returns the intervals clipped to the query range. The query
aggregates over ids, because SQLite cannot scan an aggregated timestamp
back into a time value.
Add the unobserved_s field to the forwarding ability response. It holds
the seconds of the window in which faraday did not observe lnd. The
codec applies the uptime threshold to the observed window, which is the
window minus unobserved_s, and decodes up-but-idle pairs at the full
observed window. frcli prints the field once and derives the uptime
fraction from the observed window.

The server reports zero until the analyzer computes the unobserved time.
The analyzer replayed the last known channel state across node outages,
so an outage counted as uptime for every pair that was routable before
it. The walk now skips unobserved intervals, and EffectiveUptime returns
their total.

The server reports the total as unobserved_s, and the node-down guard
uses the observed window. The server rounds the unobserved time up,
because uptime rounds down.
A broken subscription loses events, and without a sync the break was not
marked as unobserved time. The monitor now runs the initial sync each
time it reconnects. The sync batch re-baselines the balances and ends the
unobserved interval of the break.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reconnect synchronization can incorrectly mark inactive channels as online, while fractional-second window mismatches can produce uptime fractions above 1.

2 open issues
3 files not reviewed
  • db/sqlc/chanevents.sql.go: Generated file
  • db/sqlc/querier.go: Generated file
  • frdrpc/faraday.pb.go: Generated file
What changed in this PR

This PR updates Faraday’s forwarding-ability analysis to exclude unobserved periods from uptime and apply thresholds to the observed window.

Changes:

  • Derives unobserved intervals from sync batches and subtracts them during channel-state replay.
  • Repeats initial sync on reconnect, with capped retry backoff.
  • Exposes unobserved_s through the RPC and changes CLI output to an object containing unobserved_s and pairs.
File Description
frdrpcserver/​rpcserver.go Extends the analyzer interface to return unobserved duration.
frdrpcserver/​forwarding_ability.go Reports unobserved seconds and adjusts the uptime guard.
frdrpcserver/​forwarding_ability_test.go Tests observed-window thresholds and rounding.
frdrpc/​forwarding_ability_codec.go Uses observed time for encoding thresholds and decoding uptime.
frdrpc/​forwarding_ability_codec_test.go Tests observed-window calculations and codec behavior.
frdrpc/​faraday.swagger.json Updates API documentation for unobserved time.
frdrpc/​faraday.proto Adds unobserved_s and documents observed-window semantics.
frdrpc/​faraday.pb.go Updates generated protobuf bindings.
docs/​release-notes/​release-notes-next.md Documents RPC semantics, reconnect behavior, and breaking CLI output.
db/​sqlc/​queries/​chanevents.sql Adds the unobserved-interval query.
db/​sqlc/​querier.go Exposes the new generated query interface.
db/​sqlc/​migrations/​000003_chanevents_sync_idx.up.sql Adds an index for sync/live event lookups.
db/​sqlc/​migrations/​000003_chanevents_sync_idx.down.sql Removes the index on rollback.
db/​sqlc/​chanevents.sql.go Adds generated query bindings.
db/​migrations.go Registers schema migration 3.
cmd/​frcli/​forwarding_ability.go Uses observed time and emits the new JSON object.
chanevents/​store.go Retrieves and clips unobserved intervals.
chanevents/​store_test.go Tests interval grouping and clipping.
chanevents/​monitor.go Resyncs on reconnect and adds capped backoff.
chanevents/​monitor_test.go Tests backoff and sync-before-subscribe behavior.
chanevents/​analyzer.go Excludes unobserved intervals from effective uptime.
chanevents/​analyzer_test.go Tests uptime exclusion across gaps and restarts.

Review effort: Balanced

Comment thread chanevents/monitor.go
// since the last subscription broke. Do not subscribe without a
// sync batch: a live event would then end the unobserved
// interval, and the outage would count as observed time.
if err := m.initialSync(ctx); err != nil {
Comment on lines +99 to 101
abilities, unobserved, err := s.cfg.ForwardingAnalyzer.EffectiveUptime(
ctx, startTime, endTime, btcutil.Amount(liquidityFloor),
)
@litbot-9000

Copy link
Copy Markdown

@bitromortac, remember to re-request review from reviewers when ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants