Skip to content

Commit

Permalink
Merge pull request #324 from nivasan1/nv/block-sdk-integration
Browse files Browse the repository at this point in the history
block-sdk integration
  • Loading branch information
pr0n00gler authored Oct 17, 2023
2 parents 785bd59 + f9115bd commit 8e460a7
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 140 deletions.
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 @@ import (
"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 @@ import (
"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 @@ var (
),
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 @@ type App struct {
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 @@ type App struct {
sm *module.SimulationManager

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

// Lanes
Mempool auctionante.Mempool
MEVLane auctionante.MEVLane
}

func (app *App) GetTestBankKeeper() integration.TestBankKeeper {
Expand Down Expand Up @@ -358,16 +369,10 @@ func New(
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 @@ -376,7 +381,7 @@ func New(
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 @@ -589,9 +594,9 @@ func New(
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 @@ -767,7 +772,7 @@ func New(
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 @@ -776,7 +781,7 @@ func New(
// 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 @@ -807,7 +812,7 @@ func New(
)

app.mm.SetOrderEndBlockers(
buildertypes.ModuleName,
auctiontypes.ModuleName,
crisistypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
Expand Down Expand Up @@ -843,7 +848,7 @@ func New(
// 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 @@ -911,6 +916,38 @@ func New(
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 @@ -924,9 +961,11 @@ func New(
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 @@ -935,22 +974,24 @@ func New(
}

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


app.SetEndBlocker(app.EndBlocker)

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 @@ -1022,7 +1063,7 @@ func (app *App) setupUpgradeHandlers() {
SlashingKeeper: app.SlashingKeeper,
ParamsKeeper: app.ParamsKeeper,
CapabilityKeeper: app.CapabilityKeeper,
BuilderKeeper: app.BuilderKeeper,
AuctionKeeper: app.AuctionKeeper,
ContractManager: app.ContractManagerKeeper,
AdminModule: app.AdminmoduleKeeper,
ConsensusKeeper: &app.ConsensusParamsKeeper,
Expand All @@ -1045,7 +1086,7 @@ func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
}

// 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
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
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/cosmos/gaia/v11/x/globalfee/types"
v6 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/migrations/v6"
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 @@ -84,7 +84,7 @@ func CreateUpgradeHandler(
}

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 @@ -124,22 +124,22 @@ func CreateUpgradeHandler(
}
}

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
4 changes: 2 additions & 2 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 @@ -45,7 +45,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
ConsensusKeeper *consensuskeeper.Keeper
Expand Down
Loading

0 comments on commit 8e460a7

Please sign in to comment.