Skip to content

Commit b23fb63

Browse files
committed
chore(p2p): drop unused ENR xxhash versioning path
USE_XX_HASH was never true in production; discv5 already validates via checkCompressedComponentVersion. Removes xxhash/toBufferBE from versioning.ts and tests the string format only.
1 parent ce9fef6 commit b23fb63

2 files changed

Lines changed: 12 additions & 39 deletions

File tree

yarn-project/p2p/src/versioning.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { EthAddress } from '@aztec/foundation/eth-address';
22
import type { ChainConfig } from '@aztec/stdlib/config';
3+
import { checkCompressedComponentVersion, compressComponentVersions } from '@aztec/stdlib/versioning';
34

45
import type { SignableENR } from '@nethermindeth/enr';
56
import { type MockProxy, mock } from 'jest-mock-extended';
67

78
import { AZTEC_ENR_KEY } from './types/index.js';
8-
import { checkAztecEnrVersion, setAztecEnrKey } from './versioning.js';
9+
import { setAztecEnrKey } from './versioning.js';
910

1011
describe('versioning', () => {
1112
let enr: MockProxy<SignableENR>;
@@ -29,14 +30,16 @@ describe('versioning', () => {
2930
};
3031
});
3132

32-
it.each([true, false])('sets and compares versions with xxhash=%s', (useXxHash: boolean) => {
33-
const versions = setAztecEnrKey(enr, chainConfig, useXxHash);
33+
it('sets and compares compressed versions on ENR', () => {
34+
const versions = setAztecEnrKey(enr, chainConfig);
3435
expect(versions.l1ChainId).toEqual(1);
3536
expect(versions.rollupVersion).toEqual(3);
3637
expect(versions.l1RollupAddress).toEqual(chainConfig.l1Contracts.rollupAddress);
37-
expect(versionSet).toHaveLength(useXxHash ? 8 : 33);
38+
expect(Buffer.from(versionSet!).toString()).toEqual(compressComponentVersions(versions));
3839

39-
checkAztecEnrVersion(versionSet, versions);
40-
expect(() => checkAztecEnrVersion(versionSet, { ...versions, l1ChainId: 3 })).toThrow();
40+
checkCompressedComponentVersion(Buffer.from(versionSet!).toString(), versions);
41+
expect(() =>
42+
checkCompressedComponentVersion(Buffer.from(versionSet!).toString(), { ...versions, l1ChainId: 3 }),
43+
).toThrow();
4144
});
4245
});

yarn-project/p2p/src/versioning.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
1-
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
21
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
32
import { protocolContractsHash } from '@aztec/protocol-contracts';
43
import type { ChainConfig } from '@aztec/stdlib/config';
5-
import {
6-
type ComponentsVersions,
7-
checkCompressedComponentVersion,
8-
compressComponentVersions,
9-
getComponentsVersionsFromConfig,
10-
} from '@aztec/stdlib/versioning';
4+
import { compressComponentVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
115

126
import type { SignableENR } from '@nethermindeth/enr';
13-
import xxhashFactory from 'xxhash-wasm';
147

158
import { AZTEC_ENR_CLIENT_VERSION_KEY, AZTEC_ENR_KEY } from './types/index.js';
169

17-
const USE_XX_HASH = false; // Enable to reduce the size of the ENR record for production
18-
const XX_HASH_LEN = 8;
19-
const xxhash = await xxhashFactory();
20-
2110
/** Returns the component versions based on config and this build. */
2211
export function getVersions(config: ChainConfig) {
2312
return getComponentsVersionsFromConfig(config, protocolContractsHash, getVKTreeRoot());
2413
}
2514

2615
/** Sets the aztec key on the ENR record with versioning info. */
27-
export function setAztecEnrKey(enr: SignableENR, config: ChainConfig, useXxHash = USE_XX_HASH) {
16+
export function setAztecEnrKey(enr: SignableENR, config: ChainConfig) {
2817
const versions = getVersions(config);
29-
const value = versionsToEnrValue(versions, useXxHash);
30-
enr.set(AZTEC_ENR_KEY, value);
18+
enr.set(AZTEC_ENR_KEY, Buffer.from(compressComponentVersions(versions)));
3119
return versions;
3220
}
3321

@@ -37,21 +25,3 @@ export function setAztecClientVersionEnrKey(enr: SignableENR, clientVersion: str
3725
enr.set(AZTEC_ENR_CLIENT_VERSION_KEY, Buffer.from(clientVersion));
3826
}
3927
}
40-
41-
/** Checks the given value from an ENR record against the expected versions. */
42-
export function checkAztecEnrVersion(enrValue: Buffer, expectedVersions: ComponentsVersions) {
43-
if (enrValue.length === XX_HASH_LEN) {
44-
const expected = versionsToEnrValue(expectedVersions, true);
45-
if (!Buffer.from(enrValue).equals(expected)) {
46-
throw new Error(`Expected ENR version ${expected.toString('hex')} but received ${enrValue.toString('hex')}`);
47-
}
48-
} else {
49-
const actual = Buffer.from(enrValue).toString();
50-
checkCompressedComponentVersion(actual, expectedVersions);
51-
}
52-
}
53-
54-
function versionsToEnrValue(versions: ComponentsVersions, useXxHash: boolean) {
55-
const compressed = compressComponentVersions(versions);
56-
return useXxHash ? toBufferBE(xxhash.h64(compressed), XX_HASH_LEN) : Buffer.from(compressed);
57-
}

0 commit comments

Comments
 (0)