Skip to content

Commit

Permalink
chore: Granular CLI imports to reduce start time
Browse files Browse the repository at this point in the history
CLI now shows help in under a second.
  • Loading branch information
spalladino committed Dec 16, 2024
1 parent b32ae8a commit 7384479
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 109 deletions.
12 changes: 6 additions & 6 deletions yarn-project/aztec-node/src/aztec-node/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver';
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver/config';
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p';
import { type ProverClientConfig, proverClientConfigMappings } from '@aztec/prover-client';
import { type SequencerClientConfig, sequencerClientConfigMappings } from '@aztec/sequencer-client';
import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client';
import { type WorldStateConfig, worldStateConfigMappings } from '@aztec/world-state';
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
import { type ProverClientConfig, proverClientConfigMappings } from '@aztec/prover-client/config';
import { type SequencerClientConfig, sequencerClientConfigMappings } from '@aztec/sequencer-client/config';
import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
import { type WorldStateConfig, worldStateConfigMappings } from '@aztec/world-state/config';

import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"./fields": "./dest/api/fields.js",
"./init": "./dest/api/init.js",
"./log_id": "./dest/api/log_id.js",
"./rpc": "./dest/rpc_clients/index.js",
"./tx_hash": "./dest/api/tx_hash.js",
"./wallet": "./dest/api/wallet.js"
},
Expand Down Expand Up @@ -118,4 +119,4 @@
"engines": {
"node": ">=18"
}
}
}
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/rpc_clients/pxe_client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type PXE, PXESchema } from '@aztec/circuit-types';
import { type PXE, PXESchema } from '@aztec/circuit-types/interfaces';
import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';

