From f52a16333468f8e630a2b8560a5c281368af4517 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 11 Sep 2024 15:28:46 +0200 Subject: [PATCH] lnwallet: clarify usage of cancel and response channels --- lnwallet/aux_signer.go | 11 ++++++----- lnwallet/sigpool.go | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lnwallet/aux_signer.go b/lnwallet/aux_signer.go index a724f20cb..6ce2e99da 100644 --- a/lnwallet/aux_signer.go +++ b/lnwallet/aux_signer.go @@ -151,18 +151,19 @@ type AuxSigJob struct { BaseAuxJob // Resp is a channel that will be used to send the result of the sign - // job. + // job. This channel MUST be buffered. Resp chan AuxSigJobResp - // Cancel is a channel that should be closed if the caller wishes to - // abandon all pending sign jobs part of a single batch. - Cancel chan struct{} + // Cancel is a channel that is closed by the caller if they wish to + // abandon all pending sign jobs part of a single batch. This should + // never be closed by the validator. + Cancel <-chan struct{} } // NewAuxSigJob creates a new AuxSigJob. func NewAuxSigJob(sigJob SignJob, keyRing CommitmentKeyRing, incoming bool, htlc AuxHtlcDescriptor, commitBlob fn.Option[tlv.Blob], - htlcLeaf input.AuxTapLeaf, cancelChan chan struct{}) AuxSigJob { + htlcLeaf input.AuxTapLeaf, cancelChan <-chan struct{}) AuxSigJob { return AuxSigJob{ SignDesc: sigJob.SignDesc, diff --git a/lnwallet/sigpool.go b/lnwallet/sigpool.go index 2424757f9..2296e1703 100644 --- a/lnwallet/sigpool.go +++ b/lnwallet/sigpool.go @@ -45,17 +45,17 @@ type VerifyJob struct { // party's update log. HtlcIndex uint64 - // Cancel is a channel that should be closed if the caller wishes to + // Cancel is a channel that is closed by the caller if they wish to // cancel all pending verification jobs part of a single batch. This - // channel is to be closed in the case that a single signature in a - // batch has been returned as invalid, as there is no need to verify - // the remainder of the signatures. - Cancel chan struct{} + // channel is closed in the case that a single signature in a batch has + // been returned as invalid, as there is no need to verify the remainder + // of the signatures. + Cancel <-chan struct{} // ErrResp is the channel that the result of the signature verification // is to be sent over. In the see that the signature is valid, a nil // error will be passed. Otherwise, a concrete error detailing the - // issue will be passed. + // issue will be passed. This channel MUST be buffered. ErrResp chan *HtlcIndexErr } @@ -86,12 +86,13 @@ type SignJob struct { // transaction being signed. OutputIndex int32 - // Cancel is a channel that should be closed if the caller wishes to - // abandon all pending sign jobs part of a single batch. - Cancel chan struct{} + // Cancel is a channel that is closed by the caller if they wish to + // abandon all pending sign jobs part of a single batch. This should + // never be closed by the validator. + Cancel <-chan struct{} // Resp is the channel that the response to this particular SignJob - // will be sent over. + // will be sent over. This channel MUST be buffered. // // TODO(roasbeef): actually need to allow caller to set, need to retain // order mark commit sig as special