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

replace pob with the latest block-sdk #11

Merged
merged 1 commit into from
Nov 10, 2023
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
10 changes: 5 additions & 5 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

moveante "github.com/initia-labs/initia/x/move/ante"
movetypes "github.com/initia-labs/initia/x/move/types"
builderante "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 extends the SDK's AnteHandler options by requiring the IBC
Expand All @@ -22,9 +22,9 @@ type HandlerOptions struct {
Codec codec.BinaryCodec
MoveKeeper movetypes.AnteKeeper
IBCkeeper *ibckeeper.Keeper
BuilderKeeper builderkeeper.Keeper
AuctionKeeper auctionkeeper.Keeper
TxEncoder sdk.TxEncoder
Mempool builderante.Mempool
MevLane auctionante.MEVLane
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand Down Expand Up @@ -70,7 +70,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
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
102 changes: 65 additions & 37 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 @@ -144,12 +145,16 @@ import (
"github.com/initia-labs/initia/x/slashing"
slashingkeeper "github.com/initia-labs/initia/x/slashing/keeper"

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"
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"
"github.com/skip-mev/block-sdk/block/base"
baselane "github.com/skip-mev/block-sdk/lanes/base"
"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"

// unnamed import of statik for swagger UI support
_ "github.com/initia-labs/initia/client/docs/statik"
Expand Down Expand Up @@ -205,7 +210,7 @@ var (
router.AppModuleBasic{},
ibcperm.AppModuleBasic{},
move.AppModuleBasic{},
builder.AppModuleBasic{},
auction.AppModuleBasic{},
)

// module account permissions
Expand All @@ -220,9 +225,9 @@ var (
govtypes.ModuleName: {authtypes.Burner},
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,

// this is only for testing
authtypes.Minter: {authtypes.Minter},
Expand Down Expand Up @@ -287,7 +292,7 @@ type InitiaApp struct {
RouterKeeper *routerkeeper.Keeper // Router Keeper must be a pointer in the app, so we can SetTransferKeeper on it correctly
IBCPermKeeper *ibcpermkeeper.Keeper
MoveKeeper *movekeeper.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 @@ -304,7 +309,7 @@ type InitiaApp struct {
configurator module.Configurator

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

// NewInitiaApp returns a reference to an initialized Initia.
Expand Down Expand Up @@ -338,7 +343,7 @@ func NewInitiaApp(
ibctransfertypes.StoreKey, ibcnfttransfertypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, icaauthtypes.StoreKey, ibcfeetypes.StoreKey,
routertypes.StoreKey, ibcpermtypes.StoreKey, movetypes.StoreKey, buildertypes.StoreKey,
routertypes.StoreKey, ibcpermtypes.StoreKey, movetypes.StoreKey, auctiontypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -744,15 +749,15 @@ func NewInitiaApp(
// x/builder 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(*app.StakingKeeper, *app.DistrKeeper),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.BuilderKeeper = &builderKeeper
app.AuctionKeeper = &auctionKeeper

// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
Expand Down Expand Up @@ -806,7 +811,7 @@ func NewInitiaApp(
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),
ibctransfer.NewAppModule(*app.TransferKeeper),
ibcnfttransfer.NewAppModule(*app.NftTransferKeeper),
ica.NewAppModule(app.ICAControllerKeeper, app.ICAHostKeeper),
Expand Down Expand Up @@ -848,7 +853,7 @@ func NewInitiaApp(
routertypes.ModuleName,
ibcpermtypes.ModuleName,
consensusparamtypes.ModuleName,
buildertypes.ModuleName,
auctiontypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -879,7 +884,7 @@ func NewInitiaApp(
routertypes.ModuleName,
ibcpermtypes.ModuleName,
consensusparamtypes.ModuleName,
buildertypes.ModuleName,
auctiontypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -916,7 +921,7 @@ func NewInitiaApp(
routertypes.ModuleName,
ibcpermtypes.ModuleName,
consensusparamtypes.ModuleName,
buildertypes.ModuleName,
auctiontypes.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand Down Expand Up @@ -947,35 +952,58 @@ func NewInitiaApp(
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 := base.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(),
MaxTxs: 0,
SignerExtractor: signerExtractor,
}
mevLane := mev.NewMEVLane(
mevConfig,
mev.NewDefaultAuctionFactory(app.txConfig.TxDecoder(), signerExtractor),
)

defaultLaneConfig := base.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, defaultLane}
mempool := block.NewLanedMempool(app.Logger(), true, lanes...)
app.SetMempool(mempool)
anteHandler := app.setAnteHandler(mempool)

anteHandler := app.setAnteHandler(mevLane)
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 := mev.NewCheckTxHandler(
app.BaseApp,
app.txConfig.TxDecoder(),
mempool,
mevLane,
anteHandler,
app.ChainID(),
)
Expand Down Expand Up @@ -1008,11 +1036,11 @@ func (app *InitiaApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
}

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

func (app *InitiaApp) setAnteHandler(mempl buildermempool.Mempool) sdk.AnteHandler {
func (app *InitiaApp) setAnteHandler(mevLane auctionante.MEVLane) sdk.AnteHandler {
anteHandler, err := ante.NewAnteHandler(
ante.HandlerOptions{
HandlerOptions: cosmosante.HandlerOptions{
Expand All @@ -1026,8 +1054,8 @@ func (app *InitiaApp) setAnteHandler(mempl buildermempool.Mempool) sdk.AnteHandl
MoveKeeper: movekeeper.NewDexKeeper(app.MoveKeeper),
Codec: app.appCodec,
TxEncoder: app.txConfig.TxEncoder(),
BuilderKeeper: *app.BuilderKeeper,
Mempool: mempl,
AuctionKeeper: *app.AuctionKeeper,
MevLane: mevLane,
},
)
if err != nil {
Expand Down
12 changes: 9 additions & 3 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,20 @@
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil {
panic(err)

Check warning on line 116 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}
return false
})

// reinitialize all delegations
for _, del := range dels {
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()); err != nil {
panic(err)

Check warning on line 124 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L123-L124

Added lines #L123 - L124 were not covered by tests
}
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()); err != nil {
panic(err)

Check warning on line 127 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L126-L127

Added lines #L126 - L127 were not covered by tests
}
}

// reset context height
Expand Down
8 changes: 4 additions & 4 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
movetypes "github.com/initia-labs/initia/x/move/types"
stakingtypes "github.com/initia-labs/initia/x/mstaking/types"
rewardtypes "github.com/initia-labs/initia/x/reward/types"
buildertypes "github.com/skip-mev/pob/x/builder/types"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)

// GenesisState - The genesis state of the blockchain is represented here as a map of raw json
Expand Down Expand Up @@ -69,11 +69,11 @@ func (genState GenesisState) ConfigureBondDenom(cdc codec.JSONCodec, bondDenom s
genState[movetypes.ModuleName] = cdc.MustMarshalJSON(&moveGenState)

// Builder module genesis-state bond denom configuration
var builderGenState buildertypes.GenesisState
cdc.MustUnmarshalJSON(genState[buildertypes.ModuleName], &builderGenState)
var builderGenState auctiontypes.GenesisState
cdc.MustUnmarshalJSON(genState[auctiontypes.ModuleName], &builderGenState)
builderGenState.Params.ReserveFee.Denom = bondDenom
builderGenState.Params.MinBidIncrement.Denom = bondDenom
genState[buildertypes.ModuleName] = cdc.MustMarshalJSON(&builderGenState)
genState[auctiontypes.ModuleName] = cdc.MustMarshalJSON(&builderGenState)

return genState
}
Expand Down
4 changes: 2 additions & 2 deletions app/rewards_address_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
distrkeeper "github.com/initia-labs/initia/x/distribution/keeper"
mstakingkeeper "github.com/initia-labs/initia/x/mstaking/keeper"
buildertypes "github.com/skip-mev/pob/x/builder/types"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)

var _ buildertypes.RewardsAddressProvider = (*RewardsAddressProvider)(nil)
var _ auctiontypes.RewardsAddressProvider = (*RewardsAddressProvider)(nil)

// NewRewardsAddressProvider returns a new RewardsAddressProvider from a staking + distribution keeper
func NewRewardsAddressProvider(sk mstakingkeeper.Keeper, dk distrkeeper.Keeper) *RewardsAddressProvider {
Expand Down
Loading
Loading