Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

David/ping pong update #923

Merged
merged 9 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/challenger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"description": "A challenger for interacting with Nightfall",
"main": "index.js",
"scripts": {
"start": "export $(cat ../../nightfall-optimist/optimist.env | xargs) && node --trace-warnings src/app.mjs",
"start": "node --trace-warnings src/app.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "daveroga",
"license": "CC0-1.0",
"dependencies": {
"async-mutex": "^0.3.2",
"body-parser": "^1.19.2",
"common-files": "file:../../common-files",
"common-files": "file:../common-files",
"config": "^3.3.1",
"cors": "^2.8.5",
"express": "^4.17.3",
Expand Down
36 changes: 9 additions & 27 deletions apps/challenger/src/app.mjs
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
/* ignore unused exports */
/* eslint-disable import/no-unresolved */

import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import fileUpload from 'express-fileupload';
import config from 'config';
import Nf3 from '../../../cli/lib/nf3.mjs';
import startChallenger from './challenger.mjs';
import Nf3 from '../cli/lib/nf3.mjs';

const CHALLENGER_PORT = process.env.CHALLENGER_PORT || 8192;

const { SIGNING_KEY, CHALLENGER_PORT } = config;
const {
CLIENT_URL = '',
OPTIMIST_HTTP_URL = '',
OPTIMIST_WS_URL = '',
BLOCKCHAIN_URL = '',
PROPOSER_URL = '',
} = process.env;
const environment = {
clientApiUrl:
`${CLIENT_URL}` !== '' ? `${CLIENT_URL}` : `http://${config.CLIENT_HOST}:${config.CLIENT_PORT}`,
optimistApiUrl:
`${OPTIMIST_HTTP_URL}` !== ''
? `${OPTIMIST_HTTP_URL}`
: `http://${config.OPTIMIST_HOST}:${config.OPTIMIST_PORT}`,
optimistWsUrl: `${OPTIMIST_WS_URL}`
? `${OPTIMIST_WS_URL}`
: `ws://${config.OPTIMIST_HOST}:${config.OPTIMIST_WS_PORT}`,
web3WsUrl: `${BLOCKCHAIN_URL}`
? `${BLOCKCHAIN_URL}`
: `ws://${config.BLOCKCHAIN_WS_HOST}:${config.BLOCKCHAIN_PORT}`,
proposerBaseUrl: `${PROPOSER_URL}`
? `${PROPOSER_URL}`
: `http://${process.env.PROPOSER_HOST}:${process.env.PROPOSER_PORT}`,
};
const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;

const app = express();
const nf3 = new Nf3(SIGNING_KEY, environment);
const nf3 = new Nf3(environment.CHALLENGER_KEY, environment);

app.set('nf3', nf3);

Expand All @@ -53,6 +33,8 @@ app.use(
);

app.get('/healthcheck', (req, res) => res.sendStatus(200));
if (!CHALLENGER_PORT) throw new Error('Please specify a challenger port');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this exception ever happen? On line 12 we specify a fallback value of 8192 in case the port is not defined. Either we should get rid of the default value from line 12, or remove this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. Thanks


app.listen(CHALLENGER_PORT);

startChallenger(nf3);
Expand Down
4 changes: 2 additions & 2 deletions apps/challenger/src/challenger.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable import/no-unresolved */
/**
Module that runs up as a challenger
*/
import logger from '../../../common-files/utils/logger.mjs';
import logger from '../common-files/utils/logger.mjs';

/**
Does the preliminary setup and starts listening on the websocket
Expand All @@ -15,7 +16,6 @@ export default async function startChallenger(nf3) {
else throw new Error('Healthcheck failed');
logger.info('Attempting to register challenger');

await nf3.registerChallenger();
await nf3.startChallenger();
logger.info('Listening for incoming events');
}
2 changes: 0 additions & 2 deletions apps/proposer/src/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const PROPOSER_PORT = process.env.PROPOSER_PORT || 8092;

const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;

console.log(environment);

const app = express();
const nf3 = new Nf3(environment.PROPOSER_KEY, environment);

Expand Down
1 change: 0 additions & 1 deletion cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ class Nf3 {
return new Promise((resolve, reject) => {
proposerQueue.push(async () => {
try {
console.log('receipt');
const receipt = await this.submitTransaction(
res.data.txDataToSign,
this.proposersContractAddress,
Expand Down
31 changes: 17 additions & 14 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ module.exports = {
EXCLUDE_DIRS: 'common',
MAX_QUEUE: 5,
TIMBER_HEIGHT: 32,
TXHASH_TREE_HEIGHT: 5,
CONFIRMATION_POLL_TIME: 1000,
CONFIRMATIONS: 12,
DEFAULT_ACCOUNT_NUM: 10,
HASH_TYPE: 'poseidon',
TXHASH_TREE_HASH_TYPE: 'keccak256',
STATE_GENESIS_BLOCK: process.env.STATE_GENESIS_BLOCK,
CIRCUITS_HOME: process.env.CIRCUITS_HOME || '/app/circuits/',
ALWAYS_DO_TRUSTED_SETUP: process.env.ALWAYS_DO_TRUSTED_SETUP || false,
ALWAYS_DO_TRUSTED_SETUP: process.env.ALWAYS_DO_TRUSTED_SETUP || true,
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
MONGO_URL: process.env.MONGO_URL || 'mongodb://localhost:27017/',
PROTOCOL: 'http://', // connect to zokrates microservice like this
Expand All @@ -45,7 +46,7 @@ module.exports = {
MULTISIG: {
SIGNATURE_THRESHOLD: process.env.MULTISIG_SIGNATURE_THRESHOLD || 2, // number of signatures needed to perform an admin task
APPROVERS: process.env.MULTISIG_APPROVERS
? process.env.MULTISG_APPROVERS.split(',')
? process.env.MULTISIG_APPROVERS.split(',')
: [
'0x9C8B2276D490141Ae1440Da660E470E7C0349C63',
'0xfeEDA3882Dd44aeb394caEEf941386E7ed88e0E0',
Expand Down Expand Up @@ -83,7 +84,7 @@ module.exports = {
CURVE: process.env.CURVE || 'bn128',

TRANSACTIONS_PER_BLOCK: Number(process.env.TRANSACTIONS_PER_BLOCK) || 2,
RETRIES: Number(process.env.AUTOSTART_RETRIES) || 150,
RETRIES: Number(process.env.AUTOSTART_RETRIES) || 50,
USE_STUBS: process.env.USE_STUBS === 'true',
VK_IDS: { deposit: 0, transfer: 1, withdraw: 2 }, // used as an enum to mirror the Shield contracts enum for vk types. The keys of this object must correspond to a 'folderpath' (the .zok file without the '.zok' bit)
BN128_GROUP_ORDER: 21888242871839275222246405745257275088548364400416034343698204186575808495617n,
Expand Down Expand Up @@ -166,22 +167,24 @@ module.exports = {
? `wss://${process.env.BLOCKCHAIN_WS_HOST}`
: 'ws://localhost:8546',
PROPOSER_KEY:
process.env.ETH_PRIVATE_KEY ||
process.env.BOOT_PROPOSER_KEY ||
'0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d', // owner's/deployer's private key
CHALLENGER_KEY:
process.env.BOOT_CHALLENGER_KEY ||
'0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
},
aws: {
name: 'AWS',
chainId: 1337,
clientApiUrl: 'http://localhost:8080',
optimistApiUrl: 'https://optimist-api.staging.polygon-nightfall.technology',
optimistWsUrl: 'wss://optimist-ws.staging.polygon-nightfall.technology',
proposerBaseUrl: 'https://proposer.staging.polygon-nightfall.technology',
adversarialOptimistApiUrl: 'http://localhost:8088',
adversarialOptimistWsUrl: 'ws://localhost:8089',
web3WsUrl: 'wss://web3-ws.staging.polygon-nightfall.technology',
PROPOSER_KEY: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d',
PROPOSER_MNEMONIC:
'high return hold whale promote payment hat panel reduce oyster ramp mouse',
clientApiUrl: `http://${process.env.CLIENT_HOST}:${process.env.CLIENT_PORT}`,
optimistApiUrl: `https://${process.env.OPTIMIST_HTTP_HOST}`,
optimistWsUrl: `wss://${process.env.OPTIMIST_HOST}`,
proposerBaseUrl: `https://${process.env.PROPOSER_HOST}`,
web3WsUrl: `wss://${process.env.BLOCKCHAIN_WS_HOST}`,
adversarialOptimistApiUrl: `https://${process.env.OPTIMIST_HTTP_HOST}`,
adversarialOptimistWsUrl: `wss://${process.env.OPTIMIST_HOST}`,
PROPOSER_KEY: process.env.PROPOSER_KEY,
CHALLENGER_KEY: process.env.CHALLENGER_KEY,
},
},
TEST_OPTIONS: {
Expand Down
18 changes: 8 additions & 10 deletions test/ping-pong/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ const txPerBlock =

const { TX_WAIT = 1000, TEST_ERC20_ADDRESS } = process.env;

const TEST_LENGTH = 2;
const TEST_LENGTH = 4;
/**
Does the preliminary setup and starts listening on the websocket
*/
export default async function localTest(IS_TEST_RUNNER) {
logger.info('Starting local test...');
logger.debug('ENVV', environment);

const tokenType = 'ERC20';
const value = 1;
const tokenId = '0x0000000000000000000000000000000000000000000000000000000000000000';
Expand Down Expand Up @@ -109,18 +107,18 @@ export default async function localTest(IS_TEST_RUNNER) {
if (endBalance - startBalance === txPerBlock * value + value * TEST_LENGTH && IS_TEST_RUNNER) {
logger.info('Test passed');
logger.info(
'Balance of User (txPerBlock*value (txPerBlock*1) + value received) ',
endBalance - startBalance,
`Balance of User (txPerBlock*value (txPerBlock*1) + value received) :
${endBalance - startBalance}`,
);
logger.info('Amount sent to other User', value * TEST_LENGTH);
logger.info(`Amount sent to other User: ${value * TEST_LENGTH}`);
nf3.close();
process.exit(0);
} else {
logger.info(
IS_TEST_RUNNER,
'The test has not yet passed because the L2 balance has not increased, or I am not the test runner - waiting',
endBalance - startBalance,
txPerBlock * value + value * TEST_LENGTH,
`The test has not yet passed because the L2 balance has not increased, or I am not the test runner - waiting:
Current Transacted Balance is: ${endBalance - startBalance} - Expecting: ${
txPerBlock * value + value * TEST_LENGTH
}`,
);
await new Promise(resolving => setTimeout(resolving, 20 * TX_WAIT)); // TODO get balance waiting working well
loop++;
Expand Down
21 changes: 13 additions & 8 deletions test/ping-pong/ping-pong.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ const nf3Proposer = new Nf3(signingKeys.proposer1, environment);

describe('Ping-pong tests', () => {
before(async () => {
await nf3Proposer.init(mnemonics.proposer);
// we must set the URL from the point of view of the client container
await nf3Proposer.registerProposer('http://optimist');
await nf3Proposer.startProposer();
if (process.env.ENVIRONMENT !== 'aws') {
console.log('Start proposer');
await nf3Proposer.init(mnemonics.proposer);
// we must set the URL from the point of view of the client container
await nf3Proposer.registerProposer('http://optimist');
await nf3Proposer.startProposer();
}
});

it('Runs ping-pong tests', async () => {
localTest(1);
await localTest(2);
localTest(true);
await localTest(false);
});

after(async () => {
await nf3Proposer.deregisterProposer();
await nf3Proposer.close();
if (process.env.ENVIRONMENT !== 'aws') {
await nf3Proposer.deregisterProposer();
await nf3Proposer.close();
}
});
});
1 change: 1 addition & 0 deletions test/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ export const waitForSufficientBalance = (client, value, ercAddress) => {
return new Promise(resolve => {
async function isSufficientBalance() {
const balance = await retrieveL2Balance(client, ercAddress);
logger.debug(` Balance needed ${value}. Current balance ${balance}.`);
if (balance < value) {
await waitForTimeout(10000);
isSufficientBalance();
Expand Down
4 changes: 4 additions & 0 deletions zokrates-worker/src/zokrates-lib/generate-proof.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default async function generateProof(
throw new Error('generate-proof proving key path file not found');
}

if (!fs.existsSync(witnessPath)) {
throw new Error('generate-proof witness path file not found');
}

if (codePath.endsWith('.zok')) {
throw new Error("Expected the compiled code that didn't end in .code");
}
Expand Down