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

feat: refactor app struct #60

Merged
merged 8 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .github/workflows/build-linux-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
ls -l
file miniwasm_${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,020 changes: 116 additions & 904 deletions app/app.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
app := SetupWithGenesisAccounts(t.TempDir(), nil, nil)

// BlockedAddresses returns a map of addresses in app v1 and a map of modules name in app v2.
for acc := range app.ModuleAccountAddrs() {
for acc := range app.BlockedModuleAccountAddrs(app.ModuleAccountAddrs()) {
var addr sdk.AccAddress
if modAddr, err := sdk.AccAddressFromBech32(acc); err == nil {
addr = modAddr
Expand Down
154 changes: 154 additions & 0 deletions app/blocksdk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package app

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

"github.com/cosmos/cosmos-sdk/runtime"
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/miniwasm/app/ante"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

func setupBlockSDK(
app *MinitiaApp,
mempoolMaxTxs int,
wasmConfig wasmtypes.WasmConfig,
txCounterStoreKey *storetypes.KVStoreKey,
) (
mempool.Mempool,
sdk.AnteHandler,
blockchecktx.CheckTx,
sdk.PrepareProposalHandler,
sdk.ProcessProposalHandler,
error,
) {
beer-1 marked this conversation as resolved.
Show resolved Hide resolved

// 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 87 in app/blocksdk.go

View check run for this annotation

Codecov / codecov/patch

app/blocksdk.go#L86-L87

Added lines #L86 - L87 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,
WasmKeeper: app.WasmKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreService: runtime.NewKVStoreService(txCounterStoreKey),
},
)
if err != nil {
return nil, nil, nil, nil, nil, err
}

Check warning on line 111 in app/blocksdk.go

View check run for this annotation

Codecov / codecov/patch

app/blocksdk.go#L110-L111

Added lines #L110 - L111 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...,
)
beer-1 marked this conversation as resolved.
Show resolved Hide resolved

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
}
92 changes: 92 additions & 0 deletions app/indexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package app

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

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

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

func setupIndexer(
app *MinitiaApp,
appOpts servertypes.AppOptions,
kvindexerDB dbm.DB,
) (*kvindexerkeeper.Keeper, *kvindexermodule.AppModuleBasic, *storetypes.StreamingManager, error) {
// initialize the indexer keeper
kvindexerConfig, err := kvindexerconfig.NewConfig(appOpts)
if err != nil {
return nil, nil, nil, err
}

Check warning on line 29 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L28-L29

Added lines #L28 - L29 were not covered by tests
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved
kvIndexerKeeper := kvindexerkeeper.NewKeeper(
app.appCodec,
"wasm",
kvindexerDB,
kvindexerConfig,
app.ac,
app.vc,
)

smBlock, err := blocksubmodule.NewBlockSubmodule(app.appCodec, kvIndexerKeeper, app.OPChildKeeper)
if err != nil {
return 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
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved
smTx, err := tx.NewTxSubmodule(app.appCodec, kvIndexerKeeper)
if err != nil {
return nil, nil, nil, err
}

Check warning on line 46 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L45-L46

Added lines #L45 - L46 were not covered by tests
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved
smPair, err := pair.NewPairSubmodule(app.appCodec, kvIndexerKeeper, app.IBCKeeper.ChannelKeeper, app.TransferKeeper)
if err != nil {
return nil, nil, nil, err
}

Check warning on line 50 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L49-L50

Added lines #L49 - L50 were not covered by tests
Comment on lines +47 to +50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test coverage for error handling.

The error handling for pair.NewPairSubmodule is not covered by tests.

Do you want me to assist in generating the test cases for this error handling?

Tools
GitHub Check: codecov/patch

[warning] 49-50: app/indexer.go#L49-L50
Added lines #L49 - L50 were not covered by tests

smNft, err := nft.NewWasmNFTSubmodule(app.ac, app.appCodec, kvIndexerKeeper, app.WasmKeeper, smPair)
if err != nil {
return nil, nil, nil, err
}

Check warning on line 54 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L53-L54

Added lines #L53 - L54 were not covered by tests
Comment on lines +51 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test coverage for error handling.

The error handling for nft.NewWasmNFTSubmodule is not covered by tests.

Do you want me to assist in generating the test cases for this error handling?

Tools
GitHub Check: codecov/patch

[warning] 53-54: app/indexer.go#L53-L54
Added lines #L53 - L54 were not covered by tests

err = kvIndexerKeeper.RegisterSubmodules(smBlock, smTx, smPair, smNft)
if err != nil {
return nil, nil, nil, err
}

Check warning on line 58 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L57-L58

Added lines #L57 - L58 were not covered by tests
Comment on lines +55 to +58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test coverage for error handling.

The error handling for kvIndexerKeeper.RegisterSubmodules is not covered by tests.

Do you want me to assist in generating the test cases for this error handling?

Tools
GitHub Check: codecov/patch

[warning] 57-58: app/indexer.go#L57-L58
Added lines #L57 - L58 were not covered by tests


// Add your implementation here

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

Check warning on line 64 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L64

Added line #L64 was not covered by tests
} else if kvIndexer == nil {
return nil, nil, nil, nil
}

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

Check warning on line 71 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L69-L71

Added lines #L69 - L71 were not covered by tests
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved

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

Check warning on line 75 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L73-L75

Added lines #L73 - L75 were not covered by tests
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved

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

Check warning on line 79 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L77-L79

Added lines #L77 - L79 were not covered by tests
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved

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

Check warning on line 83 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L81-L83

Added lines #L81 - L83 were not covered by tests
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved

kvIndexerModule := kvindexermodule.NewAppModuleBasic(kvIndexerKeeper)
streamingManager := storetypes.StreamingManager{
ABCIListeners: []storetypes.ABCIListener{kvIndexer},
StopNodeOnErr: true,
}

return kvIndexerKeeper, &kvIndexerModule, &streamingManager, nil

Check warning on line 91 in app/indexer.go

View check run for this annotation

Codecov / codecov/patch

app/indexer.go#L85-L91

Added lines #L85 - L91 were not covered by tests
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading