The builder Keeper
is POB's gateway to processing special MsgAuctionBid
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.
type App struct {
BuilderKeeper builderkeeper.Keeper
...
}
b. Add the builder module to the list of module account permissions. This will
instantiate the builder module account on genesis.
maccPerms = map[string][]string{
builder.ModuleName: nil,
...
}
c. Instantiate the builder keeper, store keys, and module manager. Note, be
sure to do this after all the required keeper dependencies have been instantiated.
keys := storetypes.NewKVStoreKeys(
buildertypes.StoreKey,
...
)
...
app.BuilderKeeper := builderkeeper.NewKeeper(
appCodec,
keys[buildertypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.DistrKeeper,
app.StakingKeeper,
authtypes.NewModuleAddress(govv1.ModuleName).String(),
)
app.ModuleManager = module.NewManager(
builder.NewAppModule(appCodec, app.BuilderKeeper),
...
)
d. Searchers bid to have their bundles executed at the top of the block
using MsgAuctionBid
messages. While the builder Keeper
is capable of
tracking valid bids, it is unable to correctly sequence the auction
transactions alongside the normal transactions without having access to the
application’s mempool. As such, we have to instantiate POB’s custom
AuctionMempool
- a modified version of the SDK’s priority sender-nonce
mempool - into the application. Note, this should be done after BaseApp
is
instantiated.
mempool := mempool.NewAuctionMempool(txConfig.TxDecoder(), GetMaxMempoolSize())
bApp.SetMempool(mempool)
e. With Cosmos SDK version 0.47.0, the process of building blocks has been
updated and moved from the consensus layer, CometBFT, to the application layer.
When a new block is requested, the proposer for that height will utilize the
PrepareProposal
handler to build a block while the ProcessProposal
handler
will verify the contents of the block proposal by all validators. The
combination of the AuctionMempool
, PrepareProposal
and ProcessProposal
handlers allows the application to verifiably build valid blocks with
top-of-block block space reserved for auctions.
handler := proposalhandler.NewProposalHandler(
mempool,
bApp.Logger(),
bApp,
txConfig.TxEncoder(),
txConfig.TxDecoder(),
)
bApp.SetPrepareProposal(handler.PrepareProposalHandler())
bApp.SetProcessProposal(handler.ProcessProposalHandler())
f. Finally, update the app's InitGenesis
order and ante-handler chain.
genesisModuleOrder := []string{
buildertypes.ModuleName,
...,
}
anteDecorators := []sdk.AnteDecorator{
auction.NewAuctionDecorator(
app.BuilderKeeper,
txConfig.TxDecoder(),
txConfig.TxEncoder(),
mempool,
),
...,
}