Skip to content

Commit

Permalink
feat: refactor app struct (#241)
Browse files Browse the repository at this point in the history
* refactor app struct

* add shutdown signal handling

* bump opinit to v0.4.1

* remove unused params

* fix comments

* fix comments to eng

* bump cometbft to latest
  • Loading branch information
beer-1 authored Aug 2, 2024
1 parent 40153e9 commit febea5f
Show file tree
Hide file tree
Showing 23 changed files with 1,580 additions and 1,462 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-linux-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ jobs:
env:
DOCKER_BUILDKIT: 1
run: |
# BuildKit 활성화 및 새 빌더 생성
# Enable BuildKit and create a new builder
docker buildx create --use --name arm64-builder --platform linux/arm64
docker buildx inspect --bootstrap
# ARM64용 이미지 빌드
# Build the image for ARM64
docker buildx build --platform linux/arm64 --load --tag initia/initiad-shared:arm64 . -f Dockerfile.arm64
# ARM64 이미지를 사용하여 빌드 결과물 추출
# Extract the build artifacts using the ARM64 image
mkdir -p ./build
docker create --name temp initia/initiad-shared:arm64
docker cp temp:/usr/local/bin/initiad ./build/
docker cp temp:/lib/libmovevm.so ./build/
docker cp temp:/lib/libcompiler.so ./build/
docker rm temp
# 결과물 패키징
# Package the artifacts
cd ./build
mkdir -p initia_${VERSION}
mv initiad initia_${VERSION}/
Expand All @@ -60,12 +60,12 @@ jobs:
tar -czvf initia_${VERSION}_Linux_${ARCH_NAME}.tar.gz initia_${VERSION}
mv initia_${VERSION}_Linux_${ARCH_NAME}.tar.gz ../
# 빌드 결과 확인
# Check the build result
cd ..
ls -l
file initia_${VERSION}_Linux_${ARCH_NAME}.tar.gz
# 빌더 제거
# Remove the builder
docker buildx rm arm64-builder
- name: List files
Expand Down
1,197 changes: 110 additions & 1,087 deletions app/app.go

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v8/modules/core"

apporacle "github.com/initia-labs/initia/app/oracle"
"github.com/initia-labs/initia/x/bank"
"github.com/initia-labs/initia/x/distribution"
"github.com/initia-labs/initia/x/evidence"
Expand All @@ -46,13 +45,15 @@ import (
moveconfig "github.com/initia-labs/initia/x/move/config"
staking "github.com/initia-labs/initia/x/mstaking"
"github.com/initia-labs/initia/x/reward"

oracleconfig "github.com/skip-mev/slinky/oracle/config"
)

func TestSimAppExportAndBlockedAddrs(t *testing.T) {
app := SetupWithGenesisAccounts(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 All @@ -77,7 +78,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
db := dbm.NewMemDB()
logger := log.NewLogger(os.Stdout)
app := NewInitiaApp(
logger, db, nil, true, moveconfig.DefaultMoveConfig(), apporacle.DefaultConfig(), EmptyAppOptions{})
logger, db, nil, true, moveconfig.DefaultMoveConfig(), oracleconfig.NewDefaultAppConfig(), EmptyAppOptions{})
ctx := app.NewUncachedContext(false, cmtproto.Header{Height: app.LastBlockHeight()})

// Create a mock module. This module will serve as the new module we're
Expand Down Expand Up @@ -143,7 +144,7 @@ func TestGetKey(t *testing.T) {
db := dbm.NewMemDB()
app := NewInitiaApp(
log.NewLogger(os.Stdout),
db, nil, true, moveconfig.DefaultMoveConfig(), apporacle.DefaultConfig(), EmptyAppOptions{})
db, nil, true, moveconfig.DefaultMoveConfig(), oracleconfig.NewDefaultAppConfig(), EmptyAppOptions{})

require.NotEmpty(t, app.GetKey(banktypes.StoreKey))
}
Expand All @@ -153,7 +154,7 @@ func TestChainID(t *testing.T) {
db := dbm.NewMemDB()
app := NewInitiaApp(
log.NewLogger(os.Stdout),
db, nil, true, moveconfig.DefaultMoveConfig(), apporacle.DefaultConfig(), EmptyAppOptions{}, baseapp.SetChainID(chainid),
db, nil, true, moveconfig.DefaultMoveConfig(), oracleconfig.NewDefaultAppConfig(), EmptyAppOptions{}, baseapp.SetChainID(chainid),
)
require.Equal(t, chainid, app.ChainID())
}
147 changes: 147 additions & 0 deletions app/blocksdk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
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"

// this line is used by starport scaffolding # stargate/app/moduleImport

appante "github.com/initia-labs/initia/app/ante"
applanes "github.com/initia-labs/initia/app/lanes"
movekeeper "github.com/initia-labs/initia/x/move/keeper"

// block-sdk dependencies

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

func setupBlockSDK(
app *InitiaApp,
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 := applanes.NewSystemLane(blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.01"),
MaxTxs: 1,
SignerExtractor: signerExtractor,
}, applanes.RejectMatchHandler())

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 := applanes.NewFreeLane(blockbase.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.1"),
MaxTxs: 100,
SignerExtractor: signerExtractor,
}, applanes.FreeLaneMatchHandler())

defaultLane := applanes.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
}

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,
MoveKeeper: movekeeper.NewDexKeeper(app.MoveKeeper),
Codec: app.appCodec,
TxEncoder: app.txConfig.TxEncoder(),
AuctionKeeper: *app.AuctionKeeper,
MevLane: mevLane,
FreeLane: freeLane,
},
)
if err != nil {
return nil, nil, nil, nil, nil, err
}

// 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
}
9 changes: 5 additions & 4 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"

apporacle "github.com/initia-labs/initia/app/oracle"
"github.com/initia-labs/initia/app/params"
moveconfig "github.com/initia-labs/initia/x/move/config"

oracleconfig "github.com/skip-mev/slinky/oracle/config"
)

func MakeEncodingConfig() params.EncodingConfig {
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), apporacle.DefaultConfig(), EmptyAppOptions{})
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), oracleconfig.NewDefaultAppConfig(), EmptyAppOptions{})
encodingConfig := params.EncodingConfig{
InterfaceRegistry: tempApp.InterfaceRegistry(),
Codec: tempApp.AppCodec(),
Expand All @@ -29,7 +30,7 @@ func MakeEncodingConfig() params.EncodingConfig {
}

func AutoCliOpts() autocli.AppOptions {
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), apporacle.DefaultConfig(), EmptyAppOptions{})
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), oracleconfig.NewDefaultAppConfig(), EmptyAppOptions{})
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range tempApp.ModuleManager.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
Expand All @@ -50,7 +51,7 @@ func AutoCliOpts() autocli.AppOptions {
}

func BasicManager() module.BasicManager {
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), apporacle.DefaultConfig(), EmptyAppOptions{})
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), oracleconfig.NewDefaultAppConfig(), EmptyAppOptions{})
return tempApp.BasicModuleManager
}

Expand Down
Loading

0 comments on commit febea5f

Please sign in to comment.