Skip to content

Commit

Permalink
Revert "replace pob with the latest block-sdk"
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Nov 14, 2023
1 parent 78f050d commit 3b77e7e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 169 deletions.
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"
auctionante "github.com/skip-mev/block-sdk/x/auction/ante"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
builderante "github.com/skip-mev/pob/x/builder/ante"
builderkeeper "github.com/skip-mev/pob/x/builder/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
AuctionKeeper auctionkeeper.Keeper
BuilderKeeper builderkeeper.Keeper
TxEncoder sdk.TxEncoder
MevLane auctionante.MEVLane
Mempool builderante.Mempool
}

// 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),
auctionante.NewAuctionDecorator(options.AuctionKeeper, options.TxEncoder, options.MevLane),
builderante.NewBuilderDecorator(options.BuilderKeeper, options.TxEncoder, options.Mempool),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
102 changes: 37 additions & 65 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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 @@ -145,16 +144,12 @@ import (
"github.com/initia-labs/initia/x/slashing"
slashingkeeper "github.com/initia-labs/initia/x/slashing/keeper"

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"
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"

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

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

// this is only for testing
authtypes.Minter: {authtypes.Minter},
Expand Down Expand Up @@ -292,7 +287,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
AuctionKeeper *auctionkeeper.Keeper // x/builder keeper used to process bids for TOB auctions
BuilderKeeper *builderkeeper.Keeper // x/builder keeper used to process bids for TOB auctions

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

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

// NewInitiaApp returns a reference to an initialized Initia.
Expand Down Expand Up @@ -343,7 +338,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, auctiontypes.StoreKey,
routertypes.StoreKey, ibcpermtypes.StoreKey, movetypes.StoreKey, buildertypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -749,15 +744,15 @@ func NewInitiaApp(
// x/builder module keeper initialization

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

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

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

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

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand Down Expand Up @@ -952,58 +947,35 @@ func NewInitiaApp(
app.SetEndBlocker(app.EndBlocker)

// initialize and set the InitiaApp mempool. The current mempool will be the
// x/auction module's mempool which will extract the top bid from the current block's auction
// x/builder 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.
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),
factory := buildermempool.NewDefaultAuctionFactory(app.txConfig.TxDecoder())
mempool := buildermempool.NewAuctionMempool(
app.txConfig.TxDecoder(),
app.txConfig.TxEncoder(),
0,
factory,
)

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(mevLane)
for _, lane := range lanes {
lane.SetAnteHandler(anteHandler)
}
anteHandler := app.setAnteHandler(mempool)

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

// overrde base-app's CheckTx
checkTxHandler := mev.NewCheckTxHandler(
checkTxHandler := builderabci.NewCheckTxHandler(
app.BaseApp,
app.txConfig.TxDecoder(),
mevLane,
mempool,
anteHandler,
app.ChainID(),
)
Expand Down Expand Up @@ -1036,11 +1008,11 @@ func (app *InitiaApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
}

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

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

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

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

// 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"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
buildertypes "github.com/skip-mev/pob/x/builder/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 auctiontypes.GenesisState
cdc.MustUnmarshalJSON(genState[auctiontypes.ModuleName], &builderGenState)
var builderGenState buildertypes.GenesisState
cdc.MustUnmarshalJSON(genState[buildertypes.ModuleName], &builderGenState)
builderGenState.Params.ReserveFee.Denom = bondDenom
builderGenState.Params.MinBidIncrement.Denom = bondDenom
genState[auctiontypes.ModuleName] = cdc.MustMarshalJSON(&builderGenState)
genState[buildertypes.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"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
buildertypes "github.com/skip-mev/pob/x/builder/types"
)

var _ auctiontypes.RewardsAddressProvider = (*RewardsAddressProvider)(nil)
var _ buildertypes.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

0 comments on commit 3b77e7e

Please sign in to comment.