Skip to content

Commit

Permalink
feat: launch cmd (#36)
Browse files Browse the repository at this point in the history
* wip

* feat: use launch from opinit

* bump opinit

* ignore injective proto warning

* seal config in post setup

* tidy

---------

Co-authored-by: beer-1 <[email protected]>
  • Loading branch information
kjessec and beer-1 authored May 3, 2024
1 parent fc6725d commit 54df010
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 33 deletions.
20 changes: 17 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -942,9 +943,22 @@ func NewMinitiaApp(
}
err = msgservice.ValidateProtoAnnotations(protoFiles)
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
}

errMsg += s + "\n"
}

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

// Load the latest state from disk if necessary, and initialize the base-app. From this point on
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/minimove/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,
)
}
56 changes: 37 additions & 19 deletions cmd/minitiad/root.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main

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

"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"

"cosmossdk.io/log"
confixcmd "cosmossdk.io/tools/confix/cmd"
Expand Down Expand Up @@ -57,7 +59,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 @@ -139,17 +143,23 @@ 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 @@ -164,6 +174,9 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b

// add move commands
rootCmd.AddCommand(movecmd.MoveCommand(ac))

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

func addModuleInitFlags(startCmd *cobra.Command) {
Expand Down Expand Up @@ -239,25 +252,30 @@ 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)

app := minitiaapp.NewMinitiaApp(
logger, db, traceStore, true,
moveconfig.GetConfig(appOpts),
appOpts,
baseappOptions...,
)
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)

// store app in creator
a.app = app
app := minitiaapp.NewMinitiaApp(
logger, db, traceStore, true,
moveconfig.GetConfig(appOpts),
appOpts,
baseappOptions...,
)

// 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
28 changes: 25 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/cosmos/ibc-go/v8 v8.2.0
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.1
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/initia-labs/kvindexer v0.1.3
github.com/initia-labs/kvindexer/submodules/block v0.1.0
Expand All @@ -43,6 +43,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
)

require (
Expand All @@ -61,11 +62,16 @@ require (
github.com/DataDog/zstd v1.5.5 // indirect
github.com/IGLOU-EU/go-wildcard v1.0.3 // indirect
github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang v0.0.0-20231213012317-73b6bbf74833 // 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 @@ -78,13 +84,17 @@ require (
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft-db v0.10.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.1.2 // indirect
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-kzg-4844 v0.7.0 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand All @@ -97,6 +107,8 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/go-ethereum v1.13.14 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -107,6 +119,7 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.2.0 // indirect
Expand All @@ -115,6 +128,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 All @@ -137,6 +152,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
Expand All @@ -145,6 +161,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 All @@ -159,6 +176,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
Expand All @@ -180,10 +198,13 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // 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/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 @@ -195,11 +216,11 @@ 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/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 All @@ -217,6 +238,7 @@ require (
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v1.1.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

Expand Down
Loading

0 comments on commit 54df010

Please sign in to comment.