Skip to content

Commit

Permalink
pob to block-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 22, 2023
1 parent 187c5d8 commit 00dc8bf
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 70 deletions.
29 changes: 23 additions & 6 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
moveante "github.com/initia-labs/initia/x/move/ante"

builderante "github.com/skip-mev/pob/x/builder/ante"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"
"github.com/skip-mev/block-sdk/block"
auctionante "github.com/skip-mev/block-sdk/x/auction/ante"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
)

// HandlerOptions extends the SDK's AnteHandler options by requiring the IBC
Expand All @@ -24,9 +25,10 @@ type HandlerOptions struct {
Codec codec.BinaryCodec
IBCkeeper *ibckeeper.Keeper
RollupKeeper opchildtypes.AnteKeeper
BuilderKeeper builderkeeper.Keeper
AuctionKeeper auctionkeeper.Keeper
TxEncoder sdk.TxEncoder
Mempool builderante.Mempool
MevLane auctionante.MEVLane
FreeLane block.Lane
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand Down Expand Up @@ -55,6 +57,21 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
txFeeChecker = opchildante.NewMempoolFeeChecker(options.RollupKeeper).CheckTxFeeWithMinGasPrices
}

freeLaneFeeChecker := func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
// skip fee checker if the tx is free lane tx.
if !options.FreeLane.Match(ctx, tx) {
return txFeeChecker(ctx, tx)
}

// return fee without fee check
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return nil, 0, errors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

return feeTx.GetFee(), 1 /* FIFO */, nil
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
Expand All @@ -64,15 +81,15 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, txFeeChecker),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, freeLaneFeeChecker),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCkeeper),
builderante.NewBuilderDecorator(options.BuilderKeeper, options.TxEncoder, options.Mempool),
auctionante.NewAuctionDecorator(options.AuctionKeeper, options.TxEncoder, options.MevLane),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
151 changes: 101 additions & 50 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/math"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -109,21 +110,28 @@ import (
movekeeper "github.com/initia-labs/initia/x/move/keeper"
movetypes "github.com/initia-labs/initia/x/move/types"

initiaservice "github.com/initia-labs/initia/service"
moveibcmiddleware "github.com/initia-labs/initia/x/move/ibc-middleware"

opchild "github.com/initia-labs/OPinit/x/opchild"
opchildkeeper "github.com/initia-labs/OPinit/x/opchild/keeper"
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"

builderabci "github.com/skip-mev/pob/abci"
pobabci "github.com/skip-mev/pob/abci"
buildermempool "github.com/skip-mev/pob/mempool"
"github.com/skip-mev/pob/x/builder"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"
buildertypes "github.com/skip-mev/pob/x/builder/types"

"github.com/initia-labs/minimove/app/ante"
"github.com/initia-labs/minimove/app/hook"
mevabci "github.com/skip-mev/block-sdk/abci"
signer_extraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter"
"github.com/skip-mev/block-sdk/block"
blockbase "github.com/skip-mev/block-sdk/block/base"
baselane "github.com/skip-mev/block-sdk/lanes/base"
freelane "github.com/skip-mev/block-sdk/lanes/free"
mevlane "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"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"

appante "github.com/initia-labs/minimove/app/ante"
apphook "github.com/initia-labs/minimove/app/hook"
applanes "github.com/initia-labs/minimove/app/lanes"

// unnamed import of statik for swagger UI support
_ "github.com/initia-labs/minimove/client/docs/statik"
Expand Down Expand Up @@ -156,7 +164,7 @@ var (
ibcfee.AppModuleBasic{},
move.AppModuleBasic{},
opchild.AppModuleBasic{},
builder.AppModuleBasic{},
auction.AppModuleBasic{},
)

