diff --git a/golang/cosmos/Makefile b/golang/cosmos/Makefile index 3b1aee787f3c..02692a44cb3f 100644 --- a/golang/cosmos/Makefile +++ b/golang/cosmos/Makefile @@ -47,7 +47,7 @@ SHARED_BUILD_FLAGS := -tags "$(build_tags)" -gcflags '$(gcflags)' -ldflags '$(sh all: compile-chain -compile-chain: compile-agd compile-daemon +compile-chain: compile-agd compile-daemon compile-tools compile-go: compile-agd compile-libdaemon compile-node: node-compile-gyp @@ -77,6 +77,9 @@ compile-libdaemon: go-mod-cache go build -v $(MOD_READONLY) $(SHARED_BUILD_FLAGS) -buildmode=c-shared \ -o build/libagcosmosdaemon.so ./cmd/libdaemon/main.go +compile-tools: + go build -o build/runtillmsg ./cmd/runtillmsg + go-mod-cache: go.sum @echo "--> Download go modules to local cache" @go mod download @@ -106,7 +109,7 @@ t: TM_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/tendermint/tendermint)/proto/tendermint GOGO_PROTO_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/gogo/protobuf) -IBC_PROTO_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/ibc-go/v3)/proto/ibc/core +IBC_PROTO_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/ibc-go/v4)/proto/ibc/core COSMOS_SDK_PROTO_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/cosmos-sdk)/proto/cosmos GOGO_PROTO_TYPES = third_party/proto/gogoproto diff --git a/golang/cosmos/cmd/runtillmsg/main.go b/golang/cosmos/cmd/runtillmsg/main.go new file mode 100644 index 000000000000..2c99708b1db6 --- /dev/null +++ b/golang/cosmos/cmd/runtillmsg/main.go @@ -0,0 +1,60 @@ +package main + +// Runs a subcommand until a given string is seen on a line in the stderr output, +// then sends SIGINT the subprocess and propagates its exit status. + +import ( + "bufio" + "log" + "os" + "os/exec" + "strings" + "syscall" +) + +func main() { + if len(os.Args) < 3 { + log.Fatal("usage: runtillmsg msg cmd arg...") + } + msg, cmdName, args := os.Args[1], os.Args[2], os.Args[3:] + + // launch the command and listen to its stderr + cmd := exec.Command(cmdName, args...) + stderr, err := cmd.StderrPipe() + if err != nil { + log.Fatal(err) + } + err = cmd.Start() + if err != nil { + log.Fatal(err) + } + + // copy lines of stderr, but interrupt the command if we see msg + scanner := bufio.NewScanner(stderr) + for scanner.Scan() { + line := scanner.Text() + if strings.Contains(line, msg) { + err = cmd.Process.Signal(syscall.SIGINT) + if err != nil { + log.Fatal(err) + } + } + os.Stderr.WriteString(line + "\n") + } + err = scanner.Err() + if err != nil { + log.Fatal(err) + } + stderr.Close() + + // wait for the command to exit, and propagate its exit code + err = cmd.Wait() + if err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + os.Exit(exitErr.ExitCode()) + } + log.Fatal(err) + os.Exit(2) + } + // if cmd.Wait returns nil, exit code was 0, so just end +} diff --git a/packages/cosmic-swingset/Makefile b/packages/cosmic-swingset/Makefile index dd652870173e..8a14c784d4cf 100644 --- a/packages/cosmic-swingset/Makefile +++ b/packages/cosmic-swingset/Makefile @@ -156,11 +156,16 @@ scenario2-run-chain: ../vm-config/decentral-devnet-config.json OTEL_EXPORTER_PROMETHEUS_PORT=$(OTEL_EXPORTER_PROMETHEUS_PORT) \ $(AGC) --home=t1/n0 start --log_level=warn $(AGC_START_ARGS) +tools: + cd ../../golang/cosmos && make compile-tools + # Run a chain with an explicit halt. BLOCKS_TO_RUN=3 -scenario2-run-chain-to-halt: t1/decentral-economy-config.json +scenario2-run-chain-to-halt: t1/decentral-economy-config.json tools CHAIN_BOOTSTRAP_VAT_CONFIG="$$PWD/t1/decentral-economy-config.json" \ - $(AGC) --home=t1/n0 start --log_level=warn --halt-height=$$(($(INITIAL_HEIGHT) + $(BLOCKS_TO_RUN))); \ + DEBUG=$(DEBUG) PATH="$$PWD/bin:$$PATH" \ + ../../golang/cosmos/build/runtillmsg "halt application" \ + "$(SDK_ROOT)/bin/agd" --home=t1/n0 start --log_level=warn --halt-height=$$(($(INITIAL_HEIGHT) + $(BLOCKS_TO_RUN))); \ test "$$?" -eq 98 echo ran to $(INITIAL_HEIGHT) + $(BLOCKS_TO_RUN)