Documentation
¶
Overview ¶
Package forging contains types and utilities for block production.
Block Propagation ¶
Block propagation to peers is handled automatically by the chain package. When a forged block is added via chain.AddBlock(), the method closes the chain's waitingChan (see chain/chain.go lines 174-180), which signals any blocking ChainIterators. The ouroboros chainsync server (see ouroboros/chainsync.go chainsyncServerRequestNext) waits on these iterators via ChainIterator.Next(true), which blocks on waitingChan when at chain tip. When the channel is closed, iterators wake up and deliver the new block to connected peers via RollForward messages.
This means there is no need for explicit propagation logic when forging blocks - adding the block to the chain automatically triggers delivery to all subscribed chainsync clients.
Package forging provides block production functionality for Cardano SPOs.
Index ¶
- Constants
- Variables
- func CurrentKESPeriod(currentSlot uint64, slotsPerKESPeriod uint64) (uint64, error)
- func CurrentKESPeriodFromGenesis(genesis *shelley.ShelleyGenesis, currentSlot uint64) (uint64, error)
- func WallClockKESPeriod(genesis *shelley.ShelleyGenesis, now time.Time) (uint64, error)
- type BlockBroadcaster
- type BlockBuilder
- type BlockBuilderConfig
- type BlockForgedObserver
- type BlockForger
- func (f *BlockForger) IsRunning() bool
- func (f *BlockForger) RecordSlotBattle()
- func (f *BlockForger) SignBlockHeader(kesPeriod uint64, headerBytes []byte) ([]byte, error)
- func (f *BlockForger) SlotTracker() *SlotTracker
- func (f *BlockForger) Start(ctx context.Context) error
- func (f *BlockForger) Stop()
- func (f *BlockForger) VRFProofForSlot(slot uint64, epochNonce []byte) ([]byte, []byte, error)
- type BlockValidator
- type ChainTipProvider
- type DefaultBlockBuilder
- type EndorserBlockBroadcaster
- type EpochNonceProvider
- type ForgedBlockRecord
- type ForgerConfig
- type LeaderChecker
- type LedgerView
- type LeiosBlockBuilder
- type LeiosBlockData
- type LeiosCertificateProvider
- type LeiosCertifiedEndorserBlock
- type LeiosEndorserBlockAnnouncement
- type LeiosParentAnnouncementProvider
- type LeiosProduceChecker
- type MempoolProvider
- type MempoolTransaction
- type Mode
- type OpCert
- type PoolCredentials
- func (pc *PoolCredentials) GetKESPeriod() uint64
- func (pc *PoolCredentials) GetKESVKey() []byte
- func (pc *PoolCredentials) GetOpCert() *OpCert
- func (pc *PoolCredentials) GetPoolID() lcommon.PoolId
- func (pc *PoolCredentials) GetVRFSKey() []byte
- func (pc *PoolCredentials) GetVRFVKey() []byte
- func (pc *PoolCredentials) IsLoaded() bool
- func (pc *PoolCredentials) KESSign(period uint64, message []byte) ([]byte, error)
- func (pc *PoolCredentials) LoadFromFiles(vrfSKeyPath string, kesSKeyPath string, opCertPath string) error
- func (pc *PoolCredentials) OpCertExpiryPeriod() uint64
- func (pc *PoolCredentials) PeriodsRemaining(currentPeriod uint64) uint64
- func (pc *PoolCredentials) UpdateKESPeriod(period uint64) error
- func (pc *PoolCredentials) VRFProve(alpha []byte) ([]byte, []byte, error)
- func (pc *PoolCredentials) ValidateAgainstLedger(view LedgerView) (registered, vrfMatched bool, err error)
- func (pc *PoolCredentials) ValidateKESPeriod(genesis *shelley.ShelleyGenesis, currentSlot uint64) error
- func (pc *PoolCredentials) ValidateOpCert() error
- type ProtocolParamsProvider
- type SlotBattleEvent
- type SlotClockProvider
- type SlotTracker
- type TxValidator
Constants ¶
const SlotBattleEventType = event.EventType("forging.slot_battle")
SlotBattleEventType is the event type for slot battles (competing blocks)
Variables ¶
var ErrVRFKeyHashMismatch = errors.New("VRF key hash mismatch")
Functions ¶
func CurrentKESPeriod ¶ added in v0.43.0
CurrentKESPeriod returns the KES period containing currentSlot.
Semantics:
- currentSlot must be the era-aware absolute slot number from the slot clock. Reconstructing it from Shelley wall-clock slot length is wrong on networks with a Byron prefix.
- Returns an error if slotsPerKESPeriod is zero.
func CurrentKESPeriodFromGenesis ¶ added in v0.63.0
func CurrentKESPeriodFromGenesis( genesis *shelley.ShelleyGenesis, currentSlot uint64, ) (uint64, error)
CurrentKESPeriodFromGenesis returns the KES period containing currentSlot, using slotsPerKESPeriod from Shelley genesis.
func WallClockKESPeriod ¶ added in v0.63.0
WallClockKESPeriod returns the KES period implied by Shelley genesis wall time. It is retained for tests and diagnostics on networks without a Byron prefix. Block production startup must use CurrentKESPeriodFromGenesis with an era-aware slot clock instead.
Types ¶
type BlockBroadcaster ¶
type BlockBroadcaster interface {
// AddBlock adds a block to the local chain and propagates to peers.
AddBlock(block ledger.Block, cbor []byte) error
}
BlockBroadcaster submits built blocks to the chain.
type BlockBuilder ¶
type BlockBuilder interface {
// BuildBlock creates a new block for the given slot.
// Returns the block and its CBOR encoding.
BuildBlock(slot uint64, kesPeriod uint64) (ledger.Block, []byte, error)
}
BlockBuilder constructs blocks from mempool transactions.
type BlockBuilderConfig ¶
type BlockBuilderConfig struct {
Logger *slog.Logger
Mempool MempoolProvider
PParamsProvider ProtocolParamsProvider
ChainTip ChainTipProvider
EpochNonce EpochNonceProvider
Credentials *PoolCredentials
// TxValidator optionally re-validates each transaction against
// the current ledger state before including it in a block.
// When nil, ledger-level re-validation is skipped (but
// intra-block double-spend detection still applies).
TxValidator TxValidator
}
BlockBuilderConfig holds configuration for the DefaultBlockBuilder.
type BlockForgedObserver ¶ added in v0.46.2
BlockForgedObserver observes blocks after they are successfully built, before chain adoption is attempted.
type BlockForger ¶
type BlockForger struct {
// contains filtered or unexported fields
}
BlockForger coordinates block production for a stake pool.
func NewBlockForger ¶
func NewBlockForger(cfg ForgerConfig) (*BlockForger, error)
NewBlockForger creates a new block forger.
func (*BlockForger) IsRunning ¶
func (f *BlockForger) IsRunning() bool
IsRunning returns true if the forger is currently running.
func (*BlockForger) RecordSlotBattle ¶
func (f *BlockForger) RecordSlotBattle()
RecordSlotBattle increments the slot battles counter. This is called from external components (e.g., LedgerState) when a slot battle is detected.
func (*BlockForger) SignBlockHeader ¶
func (f *BlockForger) SignBlockHeader( kesPeriod uint64, headerBytes []byte, ) ([]byte, error)
SignBlockHeader signs a block header with KES.
func (*BlockForger) SlotTracker ¶
func (f *BlockForger) SlotTracker() *SlotTracker
SlotTracker returns the forger's slot tracker, which can be used by other components (e.g., chainsync) to detect slot battles.
func (*BlockForger) Start ¶
func (f *BlockForger) Start(ctx context.Context) error
Start begins the block forging process. The provided context controls the forger's lifecycle.
func (*BlockForger) Stop ¶
func (f *BlockForger) Stop()
Stop stops the block forging process. It blocks until the runLoop goroutine has exited.
func (*BlockForger) VRFProofForSlot ¶
VRFProofForSlot generates a VRF proof for leader election at the given slot. Returns (proof, output, error).
type BlockValidator ¶ added in v0.58.0
BlockValidator validates a locally-forged block before it is adopted onto the local chain and diffused to peers. If ValidateForgedBlock returns a non-nil error the block is dropped and neither adopted nor diffused.
type ChainTipProvider ¶
type ChainTipProvider interface {
Tip() ochainsync.Tip
}
ChainTipProvider provides access to the current chain tip.
type DefaultBlockBuilder ¶
type DefaultBlockBuilder struct {
// contains filtered or unexported fields
}
DefaultBlockBuilder implements BlockBuilder using LedgerState components.
func NewDefaultBlockBuilder ¶
func NewDefaultBlockBuilder(cfg BlockBuilderConfig) (*DefaultBlockBuilder, error)
NewDefaultBlockBuilder creates a new DefaultBlockBuilder.
func (*DefaultBlockBuilder) BuildBlock ¶
func (b *DefaultBlockBuilder) BuildBlock( slot uint64, kesPeriod uint64, ) (ledger.Block, []byte, error)
BuildBlock creates a new block for the given slot. Returns the block and its CBOR encoding.
func (*DefaultBlockBuilder) BuildBlockWithLeios ¶ added in v0.63.0
func (b *DefaultBlockBuilder) BuildBlockWithLeios( slot uint64, kesPeriod uint64, leios LeiosBlockData, ) (ledger.Block, []byte, error)
BuildBlockWithLeios creates a Dijkstra block with Leios prototype announcement or certificate data committed into the block body/header.
type EndorserBlockBroadcaster ¶ added in v0.54.0
type EndorserBlockBroadcaster interface {
BroadcastEndorserBlock(
slot uint64,
hash []byte,
cbor []byte,
txBodies [][]byte,
) error
}
EndorserBlockBroadcaster stores a locally-forged endorser block and notifies connected peers via the LeiosNotify protocol. txBodies are the referenced transactions' raw CBOR, in manifest order, so the endorser block can also be served over leios-fetch.
type EpochNonceProvider ¶
type EpochNonceProvider interface {
// CurrentEpoch returns the current epoch number.
CurrentEpoch() uint64
// EpochForSlot returns the epoch containing the given slot.
EpochForSlot(slot uint64) (uint64, error)
// EpochNonce returns the nonce for the given epoch.
EpochNonce(epoch uint64) []byte
}
EpochNonceProvider provides the epoch nonce for VRF proof generation.
type ForgedBlockRecord ¶
type ForgedBlockRecord struct {
BlockHash []byte
}
ForgedBlockRecord stores the hash of a block we forged for a given slot.
type ForgerConfig ¶
type ForgerConfig struct {
Mode Mode
Logger *slog.Logger
SlotDuration time.Duration
// Production mode configuration
Credentials *PoolCredentials
LeaderChecker LeaderChecker
BlockBuilder BlockBuilder
BlockBroadcaster BlockBroadcaster
BlockForged BlockForgedObserver
SlotClock SlotClockProvider
// LeiosProduceChecker enables EB forging when non-nil. Requires
// LeiosEBBroadcaster and LeiosMempool to also be set.
LeiosProduceChecker LeiosProduceChecker
// LeiosEBBroadcaster propagates locally-forged EBs to peers.
LeiosEBBroadcaster EndorserBlockBroadcaster
// LeiosMempool provides transactions for EB building. May reuse the
// same MempoolProvider as the RB builder.
LeiosMempool MempoolProvider
// LeiosCertificateProvider supplies certified EBs for Dijkstra CertRBs.
LeiosCertificateProvider LeiosCertificateProvider
// LeiosParentAnnouncementProvider supplies the EB hash announced by the
// parent RB so CertRB selection cannot certify an unrelated EB.
LeiosParentAnnouncementProvider LeiosParentAnnouncementProvider
// ForgeSyncToleranceSlots controls how far the local chain can lag the
// upstream tip before forging is skipped. Zero uses the default.
ForgeSyncToleranceSlots uint64
// ForgeStaleGapThresholdSlots controls when to log an error if the
// chain tip is far ahead of the slot clock. Zero uses the default.
ForgeStaleGapThresholdSlots uint64
// BlockValidator, when non-nil, validates the forged block (VRF/KES
// header crypto, body-hash consistency, per-tx ledger rules) before
// AddBlock is called. A validation failure drops the block without
// adopting or diffusing it. Nil disables self-validation (default).
BlockValidator BlockValidator
// Prometheus metrics registry (optional)
PromRegistry prometheus.Registerer
}
ForgerConfig holds configuration for the block forger.
type LeaderChecker ¶
type LeaderChecker interface {
// ShouldProduceBlock returns true if this pool is the leader for the slot.
ShouldProduceBlock(slot uint64) bool
// NextLeaderSlot returns the next slot where this pool is leader.
NextLeaderSlot(fromSlot uint64) (uint64, bool)
}
LeaderChecker determines if the pool should produce a block for a given slot.
type LedgerView ¶ added in v0.43.0
type LedgerView interface {
// PoolRegistrationVRFKeyHash returns the VRF key hash recorded on
// the most recent active pool registration certificate for poolID.
// found is false when the pool has no on-chain registration yet.
PoolRegistrationVRFKeyHash(poolID [28]byte) (vrfKeyHash [32]byte, found bool, err error)
// LatestOpCertSequence returns the highest opcert IssueNumber
// observed on chain for poolID. found is false when on-chain
// counter tracking is not implemented or this pool has never
// minted a block.
LatestOpCertSequence(poolID [28]byte) (sequence uint64, found bool, err error)
}
LedgerView is the subset of ledger state the post-startup credential cross-check needs. The forging package depends on it as a small interface so the package itself stays free of a ledger dependency, and tests can drive the logic with a fake.
type LeiosBlockBuilder ¶ added in v0.63.0
type LeiosBlockBuilder interface {
BuildBlockWithLeios(
slot uint64,
kesPeriod uint64,
leios LeiosBlockData,
) (ledger.Block, []byte, error)
}
LeiosBlockBuilder constructs Dijkstra blocks with Leios prototype header/body extensions. Builders that do not implement it cannot safely announce or certify Leios endorser blocks.
type LeiosBlockData ¶ added in v0.63.0
type LeiosBlockData struct {
Announcement *LeiosEndorserBlockAnnouncement
Certificate *lcommon.LeiosEbCertificate
}
LeiosBlockData carries the Leios prototype data a Dijkstra ranking block should commit to. A certifying ranking block carries a certificate and no announcement; an announcing block carries an announcement and no certificate.
type LeiosCertificateProvider ¶ added in v0.63.0
type LeiosCertificateProvider interface {
EligibleCertifiedEndorserBlocks() []LeiosCertifiedEndorserBlock
MarkEndorserBlockEmbedded(ebHash lcommon.Blake2b256)
}
LeiosCertificateProvider supplies certified EBs and records successful inclusion after the certifying ranking block is adopted.
type LeiosCertifiedEndorserBlock ¶ added in v0.63.0
type LeiosCertifiedEndorserBlock struct {
SlotNo uint64
EndorserBlockHash lcommon.Blake2b256
Certificate *lcommon.LeiosEbCertificate
AnnouncingRbHash lcommon.Blake2b256
}
LeiosCertifiedEndorserBlock is a certified EB ready for inclusion in a Dijkstra ranking block.
type LeiosEndorserBlockAnnouncement ¶ added in v0.63.0
type LeiosEndorserBlockAnnouncement struct {
Hash lcommon.Blake2b256
Size uint64
}
LeiosEndorserBlockAnnouncement is the header extension payload for an endorser block announced by a Dijkstra ranking block.
type LeiosParentAnnouncementProvider ¶ added in v0.63.0
type LeiosParentAnnouncementProvider interface {
ParentLeiosAnnouncement() (
lcommon.Blake2b256,
lcommon.Blake2b256,
bool,
error,
)
}
LeiosParentAnnouncementProvider reports the EB announced by the parent ranking block. CertRBs may only certify that announced EB.
type LeiosProduceChecker ¶ added in v0.54.0
type LeiosProduceChecker interface {
MayProduceEndorserBlock(slot uint64) (allowed bool, reason string, err error)
}
LeiosProduceChecker is the forge-loop seam into the Leios pipeline. It reports whether the slot leader may produce an endorser block for the given slot (respects the single-EB-per-slot rule and produce window). A nil checker means Leios EB forging is disabled (relay or pre-Dijkstra era).
type MempoolProvider ¶
type MempoolProvider interface {
Transactions() []MempoolTransaction
}
MempoolProvider provides access to mempool transactions.
type MempoolTransaction ¶
MempoolTransaction represents a transaction in the mempool.
type OpCert ¶
type OpCert struct {
KESVKey []byte // KES verification key (32 bytes)
IssueNumber uint64 // Certificate sequence number
KESPeriod uint64 // KES period when certificate was created
Signature []byte // Cold key signature (64 bytes)
ColdVKey []byte // Cold verification key (32 bytes)
}
OpCert represents an operational certificate that binds a KES key to a pool.
type PoolCredentials ¶
type PoolCredentials struct {
// contains filtered or unexported fields
}
PoolCredentials holds the cryptographic keys required for block production. All keys are loaded using Bursa from standard cardano-cli format files. Fields are unexported to enforce thread-safe access via the mutex.
func NewPoolCredentials ¶
func NewPoolCredentials() *PoolCredentials
NewPoolCredentials creates an empty PoolCredentials instance.
func (*PoolCredentials) GetKESPeriod ¶
func (pc *PoolCredentials) GetKESPeriod() uint64
GetKESPeriod returns the current KES period of the loaded key. Returns 0 if the KES key is not loaded.
func (*PoolCredentials) GetKESVKey ¶
func (pc *PoolCredentials) GetKESVKey() []byte
GetKESVKey returns a copy of the KES verification key.
func (*PoolCredentials) GetOpCert ¶
func (pc *PoolCredentials) GetOpCert() *OpCert
GetOpCert returns a copy of the operational certificate. Returns nil if no certificate is loaded.
func (*PoolCredentials) GetPoolID ¶
func (pc *PoolCredentials) GetPoolID() lcommon.PoolId
GetPoolID returns the pool ID (Blake2b-224 of cold vkey).
func (*PoolCredentials) GetVRFSKey ¶
func (pc *PoolCredentials) GetVRFSKey() []byte
GetVRFSKey returns a copy of the VRF secret key (seed).
func (*PoolCredentials) GetVRFVKey ¶
func (pc *PoolCredentials) GetVRFVKey() []byte
GetVRFVKey returns a copy of the VRF verification key.
func (*PoolCredentials) IsLoaded ¶
func (pc *PoolCredentials) IsLoaded() bool
IsLoaded returns true if all credentials have been loaded.
func (*PoolCredentials) KESSign ¶
func (pc *PoolCredentials) KESSign(period uint64, message []byte) ([]byte, error)
KESSign signs a message with the KES key at the specified ABSOLUTE period.
IMPORTANT: Callers must ensure UpdateKESPeriod(period) was called before KESSign to evolve the key to the correct period. The kes.Sign function expects the key to already be at the relative period within the opcert window when an opcert is loaded.
func (*PoolCredentials) LoadFromFiles ¶
func (pc *PoolCredentials) LoadFromFiles( vrfSKeyPath string, kesSKeyPath string, opCertPath string, ) error
LoadFromFiles loads all pool credentials from the specified file paths. Uses Bursa to parse cardano-cli format key files.
func (*PoolCredentials) OpCertExpiryPeriod ¶
func (pc *PoolCredentials) OpCertExpiryPeriod() uint64
OpCertExpiryPeriod returns the KES period at which the OpCert expires. For depth 6, max periods = 2^6 = 64, so expiry = startPeriod + 64.
func (*PoolCredentials) PeriodsRemaining ¶
func (pc *PoolCredentials) PeriodsRemaining(currentPeriod uint64) uint64
PeriodsRemaining returns how many KES periods remain before expiry.
func (*PoolCredentials) UpdateKESPeriod ¶
func (pc *PoolCredentials) UpdateKESPeriod(period uint64) error
UpdateKESPeriod evolves the KES key to the specified ABSOLUTE period. The secret key itself tracks the relative period within the opcert window, so we translate chain KES periods by subtracting the opcert start period when an opcert is loaded.
func (*PoolCredentials) VRFProve ¶
func (pc *PoolCredentials) VRFProve(alpha []byte) ([]byte, []byte, error)
VRFProve generates a VRF proof for leader election. alpha should be MkInputVrf(slot, epochNonce).
func (*PoolCredentials) ValidateAgainstLedger ¶ added in v0.43.0
func (pc *PoolCredentials) ValidateAgainstLedger( view LedgerView, ) (registered, vrfMatched bool, err error)
ValidateAgainstLedger cross-checks the loaded credentials against ledger state once it is available. It is best-effort: a missing pool registration is not fatal because operators commonly stage their keys before submitting the registration certificate.
Three return values describe the outcome:
- registered: true if the pool registration was found on chain.
- vrfMatched: true if registered AND the on-chain VRF key hash matched our loaded VRF verification key. False otherwise (also false when registered is false or the VRF verification key is unavailable, e.g. for a seed-only VRF skey).
- err: a non-nil error means the ledger view disagrees with the loaded credentials. Normal networks refuse startup for these; devnet callers may choose to warn on ErrVRFKeyHashMismatch.
func (*PoolCredentials) ValidateKESPeriod ¶ added in v0.43.0
func (pc *PoolCredentials) ValidateKESPeriod( genesis *shelley.ShelleyGenesis, currentSlot uint64, ) error
ValidateKESPeriod checks that the loaded operational certificate's KES period is plausible at currentSlot, given the chain's Shelley genesis. A non-nil result means the node should refuse to start: either the opcert claims a period that hasn't started yet (rotated key staged too early, or wrong network) or the opcert has expired and needs to be rotated.
The protocol-level expiry uses MaxKESEvolutions from genesis rather than the raw 2^depth ceiling, so this matches the chain's view of when an opcert stops being valid.
func (*PoolCredentials) ValidateOpCert ¶
func (pc *PoolCredentials) ValidateOpCert() error
ValidateOpCert validates that the operational certificate matches the KES key and that the cold key signature over the certificate body is valid.
type ProtocolParamsProvider ¶
type ProtocolParamsProvider interface {
GetCurrentPParams() lcommon.ProtocolParameters
// ProtocolParamsForSlot returns the pparams that should govern a
// block forged at the given slot. When the slot is in an epoch
// beyond a scheduled fork that has not yet been applied to the
// in-memory ledger state, the returned pparams are the
// post-fork pparams. The forger uses this to produce
// era-correct blocks at fork boundaries.
ProtocolParamsForSlot(slot uint64) lcommon.ProtocolParameters
}
ProtocolParamsProvider provides access to protocol parameters.
type SlotBattleEvent ¶
type SlotBattleEvent struct {
// Slot is the slot number where the battle occurred
Slot uint64
// LocalBlockHash is the hash of our locally forged block (if any)
LocalBlockHash []byte
// RemoteBlockHash is the hash of the competing block from peers
RemoteBlockHash []byte
// Won indicates whether our local block was selected for the chain
Won bool
}
SlotBattleEvent is emitted when the node detects competing blocks for the same slot, either from receiving an external block while preparing to forge or when detecting a fork at the same slot height.
type SlotClockProvider ¶
type SlotClockProvider interface {
// CurrentSlot returns the current slot number based on wall-clock time.
CurrentSlot() (uint64, error)
// SlotsPerKESPeriod returns the number of slots in a KES period.
SlotsPerKESPeriod() uint64
// ChainTipSlot returns the slot number of the current chain tip.
ChainTipSlot() uint64
// NextSlotTime returns the wall-clock time when the next slot begins.
NextSlotTime() (time.Time, error)
// UpstreamTipSlot returns the latest known tip slot from upstream peers.
// Returns 0 if no upstream tip is known.
UpstreamTipSlot() uint64
}
SlotClockProvider provides current slot information from the slot clock.
type SlotTracker ¶
type SlotTracker struct {
// contains filtered or unexported fields
}
SlotTracker is a thread-safe tracker for recently forged block slots and their hashes. It allows chainsync to detect slot battles when an incoming block from a peer occupies a slot for which the local node has already forged a block.
func NewSlotTracker ¶
func NewSlotTracker() *SlotTracker
NewSlotTracker creates a new SlotTracker with the default capacity.
func NewSlotTrackerWithCapacity ¶
func NewSlotTrackerWithCapacity(maxSlots int) *SlotTracker
NewSlotTrackerWithCapacity creates a new SlotTracker with the given maximum capacity.
func (*SlotTracker) Len ¶
func (st *SlotTracker) Len() int
Len returns the number of tracked forged slots.
func (*SlotTracker) RecordForgedBlock ¶
func (st *SlotTracker) RecordForgedBlock(slot uint64, blockHash []byte)
RecordForgedBlock records that the local node forged a block with the given hash at the given slot. If the tracker is at capacity, the oldest entry is evicted.
func (*SlotTracker) WasForgedByUs ¶
func (st *SlotTracker) WasForgedByUs( slot uint64, ) (blockHash []byte, ok bool)
WasForgedByUs checks whether the local node forged a block for the given slot. If so, it returns the block hash and true. Otherwise it returns nil, false.
type TxValidator ¶
type TxValidator interface {
ValidateTx(tx ledger.Transaction) error
// ValidateTxWithOverlay re-validates with intra-block UTxO state:
// consumedUtxos are inputs spent by earlier txs in the same block
// (double-spend guard), createdUtxos are outputs produced by those
// txs (enables spending intra-block outputs).
ValidateTxWithOverlay(
tx ledger.Transaction,
consumedUtxos map[string]struct{},
createdUtxos map[string]lcommon.Utxo,
) error
}
TxValidator re-validates a transaction against the current ledger state at block assembly time. This catches transactions whose inputs have been consumed since they entered the mempool, protocol parameter changes, or other state mutations that invalidate previously-accepted transactions.