-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4/5]: lnwallet: add new AuxSigner interface to mirror SigPool #8632
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package lnwallet | ||
|
||
import ( | ||
"github.com/btcsuite/btcd/wire" | ||
"github.com/lightningnetwork/lnd/channeldb" | ||
"github.com/lightningnetwork/lnd/fn" | ||
"github.com/lightningnetwork/lnd/input" | ||
"github.com/lightningnetwork/lnd/tlv" | ||
) | ||
|
||
// BaseAuxJob is a struct that contains the common fields that are shared among | ||
// the aux sign/verify jobs. | ||
type BaseAuxJob struct { | ||
// OutputIndex is the output index of the HTLC on the commitment | ||
// transaction being signed. | ||
// | ||
// NOTE: If the output is dust from the PoV of the commitment chain, | ||
// then this value will be -1. | ||
OutputIndex int32 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be unsigned int rather than signed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value comes from here: https://github.com/lightningnetwork/lnd/blob/a350ccd7/lnwallet/channel.go#L308 |
||
|
||
// KeyRing is the commitment key ring that contains the keys needed to | ||
// generate the second level HTLC signatures. | ||
KeyRing CommitmentKeyRing | ||
|
||
// HTLC is the HTLC that is being signed or verified. | ||
HTLC PaymentDescriptor | ||
|
||
// Incoming is a boolean that indicates if the HTLC is incoming or | ||
// outgoing. | ||
Incoming bool | ||
|
||
// CommitBlob is the commitment transaction blob that contains the aux | ||
// information for this channel. | ||
CommitBlob fn.Option[tlv.Blob] | ||
|
||
// HtlcLeaf is the aux tap leaf that corresponds to the HTLC being | ||
// signed/verified. | ||
HtlcLeaf input.AuxTapLeaf | ||
} | ||
|
||
// AuxSigJob is a struct that contains all the information needed to sign an | ||
// HTLC for custom channels. | ||
type AuxSigJob struct { | ||
// SignDesc is the sign desc for this HTLC. | ||
SignDesc input.SignDescriptor | ||
|
||
BaseAuxJob | ||
|
||
// Resp is a channel that will be used to send the result of the sign | ||
// job. | ||
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{} | ||
} | ||
|
||
// NewAuxSigJob creates a new AuxSigJob. | ||
func NewAuxSigJob(sigJob SignJob, keyRing CommitmentKeyRing, incoming bool, | ||
htlc PaymentDescriptor, commitBlob fn.Option[tlv.Blob], | ||
htlcLeaf input.AuxTapLeaf, cancelChan chan struct{}) AuxSigJob { | ||
|
||
return AuxSigJob{ | ||
SignDesc: sigJob.SignDesc, | ||
BaseAuxJob: BaseAuxJob{ | ||
OutputIndex: sigJob.OutputIndex, | ||
KeyRing: keyRing, | ||
HTLC: htlc, | ||
Incoming: incoming, | ||
CommitBlob: commitBlob, | ||
HtlcLeaf: htlcLeaf, | ||
}, | ||
Resp: make(chan AuxSigJobResp, 1), | ||
Cancel: cancelChan, | ||
} | ||
} | ||
|
||
// AuxSigJobResp is a struct that contains the result of a sign job. | ||
type AuxSigJobResp struct { | ||
// SigBlob is the signature blob that was generated for the HTLC. This | ||
// is an opaque TLV field that may contain the signature and other data. | ||
SigBlob fn.Option[tlv.Blob] | ||
|
||
// HtlcIndex is the index of the HTLC that was signed. | ||
HtlcIndex uint64 | ||
|
||
// Err is the error that occurred when executing the specified | ||
// signature job. In the case that no error occurred, this value will | ||
// be nil. | ||
Err error | ||
} | ||
|
||
// AuxVerifyJob is a struct that contains all the information needed to verify | ||
// an HTLC for custom channels. | ||
type AuxVerifyJob struct { | ||
// SigBlob is the signature blob that was generated for the HTLC. This | ||
// is an opaque TLV field that may contain the signature and other data. | ||
SigBlob fn.Option[tlv.Blob] | ||
|
||
BaseAuxJob | ||
|
||
// Cancel is a channel that should be closed if the caller wishes to | ||
// abandon the job. | ||
Cancel chan struct{} | ||
|
||
// ErrResp is a channel that will be used to send the result of the | ||
// verify job. | ||
ErrResp chan error | ||
} | ||
|
||
// NewAuxVerifyJob creates a new AuxVerifyJob. | ||
func NewAuxVerifyJob(sig fn.Option[tlv.Blob], keyRing CommitmentKeyRing, | ||
incoming bool, htlc PaymentDescriptor, commitBlob fn.Option[tlv.Blob], | ||
htlcLeaf input.AuxTapLeaf) AuxVerifyJob { | ||
|
||
return AuxVerifyJob{ | ||
SigBlob: sig, | ||
BaseAuxJob: BaseAuxJob{ | ||
KeyRing: keyRing, | ||
HTLC: htlc, | ||
Incoming: incoming, | ||
CommitBlob: commitBlob, | ||
HtlcLeaf: htlcLeaf, | ||
}, | ||
} | ||
} | ||
|
||
// AuxSigner is an interface that is used to sign and verify HTLCs for custom | ||
// channels. It is similar to the existing SigPool, but uses opaque blobs to | ||
// shuffle around signature information and other metadata. | ||
type AuxSigner interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to mock this and have some minimal test coverage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this to the tracking issue, since we currently don't have any coverage for those aux interfaces. |
||
// SubmitSecondLevelSigBatch takes a batch of aux sign jobs and | ||
// processes them asynchronously. | ||
SubmitSecondLevelSigBatch(chanState *channeldb.OpenChannel, | ||
commitTx *wire.MsgTx, sigJob []AuxSigJob) error | ||
|
||
// PackSigs takes a series of aux signatures and packs them into a | ||
// single blob that can be sent alongside the CommitSig messages. | ||
PackSigs([]fn.Option[tlv.Blob]) (fn.Option[tlv.Blob], error) | ||
|
||
// UnpackSigs takes a packed blob of signatures and returns the | ||
// original signatures for each HTLC, keyed by HTLC index. | ||
UnpackSigs(fn.Option[tlv.Blob]) ([]fn.Option[tlv.Blob], error) | ||
|
||
// VerifySecondLevelSigs attempts to synchronously verify a batch of aux | ||
// sig jobs. | ||
VerifySecondLevelSigs(chanState *channeldb.OpenChannel, | ||
commitTx *wire.MsgTx, verifyJob []AuxVerifyJob) error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this here / being removed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just in the wrong place, moved it to the
AuxComponents
sub struct. When we just had a single aux interface it made sense here, as "store" vaguely has something to do with database. But with all the other components it made sense to move everything to its own struct.