Skip to content

Commit

Permalink
feat(cosmos): clean up OnStartHook and OnExitHook signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig authored and mhofman committed Feb 18, 2024
1 parent 0bb03a0 commit e8a3a77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions golang/cosmos/cmd/agd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ import (
gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
"github.com/Agoric/agoric-sdk/golang/cosmos/daemon"
daemoncmd "github.com/Agoric/agoric-sdk/golang/cosmos/daemon/cmd"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
)

func main() {
// We need to delegate to our default app for running the actual chain.
launchVM := func(logger log.Logger) {
launchVM := func(logger log.Logger, appOpts servertypes.AppOptions) error {
args := []string{"ag-chain-cosmos", "--home", gaia.DefaultNodeHome}
args = append(args, os.Args[1:]...)

binary, lookErr := FindCosmicSwingsetBinary()
if lookErr != nil {
panic(lookErr)
return lookErr
}

logger.Info("agd delegating to JS executable", "binary", binary, "args", args)
execErr := syscall.Exec(binary, args, os.Environ())
if execErr != nil {
panic(execErr)
return execErr
}
return nil
}

daemoncmd.OnStartHook = launchVM
Expand Down
4 changes: 3 additions & 1 deletion golang/cosmos/cmd/libdaemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/Agoric/agoric-sdk/golang/cosmos/daemon"
daemoncmd "github.com/Agoric/agoric-sdk/golang/cosmos/daemon/cmd"
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
)

type goReturn = struct {
Expand Down Expand Up @@ -79,10 +80,11 @@ func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char)
// We run in the background, but exit when the job is over.
// swingset.SendToNode("hello from Initial Go!")
exitCode := 0
daemoncmd.OnStartHook = func(logger log.Logger) {
daemoncmd.OnStartHook = func(logger log.Logger, appOpts servertypes.AppOptions) error {
// We tried running start, which should never exit, so exit with non-zero
// code if we ever stop.
exitCode = 99
return nil
}
daemon.RunWithController(sendToNode)
// fmt.Fprintln(os.Stderr, "Shutting down Cosmos")
Expand Down
14 changes: 9 additions & 5 deletions golang/cosmos/daemon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import (
type Sender func(ctx context.Context, needReply bool, str string) (string, error)

var AppName = "agd"
var OnStartHook func(logger log.Logger)
var OnExportHook func(logger log.Logger)
var OnStartHook func(log.Logger, servertypes.AppOptions) error
var OnExportHook func(log.Logger, servertypes.AppOptions) error

// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
Expand All @@ -62,7 +62,7 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {

rootCmd := &cobra.Command{
Use: AppName,
Short: "Stargate Agoric App",
Short: "Agoric Cosmos App",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
Expand Down Expand Up @@ -231,7 +231,9 @@ func (ac appCreator) newApp(
appOpts servertypes.AppOptions,
) servertypes.Application {
if OnStartHook != nil {
OnStartHook(logger)
if err := OnStartHook(logger, appOpts); err != nil {
panic(err)
}
}

var cache sdk.MultiStorePersistentCache
Expand Down Expand Up @@ -370,7 +372,9 @@ func (ac appCreator) appExport(
appOpts servertypes.AppOptions,
) (servertypes.ExportedApp, error) {
if OnExportHook != nil {
OnExportHook(logger)
if err := OnExportHook(logger, appOpts); err != nil {
return servertypes.ExportedApp{}, err
}
}

homePath, ok := appOpts.Get(flags.FlagHome).(string)
Expand Down

0 comments on commit e8a3a77

Please sign in to comment.