Skip to content

Commit

Permalink
fix(ag-chain-cosmos): keep SwingSet state in the validator state dir
Browse files Browse the repository at this point in the history
Closes #433

We try our best to find the actual Cosmos state directory.
  • Loading branch information
michaelfig committed Jan 21, 2020
1 parent 1aaf14f commit c2e90a4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/cosmic-swingset/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ typings/

# next.js build output
.next
ag-cosmos-chain-state.json
lib/git-revision.txt
agoric/
/binding.gyp
4 changes: 1 addition & 3 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand All @@ -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
Expand Down Expand Up @@ -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; \
Expand Down
33 changes: 29 additions & 4 deletions packages/cosmic-swingset/lib/ag-chain-cosmos
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,35 @@ 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`;
console.log(stateFile);
process.exit(0);

const { launch } = require('./launch-chain');
const path = require('path');
Expand Down

0 comments on commit c2e90a4

Please sign in to comment.