/**
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec
import { AnvilTestWatcher, EthCheatCodes, SignerlessWallet, retryUntil } from '@aztec/aztec.js';
import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
import { type AztecNode } from '@aztec/circuit-types';
import { setupCanonicalL2FeeJuice } from '@aztec/cli/misc';
import { setupCanonicalL2FeeJuice } from '@aztec/cli/setup-contracts';
import {
type DeployL1Contracts,
NULL_KEY,
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/bb-prover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
".": "./dest/index.js",
"./prover": "./dest/prover/index.js",
"./verifier": "./dest/verifier/index.js",
"./test": "./dest/test/index.js"
"./test": "./dest/test/index.js",
"./config": "./dest/config.js"
},
"bin": {
"bb-cli": "./dest/bb/index.js"
Expand Down Expand Up @@ -107,4 +108,4 @@
"engines": {
"node": ">=18"
}
}
}
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { ProverAgentConfig, proverAgentConfigMappings } from './interfaces/prover-agent.js';
export { ProverBrokerConfig, proverBrokerConfigMappings } from './interfaces/prover-broker.js';
export { SequencerConfig, AllowedElement, SequencerConfigSchema } from './interfaces/configs.js';
5 changes: 1 addition & 4 deletions yarn-project/circuit-types/src/interfaces/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export interface SequencerConfig {
acvmBinaryPath?: string;
/** The list of functions calls allowed to run in setup */
allowedInSetup?: AllowedElement[];
/** The list of functions calls allowed to run teardown */
allowedInTeardown?: AllowedElement[];
/** Max block size */
maxBlockSizeInBytes?: number;
/** Whether to require every tx to have a fee payer */
Expand Down Expand Up @@ -63,8 +61,7 @@ export const SequencerConfigSchema = z.object({
feeRecipient: schemas.AztecAddress.optional(),
acvmWorkingDirectory: z.string().optional(),
acvmBinaryPath: z.string().optional(),
allowedInSetup: z.array(AllowedElementSchema),
allowedInTeardown: z.array(AllowedElementSchema),
allowedInSetup: z.array(AllowedElementSchema).optional(),
maxBlockSizeInBytes: z.number().optional(),
enforceFees: z.boolean().optional(),
gerousiaPayload: schemas.EthAddress.optional(),
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/cli-wallet/src/cmds/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getIdentities } from '@aztec/accounts/utils';
import { TxHash, createCompatibleClient } from '@aztec/aztec.js';
import { PublicKeys } from '@aztec/circuits.js';
import { createCompatibleClient } from '@aztec/aztec.js/rpc';
import { TxHash } from '@aztec/aztec.js/tx_hash';
import { PublicKeys } from '@aztec/circuits.js/types';
import {
ETHEREUM_HOST,
PRIVATE_KEY,
Expand Down
10 changes: 6 additions & 4 deletions yarn-project/cli-wallet/src/utils/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getEcdsaRSSHAccount } from '@aztec/accounts/ecdsa';
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import { getIdentities } from '@aztec/accounts/utils';
import { type AccountManager, type AccountWalletWithSecretKey } from '@aztec/aztec.js';
import { AztecAddress, Fr, deriveSigningKey } from '@aztec/circuits.js';
import { type PXE } from '@aztec/circuit-types/interfaces';
import { deriveSigningKey } from '@aztec/circuits.js/keys';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';

import { type PXE } from '../../../circuit-types/src/interfaces/pxe.js';
import { type WalletDB } from '../storage/wallet_db.js';
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';

Expand Down Expand Up @@ -38,6 +38,7 @@ export async function createOrRetrieveAccount(

switch (type) {
case 'schnorr': {
const { getSchnorrAccount } = await import('@aztec/accounts/schnorr');
account = getSchnorrAccount(pxe, secretKey, deriveSigningKey(secretKey), salt);
break;
}
Expand All @@ -58,6 +59,7 @@ export async function createOrRetrieveAccount(
throw new Error('Public key must be provided for ECDSA SSH account');
}

const { getEcdsaRSSHAccount } = await import('@aztec/accounts/ecdsa');
account = getEcdsaRSSHAccount(pxe, secretKey, publicSigningKey, salt);
break;
}
Expand Down
34 changes: 17 additions & 17 deletions yarn-project/cli-wallet/src/utils/options/fees.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
type AccountWallet,
FeeJuicePaymentMethod,
FeeJuicePaymentMethodWithClaim,
type FeePaymentMethod,
NoFeePaymentMethod,
type PXE,
PrivateFeePaymentMethod,
PublicFeePaymentMethod,
type SendMethodOptions,
} from '@aztec/aztec.js';
import { type AccountWallet, type FeePaymentMethod, type PXE, type SendMethodOptions } from '@aztec/aztec.js';
import { AztecAddress, Fr, Gas, GasFees, GasSettings } from '@aztec/circuits.js';
import { type LogFn } from '@aztec/foundation/log';

Expand Down Expand Up @@ -99,10 +89,15 @@ export class FeeOpts implements IFeeOpts {
return new NoFeeOpts(estimateOnly, gasSettings);
}

const defaultPaymentMethod = async () => {
const { NoFeePaymentMethod } = await import('@aztec/aztec.js/fee');
return new NoFeePaymentMethod();
};

return new FeeOpts(
estimateOnly,
gasSettings,
args.payment ? parsePaymentMethod(args.payment, log, db) : () => Promise.resolve(new NoFeePaymentMethod()),
args.payment ? parsePaymentMethod(args.payment, log, db) : defaultPaymentMethod,
!!args.estimateGas,
);
}
Expand Down Expand Up @@ -147,10 +142,12 @@ export function parsePaymentMethod(

return async (sender: AccountWallet) => {
switch (parsed.method) {
case 'none':
case 'none': {
log('Using no fee payment');
const { NoFeePaymentMethod } = await import('@aztec/aztec.js/fee');
return new NoFeePaymentMethod();
case 'native':
}
case 'native': {
if (parsed.claim || (parsed.claimSecret && parsed.claimAmount && parsed.messageLeafIndex)) {
let claimAmount, claimSecret, messageLeafIndex;
if (parsed.claim && db) {
Expand All @@ -163,25 +160,28 @@ export function parsePaymentMethod(
({ claimAmount, claimSecret, messageLeafIndex } = parsed);
}
log(`Using Fee Juice for fee payments with claim for ${claimAmount} tokens`);
const { FeeJuicePaymentMethodWithClaim } = await import('@aztec/aztec.js/fee');
return new FeeJuicePaymentMethodWithClaim(sender.getAddress(), {
claimAmount: typeof claimAmount === 'string' ? Fr.fromHexString(claimAmount) : new Fr(claimAmount),
claimSecret: Fr.fromHexString(claimSecret),
messageLeafIndex: BigInt(messageLeafIndex),
});
} else {
log(`Using Fee Juice for fee payment`);
const { FeeJuicePaymentMethod } = await import('@aztec/aztec.js/fee');
return new FeeJuicePaymentMethod(sender.getAddress());
}
}
case 'fpc-public': {
const [asset, fpc] = getFpcOpts(parsed, db);
log(`Using public fee payment with asset ${asset} via paymaster ${fpc}`);
const { PublicFeePaymentMethod } = await import('@aztec/aztec.js/fee');
return new PublicFeePaymentMethod(asset, fpc, sender);
}
case 'fpc-private': {
const [asset, fpc, feeRecipient] = getFpcOpts(parsed, db);
log(
`Using private fee payment with asset ${asset} via paymaster ${fpc} with rebate secret ${feeRecipient.toString()}`,
);
log(`Using private fee payment with asset ${asset} via paymaster ${fpc} with rebate secret ${feeRecipient}`);
const { PrivateFeePaymentMethod } = await import('@aztec/aztec.js/fee');
return new PrivateFeePaymentMethod(asset, fpc, sender, feeRecipient);
}
case undefined:
Expand Down
1 change: 1 addition & 0 deletions yarn-project/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"./pxe": "./dest/cmds/pxe/index.js",
"./cli-utils": "./dest/utils/index.js",
"./misc": "./dest/cmds/misc/index.js",
"./setup-contracts": "./dest/cmds/misc/setup_contracts.js",
"./utils": "./dest/utils/index.js",
"./inspect": "./dest/utils/inspect.js"
},
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/cli/src/cmds/misc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { type Command } from 'commander';

import { prettyPrintJSON } from '../../utils/commands.js';

export * from './setup_contracts.js';

export function injectCommands(program: Command, log: LogFn) {
program
.command('generate-keys')
Expand Down
1 change: 0 additions & 1 deletion yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export type EnvVar =
| 'REGISTRY_CONTRACT_ADDRESS'
| 'ROLLUP_CONTRACT_ADDRESS'
| 'SEQ_ALLOWED_SETUP_FN'
| 'SEQ_ALLOWED_TEARDOWN_FN'
| 'SEQ_MAX_BLOCK_SIZE_IN_BYTES'
| 'SEQ_MAX_SECONDS_BETWEEN_BLOCKS'
| 'SEQ_MAX_TX_PER_BLOCK'
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/prover-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"./broker": "./dest/proving_broker/index.js",
"./prover-agent": "./dest/prover-agent/index.js",
"./orchestrator": "./dest/orchestrator/index.js",
"./helpers": "./dest/orchestrator/block-building-helpers.js"
"./helpers": "./dest/orchestrator/block-building-helpers.js",
"./config": "./dest/config.js"
},
"typedocOptions": {
"entryPoints": [
Expand Down Expand Up @@ -108,4 +109,4 @@
"engines": {
"node": ">=18"
}
}
}
14 changes: 7 additions & 7 deletions yarn-project/prover-node/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { type ArchiverConfig, archiverConfigMappings, getArchiverConfigFromEnv } from '@aztec/archiver';
import { type ACVMConfig, type BBConfig } from '@aztec/bb-prover';
import { type ArchiverConfig, archiverConfigMappings, getArchiverConfigFromEnv } from '@aztec/archiver/config';
import { type ACVMConfig, type BBConfig } from '@aztec/bb-prover/config';
import {
type ProverAgentConfig,
type ProverBrokerConfig,
proverAgentConfigMappings,
proverBrokerConfigMappings,
} from '@aztec/circuit-types';
} from '@aztec/circuit-types/config';
import {
type ConfigMappingsType,
bigintConfigHelper,
getConfigFromMappings,
numberConfigHelper,
} from '@aztec/foundation/config';
import { type DataStoreConfig, dataConfigMappings, getDataConfigFromEnv } from '@aztec/kv-store/config';
import { type P2PConfig, getP2PConfigFromEnv, p2pConfigMappings } from '@aztec/p2p';
import { type P2PConfig, getP2PConfigFromEnv, p2pConfigMappings } from '@aztec/p2p/config';
import {
type ProverClientConfig,
bbConfigMappings,
getProverEnvVars,
proverClientConfigMappings,
} from '@aztec/prover-client';
} from '@aztec/prover-client/config';
import {
type PublisherConfig,
type TxSenderConfig,
getPublisherConfigFromEnv,
getPublisherConfigMappings,
getTxSenderConfigFromEnv,
getTxSenderConfigMappings,
} from '@aztec/sequencer-client';
import { type WorldStateConfig, getWorldStateConfigFromEnv, worldStateConfigMappings } from '@aztec/world-state';
} from '@aztec/sequencer-client/config';
import { type WorldStateConfig, getWorldStateConfigFromEnv, worldStateConfigMappings } from '@aztec/world-state/config';

