You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mempool: expand PolicyEnforcer interface for complete validation
In this commit, we expand the PolicyEnforcer interface to include methods
for validating standardness, signature costs, and SegWit deployment. This
makes PolicyEnforcer a complete abstraction for all policy-level validation,
complementing the TxValidator's consensus-level checks.
We add four new methods to the PolicyEnforcer interface:
ValidateStandardness checks transaction standardness requirements including
version, finalization, size limits, script types, and dust outputs. This
delegates to the existing CheckTransactionStandard and checkInputsStandard
helper functions.
ValidateSigCost validates that signature operation cost doesn't exceed
relay limits, using the CheckTransactionSigCost helper function we
extracted earlier.
ValidateSegWitDeployment ensures SegWit transactions are only accepted
when SegWit is active, using CheckSegWitDeployment.
ValidateRelayFee signature is updated to accept utxoView and
nextBlockHeight, enabling priority calculation for low-fee transactions.
The implementation now calls CheckRelayFee for the core validation, then
applies rate limiting separately.
The PolicyConfig structure is expanded to include MaxTxVersion,
MaxSigOpCostPerTx, IsDeploymentActive, ChainParams, and BestHeight. These
fields enable the policy enforcer to perform validation without requiring
external context from the mempool. DefaultPolicyConfig provides sensible
defaults for all new fields, assuming SegWit is active and using mainnet
parameters.
StandardPolicyEnforcer implements all new methods by delegating to the
standalone helper functions in policy.go. This keeps the implementation
thin while maintaining full test coverage through the existing helper
function tests.
The ValidateRelayFee tests are updated to pass the new parameters. We fix
a test case that was incorrectly expecting non-new transactions with
low fees to be rejected - per the CheckRelayFee implementation, non-new
transactions (from reorgs) are exempted from priority checks for
transactions under the size threshold. We add a new test case showing
that large non-new transactions are still correctly rejected if their
fees are insufficient.
This expanded interface allows TxMempoolV2's validation pipeline to use
PolicyEnforcer for all policy checks, creating a clean separation between
consensus validation (TxValidator) and policy validation (PolicyEnforcer).
0 commit comments