Skip to content

Commit

Permalink
More Agoric tweaks (cosmos#399)
Browse files Browse the repository at this point in the history
* feat: accept rly config show --json

* fix: create client when creating connection

* fix: add missing help format argument

* fix: by default, just set up the connections not the paths

* fix: turn down the agoric log level to prevent too much noise
  • Loading branch information
michaelfig authored Feb 2, 2021
1 parent 1e0ef8a commit 2f1a812
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 37 deletions.
29 changes: 24 additions & 5 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,36 @@ $ %s cfg list`, appName, defaultHome, appName)),
return fmt.Errorf("config does not exist: %s", cfgPath)
}

out, err := yaml.Marshal(config)
jsn, err := cmd.Flags().GetBool(flagJSON)
if err != nil {
return err
}

fmt.Println(string(out))
return nil
yml, err := cmd.Flags().GetBool(flagYAML)
if err != nil {
return err
}
switch {
case yml && jsn:
return fmt.Errorf("can't pass both --json and --yaml, must pick one")
case jsn:
out, err := json.Marshal(config)
if err != nil {
return err
}
fmt.Println(string(out))
return nil
default:
out, err := yaml.Marshal(config)
if err != nil {
return err
}
fmt.Println(string(out))
return nil
}
},
}

return cmd
return yamlFlag(jsonFlag(cmd))
}

// Command for inititalizing an empty config at the --home location
Expand Down
15 changes: 13 additions & 2 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,18 @@ $ %s tx con demo-path -o 3s`, appName, appName, appName)),
return err
}

modified, err := c[src].CreateOpenConnections(c[dst], retries, to)
// ensure that the clients exist
modified, err := c[src].CreateClients(c[dst])
if modified {
if err := overWriteConfig(cmd, config); err != nil {
return err
}
}
if err != nil {
return err
}

modified, err = c[src].CreateOpenConnections(c[dst], retries, to)
if modified {
if err := overWriteConfig(cmd, config); err != nil {
return err
Expand Down Expand Up @@ -401,7 +412,7 @@ $ %s tx link-then-start demo-path --timeout 5s`, appName, appName)),
return sCmd.RunE(cmd, args)
},
}
return strategyFlag(timeoutFlag(cmd))
return strategyFlag(retryFlag(timeoutFlag(cmd)))
}

func relayMsgsCmd() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion configs/agoric.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"daemon": "ag-chain-cosmos",
"cli": "ag-cosmos-helper",
"daemon-testnet": "ag-nchainz testnet $chainid -o $chainid --v 1 --chain-id $chainid --node-dir-prefix n --keyring-backend test",
"daemon-start": "ag-nchainz start-daemon $chainid --home \"$DAEMON_HOME\" start --pruning=nothing",
"daemon-start": "ag-nchainz start-daemon $chainid --home \"$DAEMON_HOME\" start --pruning=nothing --log_level=warn",
"post-light-client": "ag-nchainz start-solos $chainid",
"link": {
"account-prefix": "agoric",
Expand Down
67 changes: 38 additions & 29 deletions scripts/nchainz
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ SRCPORTS=()
DSTS=()
DSTPORTS=()

get_alphabetic() {
id="$1"
ida=$(echo "$1" | sed -e 's/0/zero/g; s/1/one/g; s/2/two/g; s/3/three/g; s/4/four/g; s/5/five/g; s/6/six/g; s/7/seven/g; s/8/eight/g; s/9/nine/g;')
}

validate() {
status=0
# Have at least one default.
Expand Down Expand Up @@ -513,22 +508,48 @@ clients)
exit 0
;;

relay)
connect)
. "$NCONFIG"

paths=
for i in ${!SRCS[@]}; do
src=${SRCS[$i]}
get_alphabetic "$src"
srca=$ida
dst=${DSTS[$i]}

path="path-$i"
paths="$paths $path"
echo "Starting 'rly tx conn $path' ($src<>$dst) logs in $LOGS/$path.log"
(
try=0
while ! rly tx conn $path --timeout=3s -d >> "$LOGS/$path.log" 2>&1; do
try=$(( $try + 1 ))
echo "$path tx conn not yet ready (try=$try)"
sleep 1
done
try=$(( $try + 1 ))
echo "$path tx conn initialized (try=$try)"
) &
done

wait
echo "==============================="
echo "=== All connections initialized"
for path in $paths; do
tail -1 "$LOGS/$path.log"
done
echo "==============================="
exit 0
;;

relay)
. "$NCONFIG"

paths=
for i in ${!SRCS[@]}; do
src=${SRCS[$i]}
dst=${DSTS[$i]}
get_alphabetic "$dst"
dsta=$ida

get_alphabetic "$i"
ia=$ida
path="$ia"
path="path-$i"
paths="$paths $path"
echo "Starting 'rly tx link $path' ($src<>$dst) logs in $LOGS/$path.log"
(
Expand Down Expand Up @@ -627,34 +648,22 @@ done
for i in ${!SRCS[@]}; do
src=${SRCS[$i]}
srcport=${SRCPORTS[$i]}
get_alphabetic "$src"
srca=$ida

dst=${DSTS[$i]}
dstport=${DSTPORTS[$i]}
get_alphabetic "$dst"
dsta=$ida

get_alphabetic "$i"
ia=$ida
path="$ida"
path="path-$i"
out="$BASEDIR/config/$path.json"
echo "creating $out"
cat >"$out" <<EOF
{
"src": {
"chain-id": "$src",
"client-id": "${dsta}client",
"connection-id": "${dsta}link",
"channel-id": "${dsta}xfer${ida}",
"port-id": "$srcport",
"order": "unordered"
},
"dst": {
"chain-id": "$dst",
"client-id": "${srca}client",
"connection-id": "${srca}link",
"channel-id": "${srca}xfer${ida}",
"port-id": "$dstport",
"order": "unordered"
},
Expand All @@ -671,7 +680,7 @@ cat <<EOF
=====================
Done generating $BASEDIR
You can use: \`$progname [run|relay]' at any time.
You can use: \`$progname [run|connect|relay]' at any time.
EOF

Expand All @@ -680,7 +689,7 @@ if [[ $SKIP == norun ]]; then
fi

if [[ $SKIP != yes ]]; then
read -p "Do you wish to \`run', and \`relay' right now (y/N)? " -n 1 -r
read -p "Do you wish to \`run', and \`connect' right now (y/N)? " -n 1 -r
echo

if [[ ! $REPLY =~ ^[Yy]$ ]]; then
Expand All @@ -689,6 +698,6 @@ if [[ $SKIP != yes ]]; then
fi

"$0" run skip &
"$0" relay skip &
"$0" connect skip &
echo "Hit Control-C to exit"
wait

0 comments on commit 2f1a812

Please sign in to comment.