Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: btcsuite/btcd
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.22.1
Choose a base ref
...
head repository: btcsuite/btcd
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.22.2
Choose a head ref
  • 8 commits
  • 6 files changed
  • 3 contributors

Commits on Apr 28, 2022

  1. Merge pull request #1851 from davecgh/v0_22_use_chainhash_module

    [release-v0.22.1] multi: Switch to chaincfg/chainhash module.
    Roasbeef authored Apr 28, 2022
    1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d40789f View commit details

Commits on Oct 10, 2022

  1. wire: remove erroneous witness size check in wire parsing

    In this commit, we fix a bug that would cause nodes to be unable to
    parse a given block from the wire. The block would be properly accepted
    if fed in via other mechanisms.
    
    The issue here is that the old checks for the maximum witness size,
    circa segwit v0 where placed in the wire package _as well_ as the tx
    engine. This check should only be in the engine, since it's properly
    gated by other related scrip validation flags.
    
    The fix itself is simple: limit witnesses only based on the maximum
    block size in bytes, or ~4MB.
    Roasbeef committed Oct 10, 2022
    Copy the full SHA
    ae3b9c9 View commit details
  2. mempool: export isDust for use in other projects

    This changes isDust to IsDust so other golang projects (btcwallet
    or lnd) can use the precise dust calculation used by btcd.
    Crypt-iQ authored and Roasbeef committed Oct 10, 2022

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    c4e7856 View commit details
  3. mempool: introduce GetDustThreshold to export dust limit calculation

    This commit modifies no behavior and would allow other projects to
    retrieve the dust limit for a particular output type before the
    amount of the output is known. This is particularly useful in the
    Lightning Network for channel negotiation.
    Crypt-iQ authored and Roasbeef committed Oct 10, 2022

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    f30a73d View commit details
  4. mempool: fix linter error

    Roasbeef committed Oct 10, 2022
    Copy the full SHA
    4f64fe9 View commit details
  5. Copy the full SHA
    7446802 View commit details
  6. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    ba2fba5 View commit details
  7. Merge pull request #1901 from Roasbeef/v-0-22-branch

    release: create release branch for v0.22.2 to backport block parsing issue
    Roasbeef authored Oct 10, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2ca4f4c View commit details
Showing with 44 additions and 31 deletions.
  1. +4 −0 btcec/signature.go
  2. +1 −1 mempool/mempool_test.go
  3. +20 −13 mempool/policy.go
  4. +2 −2 mempool/policy_test.go
  5. +1 −1 version.go
  6. +16 −14 wire/msgtx.go
4 changes: 4 additions & 0 deletions btcec/signature.go
Original file line number Diff line number Diff line change
@@ -353,6 +353,10 @@ func recoverKeyFromSignature(curve *KoblitzCurve, sig *Signature, msg []byte,
// step to prevent the jacobian conversion back and forth.
Qx, Qy := curve.Add(sRx, sRy, minuseGx, minuseGy)

if Qx.Sign() == 0 && Qy.Sign() == 0 {
return nil, errors.New("point (Qx, Qy) equals the point at infinity")
}

return &PublicKey{
Curve: curve,
X: Qx,
2 changes: 1 addition & 1 deletion mempool/mempool_test.go
Original file line number Diff line number Diff line change
@@ -560,7 +560,7 @@ func TestOrphanReject(t *testing.T) {

// Ensure no transactions were reported as accepted.
if len(acceptedTxns) != 0 {
t.Fatal("ProcessTransaction: reported %d accepted "+
t.Fatalf("ProcessTransaction: reported %d accepted "+
"transactions from failed orphan attempt",
len(acceptedTxns))
}
33 changes: 20 additions & 13 deletions mempool/policy.go
Original file line number Diff line number Diff line change
@@ -172,17 +172,10 @@ func checkPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) er
return nil
}

// isDust returns whether or not the passed transaction output amount is
// considered dust or not based on the passed minimum transaction relay fee.
// Dust is defined in terms of the minimum transaction relay fee. In
// particular, if the cost to the network to spend coins is more than 1/3 of the
// minimum transaction relay fee, it is considered dust.
func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
// Unspendable outputs are considered dust.
if txscript.IsUnspendable(txOut.PkScript) {
return true
}

// GetDustThreshold calculates the dust limit for a *wire.TxOut by taking the
// size of a typical spending transaction and multiplying it by 3 to account
// for the minimum dust relay fee of 3000sat/kvb.
func GetDustThreshold(txOut *wire.TxOut) int64 {
// The total serialized size consists of the output and the associated
// input script to redeem it. Since there is no input script
// to redeem it yet, use the minimum size of a typical input script.
@@ -253,6 +246,20 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
totalSize += 107
}

return 3 * int64(totalSize)
}

// IsDust returns whether or not the passed transaction output amount is
// considered dust or not based on the passed minimum transaction relay fee.
// Dust is defined in terms of the minimum transaction relay fee. In
// particular, if the cost to the network to spend coins is more than 1/3 of the
// minimum transaction relay fee, it is considered dust.
func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
// Unspendable outputs are considered dust.
if txscript.IsUnspendable(txOut.PkScript) {
return true
}

// The output is considered dust if the cost to the network to spend the
// coins is more than 1/3 of the minimum free transaction relay fee.
// minFreeTxRelayFee is in Satoshi/KB, so multiply by 1000 to
@@ -265,7 +272,7 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
//
// The following is equivalent to (value/totalSize) * (1/3) * 1000
// without needing to do floating point math.
return txOut.Value*1000/(3*int64(totalSize)) < int64(minRelayTxFee)
return txOut.Value*1000/GetDustThreshold(txOut) < int64(minRelayTxFee)
}

