multi: fix linter errors
This commit is contained in:
20 files changed
+187
-144
No files matched your search
+2
-1
@@ -425,7 +425,8 @@ func MakeHtlcSecondLevelTimeoutAnchorInput(signedTx *wire.MsgTx,
|
||||
// transaction. The sweeper is also able to generate witnesses on demand to
|
||||
// sweep the second level HTLC aggregated with other transactions.
|
||||
func MakeHtlcSecondLevelTimeoutTaprootInput(signedTx *wire.MsgTx,
|
||||
signDetails *SignDetails, heightHint uint32) HtlcSecondLevelAnchorInput {
|
||||
signDetails *SignDetails,
|
||||
heightHint uint32) HtlcSecondLevelAnchorInput {
|
||||
|
||||
createWitness := func(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes,
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
)
|
||||
|
||||
// UnknownScriptTypeErr is returned when an unknown script type is encountered.
|
||||
var UnknownScriptTypeErr = errors.New("unknown script type")
|
||||
// ErrUnknownScriptType is returned when an unknown script type is encountered.
|
||||
var ErrUnknownScriptType = errors.New("unknown script type")
|
||||
|
||||
// ScriptPath is used to indicate the spending path of a given script. Possible
|
||||
// paths include: timeout, success, revocation, and others.
|
||||
@@ -28,8 +28,8 @@ const (
|
||||
// breached.
|
||||
ScriptPathRevocation
|
||||
|
||||
// ScriptPathDelay is a script path used when a contract has has
|
||||
// relative delay that must elapse before it can be swept.
|
||||
// ScriptPathDelay is a script path used when a contract has relative
|
||||
// delay that must elapse before it can be swept.
|
||||
ScriptPathDelay
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ type ScriptDescriptor interface {
|
||||
|
||||
// WitnessScriptForPath returns the witness script for the given
|
||||
// spending path. An error is returned if the path is unknown. This is
|
||||
// useful as when constructing a contrl block for a given path, one
|
||||
// useful as when constructing a control block for a given path, one
|
||||
// also needs witness script being signed.
|
||||
WitnessScriptForPath(path ScriptPath) ([]byte, error)
|
||||
}
|
||||
|
||||
+13
-13
@@ -648,12 +648,12 @@ type HtlcScriptTree struct {
|
||||
func (h *HtlcScriptTree) WitnessScriptToSign() []byte {
|
||||
switch h.htlcType {
|
||||
// For incoming HLTCs on our local commitment, we care about verifying
|
||||
// the sucess path.
|
||||
// the success path.
|
||||
case htlcLocalIncoming:
|
||||
return h.SuccessTapLeaf.Script
|
||||
|
||||
// For incoming HTLCs on the remote party's commitment, we want to sign
|
||||
// the the timeout path for them.
|
||||
// the timeout path for them.
|
||||
case htlcRemoteIncoming:
|
||||
return h.TimeoutTapLeaf.Script
|
||||
|
||||
@@ -1526,7 +1526,7 @@ func SecondLevelHtlcScript(revocationKey, delayKey *btcec.PublicKey,
|
||||
// if statement.
|
||||
builder.AddOp(txscript.OP_IF)
|
||||
|
||||
// If this this is the revocation case, then we'll push the revocation
|
||||
// If this is the revocation case, then we'll push the revocation
|
||||
// public key on the stack.
|
||||
builder.AddData(revocationKey.SerializeCompressed())
|
||||
|
||||
@@ -1778,8 +1778,8 @@ func TaprootHtlcSpendSuccess(signer Signer, signDesc *SignDescriptor,
|
||||
|
||||
var ctrlBlock []byte
|
||||
if signDesc.ControlBlock == nil {
|
||||
// Now that we have the sweep signature, we'll construct the control
|
||||
// block needed to spend the script path.
|
||||
// Now that we have the sweep signature, we'll construct the
|
||||
// control block needed to spend the script path.
|
||||
redeemControlBlock := MakeTaprootCtrlBlock(
|
||||
signDesc.WitnessScript, revokeKey, tapscriptTree,
|
||||
)
|
||||
@@ -1804,9 +1804,9 @@ func TaprootHtlcSpendSuccess(signer Signer, signDesc *SignDescriptor,
|
||||
return witnessStack, nil
|
||||
}
|
||||
|
||||
// LeaseSecondLevelHtlcScript is the uniform script that's used as the output for
|
||||
// the second-level HTLC transactions. The second level transaction acts as a
|
||||
// sort of covenant, ensuring that a 2-of-2 multi-sig output can only be
|
||||
// LeaseSecondLevelHtlcScript is the uniform script that's used as the output
|
||||
// for the second-level HTLC transactions. The second level transaction acts as
|
||||
// a sort of covenant, ensuring that a 2-of-2 multi-sig output can only be
|
||||
// spent in a particular way, and to a particular output.
|
||||
//
|
||||
// Possible Input Scripts:
|
||||
@@ -2070,7 +2070,7 @@ var _ TapscriptDescriptor = (*CommitScriptTree)(nil)
|
||||
// remote party, and also verifying signatures on our transactions. As an
|
||||
// example, when we create an outgoing HTLC for the remote party, we want to
|
||||
// sign their success path.
|
||||
func (s *CommitScriptTree) WitnessScriptToSign() []byte {
|
||||
func (c *CommitScriptTree) WitnessScriptToSign() []byte {
|
||||
// TODO(roasbeef): abstraction leak here? always dependent
|
||||
return nil
|
||||
}
|
||||
@@ -2795,20 +2795,20 @@ func NewAnchorScriptTree(anchorKey *btcec.PublicKey,
|
||||
// remote party, and also verifying signatures on our transactions. As an
|
||||
// example, when we create an outgoing HTLC for the remote party, we want to
|
||||
// sign their success path.
|
||||
func (s *AnchorScriptTree) WitnessScriptToSign() []byte {
|
||||
return s.SweepLeaf.Script
|
||||
func (a *AnchorScriptTree) WitnessScriptToSign() []byte {
|
||||
return a.SweepLeaf.Script
|
||||
}
|
||||
|
||||
// WitnessScriptForPath returns the witness script for the given spending path.
|
||||
// An error is returned if the path is unknown.
|
||||
func (s *AnchorScriptTree) WitnessScriptForPath(path ScriptPath,
|
||||
func (a *AnchorScriptTree) WitnessScriptForPath(path ScriptPath,
|
||||
) ([]byte, error) {
|
||||
|
||||
switch path {
|
||||
case ScriptPathDelay:
|
||||
fallthrough
|
||||
case ScriptPathSuccess:
|
||||
return s.SweepLeaf.Script, nil
|
||||
return a.SweepLeaf.Script, nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown script path: %v", path)
|
||||
|
||||
+11
-6
@@ -247,8 +247,8 @@ const (
|
||||
// ....HTLCOutputs...
|
||||
// - LockTime: 4 bytes
|
||||
BaseTaprootCommitmentTxWeight = (4 + 1 + FundingInputSize + 3 +
|
||||
2*TaprootCommitmentOutput + 2*TaprootCommitmentAnchorOutput + 4) *
|
||||
witnessScaleFactor
|
||||
2*TaprootCommitmentOutput + 2*TaprootCommitmentAnchorOutput +
|
||||
4) * witnessScaleFactor
|
||||
|
||||
// CommitWeight 724 weight.
|
||||
CommitWeight = BaseCommitmentTxWeight + WitnessCommitmentTxWeight
|
||||
@@ -637,7 +637,8 @@ const (
|
||||
// - ctrl block size: 1 byte
|
||||
// - base control block: 33 bytes
|
||||
// - merkle proof: 32
|
||||
TaprootToLocalRevokeWitnessSize = 1 + 1 + 65 + 1 + TaprootToLocalRevokeScriptSize + 1 + 33 + 32
|
||||
TaprootToLocalRevokeWitnessSize = (1 + 1 + 65 + 1 +
|
||||
TaprootToLocalRevokeScriptSize + 1 + 33 + 32)
|
||||
|
||||
// TaprootToRemoteScriptSize
|
||||
// - OP_DATA: 1 byte
|
||||
@@ -656,8 +657,9 @@ const (
|
||||
// - taproot_to_local_script_size: 36 bytes
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
TaprootToRemoteWitnessSize = 1 + 1 + 65 + 1 + TaprootToRemoteScriptSize +
|
||||
1 + TaprootBaseControlBlockWitnessSize
|
||||
TaprootToRemoteWitnessSize = (1 + 1 + 65 + 1 +
|
||||
TaprootToRemoteScriptSize + 1 +
|
||||
TaprootBaseControlBlockWitnessSize)
|
||||
|
||||
// TaprootAnchorWitnessSize: 67 bytes
|
||||
//
|
||||
@@ -691,12 +693,14 @@ const (
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
//nolint:lll
|
||||
TaprootSecondLevelRevokeWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootAcceptedRevokeWitnessSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
//nolint:lll
|
||||
TaprootAcceptedRevokeWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootOfferedRevokeWitnessSize:
|
||||
@@ -716,7 +720,8 @@ const (
|
||||
// - cltv_expiry: 4 bytes
|
||||
// - OP_CHECKLOCKTIMEVERIFY: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
TaprootHtlcOfferedRemoteTimeoutScriptSize = 1 + 32 + 1 + 1 + 1 + 1 + 1 + 4 + 1 + 1
|
||||
TaprootHtlcOfferedRemoteTimeoutScriptSize = (1 + 32 + 1 + 1 + 1 + 1 +
|
||||
1 + 4 + 1 + 1)
|
||||
|
||||
// TaprootHtlcOfferedRemoteTimeoutwitSize: 176 bytes
|
||||
// - number_of_witness_elements: 1 byte
|
||||
|
||||
+33
-12
@@ -850,7 +850,8 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
|
||||
signer := &dummySigner{}
|
||||
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
||||
testCSVDelay, testKey.PubKey(), testKey.PubKey(),
|
||||
testCSVDelay, testKey.PubKey(),
|
||||
testKey.PubKey(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -858,10 +859,11 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
PubKey: testKey.PubKey(),
|
||||
},
|
||||
//nolint:lll
|
||||
WitnessScript: commitScriptTree.SettleLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.TaprootCommitSpendSuccess(
|
||||
@@ -869,6 +871,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
commitScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -881,7 +884,8 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
|
||||
signer := &dummySigner{}
|
||||
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
||||
testCSVDelay, testKey.PubKey(), testKey.PubKey(),
|
||||
testCSVDelay, testKey.PubKey(),
|
||||
testKey.PubKey(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -889,10 +893,11 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
PubKey: testKey.PubKey(),
|
||||
},
|
||||
//nolint:lll
|
||||
WitnessScript: commitScriptTree.RevocationLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.TaprootCommitSpendRevoke(
|
||||
@@ -900,6 +905,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
commitScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -911,6 +917,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
require.NoError(t, err)
|
||||
|
||||
signer := &dummySigner{}
|
||||
//nolint:lll
|
||||
commitScriptTree, err := input.NewRemoteCommitScriptTree(
|
||||
testKey.PubKey(),
|
||||
)
|
||||
@@ -920,10 +927,11 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
PubKey: testKey.PubKey(),
|
||||
},
|
||||
//nolint:lll
|
||||
WitnessScript: commitScriptTree.SettleLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.TaprootCommitRemoteSpend(
|
||||
@@ -931,6 +939,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
commitScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -962,6 +971,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1002,6 +1012,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
scriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1038,6 +1049,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1062,6 +1074,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
senderKey.PubKey(), receiverKey.PubKey(),
|
||||
revokeKey.PubKey(), payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
signDesc := &input.SignDescriptor{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
@@ -1077,6 +1090,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1102,6 +1116,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||
payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
signDesc := &input.SignDescriptor{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
@@ -1117,6 +1132,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1142,6 +1158,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||
payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
timeoutLeaf := htlcScriptTree.TimeoutTapLeaf
|
||||
|
||||
@@ -1152,14 +1169,16 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: timeoutLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.ReceiverHTLCScriptTaprootTimeout(
|
||||
signer, signDesc, testTx, testCLTVExpiry,
|
||||
revokeKey.PubKey(), htlcScriptTree.TapscriptTree,
|
||||
revokeKey.PubKey(),
|
||||
htlcScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1197,7 +1216,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: timeoutLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
receiverSig, err := signer.SignOutputRaw(
|
||||
testTx, receiverDesc,
|
||||
@@ -1211,7 +1230,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: timeoutLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.SenderHTLCScriptTaprootTimeout(
|
||||
@@ -1220,6 +1239,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
scriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1256,7 +1276,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: successLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.SenderHTLCScriptTaprootRedeem(
|
||||
@@ -1290,6 +1310,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||
payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
successsLeaf := htlcScriptTree.SuccessTapLeaf
|
||||
scriptTree := htlcScriptTree.TapscriptTree
|
||||
@@ -1301,7 +1322,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: successsLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
senderSig, err := signer.SignOutputRaw(
|
||||
testTx, senderDesc,
|
||||
@@ -1315,7 +1336,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: successsLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.ReceiverHTLCScriptTaprootRedeem(
|
||||
|
||||
+8
-8
@@ -522,8 +522,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block must " +
|
||||
"be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := TaprootCommitSpendSuccess(
|
||||
@@ -544,8 +544,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block must " +
|
||||
"be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := TaprootCommitRemoteSpend(
|
||||
@@ -589,8 +589,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block must " +
|
||||
"be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := TaprootHtlcSpendSuccess(
|
||||
@@ -677,8 +677,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block " +
|
||||
"must be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := ReceiverHTLCScriptTaprootTimeout(
|
||||
|
||||
Reference in new issue
Block a user