// module account permissions
Expand All @@ -166,9 +174,9 @@ var (
ibcfeetypes.ModuleName: nil,
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
movetypes.MoveStakingModuleName: nil,
// x/builder's module account must be instantiated upon genesis to accrue auction rewards not
// x/auction's module account must be instantiated upon genesis to accrue auction rewards not
// distributed to proposers
buildertypes.ModuleName: nil,
auctiontypes.ModuleName: nil,
opchildtypes.ModuleName: {authtypes.Minter, authtypes.Burner},

// this is only for testing
Expand Down Expand Up @@ -226,7 +234,7 @@ type MinitiaApp struct {
IBCFeeKeeper *ibcfeekeeper.Keeper
MoveKeeper *movekeeper.Keeper
RollupKeeper *opchildkeeper.Keeper
BuilderKeeper *builderkeeper.Keeper // x/builder keeper used to process bids for TOB auctions
AuctionKeeper *auctionkeeper.Keeper // x/builder keeper used to process bids for TOB auctions

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -244,7 +252,7 @@ type MinitiaApp struct {
configurator module.Configurator

// Override of BaseApp's CheckTx
checkTxHandler pobabci.CheckTx
checkTxHandler mevlane.CheckTx
}

// NewMinitiaApp returns a reference to an initialized Initia.
Expand Down Expand Up @@ -276,7 +284,7 @@ func NewMinitiaApp(
ibctransfertypes.StoreKey, ibcnfttransfertypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, icaauthtypes.StoreKey, ibcfeetypes.StoreKey,
movetypes.StoreKey, opchildtypes.StoreKey, buildertypes.StoreKey,
movetypes.StoreKey, opchildtypes.StoreKey, auctiontypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -350,7 +358,7 @@ func NewMinitiaApp(
keys[opchildtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
hook.NewMoveBridgeHook(app.MoveKeeper).Hook,
apphook.NewMoveBridgeHook(app.MoveKeeper).Hook,
app.MsgServiceRouter(),
authtypes.NewModuleAddress(opchildtypes.ModuleName).String(),
)
Expand Down Expand Up @@ -575,18 +583,18 @@ func NewMinitiaApp(

opchildKeeper.SetLegacyRouter(govRouter)

// x/builder module keeper initialization
// x/auction module keeper initialization

// initialize the keeper
builderKeeper := builderkeeper.NewKeeperWithRewardsAddressProvider(
auctionKeeper := auctionkeeper.NewKeeperWithRewardsAddressProvider(
app.appCodec,
app.keys[buildertypes.StoreKey],
app.keys[auctiontypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
NewRewardsAddressProvider(authtypes.FeeCollectorName),
applanes.NewRewardsAddressProvider(authtypes.FeeCollectorName),
authtypes.NewModuleAddress(opchildtypes.ModuleName).String(),
)
app.BuilderKeeper = &builderKeeper
app.AuctionKeeper = &auctionKeeper

/**** Module Options ****/

Expand All @@ -606,7 +614,7 @@ func NewMinitiaApp(
groupmodule.NewAppModule(appCodec, *app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, *app.ConsensusParamsKeeper),
move.NewAppModule(app.AccountKeeper, *app.MoveKeeper),
builder.NewAppModule(app.appCodec, *app.BuilderKeeper),
auction.NewAppModule(app.appCodec, *app.AuctionKeeper),
transferModule,
nftTransferModule,
icaModule,
Expand All @@ -630,7 +638,7 @@ func NewMinitiaApp(
paramstypes.ModuleName,
movetypes.ModuleName,
consensusparamtypes.ModuleName,
buildertypes.ModuleName,
auctiontypes.ModuleName,
// ibc modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand All @@ -652,7 +660,7 @@ func NewMinitiaApp(
upgradetypes.ModuleName,
movetypes.ModuleName,
consensusparamtypes.ModuleName,
buildertypes.ModuleName,
auctiontypes.ModuleName,
// ibc modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand All @@ -677,7 +685,7 @@ func NewMinitiaApp(
upgradetypes.ModuleName,
feegrant.ModuleName,
consensusparamtypes.ModuleName,
buildertypes.ModuleName,
auctiontypes.ModuleName,
// ibc modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -713,35 +721,73 @@ func NewMinitiaApp(
app.SetEndBlocker(app.EndBlocker)

// initialize and set the InitiaApp mempool. The current mempool will be the
// x/builder module's mempool which will extract the top bid from the current block's auction
// x/auction module's mempool which will extract the top bid from the current block's auction
// and insert the txs at the top of the block spots.
factory := buildermempool.NewDefaultAuctionFactory(app.txConfig.TxDecoder())
mempool := buildermempool.NewAuctionMempool(
app.txConfig.TxDecoder(),
app.txConfig.TxEncoder(),
0,
factory,
signerExtractor := signer_extraction.NewDefaultAdapter()

mevConfig := blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(),
MaxTxs: 0,
SignerExtractor: signerExtractor,
}
mevLane := mevlane.NewMEVLane(
mevConfig,
mevlane.NewDefaultAuctionFactory(app.txConfig.TxDecoder(), signerExtractor),
)

freeConfig := blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(),
MaxTxs: 10,
SignerExtractor: signerExtractor,
}
freeLane := freelane.NewFreeLane(
freeConfig,
blockbase.DefaultTxPriority(),
applanes.FreeLaneMatchHandler(),
)

defaultLaneConfig := blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(),
MaxTxs: 0,
SignerExtractor: signerExtractor,
}
defaultLane := baselane.NewDefaultLane(defaultLaneConfig)

lanes := []block.Lane{mevLane, freeLane, defaultLane}
mempool := block.NewLanedMempool(app.Logger(), true, lanes...)
app.SetMempool(mempool)
anteHandler := app.setAnteHandler(mempool)

anteHandler := app.setAnteHandler(mevLane, freeLane)
for _, lane := range lanes {
lane.SetAnteHandler(anteHandler)
}

// override the base-app's ABCI methods (CheckTx, PrepareProposal, ProcessProposal)
proposalHandlers := builderabci.NewProposalHandler(
mempool,
proposalHandlers := mevabci.NewProposalHandler(
app.Logger(),
anteHandler,
app.txConfig.TxEncoder(),
app.txConfig.TxDecoder(),
app.txConfig.TxEncoder(),
mempool,
)

// override base-app's ProcessProposal + PrepareProposal
app.SetPrepareProposal(proposalHandlers.PrepareProposalHandler())
app.SetProcessProposal(proposalHandlers.ProcessProposalHandler())

// overrde base-app's CheckTx
checkTxHandler := builderabci.NewCheckTxHandler(
checkTxHandler := mevlane.NewCheckTxHandler(
app.BaseApp,
app.txConfig.TxDecoder(),
mempool,
mevLane,
anteHandler,
app.ChainID(),
)
Expand Down Expand Up @@ -774,13 +820,16 @@ func (app *MinitiaApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
}

// SetCheckTx sets the checkTxHandler for the app.
func (app *MinitiaApp) SetCheckTx(handler pobabci.CheckTx) {
func (app *MinitiaApp) SetCheckTx(handler mevlane.CheckTx) {
app.checkTxHandler = handler
}

func (app *MinitiaApp) setAnteHandler(mempl buildermempool.Mempool) sdk.AnteHandler {
anteHandler, err := ante.NewAnteHandler(
ante.HandlerOptions{
func (app *MinitiaApp) setAnteHandler(
mevLane auctionante.MEVLane,
freeLane block.Lane,
) sdk.AnteHandler {
anteHandler, err := appante.NewAnteHandler(
appante.HandlerOptions{
HandlerOptions: cosmosante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
Expand All @@ -792,8 +841,9 @@ func (app *MinitiaApp) setAnteHandler(mempl buildermempool.Mempool) sdk.AnteHand
Codec: app.appCodec,
RollupKeeper: app.RollupKeeper,
TxEncoder: app.txConfig.TxEncoder(),
BuilderKeeper: *app.BuilderKeeper,
Mempool: mempl,
AuctionKeeper: *app.AuctionKeeper,
MevLane: mevLane,
FreeLane: freeLane,
},
)
if err != nil {
Expand Down Expand Up @@ -935,16 +985,17 @@ func (app *MinitiaApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error

// RegisterTxService implements the Application.RegisterTxService method.
func (app *MinitiaApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.Simulate, app.interfaceRegistry)
initiaservice.RegisterTxService(
app.BaseApp.GRPCQueryRouter(), clientCtx,
authtx.NewTxServer(clientCtx, app.Simulate, app.interfaceRegistry),
)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *MinitiaApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(
clientCtx,
initiaservice.RegisterTendermintService(
app.BaseApp.GRPCQueryRouter(),
app.interfaceRegistry,
app.Query,
tmservice.NewQueryServer(clientCtx, app.interfaceRegistry, app.Query),
)
}

Expand Down
Loading

0 comments on commit 00dc8bf

Please sign in to comment.