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

block-sdk integration #324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 21 additions & 10 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
consumerante "github.com/cosmos/interchain-security/v3/app/consumer/ante"
ibcconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
"github.com/skip-mev/pob/mempool"
ante2 "github.com/skip-mev/pob/x/builder/ante"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"
auctionante "github.com/skip-mev/block-sdk/x/auction/ante"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand All @@ -29,9 +28,13 @@ type HandlerOptions struct {
ConsumerKeeper ibcconsumerkeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
TXCounterStoreKey storetypes.StoreKey
buildKeeper builderkeeper.Keeper
txEncoder sdk.TxEncoder
mempool *mempool.AuctionMempool

// block-sdk deps
// Auction deps
AuctionKeeper auctionkeeper.Keeper
TxEncoder sdk.TxEncoder
MEVLane auctionante.MEVLane
Mempool auctionante.Mempool

// globalFee
GlobalFeeSubspace paramtypes.Subspace
Expand All @@ -57,6 +60,13 @@ func NewAnteHandler(options HandlerOptions, logger log.Logger) (sdk.AnteHandler,
return nil, errors.Wrap(gaiaerrors.ErrNotFound, "globalfee param store is required for AnteHandler")
}

if options.Mempool == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "mempool is required for AnteHandler")
}
if options.MEVLane == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "mev lane is required for AnteHandler")
}

sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
Expand Down Expand Up @@ -86,10 +96,11 @@ func NewAnteHandler(options HandlerOptions, logger log.Logger) (sdk.AnteHandler,
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ante2.NewBuilderDecorator(
options.buildKeeper,
options.txEncoder,
options.mempool,
auctionante.NewAuctionDecorator(
options.AuctionKeeper,
options.TxEncoder,
options.MEVLane,
options.Mempool,
),
}

Expand Down
113 changes: 77 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
proposalhandler "github.com/skip-mev/pob/abci"
"github.com/skip-mev/pob/mempool"
"github.com/skip-mev/pob/x/builder"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"
rewardsaddressprovider "github.com/skip-mev/pob/x/builder/rewards_address_provider"
buildertypes "github.com/skip-mev/pob/x/builder/types"

"github.com/neutron-org/neutron/docs"

Expand Down Expand Up @@ -155,6 +149,19 @@
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
routerkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/keeper"
routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"

// Block-sdk imports
blocksdkabci "github.com/skip-mev/block-sdk/abci"
signer_extraction_adapter "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter"
blocksdk "github.com/skip-mev/block-sdk/block"
blocksdkbase "github.com/skip-mev/block-sdk/block/base"
base_lane "github.com/skip-mev/block-sdk/lanes/base"
mev_lane "github.com/skip-mev/block-sdk/lanes/mev"
"github.com/skip-mev/block-sdk/x/auction"
auctionante "github.com/skip-mev/block-sdk/x/auction/ante"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
rewardsaddressprovider "github.com/skip-mev/block-sdk/x/auction/rewards"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)

const (
Expand Down Expand Up @@ -209,14 +216,14 @@
),
ibchooks.AppModuleBasic{},
router.AppModuleBasic{},
builder.AppModuleBasic{},
auction.AppModuleBasic{},
globalfee.AppModule{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
buildertypes.ModuleName: nil,
auctiontypes.ModuleName: nil,
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
wasmtypes.ModuleName: {authtypes.Burner},
Expand Down Expand Up @@ -271,8 +278,8 @@
AdminmoduleKeeper adminmodulekeeper.Keeper
AuthzKeeper authzkeeper.Keeper
BankKeeper bankkeeper.BaseKeeper
// BuilderKeeper is the keeper that handles processing auction transactions
BuilderKeeper builderkeeper.Keeper
// AuctionKeeper is the keeper that handles processing auction transactions
AuctionKeeper auctionkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
Expand Down Expand Up @@ -318,7 +325,11 @@
sm *module.SimulationManager

// Custom checkTx handler
checkTxHandler proposalhandler.CheckTx
checkTxHandler mev_lane.CheckTx

// Lanes
Mempool auctionante.Mempool

Check failure on line 331 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
MEVLane auctionante.MEVLane
}

func (app *App) GetTestBankKeeper() integration.TestBankKeeper {
Expand Down Expand Up @@ -356,16 +367,10 @@
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

cfg := mempool.NewDefaultAuctionFactory(encodingConfig.TxConfig.TxDecoder())
// 0 - unlimited amount of txs
maxTx := 0
memPool := mempool.NewAuctionMempool(encodingConfig.TxConfig.TxDecoder(), encodingConfig.TxConfig.TxEncoder(), maxTx, cfg)

bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetMempool(memPool)

keys := sdk.NewKVStoreKeys(
authzkeeper.StoreKey, authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey,
Expand All @@ -374,7 +379,7 @@
icahosttypes.StoreKey, capabilitytypes.StoreKey,
interchainqueriesmoduletypes.StoreKey, contractmanagermoduletypes.StoreKey, interchaintxstypes.StoreKey, wasmtypes.StoreKey, feetypes.StoreKey,
feeburnertypes.StoreKey, adminmoduletypes.StoreKey, ccvconsumertypes.StoreKey, tokenfactorytypes.StoreKey, routertypes.StoreKey,
crontypes.StoreKey, ibchookstypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey, buildertypes.StoreKey,
crontypes.StoreKey, ibchookstypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey, auctiontypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, feetypes.MemStoreKey)
Expand Down Expand Up @@ -587,9 +592,9 @@
app.TokenFactoryKeeper.Hooks(),
))

