Skip to content

Commit

Permalink
refactor app struct
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Aug 2, 2024
1 parent c5f12c9 commit 00b5071
Show file tree
Hide file tree
Showing 16 changed files with 1,725 additions and 1,245 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-linux-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
ls -l
file minievm_${VERSION}_Linux_${ARCH_NAME}.tar.gz
# remove builder
# Remove builder
docker buildx rm arm64-builder
- name: List files
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
go.mod
go.sum
# install golangci-lint
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${{ env.GOLANGCI_LINT_VERSION }}
- name: run go linters (long)
if: env.GIT_DIFF
id: lint_long
Expand Down
1,007 changes: 124 additions & 883 deletions app/app.go

Large diffs are not rendered by default.

146 changes: 146 additions & 0 deletions app/blocksdk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package app

import (
"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
cosmosante "github.com/cosmos/cosmos-sdk/x/auth/ante"

opchildlanes "github.com/initia-labs/OPinit/x/opchild/lanes"
initialanes "github.com/initia-labs/initia/app/lanes"

blockabci "github.com/skip-mev/block-sdk/v2/abci"
blockchecktx "github.com/skip-mev/block-sdk/v2/abci/checktx"
signer_extraction "github.com/skip-mev/block-sdk/v2/adapters/signer_extraction_adapter"
"github.com/skip-mev/block-sdk/v2/block"
blockbase "github.com/skip-mev/block-sdk/v2/block/base"
mevlane "github.com/skip-mev/block-sdk/v2/lanes/mev"

appante "github.com/initia-labs/minievm/app/ante"
)

func setupBlockSDK(
app *MinitiaApp,
mempoolMaxTxs int,
) (
mempool.Mempool,
sdk.AnteHandler,
blockchecktx.CheckTx,
sdk.PrepareProposalHandler,
sdk.ProcessProposalHandler,
error,
) {

// 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
// and insert the txs at the top of the block spots.
signerExtractor := signer_extraction.NewDefaultAdapter()

systemLane := initialanes.NewSystemLane(blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.01"),
MaxTxs: 1,
SignerExtractor: signerExtractor,
}, opchildlanes.SystemLaneMatchHandler())

factory := mevlane.NewDefaultAuctionFactory(app.txConfig.TxDecoder(), signerExtractor)
mevLane := mevlane.NewMEVLane(blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.09"),
MaxTxs: 100,
SignerExtractor: signerExtractor,
}, factory, factory.MatchHandler())

freeLane := initialanes.NewFreeLane(blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.1"),
MaxTxs: 100,
SignerExtractor: signerExtractor,
}, opchildlanes.NewFreeLaneMatchHandler(app.ac, app.OPChildKeeper).MatchHandler())

defaultLane := initialanes.NewDefaultLane(blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.8"),
MaxTxs: mempoolMaxTxs,
SignerExtractor: signerExtractor,
})

lanes := []block.Lane{systemLane, mevLane, freeLane, defaultLane}
mempool, err := block.NewLanedMempool(app.Logger(), lanes)
if err != nil {
return nil, nil, nil, nil, nil, err
}

Check warning on line 81 in app/blocksdk.go

View check run for this annotation

Codecov / codecov/patch

app/blocksdk.go#L80-L81

Added lines #L80 - L81 were not covered by tests

anteHandler, err := appante.NewAnteHandler(
appante.HandlerOptions{
HandlerOptions: cosmosante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
SignModeHandler: app.txConfig.SignModeHandler(),
},
IBCkeeper: app.IBCKeeper,
Codec: app.appCodec,
OPChildKeeper: app.OPChildKeeper,
TxEncoder: app.txConfig.TxEncoder(),
AuctionKeeper: *app.AuctionKeeper,
MevLane: mevLane,
FreeLane: freeLane,
EVMKeeper: app.EVMKeeper,
},
)
if err != nil {
return nil, nil, nil, nil, nil, err
}

Check warning on line 103 in app/blocksdk.go

View check run for this annotation

Codecov / codecov/patch

app/blocksdk.go#L102-L103

Added lines #L102 - L103 were not covered by tests

// set ante handler to lanes
opt := []blockbase.LaneOption{
blockbase.WithAnteHandler(anteHandler),
}
systemLane.(*blockbase.BaseLane).WithOptions(
opt...,
)
mevLane.WithOptions(
opt...,
)
freeLane.(*blockbase.BaseLane).WithOptions(
opt...,
)
defaultLane.(*blockbase.BaseLane).WithOptions(
opt...,
)

mevCheckTx := blockchecktx.NewMEVCheckTxHandler(
app.BaseApp,
app.txConfig.TxDecoder(),
mevLane,
anteHandler,
app.BaseApp.CheckTx,
)
checkTxHandler := blockchecktx.NewMempoolParityCheckTx(
app.Logger(), mempool,
app.txConfig.TxDecoder(), mevCheckTx.CheckTx(),
)
checkTx := checkTxHandler.CheckTx()

proposalHandler := blockabci.NewProposalHandler(
app.Logger(),
app.txConfig.TxDecoder(),
app.txConfig.TxEncoder(),
mempool,
)

prepareProposalHandler := proposalHandler.PrepareProposalHandler()
processProposalHandler := proposalHandler.ProcessProposalHandler()

return mempool, anteHandler, checkTx, prepareProposalHandler, processProposalHandler, nil
}
21 changes: 21 additions & 0 deletions app/executor_change.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app

