From bd9ebbd5afe0f3b29aa0332a0c1818ff819b04bc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 17 Nov 2018 20:46:51 -0800 Subject: [PATCH] lnwallet: add more godoc to InputScript rename ScriptSig field to SigScript --- lnwallet/btcwallet/signer.go | 17 ++++++++++------- lnwallet/interface.go | 2 +- lnwallet/reservation.go | 12 ++++++++---- lnwallet/test_utils.go | 8 +++++--- lnwallet/wallet.go | 10 +++++----- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lnwallet/btcwallet/signer.go b/lnwallet/btcwallet/signer.go index 21f095922..f45308561 100644 --- a/lnwallet/btcwallet/signer.go +++ b/lnwallet/btcwallet/signer.go @@ -180,9 +180,10 @@ func (b *BtcWallet) SignOutputRaw(tx *wire.MsgTx, // TODO(roasbeef): generate sighash midstate if not present? amt := signDesc.Output.Value - sig, err := txscript.RawTxInWitnessSignature(tx, signDesc.SigHashes, - signDesc.InputIndex, amt, witnessScript, signDesc.HashType, - privKey) + sig, err := txscript.RawTxInWitnessSignature( + tx, signDesc.SigHashes, signDesc.InputIndex, amt, + witnessScript, signDesc.HashType, privKey, + ) if err != nil { return nil, err } @@ -227,8 +228,9 @@ func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx, // spend the p2sh output. The sigScript will contain only a // single push of the p2wkh witness program corresponding to // the matching public key of this address. - p2wkhAddr, err := btcutil.NewAddressWitnessPubKeyHash(pubKeyHash, - b.netParams) + p2wkhAddr, err := btcutil.NewAddressWitnessPubKeyHash( + pubKeyHash, b.netParams, + ) if err != nil { return nil, err } @@ -244,7 +246,7 @@ func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx, return nil, err } - inputScript.ScriptSig = sigScript + inputScript.SigScript = sigScript // Otherwise, this is a regular p2wkh output, so we include the // witness program itself as the subscript to generate the proper @@ -267,7 +269,8 @@ func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx, // TODO(roasbeef): adhere to passed HashType witnessScript, err := txscript.WitnessSignature(tx, signDesc.SigHashes, signDesc.InputIndex, signDesc.Output.Value, witnessProgram, - signDesc.HashType, privKey, true) + signDesc.HashType, privKey, true, + ) if err != nil { return nil, err } diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 62cd0fa39..efe8b6192 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -127,7 +127,7 @@ type TransactionSubscription interface { type WalletController interface { // FetchInputInfo queries for the WalletController's knowledge of the // passed outpoint. If the base wallet determines this output is under - // its control, then the original txout should be returned. Otherwise, + // its control, then the original txout should be returned. Otherwise, // a non-nil error value of ErrNotMine should be returned instead. FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error) diff --git a/lnwallet/reservation.go b/lnwallet/reservation.go index 62bd449db..c7adf19da 100644 --- a/lnwallet/reservation.go +++ b/lnwallet/reservation.go @@ -50,11 +50,15 @@ func (c *ChannelContribution) toChanConfig() channeldb.ChannelConfig { } // InputScript represents any script inputs required to redeem a previous -// output. This struct is used rather than just a witness, or scripSig in -// order to accommodate nested p2sh which utilizes both types of input scripts. +// output. This struct is used rather than just a witness, or scripSig in order +// to accommodate nested p2sh which utilizes both types of input scripts. type InputScript struct { - Witness [][]byte - ScriptSig []byte + // Witness is the full witness stack required to unlock this output. + Witness wire.TxWitness + + // SigScript will only be populated if this is an input script sweeping + // a nested p2sh output. + SigScript []byte } // ChannelReservation represents an intent to open a lightning payment channel diff --git a/lnwallet/test_utils.go b/lnwallet/test_utils.go index db2cbb108..5c006c281 100644 --- a/lnwallet/test_utils.go +++ b/lnwallet/test_utils.go @@ -438,13 +438,15 @@ func (m *mockSigner) ComputeInputScript(tx *wire.MsgTx, signDesc *SignDescriptor "address %v", addresses[0]) } - scriptSig, err := txscript.SignatureScript(tx, signDesc.InputIndex, - signDesc.Output.PkScript, txscript.SigHashAll, privKey, true) + sigScript, err := txscript.SignatureScript( + tx, signDesc.InputIndex, signDesc.Output.PkScript, + txscript.SigHashAll, privKey, true, + ) if err != nil { return nil, err } - return &InputScript{ScriptSig: scriptSig}, nil + return &InputScript{SigScript: sigScript}, nil case txscript.WitnessV0PubKeyHashTy: privKey := m.findKey(addresses[0].ScriptAddress(), signDesc.SingleTweak, diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 4784efeab..6f7863dc5 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -747,14 +747,15 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) { signDesc.Output = info signDesc.InputIndex = i - inputScript, err := l.Cfg.Signer.ComputeInputScript(fundingTx, - &signDesc) + inputScript, err := l.Cfg.Signer.ComputeInputScript( + fundingTx, &signDesc, + ) if err != nil { req.err <- err return } - txIn.SignatureScript = inputScript.ScriptSig + txIn.SignatureScript = inputScript.SigScript txIn.Witness = inputScript.Witness pendingReservation.ourFundingInputScripts = append( pendingReservation.ourFundingInputScripts, @@ -958,7 +959,7 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs if len(inputScripts) != 0 && len(txin.Witness) == 0 { // Attach the input scripts so we can verify it below. txin.Witness = inputScripts[sigIndex].Witness - txin.SignatureScript = inputScripts[sigIndex].ScriptSig + txin.SignatureScript = inputScripts[sigIndex].SigScript // Fetch the alleged previous output along with the // pkscript referenced by this input. @@ -1256,7 +1257,6 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) { // selection is successful/possible, then the selected coins are available // within the passed contribution's inputs. If necessary, a change address will // also be generated. -// TODO(roasbeef): remove hardcoded fees. func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerKWeight, amt btcutil.Amount, minConfs int32, contribution *ChannelContribution) error {