cosmos-sdk/server/v2/stf
2025-01-16 08:53:49 +00:00
..
branch refactor(store/v2)!: simplify storage (#22683) 2024-12-03 16:18:19 +00:00
gas chore(server): bump cosmossdk.io/core and correct comment naming (#22245) 2024-10-15 14:00:36 +00:00
internal refactor(core): remove redundant ExecMode (#20322) 2024-05-29 16:27:07 +00:00
mock test(server/v2/cometbft): Add abci unit tests (#21020) 2024-09-09 10:34:29 +00:00
CHANGELOG.md chore: finish prep beta.2 (#23411) 2025-01-16 08:53:49 +00:00
core_branch_service_test.go test(x/upgrade): fix tests (#21582) 2024-09-07 14:41:33 +00:00
core_branch_service.go feat: unify version modifier for v2 (#21508) 2024-09-06 15:56:29 +00:00
core_event_service.go docs: Correct grammar errors across multiple files (#23074) 2025-01-06 08:31:06 +00:00
core_gas_service.go fix(server/v2/stf): include safety checks to the execution context (#21359) 2024-08-23 10:22:17 +00:00
core_header_service.go test(integration): port x/bank tests to server/v2 app (#21912) 2024-11-06 18:53:30 +00:00
core_router_service.go chore(server): bump cosmossdk.io/core and correct comment naming (#22245) 2024-10-15 14:00:36 +00:00
core_store_service.go fix(server/v2/stf): include safety checks to the execution context (#21359) 2024-08-23 10:22:17 +00:00
go.mod build(deps): Bump cosmossdk.io/core from 1.0.0-alpha.6 to 1.0.0 in standalone packages (no sdk deps) (#23241) 2025-01-08 22:32:40 +00:00
go.sum build(deps): Bump cosmossdk.io/core from 1.0.0-alpha.6 to 1.0.0 in standalone packages (no sdk deps) (#23241) 2025-01-08 22:32:40 +00:00
identity.go chore: cleanup core/app (#21368) 2024-08-27 09:55:16 +00:00
README.md chore(docs): STF readme (#23150) 2025-01-02 11:52:05 +00:00
sims_entry.go feat(sims): Integration with app v2 (#23013) 2025-01-09 08:19:35 +00:00
stf_router_test.go refactor(core/handlers): be more devx friendly (#21984) 2024-10-02 05:38:22 +00:00
stf_router.go refactor(core/handlers): be more devx friendly (#21984) 2024-10-02 05:38:22 +00:00
stf_test.go test: investigate test failure due to wal log (#22679) 2024-12-19 15:00:37 +00:00
stf.go feat(sims): Integration with app v2 (#23013) 2025-01-09 08:19:35 +00:00
util_test.go fix(server/v2/stf): include safety checks to the execution context (#21359) 2024-08-23 10:22:17 +00:00
util.go refactor: use errors.New to replace fmt.Errorf with no parameters (#21394) 2024-08-25 11:41:31 +00:00

STF (State Transition Function) Documentation

This document outlines the main external calls in the STF package, their execution flows, and dependencies.

Table of Contents

DeliverBlock

DeliverBlock is the main state transition function that processes an entire block of transactions.

sequenceDiagram
participant Caller
participant STF
participant State
participant PreBlock
participant BeginBlock
participant TxProcessor
participant EndBlock
Caller->>STF: DeliverBlock(ctx, block, state)
STF->>State: Branch(state)
STF->>State: SetHeaderInfo
STF->>PreBlock: doPreBlock(ctx, txs)
STF->>BeginBlock: doBeginBlock(ctx)
loop For each transaction
STF->>TxProcessor: deliverTx(ctx, state, tx)
TxProcessor->>TxProcessor: validateTx()
TxProcessor->>TxProcessor: execTx()
TxProcessor-->>STF: TxResult
end
STF->>EndBlock: doEndBlock(ctx)
STF->>EndBlock: validatorUpdates(ctx)
STF-->>Caller: BlockResponse, newState, error

Dependencies

  • Required Input:
    • Context
    • BlockRequest containing transactions
    • ReadOnly state
  • Required Components:
    • PreBlock handler
    • BeginBlock handler
    • EndBlock handler
    • Transaction validator
    • Message router
    • Gas meter

Simulate

Simulate executes a transaction without committing changes to the actual state.

sequenceDiagram
participant Caller
participant STF
participant State
participant TxProcessor
Caller->>STF: Simulate(ctx, state, gasLimit, tx)
STF->>State: Branch(state)
STF->>State: GetHeaderInfo()
STF->>TxProcessor: deliverTx(ctx, state, tx, SimulateMode)
TxProcessor-->>Caller: TxResult, simulationState

Dependencies

  • Required Input:
    • Context
    • ReadOnly state
    • Gas limit
    • Transaction
  • Required Components:
    • Transaction processor
    • Gas meter
    • Message router

ValidateTx

ValidateTx performs transaction validation without execution.

sequenceDiagram
participant Caller
participant STF
participant State
participant Validator
Caller->>STF: ValidateTx(ctx, state, gasLimit, tx)
STF->>State: Branch(state)
STF->>Validator: validateTx(ctx, state, gasLimit, tx)
Validator-->>Caller: TxResult

Dependencies

  • Required Input:
    • Context
    • ReadOnly state
    • Gas limit
    • Transaction
  • Required Components:
    • Transaction validator
    • Gas meter

Query

Query executes a read-only query against the application state.

sequenceDiagram
participant Caller
participant STF
participant State
participant QueryRouter
Caller->>STF: Query(ctx, state, gasLimit, req)
STF->>State: Branch(state)
STF->>State: GetHeaderInfo()
STF->>QueryRouter: Invoke(ctx, req)
QueryRouter-->>Caller: Response, error

Dependencies

  • Required Input:
    • Context
    • ReadOnly state
    • Gas limit
    • Query request message
  • Required Components:
    • Query router
    • Gas meter
    • Message handlers

Error Handling

All operations include error handling for:

  • Context cancellation
  • Gas limit exceeded
  • Invalid transactions
  • State operation failures
  • Panic recovery (in transaction execution)

Gas Management

Gas is tracked and limited for:

  • Transaction validation
  • Message execution
  • State operations
  • Query execution

Each operation that consumes gas uses a gas meter to track usage and ensure limits are not exceeded.