app.BuilderKeeper = builderkeeper.NewKeeperWithRewardsAddressProvider(
app.AuctionKeeper = auctionkeeper.NewKeeperWithRewardsAddressProvider(
appCodec,
keys[buildertypes.StoreKey],
keys[auctiontypes.StoreKey],
app.AccountKeeper,
&app.BankKeeper,
// 25% of rewards should be sent to the redistribute address
Expand Down Expand Up @@ -765,7 +770,7 @@
tokenfactory.NewAppModule(appCodec, *app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
cronModule,
globalfee.NewAppModule(app.GetSubspace(globalfee.ModuleName)),
builder.NewAppModule(appCodec, app.BuilderKeeper),
auction.NewAppModule(appCodec, app.AuctionKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
)

Expand All @@ -774,7 +779,7 @@
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
buildertypes.ModuleName,
auctiontypes.ModuleName,
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
slashingtypes.ModuleName,
Expand Down Expand Up @@ -805,7 +810,7 @@
)

app.mm.SetOrderEndBlockers(
buildertypes.ModuleName,
auctiontypes.ModuleName,
crisistypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
Expand Down Expand Up @@ -841,7 +846,7 @@
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
app.mm.SetOrderInitGenesis(
buildertypes.ModuleName,
auctiontypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -909,6 +914,38 @@
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

// initialize block-sdk Mempool
maxTxs := 0 // no limit
cfg := blocksdkbase.LaneConfig{
Logger: app.Logger(),
TxDecoder: app.GetTxConfig().TxDecoder(),
TxEncoder: app.GetTxConfig().TxEncoder(),
SignerExtractor: signer_extraction_adapter.NewDefaultAdapter(),
MaxBlockSpace: sdk.ZeroDec(),
MaxTxs: maxTxs,
}

baseLane := base_lane.NewDefaultLane(cfg)

mevLane := mev_lane.NewMEVLane(
cfg,
mev_lane.NewDefaultAuctionFactory(app.GetTxConfig().TxDecoder(), signer_extraction_adapter.NewDefaultAdapter()),
)
app.MEVLane = mevLane
// initialize mempool
mempool := blocksdk.NewLanedMempool(
app.Logger(),
true,
[]blocksdk.Lane{
mevLane, // mev-lane is first to prioritize bids being placed at the TOB
baseLane, // finally, all the rest of txs...
}...,
)

// set the mempool first
app.SetMempool(mempool)
app.Mempool = mempool

anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand All @@ -922,9 +959,11 @@
WasmConfig: &wasmConfig,
TXCounterStoreKey: keys[wasmtypes.StoreKey],
ConsumerKeeper: app.ConsumerKeeper,
buildKeeper: app.BuilderKeeper,
mempool: memPool,
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
AuctionKeeper: app.AuctionKeeper,
TxEncoder: app.GetTxConfig().TxEncoder(),
Mempool: app.Mempool,
MEVLane: app.MEVLane,
},
app.Logger(),
)
Expand All @@ -933,22 +972,24 @@
}

app.SetAnteHandler(anteHandler)
mevLane.SetAnteHandler(anteHandler)
baseLane.SetAnteHandler(anteHandler)


app.SetEndBlocker(app.EndBlocker)

Check failure on line 980 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
handler := proposalhandler.NewProposalHandler(
memPool,
bApp.Logger(),
anteHandler,
encodingConfig.TxConfig.TxEncoder(),
encodingConfig.TxConfig.TxDecoder(),
handler := blocksdkabci.NewProposalHandler(
app.Logger(),
app.GetTxConfig().TxDecoder(),
mempool,
)
app.SetPrepareProposal(handler.PrepareProposalHandler())
app.SetProcessProposal(handler.ProcessProposalHandler())

checkTxHandler := proposalhandler.NewCheckTxHandler(
checkTxHandler := mev_lane.NewCheckTxHandler(
app.BaseApp,
encodingConfig.TxConfig.TxDecoder(),
memPool,
mevLane,
anteHandler,
chainID,
)
Expand Down Expand Up @@ -1020,7 +1061,7 @@
SlashingKeeper: app.SlashingKeeper,
ParamsKeeper: app.ParamsKeeper,
CapabilityKeeper: app.CapabilityKeeper,
BuilderKeeper: app.BuilderKeeper,
AuctionKeeper: app.AuctionKeeper,
ContractManager: app.ContractManagerKeeper,
AdminModule: app.AdminmoduleKeeper,
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
Expand All @@ -1042,7 +1083,7 @@
}

// SetCheckTx sets the checkTxHandler for the app.
func (app *App) SetCheckTx(handler proposalhandler.CheckTx) {
func (app *App) SetCheckTx(handler mev_lane.CheckTx) {
app.checkTxHandler = handler
}

Expand Down Expand Up @@ -1179,8 +1220,8 @@
paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable())
paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable())
paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable())

Check failure on line 1223 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: authtypes.ParamKeyTable is deprecated: ParamKeyTable for auth module (staticcheck)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())

Check failure on line 1224 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: banktypes.ParamKeyTable is deprecated: ParamKeyTable for bank module. (staticcheck)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/nextupgrade/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/neutron-org/neutron/app/upgrades"
buildertypes "github.com/skip-mev/pob/x/builder/types"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)

const (
Expand All @@ -20,7 +20,7 @@ var Upgrade = upgrades.Upgrade{
Added: []string{
consensusparamtypes.ModuleName,
crisistypes.ModuleName,
buildertypes.ModuleName,
auctiontypes.ModuleName,
},
},
}
12 changes: 6 additions & 6 deletions app/upgrades/nextupgrade/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nextupgrade

import (
"fmt"

Check failure on line 4 in app/upgrades/nextupgrade/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -17,8 +17,8 @@
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"
buildertypes "github.com/skip-mev/pob/x/builder/types"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"

"github.com/neutron-org/neutron/app/upgrades"
contractmanagerkeeper "github.com/neutron-org/neutron/x/contractmanager/keeper"
Expand Down Expand Up @@ -83,7 +83,7 @@
}

ctx.Logger().Info("Setting pob params...")
err = setPobParams(ctx, keepers.FeeBurnerKeeper, keepers.BuilderKeeper)
err = setAuctionParams(ctx, keepers.FeeBurnerKeeper, keepers.AuctionKeeper)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -119,22 +119,22 @@
}
}

func setPobParams(ctx sdk.Context, feeBurnerKeeper *feeburnerkeeper.Keeper, builderKeeper builderkeeper.Keeper) error {
func setAuctionParams(ctx sdk.Context, feeBurnerKeeper *feeburnerkeeper.Keeper, auctionKeeper auctionkeeper.Keeper) error {
treasury := feeBurnerKeeper.GetParams(ctx).TreasuryAddress
_, data, err := bech32.DecodeAndConvert(treasury)
if err != nil {
return err
}

builderParams := buildertypes.Params{
auctionParams := auctiontypes.Params{
MaxBundleSize: 2,
EscrowAccountAddress: data,
ReserveFee: sdk.Coin{Denom: "untrn", Amount: sdk.NewInt(1_000_000)},
MinBidIncrement: sdk.Coin{Denom: "untrn", Amount: sdk.NewInt(1_000_000)},
FrontRunningProtection: true,
ProposerFee: math.LegacyNewDecWithPrec(25, 2),
}
return builderKeeper.SetParams(ctx, builderParams)
return auctionKeeper.SetParams(ctx, auctionParams)
}

func setContractManagerParams(ctx sdk.Context, keeper contractmanagerkeeper.Keeper) error {
Expand Down Expand Up @@ -243,7 +243,7 @@
// As of June 22nd, 2023 this is
// 0.9untrn,0.026ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9,0.25ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349
requiredGlobalFees := sdk.DecCoins{
sdk.NewDecCoinFromDec("untrn", sdk.MustNewDecFromStr("0.9")),

Check failure on line 246 in app/upgrades/nextupgrade/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

migrateGlobalFees - result 0 (error) is always nil (unparam)
sdk.NewDecCoinFromDec("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", sdk.MustNewDecFromStr("0.026")),
sdk.NewDecCoinFromDec("ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", sdk.MustNewDecFromStr("0.25")),
}
Expand Down Expand Up @@ -297,5 +297,5 @@

ctx.Logger().Info("Finished migrating admin module")

return nil

Check failure on line 300 in app/upgrades/nextupgrade/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

migrateAdminModule - result 0 (error) is always nil (unparam)
}
4 changes: 2 additions & 2 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"

contractmanagerkeeper "github.com/neutron-org/neutron/x/contractmanager/keeper"
cronkeeper "github.com/neutron-org/neutron/x/cron/keeper"
Expand Down Expand Up @@ -44,7 +44,7 @@ type UpgradeKeepers struct {
SlashingKeeper slashingkeeper.Keeper
ParamsKeeper paramskeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
BuilderKeeper builderkeeper.Keeper
AuctionKeeper auctionkeeper.Keeper
ContractManager contractmanagerkeeper.Keeper
AdminModule adminmodulekeeper.Keeper
// subspaces
Expand Down
Loading
Loading