Skip to content

feat(baseapp): add basic support in sdk for block-stm #24458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

thomas-nguy
Copy link

@thomas-nguy thomas-nguy commented Apr 10, 2025

Description

Initial PR to add basic support in sdk for block-stm:

  • Define Executor for custom execution logic
  • Implementation of DefaultExecutor and BlockSTMExecutor
  • introduce incarnation cache that's shared between incarnations of the same tx for performance optimisation

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Enabled parallel transaction execution with a new configurable option.
    • Enhanced transaction tracking by introducing additional metrics such as transaction index, count, message index, and gas usage.
  • Refactor

    • Optimized the transaction processing flow to improve modularity, performance, and error handling.

Copy link

ironbird-prod bot commented Apr 10, 2025

Ironbird - launch a network To use Ironbird, you can use the following commands:
  • /ironbird start - Launch a testnet with the specified chain and load test configuration.
  • /ironbird chains - List of chain images that ironbird can use to spin-up testnet
  • /ironbird loadtests - List of load test modes that ironbird can run against testnet

baseapp/abci.go Outdated
Comment on lines 758 to 765

// GasMeter must be set after we get a context with updated consensus params.
gasMeter := app.getBlockGasMeter(app.finalizeBlockState.Context())
app.finalizeBlockState.SetContext(app.finalizeBlockState.Context().WithBlockGasMeter(gasMeter))
app.finalizeBlockState.SetContext(
app.finalizeBlockState.Context().
WithBlockGasMeter(gasMeter).
WithTxCount(len(req.Txs)),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change potentially affects state.

Call sequence:

(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).internalFinalizeBlock (baseapp/abci.go:705)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).FinalizeBlock (baseapp/abci.go:869)

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

📝 Walkthrough

Walkthrough

This update refactors how transactions are executed within the BaseApp. A new method (executeTxs) is introduced to encapsulate transaction processing, and the block finalization process now sets an enhanced context with a transaction count. Several methods have been updated to accept an additional transaction index parameter. New functionality is added to support an optional custom transaction executor (TxExecutor) for parallel execution, and the Context struct has been enhanced with fields and methods to better track transaction and block execution details.

Changes

File(s) Change Summary
baseapp/abci.go, baseapp/baseapp.go, baseapp/genesis.go, baseapp/test_helpers.go - Added transaction count to the context during block finalization.
- Refactored transaction execution into a new executeTxs method.
- Updated method signatures (e.g., getContextForTx, deliverTx, and runTx) to include a new txIndex parameter and adjust context creation.
baseapp/options.go, baseapp/txexecutor.go - Introduced a new type alias TxExecutor for defining custom, parallel transaction executors.
- Added both a standalone function and a method (SetTxExecutor) to assign a custom transaction executor to BaseApp.
types/context.go - Enhanced the Context struct with new fields: txIndex, msgIndex, txCount, and blockGasUsed.
- Added accessor and mutator methods for the new fields to manage transaction and block-related data.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant BA as BaseApp (Finalize)
    participant ET as executeTxs
    participant CTX as Context Modifier
    participant DT as deliverTxWithMultiStore

    Client->>BA: Submit block (with transactions)
    BA->>CTX: Create/update context with block gas meter and txCount
    BA->>ET: Call executeTxs(txs)
    loop For each transaction
        ET->>CTX: Update context with txIndex and msgIndex
        ET->>DT: Execute transaction (deliverTxWithMultiStore)
        DT-->>ET: Return execution result or error
    end
    ET-->>BA: Return array of tx execution results
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
baseapp/txexecutor.go (1)

11-16: Good definition of the TxExecutor function type.

The TxExecutor type is well-designed to facilitate parallel transaction execution. It takes appropriate parameters (context, block size, store, and a function for individual tx execution) and returns transaction results with error handling. This cleanly encapsulates the execution logic and allows for pluggable execution strategies.

Consider adding a doc comment that explains the intended use case for this function type, particularly noting that it's designed for parallel execution strategies like block-stm. This would make the purpose clearer for developers.

