Skip to content
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

refactor: PoC for unordered txs per new spec #24010

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
007e9f1
WIP unordered refactor
technicallyty Mar 12, 2025
d0c7237
implement multiple signers handling
technicallyty Mar 13, 2025
e0cef44
use collections..
technicallyty Mar 14, 2025
fd79847
make UTXs more behind the scenes...
technicallyty Mar 14, 2025
304bfd4
set ttl max
technicallyty Mar 14, 2025
d8aa37e
ok
technicallyty Mar 14, 2025
9375652
tests
technicallyty Mar 17, 2025
4bd3769
make simapp deal with the optional unordered thing
technicallyty Mar 17, 2025
f5ca415
fix
technicallyty Mar 17, 2025
e163124
changes from adr
technicallyty Mar 18, 2025
bfc6c46
use GetSigners for addresses
technicallyty Mar 19, 2025
164ce70
move everyting to keeper, rename stuff
technicallyty Mar 19, 2025
6fd8b98
Merge branch 'release/v0.53.x' into technicallyty/23976/unordered-tx-…
technicallyty Mar 19, 2025
a2949e7
revert no longer needed testutil change
technicallyty Mar 19, 2025
87ae5c6
use int64 not uint64
technicallyty Mar 19, 2025
6512d5a
unordered sequences -> unordered nonces rename
technicallyty Mar 19, 2025
6f2a710
optional timeout set
technicallyty Mar 19, 2025
5adc7c2
add some docs
technicallyty Mar 19, 2025
4202b27
test
technicallyty Mar 19, 2025
0bebc3b
fix test util
technicallyty Mar 19, 2025
afc389f
linter
technicallyty Mar 19, 2025
0ca4fca
comments, renames, gas
technicallyty Mar 20, 2025
7816fe5
lingering unordered sequence verbiage
technicallyty Mar 20, 2025
c8805af
options
technicallyty Mar 20, 2025
1f52d1f
linter
technicallyty Mar 20, 2025
5acf257
changes
technicallyty Mar 20, 2025
070e3c9
Merge branch 'release/v0.53.x' into technicallyty/23976/unordered-tx-…
technicallyty Mar 20, 2025
5387be1
Merge branch 'release/v0.53.x' into technicallyty/23976/unordered-tx-…
technicallyty Mar 20, 2025
2deed33
Merge branch 'technicallyty/23976/unordered-tx-refactor' of ssh://git…
technicallyty Mar 20, 2025
450e2dc
fix lint
technicallyty Mar 20, 2025
a93d895
lint
technicallyty Mar 21, 2025
ec0157e
liter
technicallyty Mar 21, 2025
9a5a588
lint order
technicallyty Mar 21, 2025
2db0155
lint
technicallyty Mar 21, 2025
a4a40c2
TryAdd
technicallyty Mar 21, 2025
f38e629
structure
technicallyty Mar 21, 2025
f08858d
Merge branch 'release/v0.53.x' into technicallyty/23976/unordered-tx-…
technicallyty Mar 24, 2025
52f17be
lint fix
technicallyty Mar 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
)

