Skip to content

policy: add -scriptsigcost to reprice pre-segwit scriptSig bytes - #343

Open
kwsantiago wants to merge 5 commits into
bitcoinknots:29.x-knotsfrom
privkeyio:policy-scriptsig-cost
Open

policy: add -scriptsigcost to reprice pre-segwit scriptSig bytes#343
kwsantiago wants to merge 5 commits into
bitcoinknots:29.x-knotsfrom
privkeyio:policy-scriptsig-cost

Conversation

@kwsantiago

@kwsantiago kwsantiago commented Jul 25, 2026

Copy link
Copy Markdown

Closes #60

Adds -scriptsigcost, which prices scriptSig bytes in non-witness inputs for policy purposes. 0.25 extends the witness discount to pre-segwit inputs, higher values bias against them. Only the vsize used for relay and mining changes, never consensus weight.

  • Default 1.0, ie unchanged behavior, matching how -datacarriercost ships neutral
  • GUI control in Options > Spam filtering, next to the embedded data cost
  • Data bytes are charged the higher of -datacarriercost and -scriptsigcost, so the discount cannot be used to make embedded data cheaper
  • Negative values are rejected at startup
  • Unit and functional tests

Left at the neutral default because discounting by default would relay pre-segwit spends at a lower effective feerate than the rest of the network. Say the word if you would rather it ship at 0.25.

Based on #342, which block assembly needs once policy vsize can fall below consensus weight.

Screenshots

Options > Spam filtering, default (1.00):

default

Set to 0.25:

0.25

TestPackage() extrapolated a package's contribution to the block from its
policy vsize, while AddToBlock() accumulates the real consensus weight. That
is only correct while policy vsize is never below weight/4, which holds today
because the only policy weight adjustment is the -datacarriercost surcharge,
and that is never negative. A policy discount breaks it, and block assembly
then exceeds -blockmaxweight.

Track the consensus weight of each entry and its in-mempool ancestors, the
same way ancestor sigop cost is already tracked, and use it in TestPackage().
This also resolves the TODO that was there.

With extra_weight >= 0 the old estimate is always at least the package weight,
so this accepts exactly the same packages as before.
Mirrors -datacarriercost: a fixed-point vbytes-per-actual-byte value, stored
internally in weight units. The default leaves behavior unchanged.
Reprices scriptSig bytes in non-witness inputs, which consensus charges at
WITNESS_SCALE_FACTOR. Data bytes are charged the higher of -datacarriercost
and -scriptsigcost, so a scriptSig discount cannot be used to make embedded
data cheaper.

Consensus weight is untouched. Only the policy vsize changes, and it can now
be reduced, so the entry vsize is clamped to stay positive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mempool policy: Extend witness discount to pre-segwit txs

2 participants