+// TxExecutor defines a function type that can be used to execute transactions, potentially in parallel.
+// It is designed to support block-stm or other parallel execution strategies.
+// The function takes a context, block size, multi-store, and a function to deliver individual transactions,
+// and returns the results of all transaction executions along with any error encountered.
 type TxExecutor func(
 	ctx context.Context,
 	blockSize int,
 	cms types.MultiStore,
 	deliverTxWithMultiStore func(int, types.MultiStore) *abci.ExecTxResult,
 ) ([]*abci.ExecTxResult, error)
baseapp/baseapp.go (1)

667-678: Updated context creation to include transaction index.

The getContextForTx method now accepts and uses a txIndex parameter, initializing the context with the proper transaction index information via WithMsgIndex.

The method sets WithMsgIndex using the txIndex parameter. While this works functionally, it would be clearer to use both WithTxIndex and WithMsgIndex to properly initialize all relevant fields:

 ctx := modeState.Context().
     WithTxBytes(txBytes).
     WithGasMeter(storetypes.NewInfiniteGasMeter()).
-    WithMsgIndex(txIndex)
+    WithTxIndex(txIndex).
+    WithMsgIndex(-1)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7bcfc2 and ec25c23.

📒 Files selected for processing (7)
  • baseapp/abci.go (3 hunks)
  • baseapp/baseapp.go (7 hunks)
  • baseapp/genesis.go (1 hunks)
  • baseapp/options.go (2 hunks)
  • baseapp/test_helpers.go (1 hunks)
  • baseapp/txexecutor.go (1 hunks)
  • types/context.go (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
baseapp/txexecutor.go (2)
types/context.go (1)
  • Context (40-73)
store/types/store.go (1)
  • MultiStore (115-147)
baseapp/abci.go (3)
types/context.go (1)
  • Context (40-73)
baseapp/baseapp.go (1)
  • BaseApp (63-203)
store/types/store.go (1)
  • MultiStore (115-147)
baseapp/test_helpers.go (2)
baseapp/baseapp.go (1)
  • BaseApp (63-203)
types/context.go (1)
  • Context (40-73)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (15)
baseapp/options.go (2)

127-130: The function implementation looks good.

This function allows setting a custom transaction executor for the BaseApp, which is essential for the block-stm support being added. The implementation follows the established options pattern used throughout this file.


412-415: Good addition of the direct setter method.

This method provides a convenient way to set the transaction executor directly on a BaseApp instance, complementing the functional option defined above. This follows the same pattern as other setter methods in this file.

baseapp/genesis.go (1)

16-16: Update to match new deliverTx signature.

The change appropriately adds the required txIndex parameter (with -1 value) to align with the updated deliverTx method signature. Using -1 as the index is logical here since genesis transactions are not part of a standard block.

baseapp/test_helpers.go (2)

80-80: Correctly updated for new context creation signature.

The change properly adds the required txIndex parameter (with -1 value) to align with the updated getContextForTx method signature. The -1 value appropriately indicates this context is not for a specific transaction in a block.


84-84: Correctly updated for new context creation signature.

Similar to the above change, this properly adds the required txIndex parameter (with -1 value) to the getContextForTx call for CheckTx context creation.

baseapp/abci.go (3)

761-765: Added transaction count to the execution context.

This enhancement allows access to the total number of transactions in the current block from within the context. Good addition that will be useful for transaction execution optimizations in block-stm.


805-809: Refactored transaction execution into a separate method.

The transaction execution logic has been centralized into executeTxs(), which improves code organization and enables optional parallel execution via custom transaction executors.


839-876: Good implementation of transaction execution with parallel execution support.

The new executeTxs method provides two execution paths:

  1. Using a custom executor when txExecutor is set, allowing parallel execution
  2. Falling back to sequential execution with proper error handling

The method also includes proper cancellation checks which is important for long-running operations.

baseapp/baseapp.go (3)

201-202: Added optional transaction executor for parallel execution.

The new txExecutor field provides a hook for alternative transaction execution strategies, which is essential for block-stm parallel transaction processing. The comment clearly explains its purpose.


763-767: Introduced MultiStore variant of deliverTx.

Good refactoring that provides flexibility for transaction processing. The original deliverTx now delegates to deliverTxWithMultiStore with a nil multistore parameter, maintaining backward compatibility while supporting the new parallel execution capability.


843-852: Enhanced runTx to support custom MultiStore.

The transaction executor can now provide a custom MultiStore instance for transaction execution, which is essential for parallel transaction processing with block-stm. This allows each transaction to operate on its own isolated multistore view.

types/context.go (4)

69-72: Added transaction tracking fields to Context.

New fields added to track:

  • txIndex: Current transaction index in the block
  • msgIndex: Current message index within a transaction
  • txCount: Total transaction count in the block
  • blockGasUsed: Total gas used in the block

The comments clearly explain the purpose and initialization of each field, which is excellent.


101-104: Added accessor methods for the new transaction tracking fields.

These methods follow the established pattern for field access in the Context struct, maintaining consistency with the codebase.


151-152: Initialized transaction and message indices to -1.

The default value of -1 indicates that a context is not associated with a specific transaction or message in a finalize block context, which is consistent with the field documentation.


332-350: Added methods to modify transaction tracking fields.

These methods follow the immutable context pattern used throughout the SDK, creating a new Context with the updated field values. The implementation is correct and consistent with other similar methods.

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new TxExecutor option in the baseapp module to support parallel transaction execution. The BaseApp now enhances its transaction processing flow by refactoring inline transaction processing into a dedicated executeTxs method and updating related methods to include a transaction index and multi-store handling. Additionally, the Context struct is extended with new fields and associated accessor and mutator methods to track transaction and block metrics. New helper functions for setting the TxExecutor are also provided, and the changelog has been updated to document these modifications.

Changes

File(s) Change Summary
CHANGELOG.md Added a new changelog entry under "Features" for the baseapp module documenting the addition of the TxExecutor option and extended Context fields.
baseapp/abci.go, baseapp/baseapp.go, baseapp/genesis.go, baseapp/options.go, baseapp/test_helpers.go, baseapp/txexecutor.go Refactored transaction execution flow by introducing the executeTxs method, updating method signatures (e.g., getContextForTx, deliverTx, runTx) to include a txIndex and multi-store parameter, adding a new field txExecutor, modifying genesis and test helper methods to accommodate the new parameter, and adding the TxExecutor type alias and SetTxExecutor functions.
types/context.go Extended the Context struct with four new fields (txIndex, msgIndex, txCount, blockGasUsed) along with corresponding accessor and mutator methods.

Sequence Diagram(s)

sequenceDiagram
    participant BA as BaseApp
    participant IFB as internalFinalizeBlock
    participant ET as executeTxs
    participant RT as runTxWithMultiStore
    participant CTX as Context
    participant TE as TxExecutor

    BA->>IFB: Begin block finalization
    IFB->>CTX: Create Context (blockGasUsed, txCount)
    IFB->>ET: Invoke executeTxs(txs)
    ET->>RT: Process each transaction with txIndex
    RT->>CTX: Update Context with txIndex & msgIndex
    alt Custom Executor Set
        RT->>TE: Execute transaction in parallel
    end
    RT-->>ET: Return transaction result
    ET-->>IFB: Return executed transactions
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
baseapp/genesis.go (1)

16-16: Use a dedicated constant instead of -1 to improve clarity.
This magic number might cause confusion and reduce readability. Consider defining a named constant (e.g., NoTxIndex = -1) or adding a comment for better clarity.

-	res := ba.deliverTx(tx, -1)
+	const NoTxIndex = -1
+	res := ba.deliverTx(tx, NoTxIndex)
baseapp/abci.go (1)

759-765: Mention usage of TxCount in documentation or tests.
You’re now setting TxCount in the context, which may be crucial for tracking or analytics. Consider adding a brief note in the function’s docstring or ensuring it's tested.

baseapp/test_helpers.go (1)

80-80: Clarify the semantics of the -1 index.
Using -1 for the transaction index can cause confusion. Define a named constant or comment to indicate its purpose (e.g., not in a standard block flow). This small change improves readability.

-func (app *BaseApp) GetContextForFinalizeBlock(txBytes []byte) sdk.Context {
-	return app.getContextForTx(execModeFinalize, txBytes, -1)
+const NoTxIndex = -1
+func (app *BaseApp) GetContextForFinalizeBlock(txBytes []byte) sdk.Context {
+	return app.getContextForTx(execModeFinalize, txBytes, NoTxIndex)
 }

-func (app *BaseApp) GetContextForCheckTx(txBytes []byte) sdk.Context {
-	return app.getContextForTx(execModeCheck, txBytes, -1)
+func (app *BaseApp) GetContextForCheckTx(txBytes []byte) sdk.Context {
+	return app.getContextForTx(execModeCheck, txBytes, NoTxIndex)
 }

Also applies to: 84-84

baseapp/baseapp.go (2)

200-203: Enhance documentation for new fields.
Adding a short doc comment clarifying the interaction between disableBlockGasMeter and the new txExecutor would help future maintainers understand their roles.


763-765: Update function comments to reflect the new txIndex parameter.
Ensure the docstring for deliverTx highlights that an explicit transaction index is now expected.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7bcfc2 and 0100b57.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • baseapp/abci.go (3 hunks)
  • baseapp/baseapp.go (7 hunks)
  • baseapp/genesis.go (1 hunks)
  • baseapp/options.go (2 hunks)
  • baseapp/test_helpers.go (1 hunks)
  • baseapp/txexecutor.go (1 hunks)
  • types/context.go (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
baseapp/txexecutor.go (2)
types/context.go (1)
  • Context (40-73)
store/types/store.go (1)
  • MultiStore (115-147)
baseapp/abci.go (3)
types/context.go (1)
  • Context (40-73)
baseapp/baseapp.go (1)
  • BaseApp (63-203)
store/types/store.go (1)
  • MultiStore (115-147)
baseapp/test_helpers.go (2)
baseapp/baseapp.go (1)
  • BaseApp (63-203)
types/context.go (1)
  • Context (40-73)
baseapp/options.go (2)
baseapp/txexecutor.go (1)
  • TxExecutor (11-16)
baseapp/baseapp.go (1)
  • BaseApp (63-203)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (12)
baseapp/txexecutor.go (1)

1-16: Well-structured and clean introduction of TxExecutor

The new TxExecutor type is a well-designed function type that will serve as the foundation for parallel transaction execution. The signature captures all necessary components for transaction execution including context, block size, multi-store, and a delivery function.

baseapp/options.go (2)

127-130: Clean implementation of functional option pattern

Good implementation of the functional option pattern consistent with other option setters in the file.


412-415: Direct setter method complements the functional option

Providing a direct method on BaseApp follows the established pattern in the codebase and allows for flexibility in how the option is set.

types/context.go (4)

68-72: Well-documented new context fields for block-stm

The new fields are clearly documented with their purpose and default values, which is important for maintainability.


101-104: Clean accessor methods for new fields

The accessor methods follow the established pattern in the codebase.


151-152: Proper initialization of indexes

Setting default values of -1 for txIndex and msgIndex in the constructor is appropriate, indicating that they are not within a finalized block context by default.


332-350: Clean setter methods for new fields

The setter methods follow the established pattern for immutable context in the codebase, returning a new context with the updated field.

CHANGELOG.md (1)

63-63: Clear and concise changelog entry

The changelog entry accurately summarizes the changes made in this PR, mentioning both the new TxExecutor option and the context fields added to support parallel execution.

baseapp/abci.go (2)

805-806: Good encapsulation of transaction execution flow.
Encapsulating transactions into executeTxs makes the code more modular and easier to maintain. The current error-handling approach looks appropriate.


839-876: Add tests for both parallel and fallback paths.
This new executeTxs method introduces optional parallel execution via txExecutor. Consider adding or expanding unit tests covering both when txExecutor is set and when it is nil, to ensure correctness and stability.

Would you like assistance in generating a sample test suite script that checks both code paths?

baseapp/baseapp.go (2)

767-802: Validate multi-store concurrency and partial failures.
This new deliverTxWithMultiStore can be used in parallel contexts. Make sure to guard against partial writes or race conditions. You may want to confirm thread safety or coordinate with txExecutor usage.

Do you want a script to check for references to multi-store concurrency in your codebase?


667-667:

✅ Verification successful

Confirm feasibility of using an infinite gas meter here.
Replacing the previous meter with an InfiniteGasMeter could mask potential gas constraint issues. Verify that you handle gas consumption correctly elsewhere or justify why infinite gas is acceptable in this path.

Also applies to: 677-678


🏁 Script executed:

#!/bin/bash
# Look for references to getContextForTx usage to see if an infinite meter is always used or if there's alternate logic:
rg -A 5 "getContextForTx"

Length of output: 2933


Infinite Gas Meter Usage Confirmed

After verifying the usage of getContextForTx in multiple areas (including documentation and test helpers), we can see that while an infinite gas meter is initialized in this context, the actual gas consumption is enforced later in the transaction lifecycle. In particular, the documentation (e.g., in advanced/00-baseapp.md) clearly indicates that responsibility for gas management is deferred—via functions invoked upon returning from RunTx—which guarantees that gas consumption is properly accounted for regardless of an infinite meter at context creation.

  • Key Points:
    • The infinite gas meter is used temporarily during the creation of the transaction context.
    • Deferred functions and subsequent transaction processing (e.g., through the anteHandler and finalization in RunTx) ensure gas consumption is properly checked and errors are thrown if necessary.
    • Similar usage patterns in tests and documentation suggest that this design choice is intentional and safe, even for code at lines 677-678.

Based on these findings, using an InfiniteGasMeter in this context is acceptable as long as the later gas checks remain robust.

@thomas-nguy thomas-nguy force-pushed the thomas/block-stm branch 3 times, most recently from a6e1bbe to d12f491 Compare April 10, 2025 12:30
@thomas-nguy thomas-nguy force-pushed the thomas/block-stm branch 2 times, most recently from 43bed18 to fd7d907 Compare April 10, 2025 12:53
@thomas-nguy thomas-nguy force-pushed the thomas/block-stm branch 6 times, most recently from bd2dfa3 to ed84926 Compare April 12, 2025 06:46
@github-actions github-actions bot removed the C:x/auth label Apr 12, 2025
@thomas-nguy thomas-nguy force-pushed the thomas/block-stm branch 2 times, most recently from 1f840e8 to 8dd8556 Compare April 12, 2025 06:52
// and execute successfully. An error is returned otherwise.
// both txbytes and the decoded tx are passed to runTx to avoid the state machine encoding the tx and decoding the transaction twice
// passing the decoded tx to runTX is optional, it will be decoded if the tx is nil
func (app *BaseApp) RunTx(mode execMode, txBytes []byte, tx sdk.Tx, txMultiStore storetypes.MultiStore, incarnationCache map[string]any) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) {
Copy link
Author

@thomas-nguy thomas-nguy Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change visibility to public so that it can be accessible for "custom" executor implementation

@thomas-nguy thomas-nguy marked this pull request as draft April 14, 2025 02:13
@@ -769,7 +971,7 @@ func (app *BaseApp) beginBlock(_ *abci.RequestFinalizeBlock) (sdk.BeginBlock, er
return resp, nil
}

func (app *BaseApp) deliverTx(tx []byte) *abci.ExecTxResult {
func (app *BaseApp) deliverTx(tx []byte, txMultiStore storetypes.MultiStore, incarnationCache map[string]any) *abci.ExecTxResult {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few more parameters needed for performance optimisations

return ms.MultiStore.GetKVStore(key)
}

func (ms msWrapper) GetObjKVStore(key storetypes.StoreKey) storetypes.ObjKVStore {
Copy link
Author

@thomas-nguy thomas-nguy Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants