Skip to content

Commit

Permalink
add launch command
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha committed May 3, 2024
1 parent b3c7369 commit 66acd29
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 32 deletions.
18 changes: 17 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -917,7 +918,22 @@ func NewMinitiaApp(
if err != nil {
// Once we switch to using protoreflect-based antehandlers, we might
// want to panic here instead of logging a warning.
fmt.Fprintln(os.Stderr, err.Error())
errMsg := ""

// ignore injective proto annotations comes from github.com/cosoms/relayer
for _, s := range strings.Split(err.Error(), "\n") {
if strings.Contains(s, "injective") {
continue

Check warning on line 926 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L921-L926

Added lines #L921 - L926 were not covered by tests
}

errMsg += s + "\n"

Check warning on line 929 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L929

Added line #L929 was not covered by tests
}

if errMsg != "" {
// Once we switch to using protoreflect-based antehandlers, we might
// want to panic here instead of logging a warning.
fmt.Fprintln(os.Stderr, errMsg)
}

Check warning on line 936 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L932-L936

Added lines #L932 - L936 were not covered by tests
}

// Load the latest state from disk if necessary, and initialize the base-app. From this point on
Expand Down
2 changes: 1 addition & 1 deletion cmd/minitiad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func initAppConfig() (string, interface{}) {
srvCfg.API.Address = "tcp://0.0.0.0:1317"

srvCfg.GRPC.Enable = true
srvCfg.GRPC.Address = "tcp://0.0.0.0:9090"
srvCfg.GRPC.Address = "0.0.0.0:9090"

minitiaAppConfig := minitiaAppConfig{
Config: *srvCfg,
Expand Down
53 changes: 53 additions & 0 deletions cmd/minitiad/launch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"encoding/json"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/types/module"

"github.com/initia-labs/OPinit/contrib/launchtools"
"github.com/initia-labs/OPinit/contrib/launchtools/steps"
"github.com/initia-labs/initia/app/params"
minitiaapp "github.com/initia-labs/minievm/app"
)

// DefaultLaunchStepFactories is a list of default launch step factories.
var DefaultLaunchStepFactories = []launchtools.LauncherStepFuncFactory[launchtools.Input]{
steps.InitializeConfig,
steps.InitializeRPCHelpers,

// Initialize genesis
steps.InitializeGenesis,

// Add system keys to the keyring
steps.InitializeKeyring,

// Run the app
steps.RunApp,

// Establish IBC channels for fungible and NFT transfer
steps.EstablishIBCChannelsWithNFTTransfer(func() (string, string, string) {
return "nft-transfer", "nft-transfer", "ics721-1"
}),

// Enable oracle..?
steps.EnableOracle,

// Create OP Bridge, using open channel states
steps.InitializeOpBridge,

// Cleanup
steps.StopApp,
}

func LaunchCommand(ac *appCreator, enc params.EncodingConfig, mbm module.BasicManager) *cobra.Command {
return launchtools.LaunchCmd(
ac,
func(denom string) map[string]json.RawMessage {
return minitiaapp.NewDefaultGenesisState(enc.Codec, mbm, denom)
},
DefaultLaunchStepFactories,
)
}
55 changes: 36 additions & 19 deletions cmd/minitiad/root.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package main

import (
"context"
"errors"
"io"
"os"
"path"

tmcli "github.com/cometbft/cometbft/libs/cli"
"golang.org/x/sync/errgroup"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -58,7 +60,9 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
sdkConfig.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
sdkConfig.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
sdkConfig.SetAddressVerifier(minitiaapp.VerifyAddressLen())
sdkConfig.Seal()

// seal moved to post setup
// sdkConfig.Seal()

encodingConfig := minitiaapp.MakeEncodingConfig()
basicManager := minitiaapp.BasicManager()
Expand Down Expand Up @@ -140,18 +144,24 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, basicManager module.BasicManager) {
a := &appCreator{nil, encodingConfig}
a := &appCreator{}
// you can get app from a.app in post setup handler

rootCmd.AddCommand(
InitCmd(basicManager, minitiaapp.DefaultNodeHome),
debug.Cmd(),
confixcmd.ConfigCommand(),
pruning.Cmd(a.newApp, minitiaapp.DefaultNodeHome),
snapshot.Cmd(a.newApp),
pruning.Cmd(a.AppCreator(), minitiaapp.DefaultNodeHome),
snapshot.Cmd(a.AppCreator()),
)

server.AddCommands(rootCmd, minitiaapp.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags)
server.AddCommandsWithStartCmdOptions(rootCmd, minitiaapp.DefaultNodeHome, a.AppCreator(), a.appExport, server.StartCmdOptions{
AddFlags: addModuleInitFlags,
PostSetup: func(svrCtx *server.Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error {
sdk.GetConfig().Seal()
return nil
},
})

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
Expand All @@ -161,6 +171,9 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b
txCommand(),
keys.Commands(),
)

// add launch commands
rootCmd.AddCommand(LaunchCommand(a, encodingConfig, basicManager))
}

func addModuleInitFlags(startCmd *cobra.Command) {
Expand Down Expand Up @@ -236,25 +249,29 @@ func txCommand() *cobra.Command {
}

type appCreator struct {
app servertypes.Application
encodingConfig params.EncodingConfig
app servertypes.Application
}

// newApp is an AppCreator
func (a *appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
baseappOptions := server.DefaultBaseappOptions(appOpts)
func (a *appCreator) AppCreator() servertypes.AppCreator {
return func(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
baseappOptions := server.DefaultBaseappOptions(appOpts)

app := minitiaapp.NewMinitiaApp(
logger, db, traceStore, true,
evmconfig.GetConfig(appOpts),
appOpts,
baseappOptions...,
)
app := minitiaapp.NewMinitiaApp(
logger, db, traceStore, true,
evmconfig.GetConfig(appOpts),
appOpts,
baseappOptions...,
)

// store app in creator
a.app = app
// store app in creator
a.app = app

return app
}
}

return app
func (a *appCreator) App() servertypes.Application {
return a.app
}

func (a appCreator) appExport(
Expand Down
17 changes: 14 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/go-metrics v0.5.3
github.com/holiman/uint256 v1.2.4
github.com/initia-labs/OPinit v0.2.6
github.com/initia-labs/OPinit v0.2.7
github.com/initia-labs/initia v0.2.7
github.com/noble-assets/forwarding v0.0.0-20240416085758-ed8e9efaf69a
github.com/pkg/errors v0.9.1
Expand All @@ -45,6 +45,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
Expand All @@ -66,12 +67,16 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/aws/aws-sdk-go v1.44.312 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/celestiaorg/go-square v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
Expand All @@ -92,6 +97,7 @@ require (
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cosmos/relayer/v2 v2.5.2 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
Expand Down Expand Up @@ -128,6 +134,8 @@ require (
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v43 v43.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand Down Expand Up @@ -157,6 +165,7 @@ require (
github.com/initia-labs/OPinit/api v0.2.6 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/jsternberg/zap-logfmt v1.3.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
Expand Down Expand Up @@ -195,13 +204,15 @@ require (
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/strangelove-ventures/cometbft-client v0.1.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
Expand All @@ -213,12 +224,12 @@ require (
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
Loading

0 comments on commit 66acd29

Please sign in to comment.