-
Notifications
You must be signed in to change notification settings - Fork 108
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
feat(app): Integrate the block-sdk #413
Merged
pr0n00gler
merged 15 commits into
neutron-org:feat/block-sdk
from
nivasan1:nv/block-sdk-integration-v2
Jan 31, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5d9e1f3
initial integration
nivasan1 64fe99f
ante-handler fix
nivasan1 93810f8
update dockerfile
nivasan1 505974f
nits
nivasan1 a0446ce
factor lane logic into separate file
nivasan1 3d20e96
update upgrade handler
nivasan1 4b19be5
block-sdk version upgrade
nivasan1 10a5240
docs + nits
nivasan1 9509a9c
nits
nivasan1 cea68f7
update go mod version
nivasan1 fd61219
move upgrade handlers to next-upgrade
nivasan1 60c63a5
fix nextupgrade test
nivasan1 b79351b
pr nits
nivasan1 35c4201
nop process proposal handler
nivasan1 7ca5ba2
update go.mod patch version
nivasan1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"net/http" | ||
"os" | ||
"path/filepath" | ||
"reflect" | ||
|
||
globalfeetypes "github.com/cosmos/gaia/v11/x/globalfee/types" | ||
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward" | ||
|
@@ -21,6 +22,7 @@ import ( | |
"github.com/neutron-org/neutron/v2/docs" | ||
|
||
"github.com/neutron-org/neutron/v2/app/upgrades" | ||
"github.com/neutron-org/neutron/v2/app/upgrades/nextupgrade" | ||
v030 "github.com/neutron-org/neutron/v2/app/upgrades/v0.3.0" | ||
v044 "github.com/neutron-org/neutron/v2/app/upgrades/v0.4.4" | ||
v200 "github.com/neutron-org/neutron/v2/app/upgrades/v2.0.0" | ||
|
@@ -161,14 +163,25 @@ import ( | |
ibcswaptypes "github.com/neutron-org/neutron/v2/x/ibcswap/types" | ||
|
||
gmpmiddleware "github.com/neutron-org/neutron/v2/x/gmp" | ||
|
||
// Block-sdk imports | ||
blocksdkabci "github.com/skip-mev/block-sdk/abci" | ||
blocksdk "github.com/skip-mev/block-sdk/block" | ||
"github.com/skip-mev/block-sdk/x/auction" | ||
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper" | ||
rewardsaddressprovider "github.com/skip-mev/block-sdk/x/auction/rewards" | ||
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types" | ||
|
||
"github.com/skip-mev/block-sdk/abci/checktx" | ||
"github.com/skip-mev/block-sdk/block/base" | ||
) | ||
|
||
const ( | ||
Name = "neutrond" | ||
) | ||
|
||
var ( | ||
Upgrades = []upgrades.Upgrade{v030.Upgrade, v044.Upgrade, v200.Upgrade, v202.Upgrade} | ||
Upgrades = []upgrades.Upgrade{v030.Upgrade, v044.Upgrade, v200.Upgrade, v202.Upgrade, nextupgrade.Upgrade} | ||
|
||
// DefaultNodeHome default home directories for the application daemon | ||
DefaultNodeHome string | ||
|
@@ -215,6 +228,7 @@ var ( | |
), | ||
ibchooks.AppModuleBasic{}, | ||
packetforward.AppModuleBasic{}, | ||
auction.AppModuleBasic{}, | ||
globalfee.AppModule{}, | ||
dex.AppModuleBasic{}, | ||
ibcswap.AppModuleBasic{}, | ||
|
@@ -223,6 +237,7 @@ var ( | |
// module account permissions | ||
maccPerms = map[string][]string{ | ||
authtypes.FeeCollectorName: nil, | ||
auctiontypes.ModuleName: nil, | ||
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, | ||
icatypes.ModuleName: nil, | ||
wasmtypes.ModuleName: {}, | ||
|
@@ -275,10 +290,12 @@ type App struct { | |
memKeys map[string]*storetypes.MemoryStoreKey | ||
|
||
// keepers | ||
AccountKeeper authkeeper.AccountKeeper | ||
AdminmoduleKeeper adminmodulekeeper.Keeper | ||
AuthzKeeper authzkeeper.Keeper | ||
BankKeeper bankkeeper.BaseKeeper | ||
AccountKeeper authkeeper.AccountKeeper | ||
AdminmoduleKeeper adminmodulekeeper.Keeper | ||
AuthzKeeper authzkeeper.Keeper | ||
BankKeeper bankkeeper.BaseKeeper | ||
// AuctionKeeper handles the processing of bid-txs, the selection of winners per height, and the distribution of rewards. | ||
AuctionKeeper auctionkeeper.Keeper | ||
CapabilityKeeper *capabilitykeeper.Keeper | ||
SlashingKeeper slashingkeeper.Keeper | ||
CrisisKeeper crisiskeeper.Keeper | ||
|
@@ -324,6 +341,10 @@ type App struct { | |
|
||
// sm is the simulation manager | ||
sm *module.SimulationManager | ||
|
||
// Custom checkTx handler -> this check-tx is used to simulate txs that are | ||
// wrapped in a bid-tx | ||
checkTxHandler checktx.CheckTx | ||
} | ||
|
||
func (app *App) GetTestBankKeeper() integration.TestBankKeeper { | ||
|
@@ -374,7 +395,7 @@ func New( | |
icahosttypes.StoreKey, capabilitytypes.StoreKey, | ||
interchainqueriesmoduletypes.StoreKey, contractmanagermoduletypes.StoreKey, interchaintxstypes.StoreKey, wasmtypes.StoreKey, feetypes.StoreKey, | ||
feeburnertypes.StoreKey, adminmoduletypes.StoreKey, ccvconsumertypes.StoreKey, tokenfactorytypes.StoreKey, pfmtypes.StoreKey, | ||
crontypes.StoreKey, ibchookstypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey, dextypes.StoreKey, | ||
crontypes.StoreKey, ibchookstypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey, dextypes.StoreKey, auctiontypes.StoreKey, | ||
) | ||
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) | ||
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, feetypes.MemStoreKey) | ||
|
@@ -595,6 +616,16 @@ func New( | |
authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), | ||
) | ||
|
||
app.AuctionKeeper = auctionkeeper.NewKeeperWithRewardsAddressProvider( | ||
appCodec, | ||
keys[auctiontypes.StoreKey], | ||
app.AccountKeeper, | ||
&app.BankKeeper, | ||
// 25% of rewards should be sent to the redistribute address | ||
rewardsaddressprovider.NewFixedAddressRewardsAddressProvider(app.AccountKeeper.GetModuleAddress(ccvconsumertypes.ConsumerRedistributeName)), | ||
authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), | ||
) | ||
|
||
dexModule := dex.NewAppModule(appCodec, app.DexKeeper, app.BankKeeper) | ||
|
||
app.SwapKeeper = ibcswapkeeper.NewKeeper( | ||
|
@@ -779,6 +810,7 @@ func New( | |
globalfee.NewAppModule(app.GetSubspace(globalfee.ModuleName)), | ||
swapModule, | ||
dexModule, | ||
auction.NewAppModule(appCodec, app.AuctionKeeper), | ||
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them | ||
) | ||
|
||
|
@@ -787,6 +819,7 @@ func New( | |
// CanWithdrawInvariant invariant. | ||
// NOTE: staking module is required if HistoricalEntries param > 0 | ||
app.mm.SetOrderBeginBlockers( | ||
auctiontypes.ModuleName, | ||
upgradetypes.ModuleName, | ||
capabilitytypes.ModuleName, | ||
slashingtypes.ModuleName, | ||
|
@@ -819,6 +852,7 @@ func New( | |
) | ||
|
||
app.mm.SetOrderEndBlockers( | ||
auctiontypes.ModuleName, | ||
crisistypes.ModuleName, | ||
capabilitytypes.ModuleName, | ||
authtypes.ModuleName, | ||
|
@@ -858,6 +892,7 @@ func New( | |
// so that other modules that want to create or claim capabilities afterwards in InitChain | ||
// can do so safely. | ||
app.mm.SetOrderInitGenesis( | ||
auctiontypes.ModuleName, | ||
capabilitytypes.ModuleName, | ||
authtypes.ModuleName, | ||
ibctransfertypes.ModuleName, | ||
|
@@ -928,6 +963,19 @@ func New( | |
app.SetInitChainer(app.InitChainer) | ||
app.SetBeginBlocker(app.BeginBlocker) | ||
|
||
app.SetEndBlocker(app.EndBlocker) | ||
|
||
// create the lanes | ||
mevLane, baseLane := app.CreateLanes() | ||
mempool, err := blocksdk.NewLanedMempool(app.Logger(), []blocksdk.Lane{mevLane, baseLane}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// set the mempool first | ||
app.SetMempool(mempool) | ||
|
||
// then create the ante-handler | ||
anteHandler, err := NewAnteHandler( | ||
HandlerOptions{ | ||
HandlerOptions: ante.HandlerOptions{ | ||
|
@@ -942,16 +990,57 @@ func New( | |
TXCounterStoreKey: keys[wasmtypes.StoreKey], | ||
ConsumerKeeper: app.ConsumerKeeper, | ||
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName), | ||
AuctionKeeper: app.AuctionKeeper, | ||
TxEncoder: app.GetTxConfig().TxEncoder(), | ||
MEVLane: mevLane, | ||
}, | ||
app.Logger(), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
app.SetAnteHandler(anteHandler) | ||
|
||
app.SetEndBlocker(app.EndBlocker) | ||
// set ante-handlers | ||
opts := []base.LaneOption{ | ||
base.WithAnteHandler(anteHandler), | ||
} | ||
baseLane.WithOptions(opts...) | ||
mevLane.WithOptions(opts...) | ||
|
||
// set the block-sdk prepare / process-proposal handlers | ||
handler := blocksdkabci.NewProposalHandler( | ||
app.Logger(), | ||
app.GetTxConfig().TxDecoder(), | ||
app.GetTxConfig().TxEncoder(), | ||
mempool, | ||
) | ||
app.SetPrepareProposal(handler.PrepareProposalHandler()) | ||
|
||
// we use a no-op ProcessProposal, this way, we accept all proposals in avoidance | ||
// of liveness failures due to Prepare / Process inconsistency. In other words, | ||
// this ProcessProposal always returns ACCEPT. | ||
app.SetProcessProposal(baseapp.NoOpProcessProposal()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting ProcessProposal to a nop |
||
|
||
// block-sdk CheckTx handler | ||
mevCheckTxHandler := checktx.NewMEVCheckTxHandler( | ||
app, | ||
app.GetTxConfig().TxDecoder(), | ||
mevLane, | ||
anteHandler, | ||
app.BaseApp.CheckTx, | ||
app.ChainID(), | ||
) | ||
|
||
// wrap checkTxHandler with mempool parity handler | ||
parityCheckTx := checktx.NewMempoolParityCheckTx( | ||
app.Logger(), | ||
mempool, | ||
app.GetTxConfig().TxDecoder(), | ||
mevCheckTxHandler.CheckTx(), | ||
) | ||
|
||
app.SetCheckTx(parityCheckTx.CheckTx()) | ||
|
||
// must be before Loading version | ||
// requires the snapshot store to be created and registered as a BaseAppOption | ||
|
@@ -1021,6 +1110,7 @@ func (app *App) setupUpgradeHandlers() { | |
SlashingKeeper: app.SlashingKeeper, | ||
ParamsKeeper: app.ParamsKeeper, | ||
CapabilityKeeper: app.CapabilityKeeper, | ||
AuctionKeeper: app.AuctionKeeper, | ||
ContractManager: app.ContractManagerKeeper, | ||
AdminModule: app.AdminmoduleKeeper, | ||
ConsensusKeeper: &app.ConsensusParamsKeeper, | ||
|
@@ -1034,6 +1124,26 @@ func (app *App) setupUpgradeHandlers() { | |
} | ||
} | ||
|
||
// ChainID gets chainID from private fields of BaseApp | ||
// Should be removed once SDK 0.50.x will be adopted | ||
func (app *App) ChainID() string { | ||
field := reflect.ValueOf(app.BaseApp).Elem().FieldByName("chainID") | ||
return field.String() | ||
} | ||
|
||
// 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 Block-SDK CheckTx, we can verify the bid transaction and all of the bundled transactions | ||
// before inserting the bid transaction into the mempool. | ||
func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { | ||
return app.checkTxHandler(req) | ||
} | ||
|
||
// SetCheckTx sets the checkTxHandler for the app. | ||
func (app *App) SetCheckTx(handler checktx.CheckTx) { | ||
app.checkTxHandler = handler | ||
} | ||
|
||
// Name returns the name of the App | ||
func (app *App) Name() string { return app.BaseApp.Name() } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package app | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
signer_extraction_adapter "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter" | ||
blocksdkbase "github.com/skip-mev/block-sdk/block/base" | ||
base_lane "github.com/skip-mev/block-sdk/lanes/base" | ||
mev_lane "github.com/skip-mev/block-sdk/lanes/mev" | ||
) | ||
|
||
const ( | ||
MaxTxsForDefaultLane = 3000 // maximal number of txs that can be stored in this lane at any point in time | ||
MaxTxsForMEVLane = 500 // ditto | ||
) | ||
|
||
var ( | ||
MaxBlockspaceForDefaultLane = math.LegacyMustNewDecFromStr("0.9") // maximal fraction of blockMaxBytes / gas that can be used by this lane at any point in time (90%) | ||
MaxBlockspaceForMEVLane = math.LegacyMustNewDecFromStr("0.1") // ditto (10%) | ||
) | ||
|
||
// CreateLanes creates a LaneMempool containing MEV, default lanes (in that order) | ||
func (app *App) CreateLanes() (*mev_lane.MEVLane, *blocksdkbase.BaseLane) { | ||
// initialize the default lane | ||
basecfg := blocksdkbase.LaneConfig{ | ||
Logger: app.Logger(), | ||
TxDecoder: app.GetTxConfig().TxDecoder(), | ||
TxEncoder: app.GetTxConfig().TxEncoder(), | ||
SignerExtractor: signer_extraction_adapter.NewDefaultAdapter(), | ||
MaxBlockSpace: MaxBlockspaceForDefaultLane, | ||
MaxTxs: MaxTxsForDefaultLane, | ||
} | ||
|
||
// BaseLane (DefaultLane) is intended to hold all txs that are not matched by any lanes ordered before this | ||
// lane. | ||
baseLane := base_lane.NewDefaultLane(basecfg, blocksdkbase.DefaultMatchHandler()) | ||
|
||
// initialize the MEV lane, this lane is intended to hold all bid txs | ||
factory := mev_lane.NewDefaultAuctionFactory(app.GetTxConfig().TxDecoder(), signer_extraction_adapter.NewDefaultAdapter()) | ||
|
||
mevcfg := blocksdkbase.LaneConfig{ | ||
Logger: app.Logger(), | ||
TxDecoder: app.GetTxConfig().TxDecoder(), | ||
TxEncoder: app.GetTxConfig().TxEncoder(), | ||
SignerExtractor: signer_extraction_adapter.NewDefaultAdapter(), | ||
MaxBlockSpace: MaxBlockspaceForMEVLane, | ||
MaxTxs: MaxTxsForMEVLane, | ||
} | ||
mevLane := mev_lane.NewMEVLane( | ||
mevcfg, | ||
factory, | ||
factory.MatchHandler(), | ||
) | ||
|
||
return mevLane, baseLane | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package nextupgrade | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types" | ||
|
||
"github.com/neutron-org/neutron/v2/app/upgrades" | ||
) | ||
|
||
const ( | ||
// UpgradeName defines the on-chain upgrade name. | ||
UpgradeName = "nextupgrade" | ||
|
||
AuctionParamsMaxBundleSize = 2 | ||
AuctionParamsFrontRunningProtection = true | ||
) | ||
|
||
var ( | ||
Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{auctiontypes.ModuleName}, | ||
}, | ||
} | ||
AuctionParamsReserveFee = sdk.Coin{Denom: "untrn", Amount: sdk.NewInt(500_000)} | ||
AuctionParamsMinBidIncrement = sdk.Coin{Denom: "untrn", Amount: sdk.NewInt(100_000)} | ||
AuctionParamsProposerFee = math.LegacyNewDecWithPrec(25, 2) | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same method called on L1016, pls remove one of