Repository navigation
chanevents: exclude unobserved time from forwarding uptime - #260
Open
bitromortac wants to merge 5 commits into
Open
bitromortac wants to merge 5 commits into
bitromortac wants to merge 5 commits into
Conversation
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.
There was a problem hiding this comment.
🟡 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 filedb/sqlc/querier.go: Generated filefrdrpc/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_sthrough the RPC and changes CLI output to an object containingunobserved_sandpairs.
| 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
| // 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), | ||
| ) |
|
@bitromortac, remember to re-request review from reviewers when ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.
EffectiveUptimeSkeeps 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 forwardingabilitynow prints an object withunobserved_sandpairs, andpairsholds the array it printed before.