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: NodeInfo cleanup #2370

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 6 additions & 7 deletions yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class AztecRPCServer implements AztecRPC {
private contractDataOracle: ContractDataOracle;
private simulator: AcirSimulator;
private log: DebugLogger;
private clientInfo: string;
private sandboxVersion: string;

constructor(
private keyStore: KeyStore,
Expand All @@ -82,8 +82,7 @@ export class AztecRPCServer implements AztecRPC {
this.contractDataOracle = new ContractDataOracle(db, node);
this.simulator = getAcirSimulator(db, node, node, node, keyStore, this.contractDataOracle);

const { version, name } = getPackageInfo();
this.clientInfo = `${name.split('/')[name.split('/').length - 1]}@${version}`;
this.sandboxVersion = getPackageInfo().version;
}

/**
Expand All @@ -94,7 +93,7 @@ export class AztecRPCServer implements AztecRPC {
public async start() {
await this.synchroniser.start(INITIAL_L2_BLOCK_NUM, 1, this.config.l2BlockPollingIntervalMS);
const info = await this.getNodeInfo();
this.log.info(`Started RPC server connected to chain ${info.chainId} version ${info.version}`);
this.log.info(`Started RPC server connected to chain ${info.chainId} version ${info.protocolVersion}`);
}

/**
Expand Down Expand Up @@ -345,11 +344,11 @@ export class AztecRPCServer implements AztecRPC {
]);

return {
version,
sandboxVersion: this.sandboxVersion,
compatibleNargoVersion: NoirVersion.tag,
chainId,
protocolVersion: version,
rollupAddress,
client: this.clientInfo,
compatibleNargoVersion: NoirVersion.tag,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const aztecRpcTestSuite = (testName: string, aztecRpcSetup: () => Promise

it('successfully gets node info', async () => {
const nodeInfo = await rpc.getNodeInfo();
expect(typeof nodeInfo.version).toEqual('number');
expect(typeof nodeInfo.protocolVersion).toEqual('number');
expect(typeof nodeInfo.chainId).toEqual('number');
expect(nodeInfo.rollupAddress.toString()).toMatch(/0x[a-fA-F0-9]+/);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export class DefaultAccountInterface implements AccountInterface {
constructor(
private authWitnessProvider: AuthWitnessProvider,
private address: CompleteAddress,
nodeInfo: Pick<NodeInfo, 'chainId' | 'version'>,
nodeInfo: Pick<NodeInfo, 'chainId' | 'protocolVersion'>,
) {
this.entrypoint = new DefaultAccountEntrypoint(
address.address,
authWitnessProvider,
nodeInfo.chainId,
nodeInfo.version,
nodeInfo.protocolVersion,
);
}

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('Contract Class', () => {
const mockTxReceipt = { type: 'TxReceipt' } as any as TxReceipt;
const mockViewResultValue = 1;
const mockNodeInfo: NodeInfo = {
version: 1,
sandboxVersion: 'vx.x.x',
compatibleNargoVersion: 'vx.x.x-aztec.x',
protocolVersion: 1,
chainId: 2,
rollupAddress: EthAddress.random(),
client: '',
compatibleNargoVersion: 'vx.x.x-aztec.x',
};

const defaultAbi: ContractAbi = {
Expand Down
11 changes: 9 additions & 2 deletions yarn-project/aztec.js/src/contract_deployer/deploy_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
const portalContract = options.portalContract ?? EthAddress.ZERO;
const contractAddressSalt = options.contractAddressSalt ?? Fr.random();

const { chainId, version } = await this.rpc.getNodeInfo();
const { chainId, protocolVersion } = await this.rpc.getNodeInfo();

const { completeAddress, constructorHash, functionTreeRoot } = await getContractDeploymentInfo(
this.abi,
Expand All @@ -77,7 +77,14 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
portalContract,
);

const txContext = new TxContext(false, false, true, contractDeploymentData, new Fr(chainId), new Fr(version));
const txContext = new TxContext(
false,
false,
true,
contractDeploymentData,
new Fr(chainId),
new Fr(protocolVersion),
);
const args = encodeArguments(this.constructorAbi, this.args);
const functionData = FunctionData.fromAbi(this.constructorAbi);
const execution = { args, functionData, to: completeAddress.address };
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/wallet/signerless_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class SignerlessWallet extends BaseWallet {
const [execution] = executions;
const wasm = await CircuitsWasm.get();
const packedArguments = await PackedArguments.fromArgs(execution.args, wasm);
const { chainId, version } = await this.rpc.getNodeInfo();
const txContext = TxContext.empty(chainId, version);
const { chainId, protocolVersion } = await this.rpc.getNodeInfo();
const txContext = TxContext.empty(chainId, protocolVersion);
return Promise.resolve(
new TxExecutionRequest(
execution.to,
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/cli/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ describe('client', () => {
});

it('checks versions match', async () => {
rpc.getNodeInfo.mockResolvedValue({ client: 'rpc@0.1.0-alpha47' } as NodeInfo);
rpc.getNodeInfo.mockResolvedValue({ sandboxVersion: '0.1.0-alpha47' } as NodeInfo);
await checkServerVersion(rpc, '0.1.0-alpha47');
});

it('reports mismatch on older rpc version', async () => {
rpc.getNodeInfo.mockResolvedValue({ client: 'rpc@0.1.0-alpha47' } as NodeInfo);
rpc.getNodeInfo.mockResolvedValue({ sandboxVersion: '0.1.0-alpha47' } as NodeInfo);
await expect(checkServerVersion(rpc, '0.1.0-alpha48')).rejects.toThrowError(
/is older than the expected by this CLI/,
);
});

it('reports mismatch on newer rpc version', async () => {
rpc.getNodeInfo.mockResolvedValue({ client: 'rpc@0.1.0-alpha48' } as NodeInfo);
rpc.getNodeInfo.mockResolvedValue({ sandboxVersion: '0.1.0-alpha48' } as NodeInfo);
await expect(checkServerVersion(rpc, '0.1.0-alpha47')).rejects.toThrowError(
/is newer than the expected by this CLI/,
);
Expand Down
23 changes: 12 additions & 11 deletions yarn-project/cli/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,26 @@ class VersionMismatchError extends Error {}
*/
export async function checkServerVersion(rpc: AztecRPC, expectedVersionRange: string) {
const serverName = 'Aztec Sandbox';
const { client } = await rpc.getNodeInfo();
if (!client) {
const { sandboxVersion } = await rpc.getNodeInfo();
if (!sandboxVersion) {
throw new VersionMismatchError(`Couldn't determine ${serverName} version. You may run into issues.`);
}
const version = client.split('@')[1];
if (!version || !valid(version)) {
throw new VersionMismatchError(`Missing or invalid version identifier for ${serverName} (${version ?? 'empty'}).`);
} else if (!satisfies(version, expectedVersionRange)) {
if (gtr(version, expectedVersionRange)) {
if (!sandboxVersion || !valid(sandboxVersion)) {
throw new VersionMismatchError(
`Missing or invalid version identifier for ${serverName} (${sandboxVersion ?? 'empty'}).`,
);
} else if (!satisfies(sandboxVersion, expectedVersionRange)) {
if (gtr(sandboxVersion, expectedVersionRange)) {
throw new VersionMismatchError(
`${serverName} is running version ${version} which is newer than the expected by this CLI (${expectedVersionRange}). Consider upgrading your CLI to a newer version.`,
`${serverName} is running version ${sandboxVersion} which is newer than the expected by this CLI (${expectedVersionRange}). Consider upgrading your CLI to a newer version.`,
);
} else if (ltr(version, expectedVersionRange)) {
} else if (ltr(sandboxVersion, expectedVersionRange)) {
throw new VersionMismatchError(
`${serverName} is running version ${version} which is older than the expected by this CLI (${expectedVersionRange}). Consider upgrading your ${serverName} to a newer version.`,
`${serverName} is running version ${sandboxVersion} which is older than the expected by this CLI (${expectedVersionRange}). Consider upgrading your ${serverName} to a newer version.`,
);
} else {
throw new VersionMismatchError(
`${serverName} is running version ${version} which does not match the expected by this CLI (${expectedVersionRange}).`,
`${serverName} is running version ${sandboxVersion} which does not match the expected by this CLI (${expectedVersionRange}).`,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_sandbox_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('e2e_sandbox_example', () => {
logger('Aztec Sandbox Info ', nodeInfo);
// docs:end:setup

expect(typeof nodeInfo.version).toBe('number');
expect(typeof nodeInfo.protocolVersion).toBe('number');
expect(typeof nodeInfo.chainId).toBe('number');
expect(typeof nodeInfo.rollupAddress).toBe('object');

Expand Down
20 changes: 10 additions & 10 deletions yarn-project/types/src/interfaces/aztec_rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ export interface DeployedContract {
*/
export type NodeInfo = {
/**
* The version number of the node.
* Version as tracked in the aztec-packages repository.
*/
version: number;
sandboxVersion: string;
/**
* The network's chain id.
* The nargo version compatible with this sandbox version
*/
chainId: number;
compatibleNargoVersion: string;
/**
* The rollup contract address
* L1 chain id.
*/
rollupAddress: EthAddress;
chainId: number;
/**
* Identifier of the client software.
* Protocol version.
*/
client: string;
protocolVersion: number;
/**
* The nargo version compatible with this node.
* The rollup contract address
*/
compatibleNargoVersion: string;
rollupAddress: EthAddress;
};

/** Provides up to which block has been synced by different components. */
Expand Down