1- import { toBufferBE } from '@aztec/foundation/bigint-buffer' ;
21import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree' ;
32import { protocolContractsHash } from '@aztec/protocol-contracts' ;
43import 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
126import type { SignableENR } from '@nethermindeth/enr' ;
13- import xxhashFactory from 'xxhash-wasm' ;
147
158import { 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. */
2211export 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