discovery: add gossip result helpers wrapping actor.Future[error]
What changed, and why it matters
This commit adds a small helper file in the discovery package that wraps a generic 'future/promise' concurrency pattern for gossip message processing. It does not change behavior, fix a bug, or alter security controls. There is no security issue visible in the diff.
No security action required. Review as normal code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces discovery/gossip_result.go containing two functions: completeGossipResult, which resolves an actor.Promise[error] using actor.CompleteWith, and AwaitGossipResult, which blocks on an actor.Future[error] and returns either the gossip error or a context cancellation error. The code is a thin abstraction over existing actor.Future/Promise machinery and contains no parsing, validation, cryptographic, or network logic. The nil promise guard is defensive but unremarkable.
Changed components
discovery/gossip_result.goInspect captured patch +33 / −0
diff --git a/discovery/gossip_result.go b/discovery/gossip_result.go
new file mode 100644
index 0000000..0f661bd
--- /dev/null
+++ b/discovery/gossip_result.go
@@ -0,0 +1,33 @@
+package discovery
+
+import (
+ "context"
+
+ "github.com/lightningnetwork/lnd/actor"
+)
+
+// completeGossipResult resolves a gossip processing promise with the provided
+// error value. A nil error indicates successful processing. This function is
+// safe to call multiple times; only the first call takes effect.
+//
+// NOTE: The error is wrapped via fn.Ok (the "success" side of Result), so
+// AwaitGossipResult can distinguish gossip errors from context cancellation.
+func completeGossipResult(p actor.Promise[error], err error) {
+ if p == nil {
+ return
+ }
+
+ actor.CompleteWith(p, err)
+}
+
+// AwaitGossipResult blocks until the gossip processing future resolves or the
+// provided context is cancelled. It returns the gossip processing error on
+// success, or a context cancellation error if the context expired first.
+func AwaitGossipResult(ctx context.Context, f actor.Future[error]) error {
+ gossipErr, ctxErr := actor.AwaitFuture[error](ctx, f)
+ if ctxErr != nil {
+ return ctxErr
+ }
+
+ return gossipErr
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.