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

feat: PXE sync on demand #10613

Merged
merged 33 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
74420bb
wait for pxe to synch before checking balances
Thunkar Dec 9, 2024
92ba769
actually commit
Thunkar Dec 9, 2024
0337f73
comment
Thunkar Dec 9, 2024
a0483db
fix
Thunkar Dec 9, 2024
d989cad
Merge branch 'master' into gj/deflate_e2e_2_pxes
Thunkar Dec 9, 2024
823921e
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Dec 9, 2024
0fde995
merge
Thunkar Dec 9, 2024
0d58475
Merge branch 'gj/deflate_e2e_2_pxes' of github.com:AztecProtocol/azte…
Thunkar Dec 9, 2024
fe40d4f
fmt
Thunkar Dec 10, 2024
3721212
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Dec 10, 2024
9540975
Merge branch 'master' into gj/deflate_e2e_2_pxes
Thunkar Dec 10, 2024
782902a
Merge branch 'master' into gj/deflate_e2e_2_pxes
Thunkar Dec 10, 2024
4a180a0
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Dec 10, 2024
9499176
Merge branch 'master' into gj/deflate_e2e_2_pxes
Thunkar Dec 10, 2024
f91e77e
Merge branch 'master' into gj/deflate_e2e_2_pxes
Thunkar Dec 11, 2024
11a8b71
Merge branch 'gj/deflate_e2e_2_pxes' of github.com:AztecProtocol/azte…
Thunkar Dec 11, 2024
712f25e
synchronize on demand
Thunkar Dec 11, 2024
64b4996
Merge branch 'master' into gj/deflate_e2e_2_pxes
Thunkar Dec 11, 2024
307b76b
Merge branch 'gj/deflate_e2e_2_pxes' of github.com:AztecProtocol/azte…
Thunkar Dec 11, 2024
a120e99
improvements and comments
Thunkar Dec 11, 2024
5a2a6f7
don't sync on note sync
Thunkar Dec 11, 2024
13ff2a6
fmt
Thunkar Dec 11, 2024
3ddccf1
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Dec 11, 2024
2f9a2ee
fix
Thunkar Dec 11, 2024
278c6fe
ffs
Thunkar Dec 11, 2024
da9353f
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Dec 12, 2024
725759e
removed jobqueue, stop, etc
Thunkar Dec 12, 2024
f50c8e9
fmt
Thunkar Dec 12, 2024
00fd955
renaming
Thunkar Dec 12, 2024
bc56c9c
fix
Thunkar Dec 12, 2024
ff200de
typo
Thunkar Dec 12, 2024
77f8ddb
fmt
Thunkar Dec 12, 2024
a2385ba
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Dec 12, 2024
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
1 change: 0 additions & 1 deletion aztec-up/bin/docker-compose.sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ services:
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
PXE_PORT: ${PXE_PORT:-8080}
PORT: ${AZTEC_NODE_PORT:-8080}
Expand Down
25 changes: 14 additions & 11 deletions boxes/boxes/vite/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export class PrivateEnv {
accountContract;
account: AccountManager;

constructor(private secretKey: Fr, private nodeURL: string) {}
constructor(
private secretKey: Fr,
private nodeURL: string,
) {}

async init() {
const config = getPXEServiceConfig();
Expand All @@ -33,20 +36,20 @@ export class PrivateEnv {
const proofCreator = new TestPrivateKernelProver();
this.pxe = await this.createPXEService(aztecNode, config, proofCreator);
const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(
this.secretKey
this.secretKey,
);
this.accountContract = new SingleKeyAccountContract(encryptionPrivateKey);
this.account = new AccountManager(
this.pxe,
this.secretKey,
this.accountContract
this.accountContract,
);
}

async createPXEService(
aztecNode: AztecNode,
config: PXEServiceConfig,
proofCreator?: PrivateKernelProver
proofCreator?: PrivateKernelProver,
) {
const l1Contracts = await aztecNode.getL1ContractAddresses();
const configWithContracts = {
Expand All @@ -57,24 +60,24 @@ export class PrivateEnv {
const store = await createStore(
"pxe_data",
configWithContracts,
createLogger("pxe:data:indexeddb")
createLogger("pxe:data:indexeddb"),
);

const keyStore = new KeyStore(store);

const db = await KVPxeDatabase.create(store);
const tips = new L2TipsStore(store, "pxe");

const server = new PXEService(
const pxe = new PXEService(
keyStore,
aztecNode,
db,
tips,
proofCreator,
config
config,
);
await server.start();
return server;
await pxe.init();
return pxe;
}

async getWallet() {
Expand All @@ -85,7 +88,7 @@ export class PrivateEnv {

export const deployerEnv = new PrivateEnv(
SECRET_KEY,
process.env.PXE_URL || "http://localhost:8080"
process.env.PXE_URL || "http://localhost:8080",
);

const IGNORE_FUNCTIONS = [
Expand All @@ -94,5 +97,5 @@ const IGNORE_FUNCTIONS = [
"sync_notes",
];
export const filteredInterface = BoxReactContractArtifact.functions.filter(
(f) => !IGNORE_FUNCTIONS.includes(f.name)
(f) => !IGNORE_FUNCTIONS.includes(f.name),
);
1 change: 0 additions & 1 deletion boxes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ services:
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
depends_on:
- ethereum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ARCHIVER_POLLING_INTERVAL_MS=50
P2P_BLOCK_CHECK_INTERVAL_MS=50
SEQ_TX_POLLING_INTERVAL_MS=50
WS_BLOCK_CHECK_INTERVAL_MS=50
PXE_BLOCK_POLLING_INTERVAL_MS=50
ARCHIVER_VIEM_POLLING_INTERVAL_MS=500
```

Expand Down Expand Up @@ -90,7 +89,6 @@ Variables like `TEST_ACCOUNTS` & `PXE_PORT` are valid here as described above.
AZTEC_NODE_URL='http://localhost:8079' # The address of an Aztec Node URL that the PXE will connect to (default: http://localhost:8079)
PXE_PORT=8080 # The port that the PXE will be listening to (default: 8080)
TEST_ACCOUNTS='true' # Option to deploy 3 test account when sandbox starts. (default: true)
PXE_BLOCK_POLLING_INTERVAL_MS=50 # Interval to check for new L2 blocks. (default: 50)
PXE_L2_STARTING_BLOCK=1 # L2 Block to start synching the PXE from (default: 1)
```

Expand Down
4 changes: 2 additions & 2 deletions spartan/aztec-network/templates/pxe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ spec:
- -c
- |
curl -s -X POST -H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","method":"pxe_isGlobalStateSynchronized","params":[],"id":67}' \
127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"result":true'
-d '{"jsonrpc":"2.0","method":"pxe_getNodeInfo","params":[],"id":67}' \
127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"protocolVersion":1'
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
initialDelaySeconds: {{ .Values.pxe.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.pxe.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.pxe.readinessProbe.timeoutSeconds }}
Expand Down
14 changes: 0 additions & 14 deletions yarn-project/aztec.js/src/contract/sent_tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,8 @@ describe('SentTx', () => {
pxe.getTxReceipt.mockResolvedValue(txReceipt);
});

it('waits for all notes of the accounts to be available', async () => {
pxe.getSyncStatus.mockResolvedValueOnce({ blocks: 25 }).mockResolvedValueOnce({ blocks: 25 });

const actual = await sentTx.wait({ timeout: 1, interval: 0.4 });
expect(actual).toEqual(txReceipt);
});

it('does not wait for notes sync', async () => {
pxe.getSyncStatus.mockResolvedValue({ blocks: 19 });
const actual = await sentTx.wait({ timeout: 1, interval: 0.4, waitForNotesAvailable: false });
expect(actual).toEqual(txReceipt);
});

it('throws if tx is dropped', async () => {
pxe.getTxReceipt.mockResolvedValue({ ...txReceipt, status: TxStatus.DROPPED } as TxReceipt);
pxe.getSyncStatus.mockResolvedValue({ blocks: 19 });
await expect(sentTx.wait({ timeout: 1, interval: 0.4, ignoreDroppedReceiptsFor: 0 })).rejects.toThrow(/dropped/);
});

Expand Down
17 changes: 1 addition & 16 deletions yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ export type WaitOpts = {
interval?: number;
/** Whether to wait for the tx to be proven. */
proven?: boolean;
/**
* Whether to wait for the node to notify that the block in which this tx was mined is available to fetch notes from.
* If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true.
**/
waitForNotesAvailable?: boolean;
/** Whether to include information useful for debugging/testing in the receipt. */
debug?: boolean;
/** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
Expand All @@ -31,7 +26,6 @@ export const DefaultWaitOpts: WaitOpts = {
provenTimeout: 600,
interval: 1,
debug: false,
waitForNotesAvailable: true,
};

/**
Expand Down Expand Up @@ -124,16 +118,7 @@ export class SentTx {
}
return undefined;
}
// If we don't care about waiting for notes to be synced, return the receipt
const waitForNotesAvailable = opts?.waitForNotesAvailable ?? DefaultWaitOpts.waitForNotesAvailable;
if (!waitForNotesAvailable) {
return txReceipt;
}
// Check if all sync blocks on the PXE Service are greater or equal than the block in which the tx was mined
const { blocks } = await this.pxe.getSyncStatus();
const targetBlock = txReceipt.blockNumber!;
const areNotesAvailable = blocks >= targetBlock;
return areNotesAvailable ? txReceipt : undefined;
return txReceipt;
},
'isMined',
opts?.timeout ?? DefaultWaitOpts.timeout,
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export {
type PXE,
type PartialAddress,
type PublicKey,
type SyncStatus,
} from '@aztec/circuit-types';

// TODO: These kinds of things have no place on our public api.
Expand Down
7 changes: 0 additions & 7 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
type PXEInfo,
type PrivateExecutionResult,
type SiblingPath,
type SyncStatus,
type Tx,
type TxExecutionRequest,
type TxHash,
Expand Down Expand Up @@ -170,12 +169,6 @@ export abstract class BaseWallet implements Wallet {
getNodeInfo(): Promise<NodeInfo> {
return this.pxe.getNodeInfo();
}
isGlobalStateSynchronized() {
return this.pxe.isGlobalStateSynchronized();
}
getSyncStatus(): Promise<SyncStatus> {
return this.pxe.getSyncStatus();
}
addAuthWitness(authWitness: AuthWitness) {
return this.pxe.addAuthWitness(authWitness);
}
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ services:
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
volumes:
- ./log:/usr/src/yarn-project/aztec/log:rw
3 changes: 0 additions & 3 deletions yarn-project/aztec/src/cli/cmds/start_pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,5 @@ export async function addPXE(
// Add PXE to services list
services.pxe = [pxe, PXESchema];

// Add PXE stop function to signal handlers
signalHandlers.push(pxe.stop);

return pxe;
}
1 change: 0 additions & 1 deletion yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
}

const stop = async () => {
await pxe.stop();
await node.stop();
await watcher?.stop();
};
Expand Down
11 changes: 0 additions & 11 deletions yarn-project/bot/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type DeployOptions,
createLogger,
createPXEClient,
retryUntil,
} from '@aztec/aztec.js';
import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types';
import { Fr, deriveSigningKey } from '@aztec/circuits.js';
Expand Down Expand Up @@ -67,16 +66,6 @@ export class BotFactory {
if (isInit) {
this.log.info(`Account at ${account.getAddress().toString()} already initialized`);
const wallet = await account.register();
const blockNumber = await this.pxe.getBlockNumber();
await retryUntil(
async () => {
const status = await this.pxe.getSyncStatus();
return blockNumber <= status.blocks;
},
'pxe synch',
3600,
1,
);
return wallet;
} else {
this.log.info(`Initializing account at ${account.getAddress().toString()}`);
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuit-types/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export * from './proving-job.js';
export * from './pxe.js';
export * from './server_circuit_prover.js';
export * from './service.js';
export * from './sync-status.js';
export * from './world_state.js';
export * from './prover-broker.js';
export * from './p2p.js';
Expand Down
19 changes: 0 additions & 19 deletions yarn-project/circuit-types/src/interfaces/pxe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../t
import { TxEffect } from '../tx_effect.js';
import { TxExecutionRequest } from '../tx_execution_request.js';
import { type EventMetadataDefinition, type PXE, type PXEInfo, PXESchema } from './pxe.js';
import { type SyncStatus } from './sync-status.js';

jest.setTimeout(12_000);

Expand Down Expand Up @@ -258,16 +257,6 @@ describe('PXESchema', () => {
expect(result).toEqual(await handler.getPXEInfo());
});

it('isGlobalStateSynchronized', async () => {
const result = await context.client.isGlobalStateSynchronized();
expect(result).toBe(true);
});

it('getSyncStatus', async () => {
const result = await context.client.getSyncStatus();
expect(result).toEqual(await handler.getSyncStatus());
});

it('getContractInstance', async () => {
const result = await context.client.getContractInstance(address);
expect(result).toEqual(instance);
Expand Down Expand Up @@ -502,14 +491,6 @@ class MockPXE implements PXE {
pxeVersion: '1.0',
});
}
isGlobalStateSynchronized(): Promise<boolean> {
return Promise.resolve(true);
}
getSyncStatus(): Promise<SyncStatus> {
return Promise.resolve({
blocks: 1,
});
}
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
expect(address).toEqual(this.address);
return Promise.resolve(this.instance);
Expand Down
19 changes: 0 additions & 19 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { SiblingPath } from '../sibling_path/sibling_path.js';
import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../tx/index.js';
import { TxEffect } from '../tx_effect.js';
import { TxExecutionRequest } from '../tx_execution_request.js';
import { type SyncStatus, SyncStatusSchema } from './sync-status.js';

// docs:start:pxe-interface
/**
Expand Down Expand Up @@ -351,22 +350,6 @@ export interface PXE {
*/
getPXEInfo(): Promise<PXEInfo>;

/**
* Checks whether all the blocks were processed (tree roots updated, txs updated with block info, etc.).
* @returns True if there are no outstanding blocks to be synched.
* @remarks This indicates that blocks and transactions are synched even if notes are not. Compares local block number with the block number from aztec node.
* @deprecated Use `getSyncStatus` instead.
*/
isGlobalStateSynchronized(): Promise<boolean>;

/**
* Returns the latest block that has been synchronized globally and for each account. The global block number
* indicates whether global state has been updated up to that block, whereas each address indicates up to which
* block the private state has been synced for that account.
* @returns The latest block synchronized for blocks, and the latest block synched for notes for each public key being tracked.
*/
getSyncStatus(): Promise<SyncStatus>;

/**
* Returns a Contract Instance given its address, which includes the contract class identifier,
* initialization hash, deployment salt, and public keys hash.
Expand Down Expand Up @@ -540,8 +523,6 @@ export const PXESchema: ApiSchemaFor<PXE> = {
getProvenBlockNumber: z.function().returns(z.number()),
getNodeInfo: z.function().returns(NodeInfoSchema),
getPXEInfo: z.function().returns(PXEInfoSchema),
isGlobalStateSynchronized: z.function().returns(z.boolean()),
getSyncStatus: z.function().returns(SyncStatusSchema),
getContractInstance: z
.function()
.args(schemas.AztecAddress)
Expand Down
13 changes: 0 additions & 13 deletions yarn-project/circuit-types/src/interfaces/sync-status.ts

This file was deleted.

6 changes: 0 additions & 6 deletions yarn-project/cli-wallet/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js';
import { LOCALHOST } from '@aztec/cli/cli-utils';
import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log';
import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
import { type PXEService } from '@aztec/pxe';

import { Argument, Command, Option } from 'commander';
import { readFileSync } from 'fs';
Expand Down Expand Up @@ -94,11 +93,6 @@ async function main() {
await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe'));
}
db.init(AztecLmdbStore.open(dataDir));
})
.hook('postAction', async () => {
if (pxeWrapper.getPXE()) {
await (pxeWrapper.getPXE() as PXEService).stop();
}
});

injectCommands(program, userLog, debugLogger, db, pxeWrapper);
Expand Down
Loading
Loading