Validation
ValidationMode
Bases: IntEnum
Result of validation processing.
Indicates whether a data structure (such as a block or transaction) passed validation, failed validation, or encountered an error during processing.
Source code in pbk/validation.py
BlockValidationResult
Bases: IntEnum
Specific reason why a block failed validation.
Provides detailed information about which validation rule was violated when a block is rejected. These results help diagnose why blocks fail to be accepted into the blockchain.
Source code in pbk/validation.py
CACHED_INVALID
class-attribute
instance-attribute
This block was cached as being invalid and we didn't store the reason why
CONSENSUS
class-attribute
instance-attribute
Invalid by consensus rules (excluding any below reasons)
HEADER_LOW_WORK
class-attribute
instance-attribute
The block header may be on a too-little-work chain
INVALID_HEADER
class-attribute
instance-attribute
Invalid proof of work or time too old
INVALID_PREV
class-attribute
instance-attribute
A block this one builds on is invalid
MISSING_PREV
class-attribute
instance-attribute
We don't have the previous block the checked one is built on
MUTATED
class-attribute
instance-attribute
The block's data didn't match the data committed to by the PoW
TIME_FUTURE
class-attribute
instance-attribute
Block timestamp was > 2 hours in the future (or our clock is bad)
BlockValidationState
Bases: KernelOpaquePtr
State of a block during validation.
Contains information about whether validation was successful and, if not, which specific validation step failed. This state is provided to validation interface callbacks to communicate detailed validation results.
Source code in pbk/validation.py
block_validation_result
property
Specific validation failure reason.
| RETURNS | DESCRIPTION |
|---|---|
BlockValidationResult
|
The granular reason why validation failed, or UNSET if valid. |
validation_mode
property
Overall validation result.
| RETURNS | DESCRIPTION |
|---|---|
ValidationMode
|
Whether the block is valid, invalid, or encountered an error. |
__init__
__repr__
Return a string representation of the block validation state.
TxValidationResult
Bases: IntEnum
Specific reason why a transaction failed validation.
The subset of values that can occur depends on which validation function was used.
Source code in pbk/validation.py
CONFLICT
class-attribute
instance-attribute
Tx already in mempool or conflicts with a tx in the chain
INPUTS_NOT_STANDARD
class-attribute
instance-attribute
Inputs (covered by txid) failed policy rules
MEMPOOL_POLICY
class-attribute
instance-attribute
Violated mempool's fee/size/descendant/RBF/etc limits
MISSING_INPUTS
class-attribute
instance-attribute
Transaction was missing some of its inputs
NOT_STANDARD
class-attribute
instance-attribute
Otherwise didn't meet local policy rules
NO_MEMPOOL
class-attribute
instance-attribute
This node does not have a mempool so can't validate the transaction
PREMATURE_SPEND
class-attribute
instance-attribute
Transaction spends a coinbase too early, or violates locktime/sequence locks
RECONSIDERABLE
class-attribute
instance-attribute
Fails some policy, but might be acceptable if submitted in a (different) package
UNKNOWN
class-attribute
instance-attribute
Transaction was not validated because package failed
WITNESS_MUTATED
class-attribute
instance-attribute
Witness may have been malleated or is prior to SegWit activation
TxValidationState
Bases: KernelOpaquePtr
State of a transaction during validation.
Contains information about whether validation was successful and, if not, which specific validation step failed.
Source code in pbk/validation.py
tx_validation_result
property
Specific validation failure reason.
| RETURNS | DESCRIPTION |
|---|---|
TxValidationResult
|
The granular reason why validation failed, or UNSET if valid. |
validation_mode
property
Overall validation result.
| RETURNS | DESCRIPTION |
|---|---|
ValidationMode
|
Whether the transaction is valid, invalid, or encountered an error. |
__init__
__repr__
Return a string representation of the transaction validation state.
ValidationInterfaceCallbacks
Bases: btck_ValidationInterfaceCallbacks
Callbacks for receiving validation events.
These callbacks allow monitoring of block validation progress and results. Callbacks are invoked synchronously during validation and will block further validation execution until they complete, so they should execute quickly.
All callbacks are optional; only those passed as keyword arguments are registered, and any unspecified event is silently ignored.
Available callbacks, each invoked with (block, entry_or_state):
- block_checked(block: Block, state: BlockValidationState):
a block has been fully validated. state is only valid for the duration
of the callback — do not retain it.
- pow_valid_block(block: Block, entry: BlockTreeEntry):
a block extends the header chain with valid PoW.
- block_connected(block: Block, entry: BlockTreeEntry):
a valid block was connected to the best chain.
- block_disconnected(block: Block, entry: BlockTreeEntry):
a block was disconnected during a reorg.
block is owned by the callback; entry is a view into the kernel's
block index and remains valid for the kernel's lifetime.
Example
Register only block_disconnected:
cbs = ValidationInterfaceCallbacks( ... block_disconnected=lambda block, entry: print(entry.height) ... )
Source code in pbk/validation_interface.py
__init__
Create validation interface callbacks.
| PARAMETER | DESCRIPTION |
|---|---|
**callbacks
|
Callback functions for validation events, keyed by callback name
(e.g.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an unknown callback name is passed. |