Skip to content

Commit

Permalink
feat(agoricd): have agoricd start delegate to ag-chain-cosmos
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 11, 2021
1 parent 26c9994 commit 1740795
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func NewAgoricApp(

// This function is tricky to get right, so we build it ourselves.
callToController := func(ctx sdk.Context, str string) (string, error) {
if sendToController == nil || vm.IsSimulation(ctx) {
if vm.IsSimulation(ctx) {
// Just return empty, since the message is being simulated.
return "", nil
}
Expand Down
29 changes: 29 additions & 0 deletions golang/cosmos/cmd/agoricd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package main

import (
"os"
"os/exec"
"path/filepath"
"syscall"

"github.com/tendermint/tendermint/libs/log"

gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
"github.com/Agoric/agoric-sdk/golang/cosmos/daemon"
Expand All @@ -16,6 +20,31 @@ func main() {
}

gaia.DefaultNodeHome = filepath.Join(userHomeDir, ".agoricd")

oldAppName := daemoncmd.AppName
daemoncmd.AppName = "agoricd"

if daemoncmd.AppName != oldAppName {
// We need to delegate to our default app for running the actual chain.
daemoncmd.OnStartHook = func(logger log.Logger) {
logger.Info("Start chain delegating to another executable",
"startApp", oldAppName,
)

binary, lookErr := exec.LookPath(oldAppName)
if lookErr != nil {
panic(lookErr)
}

args := append([]string{oldAppName}, "--home", gaia.DefaultNodeHome)
args = append(args, os.Args[1:]...)

execErr := syscall.Exec(binary, args, os.Environ())
if execErr != nil {
panic(execErr)
}
}
}

daemon.RunWithController(nil)
}
5 changes: 5 additions & 0 deletions golang/cosmos/daemon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
type Sender func(needReply bool, str string) (string, error)

var AppName = "ag-chain-cosmos"
var OnStartHook func(log.Logger)

// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
Expand Down Expand Up @@ -190,6 +191,10 @@ func txCommand() *cobra.Command {

func makeNewApp(sender Sender) func(log.Logger, dbm.DB, io.Writer, servertypes.AppOptions) servertypes.Application {
return func(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
if OnStartHook != nil {
OnStartHook(logger)
}

var cache sdk.MultiStorePersistentCache

if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
Expand Down

0 comments on commit 1740795

Please sign in to comment.