Skip to content

Commit

Permalink
fix: TXE logs in docker (#8365)
Browse files Browse the repository at this point in the history
Closes #8270

Changed strategy when running `TXE` from aztec binary, now using compose
to avoid logs being swallowed. Env variables `DEBUG` and `LOG_LEVEL` can
be used as usual to control verbosity.

This allows using `dep::aztec::oracle::debug_log::debug_log_format` and
variants when running `aztec test`.
  • Loading branch information
Thunkar authored Sep 4, 2024
1 parent 0330ced commit 157dd11
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
21 changes: 13 additions & 8 deletions aztec-up/bin/aztec
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,34 @@ function parse_ts_file {
grep -oE "\| '[^']+'" "$LOCAL_TS_FILE" | sed "s/| '//; s/'//g" >"$LOCAL_ENV_VAR_FILE"
}

function cleanup {
get_compose $@ down
}

CALLED_FROM=$PWD

if [ "${1:-}" == "test" ]; then
# Change working dir, so relative volume mounts are in the right place.
cd $(dirname $0)/..
# Compose file to use
FILE_ARG="-f $HOME/.aztec/docker-compose.test.yml"

# Set trap to catch SIGINT and call the cleanup function.
trap "cleanup $FILE_ARG" SIGINT

# Aztec contract test args for nargo
TEST_ARGS="$@ --silence-warnings --oracle-resolver http://aztec:8081"
get_compose -p aztec-test $FILE_ARG run -e NARGO_FOREIGN_CALL_TIMEOUT=300000 --workdir $CALLED_FROM --rm -it aztec-nargo $TEST_ARGS
export TEST_ARGS="$@ --silence-warnings --oracle-resolver http://txe:8081"
export NARGO_FOREIGN_CALL_TIMEOUT=300000
export WORKDIR=$CALLED_FROM
get_compose -p aztec-test $FILE_ARG up --force-recreate --remove-orphans --abort-on-container-exit
elif [ $# == 2 ] && [ "$1" == "start" ] && [ "$2" == "--sandbox" ]; then
# Change working dir, so relative volume mounts are in the right place.
cd $(dirname $0)/..
# Compose file to use
FILE_ARG="-f $HOME/.aztec/docker-compose.sandbox.yml"

# Function to be executed when SIGINT is received.
cleanup() {
get_compose $FILE_ARG down
}

# Set trap to catch SIGINT and call the cleanup function.
trap cleanup SIGINT
trap "cleanup $FILE_ARG" SIGINT

get_compose -p sandbox $FILE_ARG up --force-recreate --remove-orphans
elif [ "${1:-}" == "start" ]; then
Expand Down
11 changes: 7 additions & 4 deletions aztec-up/bin/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
services:
aztec:
txe:
image: "aztecprotocol/aztec"
environment:
DEBUG: # Loaded from the user shell if explicitly set
LOG_LEVEL: # Loaded from the user shell if explicitly set
HOST_WORKDIR: "${PWD}" # Loaded from the user shell to show log files absolute path in host
volumes:
- ./log:/usr/src/yarn-project/aztec/log:rw
- ${HOME}:${HOME}
command: start --txe --port 8081

aztec-nargo:
image: "aztecprotocol/aztec-nargo"
environment:
HOME: # Loaded from the user shell
NARGO_FOREIGN_CALL_TIMEOUT: 300000 # To avoid timeouts when many tests run at once
NARGO_FOREIGN_CALL_TIMEOUT: "${NARGO_FOREIGN_CALL_TIMEOUT}" # To avoid timeouts when many tests run at once
working_dir: "${WORKDIR}"
command: "${TEST_ARGS}"
volumes:
- ${HOME}:${HOME}
depends_on:
- aztec
- txe
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ You can also use the `assert_public_call_fails` or `assert_private_call_fails` m

#include_code assert_public_fail /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_public.nr rust

### Logging

You can use `aztec.nr`'s oracles as usual for debug logging, as explained [here](../../../../reference/developer_references/debugging.md)

:::warning
Remember to set the following environment variables to activate debug logging:
```bash
export DEBUG="aztec:*"
export LOG_LEVEL="debug"
```
:::

### All Cheatcodes

You can find the full list of cheatcodes available in the TXE [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr)
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ unconstrained fn access_control() {
// Impersonate original admin
env.impersonate(owner);

// Try to set ourselves as admin, fail miserably
// Try to set ourselves as admin, fail miserably
let set_admin_call_interface = Token::at(token_contract_address).set_admin(recipient);
env.assert_public_call_fails(set_admin_call_interface);

// Try to revoke minter status to recipient, fail miserably
// Try to revoke minter status to recipient, fail miserably
let set_minter_call_interface = Token::at(token_contract_address).set_minter(recipient, false);
env.assert_public_call_fails(set_minter_call_interface);
}
4 changes: 2 additions & 2 deletions yarn-project/txe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ class TXEDispatcher {
this.logger.debug(`Calling ${functionName} on session ${sessionId}`);

if (!TXESessions.has(sessionId) && functionName != 'reset') {
this.logger.info(`Creating new session ${sessionId}`);
this.logger.debug(`Creating new session ${sessionId}`);
TXESessions.set(sessionId, await TXEService.init(this.logger));
}

switch (functionName) {
case 'reset': {
TXESessions.delete(sessionId) &&
this.logger.info(`Called reset on session ${sessionId}, yeeting it out of existence`);
this.logger.debug(`Called reset on session ${sessionId}, yeeting it out of existence`);
return toForeignCallResult([]);
}
case 'deploy': {
Expand Down
12 changes: 11 additions & 1 deletion yarn-project/txe/src/txe_service/txe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class TXEService {
const noteCache = new ExecutionNoteCache(txHash);
const keyStore = new KeyStore(store);
const txeDatabase = new TXEDatabase(store);
logger.info(`TXE service initialized`);
logger.debug(`TXE service initialized`);
const txe = new TXE(logger, trees, packedValuesCache, noteCache, keyStore, txeDatabase);
const service = new TXEService(logger, txe);
await service.advanceBlocksBy(toSingle(new Fr(1n)));
Expand Down Expand Up @@ -308,6 +308,16 @@ export class TXEService {
return toForeignCallResult([toSingle(functionSelector.toField())]);
}

async avmOpcodeChainId() {
const chainId = await (this.typedOracle as TXE).getChainId();
return toForeignCallResult([toSingle(chainId)]);
}

async avmOpcodeVersion() {
const version = await (this.typedOracle as TXE).getVersion();
return toForeignCallResult([toSingle(version)]);
}

async packArgumentsArray(args: ForeignCallArray) {
const packed = await this.typedOracle.packArgumentsArray(fromArray(args));
return toForeignCallResult([toSingle(packed)]);
Expand Down

0 comments on commit 157dd11

Please sign in to comment.