Skip to content

Commit

Permalink
Merge pull request #92 from Agoric/ta/misc-improvements
Browse files Browse the repository at this point in the history
misc improvements (caching, logging, robustness)
  • Loading branch information
turadg authored Feb 6, 2024
2 parents 64c1300 + 18db885 commit 6aa9610
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 69 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
name: Proposal tests

# run on all PRs
# NB: This job works differently for PRs and non-PRs. If you make significant changes,
# be sure to manually trigger the non-PR workflow before merging.

# In PRS,
# - build and run 'test' images
# - no pushing of images
#
# In `main` pushes and manual triggers,
# - build and run 'test' images
# - build 'use' images for *all passed proposals* AND push to registry (e.g. use-upgrade-10)

# In both cases it uses a remote builder with depot.dev (see depot.json) to get a persistent
# build cache and automatic multiplatform builds and image management.

# If `main` fails, you'll make a PR to fix it but its CI will only run the PR flow above.
# To test the non-PR way, you need to manually trigger this workflow by going to,
# https://github.com/Agoric/agoric-3-proposals/actions/workflows/ci.yml
# and clicking "Run workflow", specifying this branch.
on:
pull_request:
workflow_dispatch:
Expand Down Expand Up @@ -103,11 +120,13 @@ jobs:
done
echo "tags=$SUFFIXED" | tee -a $GITHUB_OUTPUT
# The .ts scripts depend upon this
- run: tsx --version || npm install --global tsx
# Enable corepack for packageManager config
- run: corepack enable || sudo corepack enable
- run: yarn install
- name: Setup synthetic-chain
run: |
# The .ts scripts depend upon this
tsx --version || npm install --global tsx
# Enable corepack for packageManager config
corepack enable || sudo corepack enable
yarn install
- run: docker system df
- run: docker buildx du --verbose
Expand Down
9 changes: 8 additions & 1 deletion packages/synthetic-chain/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ doctor - diagnostics and quick fixes
*/
const prepareDockerBuild = () => {
const cliPath = new URL(import.meta.url).pathname;
execSync(`cp -r ${path.resolve(cliPath, '..', 'upgrade-test-scripts')} .`);
// copy and generate files of the build context that aren't in the build contents
execSync(`cp -r ${path.resolve(cliPath, '..', 'docker-bake.hcl')} .`);
writeDockerfile(allProposals, buildConfig.fromTag);
writeBakefileProposals(allProposals);
// copy and generate files to include in the build
execSync(`cp -r ${path.resolve(cliPath, '..', 'upgrade-test-scripts')} .`);
buildProposalSubmissions(proposals);
// set timestamp of build content to zero to avoid invalidating the build cache
// (change in contents will still invalidate)
execSync(
'find upgrade-test-scripts -type f -exec touch -t 197001010000 {} +',
);
};

