input: add anchor witness type

This commit is contained in:
Joost Jager committed 2020-03-17 16:25:35 +01:00
1 parent dd77d9263e
commit c376cdb733
6 files changed
+155 -67

No files matched your search

+45
View File
@@ -1,8 +1,12 @@
package input
import (
"math/big"
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/keychain"
)
const (
@@ -406,6 +410,47 @@ const (
OfferedHtlcPenaltyWitnessSize = 1 + 1 + 73 + 1 + 33 + 1 + OfferedHtlcScriptSize
)
// dummySigner is a fake signer used for size (upper bound) calculations.
type dummySigner struct {
Signer
}
// SignOutputRaw generates a signature for the passed transaction according to
// the data within the passed SignDescriptor.
func (s *dummySigner) SignOutputRaw(tx *wire.MsgTx, signDesc *SignDescriptor) (
[]byte, error) {
// Always return worst-case signature length, excluding the one byte
// sighash flag.
return make([]byte, 73-1), nil
}
var (
// dummyPubKey is a pubkey used in script size calculation.
dummyPubKey = btcec.PublicKey{
X: &big.Int{},
Y: &big.Int{},
}
// dummyAnchorScript is a script used for size calculation.
dummyAnchorScript, _ = CommitScriptAnchor(&dummyPubKey)
// dummyAnchorWitness is a witness used for size calculation.
dummyAnchorWitness, _ = CommitSpendAnchor(
&dummySigner{},
&SignDescriptor{
KeyDesc: keychain.KeyDescriptor{
PubKey: &dummyPubKey,
},
WitnessScript: dummyAnchorScript,
},
nil,
)
// AnchorWitnessSize 116 bytes
AnchorWitnessSize = dummyAnchorWitness.SerializeSize()
)
// EstimateCommitTxWeight estimate commitment transaction weight depending on
// the precalculated weight of base transaction, witness data, which is needed
// for paying for funding tx, and htlc weight multiplied by their count.