// Executor change plans

func (app *MinitiaApp) RegisterExecutorChangePlans() error {
// err := app.OPChildKeeper.RegisterExecutorChangePlan(
// 1,
// 361,
// "initvaloper158x0dpu5f4x703fhtseg5kpytsj02hw04qyw0t",
// "init158x0dpu5f4x703fhtseg5kpytsj02hw0p9ahpm",
// "op2",
// "{\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"GTJEksmVK7gkzPXdj+YIJxipfJ+yYUlc6jzIuh9s2t0=\"}",
// "testestestestsetsetestsetest",
// )

// if err != nil {
// return err
// }

return nil
}
115 changes: 115 additions & 0 deletions app/indexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package app

import (
storetypes "cosmossdk.io/store/types"

dbm "github.com/cosmos/cosmos-db"
servertypes "github.com/cosmos/cosmos-sdk/server/types"

// ibc imports

// initia imports

// OPinit imports

// skip imports

// local imports

evmindexer "github.com/initia-labs/minievm/indexer"

// noble forwarding keeper

// kvindexer
kvindexer "github.com/initia-labs/kvindexer"
kvindexerconfig "github.com/initia-labs/kvindexer/config"
blocksubmodule "github.com/initia-labs/kvindexer/submodules/block"
"github.com/initia-labs/kvindexer/submodules/pair"
tx "github.com/initia-labs/kvindexer/submodules/tx"
kvindexermodule "github.com/initia-labs/kvindexer/x/kvindexer"
kvindexerkeeper "github.com/initia-labs/kvindexer/x/kvindexer/keeper"
)

func setupIndexer(
app *MinitiaApp,
appOpts servertypes.AppOptions,
indexerDB, kvindexerDB dbm.DB,
) (evmindexer.EVMIndexer, *kvindexerkeeper.Keeper, *kvindexermodule.AppModuleBasic, *storetypes.StreamingManager, error) {
// setup evm indexer
evmIndexer, err := evmindexer.NewEVMIndexer(indexerDB, app.appCodec, app.Logger(), app.txConfig, app.EVMKeeper, app.OPChildKeeper)
if err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 42 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L41-L42

Added lines #L41 - L42 were not covered by tests

// initialize the indexer keeper
kvindexerConfig, err := kvindexerconfig.NewConfig(appOpts)
if err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 48 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L47-L48

Added lines #L47 - L48 were not covered by tests
kvIndexerKeeper := kvindexerkeeper.NewKeeper(
app.appCodec,
"evm",
kvindexerDB,
kvindexerConfig,
app.ac,
app.vc,
)

smBlock, err := blocksubmodule.NewBlockSubmodule(app.appCodec, kvIndexerKeeper, app.OPChildKeeper)
if err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 61 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L60-L61

Added lines #L60 - L61 were not covered by tests
smTx, err := tx.NewTxSubmodule(app.appCodec, kvIndexerKeeper)
if err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 65 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L64-L65

Added lines #L64 - L65 were not covered by tests
smPair, err := pair.NewPairSubmodule(app.appCodec, kvIndexerKeeper, app.IBCKeeper.ChannelKeeper, app.TransferKeeper)
if err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 69 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L68-L69

Added lines #L68 - L69 were not covered by tests
err = kvIndexerKeeper.RegisterSubmodules(smBlock, smTx, smPair)
if err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 73 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L72-L73

Added lines #L72 - L73 were not covered by tests

// Add your implementation here

kvIndexer, err := kvindexer.NewIndexer(app.GetBaseApp().Logger(), kvIndexerKeeper)
if err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 80 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L79-L80

Added lines #L79 - L80 were not covered by tests

listeners := []storetypes.ABCIListener{evmIndexer}

var kvIndexerModule *kvindexermodule.AppModuleBasic
if kvIndexer != nil {
if err = kvIndexer.Validate(); err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 88 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L86-L88

Added lines #L86 - L88 were not covered by tests

if err = kvIndexer.Prepare(nil); err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 92 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L90-L92

Added lines #L90 - L92 were not covered by tests

if err = kvIndexerKeeper.Seal(); err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 96 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L94-L96

Added lines #L94 - L96 were not covered by tests

if err = kvIndexer.Start(nil); err != nil {
return nil, nil, nil, nil, err
}

Check warning on line 100 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L98-L100

Added lines #L98 - L100 were not covered by tests

listeners = append(listeners, kvIndexer)

// set kvindexer module
m := kvindexermodule.NewAppModuleBasic(kvIndexerKeeper)
kvIndexerModule = &m

Check warning on line 106 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L102-L106

Added lines #L102 - L106 were not covered by tests
}

streamingManager := storetypes.StreamingManager{
ABCIListeners: listeners,
StopNodeOnErr: true,
}

return evmIndexer, kvIndexerKeeper, kvIndexerModule, &streamingManager, nil
}
2 changes: 1 addition & 1 deletion app/keepers/community_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CommunityPoolKeeper struct {
feeCollectorName string
}

func NewCommunityPoolKeeper(bk bankKeeperForCommunityPoolKeeper, feeCollectorName string) CommunityPoolKeeper {
func newCommunityPoolKeeper(bk bankKeeperForCommunityPoolKeeper, feeCollectorName string) CommunityPoolKeeper {
return CommunityPoolKeeper{
bk: bk,
feeCollectorName: feeCollectorName,
Expand Down
Loading

0 comments on commit 00b5071

Please sign in to comment.