Documentation
¶
Index ¶
- Constants
- func EncodeTx(encCache *EncoderCache, enc sdk.TxEncoder, tx sdk.Tx) (bz []byte, hit bool, err error)
- func NewCachingDecoder(base sdk.TxDecoder, cache *DecodeCache) sdk.TxDecoder
- func NewReapTxsHandler(mpool mempool.Mempool, txEncoder sdk.TxEncoder, encCache *EncoderCache, ...) sdk.ReapTxsHandler
- func PoolSnapshot(ctx context.Context, mp sdkmempool.Mempool) []sdk.Tx
- func ProtoSizeForTx(bz []byte) int64
- type DecodeCache
- type EncoderCache
- type Manager
- func (a *Manager) AdmissionMutex() *sync.Mutex
- func (a *Manager) CheckTxHandler() sdk.CheckTxHandler
- func (a *Manager) Close()
- func (a *Manager) CountTx() int
- func (a *Manager) InsertTx(txBytes []byte) (*sdk.TxResponse, error)
- func (a *Manager) InsertTxHandler() sdk.InsertTxHandler
- func (a *Manager) PendingTxs() []sdk.Tx
- func (a *Manager) RecheckDisabled() bool
- func (a *Manager) RecheckTxs()
- func (a *Manager) SetPreVerify(fn func([]byte) error)
- func (a *Manager) StageRecheckSenders(height int64, txs [][]byte)
- func (a *Manager) StageSkippedSenders(txs [][]byte)
- func (a *Manager) TriggerRecheck()
- func (a *Manager) WaitForRecheck(ctx context.Context)
- func (a *Manager) WaitForRecheckTimedOut(ctx context.Context, timeout time.Duration) bool
- type PreVerifierRegistry
Constants ¶
const TypeApp = "app"
Variables ¶
This section is empty.
Functions ¶
func EncodeTx ¶
func EncodeTx(encCache *EncoderCache, enc sdk.TxEncoder, tx sdk.Tx) (bz []byte, hit bool, err error)
EncodeTx returns the raw bytes of a transaction, prioritizing the cache if available.
func NewCachingDecoder ¶
func NewCachingDecoder(base sdk.TxDecoder, cache *DecodeCache) sdk.TxDecoder
NewCachingDecoder wraps base with the shared cache, so PrepareProposal and BaseApp.runTx reuse each other's decodes.
func NewReapTxsHandler ¶
func NewReapTxsHandler(mpool mempool.Mempool, txEncoder sdk.TxEncoder, encCache *EncoderCache, ttl time.Duration, maxPerReap int, logger log.Logger) sdk.ReapTxsHandler
NewReapTxsHandler scans the app mempool to gather txs to be gossiped to other peers, stopping at MaxBytes/MaxGas (0 = no cap, per CometBFT convention). Prefix scan: breaks at the first tx over a cap (not best-fit), so a large high-priority tx may leave budget unused. Encoder errors skip the tx; encCache hits skip proto.Marshal.
func PoolSnapshot ¶
PoolSnapshot returns a snapshot of the current mempool transactions.
func ProtoSizeForTx ¶
ProtoSizeForTx returns the wire size one tx contributes to a CometBFT block's Data message. Same result as cmttypes.ComputeProtoSizeForTxs([]cmttypes.Tx{bz}) but without its ~4 allocs/tx ([]Tx slice + Data{}.ToProto) in the proposal hot loop. Data.Txs is `repeated bytes txs = 1`: each element is a 1-byte field tag + varint length + payload, matching gogoproto's generated Size().
Types ¶
type DecodeCache ¶
type DecodeCache struct {
// contains filtered or unexported fields
}
DecodeCache is a sharded LRU cache of decoded txs. Returned sdk.Tx pointers are shared across consumers (PrepareProposal, runTx, CheckTx) — callers MUST NOT mutate them. Safe today because decode is the only writer: the EVM ante's VerifySender only compares against MsgEthereumTx.From (set at proto-decode), never writes it. A future ante that mutates a decoded msg would break sharing.
func NewDecodeCache ¶
func NewDecodeCache(size, maxTxBytes uint) *DecodeCache
NewDecodeCache returns a cache with total capacity ~size and per-entry payload cap maxTxBytes. Pass 0 for either to use defaults.
type EncoderCache ¶
type EncoderCache struct {
// contains filtered or unexported fields
}
EncoderCache caches tx encoding
func NewEncoderCache ¶
func NewEncoderCache(size, maxTxBytes uint) *EncoderCache
NewEncoderCache returns an LRU-bounded cache holding at most size entries, skipping txs whose canonical bytes exceed maxTxBytes (mirrors DecodeCache). Pass 0 for size or maxTxBytes to fall back to the cmdcfg defaults.
func (*EncoderCache) Evict ¶
func (e *EncoderCache) Evict(tx sdk.Tx)
Evict drops tx's entry so a stale/removed tx stops pinning the heap. No op if tx is absent.
func (*EncoderCache) Get ¶
func (e *EncoderCache) Get(tx sdk.Tx) ([]byte, bool)
Get returns a copy of the registered bytes for tx, promoting it to MRU. Safe on a nil *EncoderCache (returns nil, false). Copies because the bytes escape into block proposals/reap/ReCheck; sharing the internal slice would let a caller corrupt every hit.
func (*EncoderCache) HashTx ¶
func (e *EncoderCache) HashTx(tx sdk.Tx, bz []byte) [32]byte
HashTx returns sha256(bz), caching it on tx's entry so repeated reaps don't re-hash the same canonical bytes. bz must be the canonical bytes EncodeTx returned for tx. Safe on a nil receiver (hashes without caching). The hash is computed outside the lock so a slow hash never blocks admission's Set.
func (*EncoderCache) Set ¶
func (e *EncoderCache) Set(tx sdk.Tx, bz []byte)
Set stores canonical proto bytes for a tx (raw req.Tx bytes on encode error). Concurrency-safe. Evicts the LRU entry when at capacity. Bytes above maxTxBytes aren't cached: EncodeTx re-encodes them on miss (rare; bounds heap).
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the app-side mempool for mempool.type=app
func NewManager ¶
func NewManager(app *baseapp.BaseApp, encCache *EncoderCache, txEncoder sdk.TxEncoder, mpool sdkmempool.Mempool, signer sdkmempool.SignerExtractionAdapter, decoder sdk.TxDecoder, recheckBatchSize int, ttlNumBlocks int64, recheckDisabled bool) *Manager
NewManager builds the Manager for mempool.type=app;
func (*Manager) AdmissionMutex ¶
AdmissionMutex exposes mu so App.Commit can serialize its checkState reset against lock-free admission.
func (*Manager) CheckTxHandler ¶
func (a *Manager) CheckTxHandler() sdk.CheckTxHandler
CheckTxHandler runs RPC CheckTx.
func (*Manager) InsertTx ¶
func (a *Manager) InsertTx(txBytes []byte) (*sdk.TxResponse, error)
InsertTx returns the sync ABCI result; error is always nil (failures surface as ABCI codes).
func (*Manager) InsertTxHandler ¶
func (a *Manager) InsertTxHandler() sdk.InsertTxHandler
InsertTxHandler validates peer-relayed txs via RunTx(ExecModeCheck) before admitting them.
func (*Manager) PendingTxs ¶
func (*Manager) RecheckDisabled ¶
RecheckDisabled reports whether mempool recheck is disabled
func (*Manager) RecheckTxs ¶
func (a *Manager) RecheckTxs()
RecheckTxs evicts pool txs invalidated by the last block.
func (*Manager) SetPreVerify ¶
SetPreVerify sets the pre-verification hook.
func (*Manager) StageRecheckSenders ¶
StageRecheckSenders records the senders of the just-committed block's txs so RecheckTxs can re-validate only their remaining pending txs, and stages the committed height.
func (*Manager) StageSkippedSenders ¶
StageSkippedSenders merges the senders of proposal-gate-rejected txs into recheckSenders without touching lastCommittedHeight
func (*Manager) TriggerRecheck ¶
func (a *Manager) TriggerRecheck()
TriggerRecheck schedules an async recheck. Call only from the consensus path (App.Commit).
func (*Manager) WaitForRecheck ¶
WaitForRecheck blocks until the pending recheck finishes;
type PreVerifierRegistry ¶
type PreVerifierRegistry struct {
// contains filtered or unexported fields
}
PreVerifierRegistry collects lock-free admission pre-verifiers contributed by modules. The app composes them and hands Verify to the mempool manager, which runs it before the admission mutex (mempool.type=app). First rejection wins; a nil result defers to the locked admission path.
func (*PreVerifierRegistry) Register ¶
func (r *PreVerifierRegistry) Register(v func([]byte) error)
Register adds a pre-verifier; nil is ignored.
func (*PreVerifierRegistry) Verify ¶
func (r *PreVerifierRegistry) Verify(raw []byte) error
Verify runs the registered pre-verifiers, returning the first rejection or nil.