// checkTransactionStandard performs a series of checks on a transaction to
@@ -351,7 +358,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32,
// "dust".
if scriptClass == txscript.NullDataTy {
numNullDataOutputs++
} else if isDust(txOut, minRelayTxFee) {
} else if IsDust(txOut, minRelayTxFee) {
str := fmt.Sprintf("transaction output %d: payment "+
"of %d is dust", i, txOut.Value)
return txRuleError(wire.RejectDust, str)
4 changes: 2 additions & 2 deletions mempool/policy_test.go
Original file line number Diff line number Diff line change
@@ -204,7 +204,7 @@ func TestCheckPkScriptStandard(t *testing.T) {
}
}

// TestDust tests the isDust API.
// TestDust tests the IsDust API.
func TestDust(t *testing.T) {
pkScript := []byte{0x76, 0xa9, 0x21, 0x03, 0x2f, 0x7e, 0x43,
0x0a, 0xa4, 0xc9, 0xd1, 0x59, 0x43, 0x7e, 0x84, 0xb9,
@@ -268,7 +268,7 @@ func TestDust(t *testing.T) {
},
}
for _, test := range tests {
res := isDust(&test.txOut, test.relayFee)
res := IsDust(&test.txOut, test.relayFee)
if res != test.isDust {
t.Fatalf("Dust test '%s' failed: want %v got %v",
test.name, test.isDust, res)
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr
const (
appMajor uint = 0
appMinor uint = 22
appPatch uint = 1
appPatch uint = 2

// appPreRelease MUST only contain characters from semanticAlphabet
// per the semantic versioning spec.
30 changes: 16 additions & 14 deletions wire/msgtx.go
Original file line number Diff line number Diff line change
@@ -103,27 +103,28 @@ const (
maxWitnessItemsPerInput = 500000

// maxWitnessItemSize is the maximum allowed size for an item within
// an input's witness data. This number is derived from the fact that
// for script validation, each pushed item onto the stack must be less
// than 10k bytes.
maxWitnessItemSize = 11000
// an input's witness data. This value is bounded by the largest
// possible block size, post segwit v1 (taproot).
maxWitnessItemSize = 4_000_000
)

// TxFlagMarker is the first byte of the FLAG field in a bitcoin tx
// message. It allows decoders to distinguish a regular serialized
// transaction from one that would require a different parsing logic.
//
// Position of FLAG in a bitcoin tx message:
// ┌─────────┬────────────────────┬─────────────┬─────┐
// │ VERSION │ FLAG │ TX-IN-COUNT │ ... │
// │ 4 bytes │ 2 bytes (optional) │ varint │ │
// └─────────┴────────────────────┴─────────────┴─────┘
//
// ┌─────────┬────────────────────┬─────────────┬─────┐
// │ VERSION │ FLAG │ TX-IN-COUNT │ ... │
// │ 4 bytes │ 2 bytes (optional) │ varint │ │
// └─────────┴────────────────────┴─────────────┴─────┘
//
// Zooming into the FLAG field:
// ┌── FLAG ─────────────┬────────┐
// │ TxFlagMarker (0x00) │ TxFlag │
// │ 1 byte │ 1 byte │
// └─────────────────────┴────────┘
//
// ┌── FLAG ─────────────┬────────┐
// │ TxFlagMarker (0x00) │ TxFlag │
// │ 1 byte │ 1 byte │
// └─────────────────────┴────────┘
const TxFlagMarker = 0x00

// TxFlag is the second byte of the FLAG field in a bitcoin tx message.
@@ -586,8 +587,9 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
// item itself.
txin.Witness = make([][]byte, witCount)
for j := uint64(0); j < witCount; j++ {
txin.Witness[j], err = readScript(r, pver,
maxWitnessItemSize, "script witness item")
txin.Witness[j], err = readScript(
r, pver, maxWitnessItemSize, "script witness item",
)
if err != nil {
returnScriptBuffers()
return err