feat: backport unordered transactions (#23708)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: Facundo <facundomedica@gmail.com> Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
This commit is contained in:
co-authored by
Aleksandr Bezobchuk
yihuang
Facundo
Facundo Medica
Alex | Interchain Labs
parent
ff779eca8d
commit
7f7c41e4aa
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx"
|
||||
)
|
||||
|
||||
// HandlerOptions are the options required for constructing a default SDK AnteHandler.
|
||||
@@ -47,5 +48,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
|
||||
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
|
||||
}
|
||||
|
||||
if options.UnorderedTxManager != nil {
|
||||
anteDecorators = append(anteDecorators, ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxTimeoutDuration, options.UnorderedTxManager, ante.DefaultSha256GasCost))
|
||||
}
|
||||
|
||||
return sdk.ChainAnteDecorators(anteDecorators...), nil
|
||||
}
|
||||
|
||||
+42
-10
@@ -7,6 +7,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||
@@ -31,10 +37,6 @@ import (
|
||||
"cosmossdk.io/x/upgrade"
|
||||
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
|
||||
upgradetypes "cosmossdk.io/x/upgrade/types"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@@ -59,6 +61,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx"
|
||||
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
|
||||
@@ -163,6 +166,8 @@ type SimApp struct {
|
||||
ModuleManager *module.Manager
|
||||
BasicModuleManager module.BasicManager
|
||||
|
||||
UnorderedTxManager *unorderedtx.Manager
|
||||
|
||||
// simulation manager
|
||||
sm *module.SimulationManager
|
||||
|
||||
@@ -373,7 +378,7 @@ func NewSimApp(
|
||||
|
||||
app.GovKeeper = *govKeeper.SetHooks(
|
||||
govtypes.NewMultiGovHooks(
|
||||
// register the governance hooks
|
||||
// register the governance hooks
|
||||
),
|
||||
)
|
||||
|
||||
@@ -525,6 +530,25 @@ func NewSimApp(
|
||||
}
|
||||
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules)
|
||||
|
||||
// create, start, and load the unordered tx manager
|
||||
utxDataDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data")
|
||||
app.UnorderedTxManager = unorderedtx.NewManager(utxDataDir)
|
||||
app.UnorderedTxManager.Start()
|
||||
|
||||
if err := app.UnorderedTxManager.OnInit(); err != nil {
|
||||
panic(fmt.Errorf("failed to initialize unordered tx manager: %w", err))
|
||||
}
|
||||
|
||||
// register custom snapshot extensions (if any)
|
||||
if manager := app.SnapshotManager(); manager != nil {
|
||||
err := manager.RegisterExtensions(
|
||||
unorderedtx.NewSnapshotter(app.UnorderedTxManager),
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
app.sm.RegisterStoreDecoders()
|
||||
|
||||
// initialize stores
|
||||
@@ -578,11 +602,12 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) {
|
||||
anteHandler, err := NewAnteHandler(
|
||||
HandlerOptions{
|
||||
ante.HandlerOptions{
|
||||
AccountKeeper: app.AccountKeeper,
|
||||
BankKeeper: app.BankKeeper,
|
||||
SignModeHandler: txConfig.SignModeHandler(),
|
||||
FeegrantKeeper: app.FeeGrantKeeper,
|
||||
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
||||
AccountKeeper: app.AccountKeeper,
|
||||
BankKeeper: app.BankKeeper,
|
||||
SignModeHandler: txConfig.SignModeHandler(),
|
||||
FeegrantKeeper: app.FeeGrantKeeper,
|
||||
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
||||
UnorderedTxManager: app.UnorderedTxManager,
|
||||
},
|
||||
&app.CircuitKeeper,
|
||||
},
|
||||
@@ -606,11 +631,18 @@ func (app *SimApp) setPostHandler() {
|
||||
app.SetPostHandler(postHandler)
|
||||
}
|
||||
|
||||
// Close implements the Application interface and closes all necessary application
|
||||
// resources.
|
||||
func (app *SimApp) Close() error {
|
||||
return app.UnorderedTxManager.Close()
|
||||
}
|
||||
|
||||
// Name returns the name of the App
|
||||
func (app *SimApp) Name() string { return app.BaseApp.Name() }
|
||||
|
||||
// PreBlocker application updates every pre block
|
||||
func (app *SimApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
|
||||
app.UnorderedTxManager.OnNewBlock(ctx.BlockTime())
|
||||
return app.ModuleManager.PreBlock(ctx)
|
||||
}
|
||||
|
||||
|
||||
+35
-8
@@ -3,9 +3,12 @@
|
||||
package simapp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
clienthelpers "cosmossdk.io/client/v2/helpers"
|
||||
"cosmossdk.io/depinject"
|
||||
@@ -19,6 +22,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
@@ -30,6 +34,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
@@ -63,6 +68,8 @@ type SimApp struct {
|
||||
txConfig client.TxConfig
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
|
||||
UnorderedTxManager *unorderedtx.Manager
|
||||
|
||||
// keepers
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
BankKeeper bankkeeper.Keeper
|
||||
@@ -243,9 +250,6 @@ func NewSimApp(
|
||||
|
||||
app.sm.RegisterStoreDecoders()
|
||||
|
||||
// set custom ante handler
|
||||
app.setAnteHandler(app.txConfig)
|
||||
|
||||
// A custom InitChainer can be set if extra pre-init-genesis logic is required.
|
||||
// By default, when using app wiring enabled module, this is not required.
|
||||
// For instance, the upgrade module will set automatically the module version map in its init genesis thanks to app wiring.
|
||||
@@ -257,6 +261,28 @@ func NewSimApp(
|
||||
// return app.App.InitChainer(ctx, req)
|
||||
// })
|
||||
|
||||
// create, start, and load the unordered tx manager
|
||||
utxDataDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data")
|
||||
app.UnorderedTxManager = unorderedtx.NewManager(utxDataDir)
|
||||
app.UnorderedTxManager.Start()
|
||||
|
||||
if err := app.UnorderedTxManager.OnInit(); err != nil {
|
||||
panic(fmt.Errorf("failed to initialize unordered tx manager: %w", err))
|
||||
}
|
||||
|
||||
// register custom snapshot extensions (if any)
|
||||
if manager := app.SnapshotManager(); manager != nil {
|
||||
err := manager.RegisterExtensions(
|
||||
unorderedtx.NewSnapshotter(app.UnorderedTxManager),
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to register snapshot extension: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
// set custom ante handler
|
||||
app.setAnteHandler(app.txConfig)
|
||||
|
||||
if err := app.Load(loadLatest); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -270,11 +296,12 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) {
|
||||
anteHandler, err := NewAnteHandler(
|
||||
HandlerOptions{
|
||||
ante.HandlerOptions{
|
||||
AccountKeeper: app.AccountKeeper,
|
||||
BankKeeper: app.BankKeeper,
|
||||
SignModeHandler: txConfig.SignModeHandler(),
|
||||
FeegrantKeeper: app.FeeGrantKeeper,
|
||||
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
||||
AccountKeeper: app.AccountKeeper,
|
||||
BankKeeper: app.BankKeeper,
|
||||
SignModeHandler: txConfig.SignModeHandler(),
|
||||
FeegrantKeeper: app.FeeGrantKeeper,
|
||||
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
||||
UnorderedTxManager: app.UnorderedTxManager,
|
||||
},
|
||||
&app.CircuitKeeper,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user