From 95131ce3f2c691bbe548bcd73198220bb3387836 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Tue, 21 Jan 2020 11:03:23 -0600 Subject: [PATCH] fix(ag-chain-cosmos): keep SwingSet state in the validator state dir Closes #433 We try our best to find the actual Cosmos state directory. --- packages/cosmic-swingset/.gitignore | 1 - packages/cosmic-swingset/Makefile | 4 +-- packages/cosmic-swingset/lib/ag-chain-cosmos | 31 +++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/cosmic-swingset/.gitignore b/packages/cosmic-swingset/.gitignore index 8b774430eb3..e865f9cdfac 100644 --- a/packages/cosmic-swingset/.gitignore +++ b/packages/cosmic-swingset/.gitignore @@ -85,7 +85,6 @@ typings/ # next.js build output .next -ag-cosmos-chain-state.json lib/git-revision.txt agoric/ /binding.gyp diff --git a/packages/cosmic-swingset/Makefile b/packages/cosmic-swingset/Makefile index 899f697ba03..c291773f302 100644 --- a/packages/cosmic-swingset/Makefile +++ b/packages/cosmic-swingset/Makefile @@ -27,7 +27,6 @@ all: build-cosmos install scenario0-setup: rm -rf ~/.ag-chain-cosmos - rm -f ag-cosmos-chain-state.json python3 -mvenv ve3 ve3/bin/pip install setup-solo/ @@ -49,7 +48,6 @@ scenario1-run-client: AGC = ./lib/ag-chain-cosmos scenario2-setup: build-cosmos rm -rf ~/.ag-chain-cosmos - rm -f ag-cosmos-chain-state.json $(AGC) init scenario2-chain --chain-id=$(CHAIN_ID) rm -rf t1 mkdir t1 @@ -148,7 +146,7 @@ start-ag-solo: cd t1 && ../bin/ag-solo start show-local-gci: - @./calc-gci.js ~/.ag-cosmos-chain/config/genesis.json + @./calc-gci.js ~/.ag-chain-cosmos/config/genesis.json set-local-gci-ingress: set -e; \ diff --git a/packages/cosmic-swingset/lib/ag-chain-cosmos b/packages/cosmic-swingset/lib/ag-chain-cosmos index a564e7e271f..557556d5f67 100755 --- a/packages/cosmic-swingset/lib/ag-chain-cosmos +++ b/packages/cosmic-swingset/lib/ag-chain-cosmos @@ -8,10 +8,33 @@ const BEGIN_BLOCK = 'BEGIN_BLOCK'; const DELIVER_INBOUND = 'DELIVER_INBOUND'; const AG_COSMOS_INIT = 'AG_COSMOS_INIT'; -// TODO: use the 'basedir' pattern, or find the cosmos state directory -// (~/.ag-chain-cosmos ?), or something anything better than scribbling -// into the current directory. -const stateFile = 'ag-cosmos-chain-state.json'; +// TODO: use the 'basedir' pattern + +// Try to determine the cosmos chain home. +function getFlagValue(flagName, deflt) { + let flagValue = deflt; + const envValue = process.env[`AG_CHAIN_COSMOS_${flagName.toUpperCase()}`]; + if (envValue !== undefined) { + flagValue = envValue; + } + const flag = `--${flagName}`; + const flagEquals = `--${flagName}=`; + for (let i = 0; i < process.argv.length; i += 1) { + const arg = process.argv[i]; + if (arg === flag) { + i += 1; + flagValue = process.argv[i]; + } else if (arg.startsWith(flagEquals)) { + flagValue = arg.substr(flagEquals.length); + } + } + return flagValue; +} + +// We try to find the actual cosmos state directory (default=~/.ag-chain-cosmos), which +// is better than scribbling into the current directory. +const cosmosHome = getFlagValue('home', `${process.env.HOME}/.ag-chain-cosmos`); +const stateFile = `${cosmosHome}/data/ag-cosmos-chain-state.json`; const { launch } = require('./launch-chain'); const path = require('path');