Expand All @@ -41,8 +40,7 @@ import (
type App struct {
*baseapp.BaseApp

ModuleManager *module.Manager
UnorderedTxManager *unorderedtx.Manager
ModuleManager *module.Manager

configurator module.Configurator
config *runtimev1alpha1.Module
Expand Down Expand Up @@ -160,9 +158,6 @@ func (a *App) Load(loadLatest bool) error {

// PreBlocker application updates every pre block
func (a *App) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
if a.UnorderedTxManager != nil {
a.UnorderedTxManager.OnNewBlock(ctx.BlockTime())
}
return a.ModuleManager.PreBlock(ctx)
}

Expand Down
5 changes: 2 additions & 3 deletions simapp/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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.
Expand Down Expand Up @@ -48,8 +47,8 @@ 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))
if options.UnorderedNonceManager != nil {
anteDecorators = append(anteDecorators, ante.NewUnorderedTxDecorator(options.UnorderedNonceManager, options.UnorderedTxOptions...))
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
43 changes: 7 additions & 36 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"maps"
"os"
"path/filepath"

abci "github.com/cometbft/cometbft/abci/types"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -62,7 +61,6 @@ 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"
Expand Down Expand Up @@ -169,8 +167,6 @@ type SimApp struct {
ModuleManager *module.Manager
BasicModuleManager module.BasicManager

UnorderedTxManager *unorderedtx.Manager

// simulation manager
sm *module.SimulationManager

Expand Down Expand Up @@ -537,6 +533,7 @@ func NewSimApp(
// NOTE: upgrade module is required to be prioritized
app.ModuleManager.SetOrderPreBlockers(
upgradetypes.ModuleName,
authtypes.ModuleName,
Copy link
Collaborator

Choose a reason for hiding this comment

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

note to make sure we have this added in the upgrade guide for adding utx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

opened #24078

)
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
Expand Down Expand Up @@ -619,25 +616,6 @@ 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
Expand Down Expand Up @@ -691,12 +669,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,
UnorderedTxManager: app.UnorderedTxManager,
UnorderedNonceManager: app.AccountKeeper,
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
&app.CircuitKeeper,
},
Expand All @@ -720,18 +698,11 @@ 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)
}

Expand Down
1 change: 1 addition & 0 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ var (
// NOTE: upgrade module is required to be prioritized
PreBlockers: []string{
upgradetypes.ModuleName,
authtypes.ModuleName,
},
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
Expand Down
38 changes: 6 additions & 32 deletions simapp/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
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"
Expand All @@ -22,7 +19,6 @@ 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"
Expand All @@ -34,7 +30,6 @@ 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"
Expand Down Expand Up @@ -68,8 +63,6 @@ type SimApp struct {
txConfig client.TxConfig
interfaceRegistry codectypes.InterfaceRegistry

UnorderedTxManager *unorderedtx.Manager

// essential keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.BaseKeeper
Expand Down Expand Up @@ -263,25 +256,6 @@ 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)

Expand All @@ -298,12 +272,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,
UnorderedTxManager: app.UnorderedTxManager,
UnorderedNonceManager: app.AccountKeeper,
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
&app.CircuitKeeper,
},
Expand Down
10 changes: 6 additions & 4 deletions x/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

Expand All @@ -21,7 +20,10 @@ type HandlerOptions struct {
SignModeHandler *txsigning.HandlerMap
SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error
TxFeeChecker TxFeeChecker
UnorderedTxManager *unorderedtx.Manager
// UnorderedNonceManager is an opt-in feature for x/auth.
// When set, this application will be able to receive and process unordered transactions.
UnorderedNonceManager UnorderedNonceManager
UnorderedTxOptions []UnorderedTxDecoratorOptions
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand Down Expand Up @@ -55,8 +57,8 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
NewIncrementSequenceDecorator(options.AccountKeeper),
}

if options.UnorderedTxManager != nil {
anteDecorators = append(anteDecorators, NewUnorderedTxDecorator(unorderedtx.DefaultMaxTimeoutDuration, options.UnorderedTxManager, DefaultSha256GasCost))
if options.UnorderedNonceManager != nil {
anteDecorators = append(anteDecorators, NewUnorderedTxDecorator(options.UnorderedNonceManager, options.UnorderedTxOptions...))
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
7 changes: 7 additions & 0 deletions x/auth/ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ante

import (
"context"
"time"

"cosmossdk.io/core/address"

Expand All @@ -19,6 +20,12 @@ type AccountKeeper interface {
AddressCodec() address.Codec
}

// UnorderedNonceManager defines the contract needed for UnorderedNonce management.
type UnorderedNonceManager interface {
RemoveExpiredUnorderedNonces(ctx sdk.Context) error
TryAddUnorderedNonce(ctx sdk.Context, sender []byte, timestamp time.Time) error
}

// FeegrantKeeper defines the expected feegrant keeper.
type FeegrantKeeper interface {
UseGrantedFees(ctx context.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error
Expand Down
Loading
Loading