mirror of
https://github.com/lightningnetwork/lnd.git
synced 2026-08-13 12:32:48 +02:00
In this commit, we eliminate the three buffered chan error patterns in the discovery package and replace them with actor.Promise[error]/ actor.Future[error]. The old pattern is error-prone: if a channel is completed more than once (e.g. when a deferred message copy is re-enqueued and processed again), the second write to a capacity-1 channel blocks forever. actor.Promise.Complete() is idempotent via sync.Once, so the second call is always a safe no-op regardless of whether anyone holds a reference to the Future. Additionally, PropagateChanPolicyUpdate previously blocked on <-errChan after enqueuing a policy update with no quit-channel check, creating a latent deadlock if the gossiper shut down between enqueue and send. It now uses AwaitGossipResult with a ContextFromQuit-derived context, so shutdown is always respected. This is an atomic migration that updates all callers in the same commit so each commit builds standalone. The three main pieces are: discovery networkMsg.err chan error becomes errPromise actor.Promise[error]. chanPolicyUpdateRequest.errChan chan error becomes errPromise. syncTransitionReq.errChan chan error becomes errPromise. All ~65 sites that previously wrote to the error channel now call completeGossipResult(nMsg.errPromise, err) instead. ProcessRemoteAnnouncement and ProcessLocalAnnouncement now return actor.Future[error] instead of chan error. The capacity-2 buffer comment on ProcessRemoteAnnouncement, which was itself a workaround for the old pattern, is removed along with the TODO referencing the actor model redesign. ProcessSyncTransition in syncer.go follows the same pattern: the errChan select is replaced with AwaitGossipResult using a ContextFromQuit-derived context. funding The SendAnnouncement function type in funding.Config changes from returning chan error to returning actor.Future[error]. The call sites in addToGraph and announceChannel are updated to await the future with AwaitGossipResult, passing a context derived from f.quit via ContextFromQuit. Shutdown signals (context.Canceled and discovery.ErrGossiperShuttingDown) are both mapped to ErrFundingManagerShuttingDown via the new mapGossipError helper, which also factors out the duplicated graph-rejected / unknown-error handling. The three mock SendAnnouncement implementations in manager_test.go are updated accordingly. peer+server In peer/brontide.go, the ProcessRemoteAnnouncement call in the gossip stream handler intentionally discards the result since remote gossip messages are fire-and-forget from the peer's perspective. The old comment explaining why the chan error was unsafe to use is replaced with a note that an unawaited Future[error] carries no overhead. In server.go (applyChannelUpdate), the previous select on errChan and the quit channel is replaced with ContextFromQuit + AwaitGossipResult. |
||
|---|---|---|
| .. | ||
| alloy-models | ||
| grpc | ||
| release-notes | ||
| rest | ||
| backport-workflow.md | ||
| benchmark_perf_loop.md | ||
| code_contribution_guidelines.md | ||
| configuring_tor.md | ||
| db_migration_guide.md | ||
| debugging_lnd.md | ||
| development_guidelines.md | ||
| DOCKER.md | ||
| estimate_route_fee.md | ||
| forwarding_history_privacy.md | ||
| fuzz.md | ||
| gossip_rate_limiting.md | ||
| INSTALL.md | ||
| key_import.md | ||
| leader_election.md | ||
| macaroons.md | ||
| MAKEFILE.md | ||
| musig2.md | ||
| postgres.md | ||
| psbt.md | ||
| recovery.md | ||
| release.md | ||
| release_branch_management.md | ||
| remote-signing.md | ||
| review.md | ||
| safety.md | ||
| signing_release_candidate.md | ||
| SphinxReplayDB.md | ||
| sqlite.md | ||
| wallet.md | ||
| watchtower.md | ||
| zero_conf_channels.md | ||