import { type ProverBondManagerConfig, proverBondManagerConfigMappings } from './bond/config.js';
import {
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/sequencer-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "@aztec/sequencer-client",
"version": "0.1.0",
"type": "module",
"exports": "./dest/index.js",
"exports": {
".": "./dest/index.js",
"./config": "./dest/config.js"
},
"typedocOptions": {
"entryPoints": [
"./src/index.ts"
Expand Down Expand Up @@ -115,4 +118,4 @@
"../../foundation/src/jest/setup.mjs"
]
}
}
}
51 changes: 4 additions & 47 deletions yarn-project/sequencer-client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AllowedElement } from '@aztec/circuit-types';
import { AztecAddress, Fr, FunctionSelector, getContractClassFromArtifact } from '@aztec/circuits.js';
import { AztecAddress, Fr, FunctionSelector } from '@aztec/circuits.js';
import {
type L1ContractsConfig,
type L1ReaderConfig,
Expand All @@ -14,9 +14,6 @@ import {
} from '@aztec/foundation/config';
import { pickConfigMappings } from '@aztec/foundation/config';
import { EthAddress } from '@aztec/foundation/eth-address';
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';

import {
type PublisherConfig,
Expand All @@ -26,6 +23,9 @@ import {
} from './publisher/config.js';
import { type SequencerConfig } from './sequencer/config.js';

export * from './publisher/config.js';
export * from './sequencer/config.js';

/** Chain configuration. */
type ChainConfig = {
/** The chain id of the ethereum host. */
Expand Down Expand Up @@ -92,18 +92,10 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
allowedInSetup: {
env: 'SEQ_ALLOWED_SETUP_FN',
parseEnv: (val: string) => parseSequencerAllowList(val),
defaultValue: getDefaultAllowedSetupFunctions(),
description: 'The list of functions calls allowed to run in setup',
printDefault: () =>
'AuthRegistry, FeeJuice.increase_public_balance, Token.increase_public_balance, FPC.prepare_fee',
},
allowedInTeardown: {
env: 'SEQ_ALLOWED_TEARDOWN_FN',
parseEnv: (val: string) => parseSequencerAllowList(val),
defaultValue: getDefaultAllowedTeardownFunctions(),
description: 'The list of functions calls allowed to run teardown',
printDefault: () => 'FPC.pay_refund',
},
maxBlockSizeInBytes: {
env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
description: 'Max block size',
Expand Down Expand Up @@ -202,38 +194,3 @@ export function parseSequencerAllowList(value: string): AllowedElement[] {

return entries;
}

function getDefaultAllowedSetupFunctions(): AllowedElement[] {
return [
// needed for authwit support
{
address: ProtocolContractAddress.AuthRegistry,
},
// needed for claiming on the same tx as a spend
{
address: ProtocolContractAddress.FeeJuice,
// We can't restrict the selector because public functions get routed via dispatch.
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'),
},
// needed for private transfers via FPC
{
classId: getContractClassFromArtifact(TokenContractArtifact).id,
// We can't restrict the selector because public functions get routed via dispatch.
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'),
},
{
classId: getContractClassFromArtifact(FPCContract.artifact).id,
// We can't restrict the selector because public functions get routed via dispatch.
// selector: FunctionSelector.fromSignature('prepare_fee((Field),Field,(Field),Field)'),
},
];
}

function getDefaultAllowedTeardownFunctions(): AllowedElement[] {
return [
{
classId: getContractClassFromArtifact(FPCContract.artifact).id,
selector: FunctionSelector.fromSignature('pay_refund((Field),Field,(Field))'),
},
];
}
Loading

0 comments on commit 7384479

Please sign in to comment.