switch (cmd) {
Expand Down
2 changes: 2 additions & 0 deletions packages/synthetic-chain/src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const buildProposalSubmissions = (proposals: ProposalInfo[]) => {
for (const { fileName } of plan.bundles) {
// Copy the bundle into the submission path.
execSync(`cp ${fileName} ${submissionPath}`);
// Set timestamp to zero to avoid invalidating the build cache
execSync(`touch -t 197001010000 ${submissionPath}/${fileName}`);
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion packages/synthetic-chain/src/cli/dockerfileGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type SoftwareUpgradeProposal,
encodeUpgradeInfo,
imageNameForProposal,
isPassed,
} from './proposals.js';

/**
Expand Down Expand Up @@ -247,7 +248,7 @@ export function writeDockerfile(
previousProposal = proposal;
}
// If one of the proposals is a passed proposal, make the latest one the default entrypoint
const lastPassed = lastPassedProposal(allProposals);
const lastPassed = allProposals.findLast(isPassed);
if (lastPassed) {
blocks.push(stage.DEFAULT(lastPassed));
}
Expand Down
10 changes: 4 additions & 6 deletions packages/synthetic-chain/src/cli/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ export const matchOneProposal = (
return proposals[0];
};

export function lastPassedProposal(
proposals: ProposalInfo[],
): ProposalInfo | undefined {
return proposals.findLast(p => p.proposalIdentifier.match(/^\d/));
}

export function imageNameForProposal(
proposal: Pick<ProposalCommon, 'proposalName'>,
stage: 'test' | 'use',
Expand All @@ -94,3 +88,7 @@ export function imageNameForProposal(
target,
};
}

export function isPassed(proposal: ProposalInfo) {
return proposal.proposalIdentifier.match(/^\d/);
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
// @ts-check
// @jessie-check
import { ExecFileSyncOptionsWithStringEncoding } from 'child_process';

import assert from 'node:assert';

const { freeze } = Object;

const agdBinary = 'agd';

/** @param {{ execFileSync: typeof import('child_process').execFileSync }} io */
export const makeAgd = ({ execFileSync }) => {
console.warn('XXX is sync IO essential?');

/** @param {{ home?: string, keyringBackend?: string, rpcAddrs?: string[] }} keyringOpts */
const make = ({ home, keyringBackend, rpcAddrs } = {}) => {
export const makeAgd = ({
execFileSync,
}: {
execFileSync: typeof import('child_process').execFileSync;
}) => {
const make = (
{ home, keyringBackend, rpcAddrs } = {} as {
home?: string;
keyringBackend?: string;
rpcAddrs?: string[];
},
) => {
const keyringArgs = [
...(home ? ['--home', home] : []),
...(keyringBackend ? [`--keyring-backend`, keyringBackend] : []),
];
console.warn('XXX: rpcAddrs after [0] are ignored');
if (rpcAddrs) {
assert.equal(
rpcAddrs.length,
1,
'XXX rpcAddrs must contain only one entry',
);
}
const nodeArgs = [...(rpcAddrs ? [`--node`, rpcAddrs[0]] : [])];

/**
* @param {string[]} args
* @param {*} [opts]
*/
const exec = (args, opts) => execFileSync(agdBinary, args, opts).toString();
const exec = (
args: string[],
opts?: ExecFileSyncOptionsWithStringEncoding,
) => execFileSync(agdBinary, args, opts).toString();

const outJson = ['--output', 'json'];

const ro = freeze({
status: async () => JSON.parse(exec([...nodeArgs, 'status'])),
/**
* @param {
* | [kind: 'tx', txhash: string]
* | [mod: 'vstorage', kind: 'data' | 'children', path: string]
* } qArgs
*/
query: async qArgs => {
const out = await exec(['query', ...qArgs, ...nodeArgs, ...outJson], {
query: async (
qArgs:
| [kind: 'gov', domain: string, ...rest: any]
| [kind: 'tx', txhash: string]
| [mod: 'vstorage', kind: 'data' | 'children', path: string],
) => {
const out = exec(['query', ...qArgs, ...nodeArgs, ...outJson], {
encoding: 'utf-8',
stdio: ['ignore', 'pipe', 'ignore'],
});

try {
return JSON.parse(out);
} catch (e) {
Expand Down Expand Up @@ -67,11 +80,15 @@ export const makeAgd = ({ execFileSync }) => {
const rw = freeze({
/**
* TODO: gas
*
* @param {string[]} txArgs
* @param {{ chainId: string, from: string, yes?: boolean }} opts
*/
tx: async (txArgs, { chainId, from, yes }) => {
tx: async (
txArgs: string[],
{
chainId,
from,
yes,
}: { chainId: string; from: string; yes?: boolean },
) => {
const yesArg = yes ? ['--yes'] : [];
const args = [
...nodeArgs,
Expand All @@ -97,15 +114,16 @@ export const makeAgd = ({ execFileSync }) => {
readOnly: () => ro,
nameHub: () => nameHub,
keys: {
add: (name, mnemonic) => {
add: (name: string, mnemonic: string) => {
return execFileSync(
agdBinary,
[...keyringArgs, 'keys', 'add', name, '--recover'],
{ input: mnemonic },
).toString();
},
},
withOpts: opts => make({ home, keyringBackend, rpcAddrs, ...opts }),
withOpts: (opts: Record<string, unknown>) =>
make({ home, keyringBackend, rpcAddrs, ...opts }),
});
return rw;
};
Expand Down
9 changes: 7 additions & 2 deletions packages/synthetic-chain/upgrade-test-scripts/env_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ fi

export binary=ag0
if [ -x "$(command -v "agd")" ]; then
# Skip the agoric-sdk/bin/agd wrapper script to prevent it rebuilding sdk
ln -fs /usr/src/agoric-sdk/golang/cosmos/build/agd /usr/local/bin/agd
export binary=agd
fi
export GOV1ADDR=$($binary keys show gov1 -a --keyring-backend="test")
Expand All @@ -25,7 +27,9 @@ export USER1ADDR=$($binary keys show user1 -a --keyring-backend="test")

if [[ "$binary" == "agd" ]]; then
configdir=/usr/src/agoric-sdk/packages/vm-config
test -d "$configdir" || configdir=/usr/src/agoric-sdk/packages/vats
# Check specifically for package.json because the directory may persist in the file system
# across branch changes due to gitignored node_modules
test -f "$configdir/package.json" || configdir=/usr/src/agoric-sdk/packages/vats
# Support testnet addresses
sed -i "s/agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce/$GOV1ADDR/g" "$configdir"/*.json
sed -i "s/agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang/$GOV2ADDR/g" "$configdir"/*.json
Expand Down Expand Up @@ -57,6 +61,7 @@ if [[ "$binary" == "agd" ]]; then
fi

startAgd() {
echo "Starting agd in background"
agd start --log_level warn "$@" &
AGD_PID=$!
echo $AGD_PID >$HOME/.agoric/agd.pid
Expand Down Expand Up @@ -193,7 +198,7 @@ printKeys() {
echo "========== GOVERNANCE KEYS =========="
for i in ~/.agoric/*.key; do
name=$(basename $i .key)
echo "$name:"$'\t'$(agd keys add $name --dry-run --recover --keyring-backend=test --output=json < $i | jq -r .address) || true
echo "$name:"$'\t'$(agd keys add $name --dry-run --recover --keyring-backend=test --output=json <$i | jq -r .address) || true
echo $'\t'$(cat $i)
done
echo "========== GOVERNANCE KEYS =========="
Expand Down
16 changes: 10 additions & 6 deletions packages/synthetic-chain/upgrade-test-scripts/run_eval.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@ set -e

source ./env_setup.sh

PROPOSAL_PATH=$1
PROPOSAL=$1
if [ -z "$PROPOSAL" ]; then
echo "Must specify what proposal to use"
exit 1
fi

startAgd

echo "Agd started. Running CoreEval submission."
cd /usr/src/proposals/"$PROPOSAL_PATH/" || exit
echo "[$PROPOSAL] Agd started. Running CoreEval submission."
cd /usr/src/proposals/"$PROPOSAL/" || exit

# eval_submission doesn't really need to be .ts but it imports .ts files
tsx --version || npm install --global tsx

if [ -f "eval.sh" ]; then
# this is what the script used to do. Also allows a proposal to override how they are eval-ed
echo "Running eval.sh"
echo "[$PROPOSAL] Running eval.sh"
./eval.sh
else
# newer proposals declare a submission
echo "Running proposal declared in package.json"
echo "[$PROPOSAL] Running proposal declared in package.json"
# copy to run in the proposal package so the dependencies can be resolved
cp /usr/src/upgrade-test-scripts/eval_submission.ts .
./eval_submission.ts
fi

echo "Eval completed. Running 10 blocks and exiting."
echo "[$PROPOSAL] Eval completed. Running 10 blocks and exiting."
waitForBlock 10
16 changes: 12 additions & 4 deletions packages/synthetic-chain/upgrade-test-scripts/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ set -e

source ./env_setup.sh

PROPOSAL_PATH=$1
PROPOSAL=$1
if [ -z "$PROPOSAL" ]; then
echo "Must specify what proposal to use"
exit 1
fi

echo "[$PROPOSAL] Starting agd"

echo "[$PROPOSAL_PATH] Starting agd"

startAgd

echo "Agd started. Running test.sh."
cd /usr/src/proposals/"$PROPOSAL_PATH/" || exit
echo "[$PROPOSAL] Running test.sh."
cd /usr/src/proposals/"$PROPOSAL/" || exit
./test.sh

echo "Testing completed."
echo "[$PROPOSAL] Testing completed."
22 changes: 11 additions & 11 deletions packages/synthetic-chain/upgrade-test-scripts/run_use.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

set -e

ID=$1
if [ -z "$ID" ]; then
PROPOSAL=$1
if [ -z "$PROPOSAL" ]; then
echo "Must specify what proposal to use"
exit 1
fi
PROPOSAL_PATH="/usr/src/proposals/$ID/"
PROPOSAL_PROPOSAL="/usr/src/proposals/$PROPOSAL/"

if [ ! -d "$PROPOSAL_PATH" ]; then
echo "Proposal $ID does not exist"
if [ ! -d "$PROPOSAL_PROPOSAL" ]; then
echo "Proposal $PROPOSAL does not exist"
exit 1
fi

if [ ! -f "$PROPOSAL_PATH/use.sh" ]; then
echo "Proposal $ID does not have a use.sh. Skipping."
if [ ! -f "$PROPOSAL_PROPOSAL/use.sh" ]; then
echo "Proposal $PROPOSAL does not have a use.sh. Skipping."
exit 0
fi

source ./env_setup.sh

echo "Starting agd in the background."
echo "[$PROPOSAL] Starting agd in the background."
startAgd

echo "Agd started. Running use.sh."
cd "$PROPOSAL_PATH"
echo "[$PROPOSAL] Agd started. Running use.sh."
cd "$PROPOSAL_PROPOSAL"
./use.sh

echo "Actions completed. Running for a few blocks and exiting."
echo "[$PROPOSAL] Actions completed. Running for a few blocks and exiting."
waitForBlock 5
1 change: 1 addition & 0 deletions packages/synthetic-chain/upgrade-test-scripts/start_agd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ source ./env_setup.sh
export SLOGFILE=slog.slog

# don't use startAgd() because that backgrounds
echo "Starting agd in foreground"
agd start --log_level warn "$@"
4 changes: 3 additions & 1 deletion proposals/16:upgrade-8/use.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ set -e

source /usr/src/upgrade-test-scripts/env_setup.sh

# XXX fix bug in this SDK's verison of agops
sed -i "s/--econCommAcceptOfferId /--previousOfferId /g" "/usr/src/agoric-sdk/packages/agoric-cli/src/commands/psm.js"

#region precheck
# ensure there's nothing in the provision pool
test_val "$(agd q bank balances agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346 -o json | jq -r '.balances | length')" "0" "ensure nothing is in provisionpool"
BALANCE="$(agd q bank balances agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346 -o json)"
test_val "$(echo $BALANCE | jq -r '.balances | length')" "0" "provisionpool balance should be empty but was $BALANCE"

# Test no smart wallet for
test_val "$(agd q vstorage data published.wallet.$GOV1ADDR -o json | jq -r .value)" "" "ensure gov1 not provisioned"
Expand Down
Loading

0 comments on commit 6aa9610

Please sign in to comment.