diff --git a/lanes/mev/README.md b/lanes/mev/README.md index 03c8939..4a27c2a 100644 --- a/lanes/mev/README.md +++ b/lanes/mev/README.md @@ -80,118 +80,120 @@ NOTE: This example walks through setting up the MEV and Default lanes. messages that allow users to participate in the top of block auction, distribute revenue to the auction house, and ensure the validity of auction transactions. - a. First add the keeper to the app's struct definition. We also want to add - MEV lane's custom checkTx handler to the app's struct definition. This will - allow us to override the default checkTx handler to process bid transactions - before they are inserted into the `LanedMempool`. NOTE: The custom handler is - required as otherwise the auction can be held hostage by a malicious - users. + a. First add the keeper to the app's struct definition. We also want to add + MEV lane's custom checkTx handler to the app's struct definition. This will + allow us to override the default checkTx handler to process bid transactions + before they are inserted into the `LanedMempool`. NOTE: The custom handler + is required as otherwise the auction can be held hostage by a malicious + users. - ```go - type App struct { - ... - // BuilderKeeper is the keeper that handles processing auction transactions - BuilderKeeper builderkeeper.Keeper + ```go + type App struct { + ... + // BuilderKeeper is the keeper that handles processing auction transactions + BuilderKeeper builderkeeper.Keeper - // Custom checkTx handler - checkTxHandler mev.CheckTx - } - ``` + // Custom checkTx handler + checkTxHandler mev.CheckTx + } + ``` b. Add the builder module to the list of module account permissions. This will instantiate the builder module account on genesis. - ```go - maccPerms = map[string][]string{ - builder.ModuleName: nil, - ... - } - ``` + ```go + maccPerms = map[string][]string{ + builder.ModuleName: nil, + ... + } + ``` - c. Instantiate the Block SDK's `LanedMempool` with the application's desired lanes. + c. Instantiate the Block SDK's `LanedMempool` with the application's + desired lanes. - ```go - // 1. Create the lanes. - // - // NOTE: The lanes are ordered by priority. The first lane is the highest priority - // lane and the last lane is the lowest priority lane. Top of block lane allows - // transactions to bid for inclusion at the top of the next block. - // - // For more information on how to utilize the LaneConfig please - // visit the README in docs.skip.money/chains/lanes/build-your-own-lane#-lane-config. - // - // MEV lane hosts an auction at the top of the block. - mevConfig := base.LaneConfig{ - Logger: app.Logger(), - TxEncoder: app.txConfig.TxEncoder(), - TxDecoder: app.txConfig.TxDecoder(), - MaxBlockSpace: math.LegacyZeroDec(), - MaxTxs: 0, - } - mevLane := mev.NewMEVLane( - mevConfig, - mev.NewDefaultAuctionFactory(app.txConfig.TxDecoder()), - ) + ```go + // 1. Create the lanes. + // + // NOTE: The lanes are ordered by priority. The first lane is the + // highest priority + // lane and the last lane is the lowest priority lane. Top of block + // lane allows transactions to bid for inclusion at the top of the next block. + // + // For more information on how to utilize the LaneConfig please + // visit the README in docs.skip.money/chains/lanes/build-your-own-lane#-lane-config. + // + // MEV lane hosts an auction at the top of the block. + mevConfig := base.LaneConfig{ + Logger: app.Logger(), + TxEncoder: app.txConfig.TxEncoder(), + TxDecoder: app.txConfig.TxDecoder(), + MaxBlockSpace: math.LegacyZeroDec(), + MaxTxs: 0, + } + mevLane := mev.NewMEVLane( + mevConfig, + mev.NewDefaultAuctionFactory(app.txConfig.TxDecoder()), + ) - // default lane accepts all other transactions. - defaultConfig := base.LaneConfig{ - Logger: app.Logger(), - TxEncoder: app.txConfig.TxEncoder(), - TxDecoder: app.txConfig.TxDecoder(), - MaxBlockSpace: math.LegacyZeroDec(), - MaxTxs: 0, - } - defaultLane := base.NewStandardLane(defaultConfig) + // default lane accepts all other transactions. + defaultConfig := base.LaneConfig{ + Logger: app.Logger(), + TxEncoder: app.txConfig.TxEncoder(), + TxDecoder: app.txConfig.TxDecoder(), + MaxBlockSpace: math.LegacyZeroDec(), + MaxTxs: 0, + } + defaultLane := base.NewStandardLane(defaultConfig) - // 2. Set up the relateive priority of lanes - lanes := []block.Lane{ - mevLane, - defaultLane, - } - mempool := block.NewLanedMempool(app.Logger(), true, lanes...) - app.App.SetMempool(mempool) - ``` + // 2. Set up the relateive priority of lanes + lanes := []block.Lane{ + mevLane, + defaultLane, + } + mempool := block.NewLanedMempool(app.Logger(), true, lanes...) + app.App.SetMempool(mempool) + ``` d. Add the `x/builder` module's `AuctionDecorator` to the ante-handler chain. The `AuctionDecorator` is an AnteHandler decorator that enforces various chain configurable MEV rules. - ```go - anteDecorators := []sdk.AnteDecorator{ - ante.NewSetUpContextDecorator(), - ... - builderante.NewBuilderDecorator( - options.BuilderKeeper, - options.TxEncoder, - options.TOBLane, - options.Mempool, - ), - } + ```go + anteDecorators := []sdk.AnteDecorator{ + ante.NewSetUpContextDecorator(), + ... + builderante.NewBuilderDecorator( + options.BuilderKeeper, + options.TxEncoder, + options.TOBLane, + options.Mempool, + ), + } - anteHandler := sdk.ChainAnteDecorators(anteDecorators...) - app.SetAnteHandler(anteHandler) + anteHandler := sdk.ChainAnteDecorators(anteDecorators...) + app.SetAnteHandler(anteHandler) - // Set the antehandlers on the lanes. - // - // NOTE: This step is required as otherwise the lanes will not be able to - // process auction transactions. - for _, lane := range lanes { - lane.SetAnteHandler(anteHandler) - } - app.App.SetAnteHandler(anteHandler) - ``` + // Set the antehandlers on the lanes. + // + // NOTE: This step is required as otherwise the lanes will not be able to + // process auction transactions. + for _, lane := range lanes { + lane.SetAnteHandler(anteHandler) + } + app.App.SetAnteHandler(anteHandler) + ``` e. Instantiate the builder keeper, store keys, and module manager. Note, be sure to do this after all the required keeper dependencies have been instantiated. - ```go - keys := storetypes.NewKVStoreKeys( + ```go + keys := storetypes.NewKVStoreKeys( buildertypes.StoreKey, ... - ) + ) - ... - app.BuilderKeeper := builderkeeper.NewKeeper( + ... + app.BuilderKeeper := builderkeeper.NewKeeper( appCodec, keys[buildertypes.StoreKey], app.AccountKeeper, @@ -199,43 +201,39 @@ NOTE: This example walks through setting up the MEV and Default lanes. app.DistrKeeper, app.StakingKeeper, authtypes.NewModuleAddress(govv1.ModuleName).String(), - ) + ) - - app.ModuleManager = module.NewManager( + + app.ModuleManager = module.NewManager( builder.NewAppModule(appCodec, app.BuilderKeeper), ... - ) - ``` + ) + ``` - e. Configure the proposal/checkTx handlers on base app. + f. Configure the proposal/checkTx handlers on base app. ```go - // Create the proposal handler that will be used to build and validate blocks. proposalHandler := abci.NewProposalHandler( - app.Logger(), - app.txConfig.TxDecoder(), - lanes, + app.Logger(), + app.txConfig.TxDecoder(), + lanes, ) app.App.SetPrepareProposal(proposalHandler.PrepareProposalHandler()) app.App.SetProcessProposal(proposalHandler.ProcessProposalHandler()) - // Set the custom CheckTx handler on BaseApp. - checkTxHandler := mev.NewCheckTxHandler( - app.App, - app.txConfig.TxDecoder(), - mevLane, - anteHandler, - ) - app.SetCheckTx(checkTxHandler.CheckTx()) - ... - + checkTxHandler := mev.NewCheckTxHandler( + app.App, + app.txConfig.TxDecoder(), + mevLane, + anteHandler, + ) + app.SetCheckTx(checkTxHandler.CheckTx()) // CheckTx will check the transaction with the provided checkTxHandler. - // We override the default handler so that we can verify bid transactions - // before they are inserted into the mempool. With the POB CheckTx, we can + // We override the default handler so that we can verify transactions + // before they are inserted into the mempool. With the CheckTx, we can // verify the bid transaction and all of the bundled transactions // before inserting the bid transaction into the mempool. func (app *TestApp) CheckTx(req *cometabci.RequestCheckTx) @@ -249,12 +247,12 @@ NOTE: This example walks through setting up the MEV and Default lanes. } ``` - f. Finally, update the app's `InitGenesis` order. + g. Finally, update the app's `InitGenesis` order. ```go genesisModuleOrder := []string{ - buildertypes.ModuleName, - ..., + buildertypes.ModuleName, + ..., } ```