Skip to content

Commit 2f1a812

Browse files
authored
More Agoric tweaks (cosmos#399)
* 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
1 parent 1e0ef8a commit 2f1a812

File tree

4 files changed

+76
-37
lines changed

4 files changed

+76
-37
lines changed

cmd/config.go

+24-5
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,36 @@ $ %s cfg list`, appName, defaultHome, appName)),
8080
return fmt.Errorf("config does not exist: %s", cfgPath)
8181
}
8282

83-
out, err := yaml.Marshal(config)
83+
jsn, err := cmd.Flags().GetBool(flagJSON)
8484
if err != nil {
8585
return err
8686
}
87-
88-
fmt.Println(string(out))
89-
return nil
87+
yml, err := cmd.Flags().GetBool(flagYAML)
88+
if err != nil {
89+
return err
90+
}
91+
switch {
92+
case yml && jsn:
93+
return fmt.Errorf("can't pass both --json and --yaml, must pick one")
94+
case jsn:
95+
out, err := json.Marshal(config)
96+
if err != nil {
97+
return err
98+
}
99+
fmt.Println(string(out))
100+
return nil
101+
default:
102+
out, err := yaml.Marshal(config)
103+
if err != nil {
104+
return err
105+
}
106+
fmt.Println(string(out))
107+
return nil
108+
}
90109
},
91110
}
92111

93-
return cmd
112+
return yamlFlag(jsonFlag(cmd))
94113
}
95114

96115
// Command for inititalizing an empty config at the --home location

cmd/tx.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,18 @@ $ %s tx con demo-path -o 3s`, appName, appName, appName)),
207207
return err
208208
}
209209

210-
modified, err := c[src].CreateOpenConnections(c[dst], retries, to)
210+
// ensure that the clients exist
211+
modified, err := c[src].CreateClients(c[dst])
212+
if modified {
213+
if err := overWriteConfig(cmd, config); err != nil {
214+
return err
215+
}
216+
}
217+
if err != nil {
218+
return err
219+
}
220+
221+
modified, err = c[src].CreateOpenConnections(c[dst], retries, to)
211222
if modified {
212223
if err := overWriteConfig(cmd, config); err != nil {
213224
return err
@@ -401,7 +412,7 @@ $ %s tx link-then-start demo-path --timeout 5s`, appName, appName)),
401412
return sCmd.RunE(cmd, args)
402413
},
403414
}
404-
return strategyFlag(timeoutFlag(cmd))
415+
return strategyFlag(retryFlag(timeoutFlag(cmd)))
405416
}
406417

407418
func relayMsgsCmd() *cobra.Command {

configs/agoric.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"daemon": "ag-chain-cosmos",
55
"cli": "ag-cosmos-helper",
66
"daemon-testnet": "ag-nchainz testnet $chainid -o $chainid --v 1 --chain-id $chainid --node-dir-prefix n --keyring-backend test",
7-
"daemon-start": "ag-nchainz start-daemon $chainid --home \"$DAEMON_HOME\" start --pruning=nothing",
7+
"daemon-start": "ag-nchainz start-daemon $chainid --home \"$DAEMON_HOME\" start --pruning=nothing --log_level=warn",
88
"post-light-client": "ag-nchainz start-solos $chainid",
99
"link": {
1010
"account-prefix": "agoric",

scripts/nchainz

+38-29
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ SRCPORTS=()
5656
DSTS=()
5757
DSTPORTS=()
5858

59-
get_alphabetic() {
60-
id="$1"
61-
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;')
62-
}
63-
6459
validate() {
6560
status=0
6661
# Have at least one default.
@@ -513,22 +508,48 @@ clients)
513508
exit 0
514509
;;
515510

516-
relay)
511+
connect)
517512
. "$NCONFIG"
518513

519514
paths=
520515
for i in ${!SRCS[@]}; do
521516
src=${SRCS[$i]}
522-
get_alphabetic "$src"
523-
srca=$ida
517+
dst=${DSTS[$i]}
524518

519+
path="path-$i"
520+
paths="$paths $path"
521+
echo "Starting 'rly tx conn $path' ($src<>$dst) logs in $LOGS/$path.log"
522+
(
523+
try=0
524+
while ! rly tx conn $path --timeout=3s -d >> "$LOGS/$path.log" 2>&1; do
525+
try=$(( $try + 1 ))
526+
echo "$path tx conn not yet ready (try=$try)"
527+
sleep 1
528+
done
529+
try=$(( $try + 1 ))
530+
echo "$path tx conn initialized (try=$try)"
531+
) &
532+
done
533+
534+
wait
535+
echo "==============================="
536+
echo "=== All connections initialized"
537+
for path in $paths; do
538+
tail -1 "$LOGS/$path.log"
539+
done
540+
echo "==============================="
541+
exit 0
542+
;;
543+
544+
relay)
545+
. "$NCONFIG"
546+
547+
paths=
548+
for i in ${!SRCS[@]}; do
549+
src=${SRCS[$i]}
525550
dst=${DSTS[$i]}
526-
get_alphabetic "$dst"
527-
dsta=$ida
528551

529-
get_alphabetic "$i"
530-
ia=$ida
531-
path="$ia"
552+
path="path-$i"
532553
paths="$paths $path"
533554
echo "Starting 'rly tx link $path' ($src<>$dst) logs in $LOGS/$path.log"
534555
(
@@ -627,34 +648,22 @@ done
627648
for i in ${!SRCS[@]}; do
628649
src=${SRCS[$i]}
629650
srcport=${SRCPORTS[$i]}
630-
get_alphabetic "$src"
631-
srca=$ida
632651

633652
dst=${DSTS[$i]}
634653
dstport=${DSTPORTS[$i]}
635-
get_alphabetic "$dst"
636-
dsta=$ida
637654

638-
get_alphabetic "$i"
639-
ia=$ida
640-
path="$ida"
655+
path="path-$i"
641656
out="$BASEDIR/config/$path.json"
642657
echo "creating $out"
643658
cat >"$out" <<EOF
644659
{
645660
"src": {
646661
"chain-id": "$src",
647-
"client-id": "${dsta}client",
648-
"connection-id": "${dsta}link",
649-
"channel-id": "${dsta}xfer${ida}",
650662
"port-id": "$srcport",
651663
"order": "unordered"
652664
},
653665
"dst": {
654666
"chain-id": "$dst",
655-
"client-id": "${srca}client",
656-
"connection-id": "${srca}link",
657-
"channel-id": "${srca}xfer${ida}",
658667
"port-id": "$dstport",
659668
"order": "unordered"
660669
},
@@ -671,7 +680,7 @@ cat <<EOF
671680
=====================
672681
Done generating $BASEDIR
673682
674-
You can use: \`$progname [run|relay]' at any time.
683+
You can use: \`$progname [run|connect|relay]' at any time.
675684
676685
EOF
677686

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

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

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

691700
"$0" run skip &
692-
"$0" relay skip &
701+
"$0" connect skip &
693702
echo "Hit Control-C to exit"
694703
wait

0 commit comments

Comments
 (0)