@aztec/epoch-cache 3.0.0-canary.a9708bd → 3.0.0-manual.20251030

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dest/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { type L1ContractsConfig, type L1ReaderConfig } from '@aztec/ethereum';
2
- export type EpochCacheConfig = Pick<L1ReaderConfig & L1ContractsConfig, 'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'aztecSlotDuration' | 'ethereumSlotDuration' | 'aztecEpochDuration'>;
2
+ export type EpochCacheConfig = Pick<L1ReaderConfig & L1ContractsConfig, 'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration'>;
3
3
  export declare function getEpochCacheConfigEnvVars(): EpochCacheConfig;
4
4
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,cAAc,GAAG,iBAAiB,EAChC,WAAW,GACX,WAAW,GACX,uBAAuB,GACvB,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,CACvB,CAAC;AAEF,wBAAgB,0BAA0B,IAAI,gBAAgB,CAE7D"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,cAAc,GAAG,iBAAiB,EAClC,WAAW,GAAG,WAAW,GAAG,uBAAuB,GAAG,sBAAsB,CAC7E,CAAC;AAEF,wBAAgB,0BAA0B,IAAI,gBAAgB,CAE7D"}
@@ -45,16 +45,19 @@ export declare class EpochCache implements EpochCacheInterface {
45
45
  private rollup;
46
46
  private readonly l1constants;
47
47
  private readonly dateProvider;
48
- private readonly config;
49
- private cache;
48
+ protected readonly config: {
49
+ cacheSize: number;
50
+ validatorRefreshIntervalSeconds: number;
51
+ };
52
+ protected cache: Map<bigint, EpochCommitteeInfo>;
50
53
  private allValidators;
51
54
  private lastValidatorRefresh;
52
55
  private readonly log;
53
- constructor(rollup: RollupContract, initialEpoch?: bigint, initialValidators?: EthAddress[] | undefined, initialSampleSeed?: bigint, l1constants?: L1RollupConstants, dateProvider?: DateProvider, config?: {
56
+ constructor(rollup: RollupContract, l1constants?: L1RollupConstants, dateProvider?: DateProvider, config?: {
54
57
  cacheSize: number;
55
58
  validatorRefreshIntervalSeconds: number;
56
59
  });
57
- static create(rollupAddress: EthAddress, config?: EpochCacheConfig, deps?: {
60
+ static create(rollupOrAddress: EthAddress | RollupContract, config?: EpochCacheConfig, deps?: {
58
61
  dateProvider?: DateProvider;
59
62
  }): Promise<EpochCache>;
60
63
  getL1Constants(): L1RollupConstants;
@@ -93,6 +96,12 @@ export declare class EpochCache implements EpochCacheInterface {
93
96
  currentProposer: EthAddress | undefined;
94
97
  nextProposer: EthAddress | undefined;
95
98
  }>;
99
+ /**
100
+ * Get the proposer attester address in the given L2 slot
101
+ * @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
102
+ * If the committee is empty (i.e. target committee size is 0, and anyone can propose), we return undefined.
103
+ */
104
+ getProposerAttesterAddressInSlot(slot: bigint): Promise<EthAddress | undefined>;
96
105
  /**
97
106
  * Get the proposer attester address in the next slot
98
107
  * @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
@@ -1 +1 @@
1
- {"version":3,"file":"epoch_cache.d.ts","sourceRoot":"","sources":["../src/epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAuB,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,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AC,kBAAkB,CAAC;IAsB7E,OAAO,CAAC,oBAAoB;YAUd,gBAAgB;IAO9B;;OAEG;IACH,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE;IAW3E,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAQ5F;;;;;OAKG;IACU,6CAA6C,IAAI,OAAO,CAAC;QACpE,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,eAAe,EAAE,UAAU,GAAG,SAAS,CAAC;QACxC,YAAY,EAAE,UAAU,GAAG,SAAS,CAAC;KACtC,CAAC;IAYF;;;;OAIG;IACI,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAKtF;;;;OAIG;IACI,oCAAoC,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAK9E;;;;;OAKG;YACW,4BAA4B;IAanC,6BAA6B,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAclH,4DAA4D;IACtD,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ3E,+FAA+F;IACzF,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IASjF,uBAAuB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAUvD"}
@@ -22,7 +22,7 @@ import { getEpochCacheConfigEnvVars } from './config.js';
22
22
  allValidators;
23
23
  lastValidatorRefresh;
24
24
  log;
25
- constructor(rollup, initialEpoch = 0n, initialValidators = undefined, initialSampleSeed = 0n, l1constants = EmptyL1RollupConstants, dateProvider = new DateProvider(), config = {
25
+ constructor(rollup, l1constants = EmptyL1RollupConstants, dateProvider = new DateProvider(), config = {
26
26
  cacheSize: 12,
27
27
  validatorRefreshIntervalSeconds: 60
28
28
  }){
@@ -34,44 +34,41 @@ import { getEpochCacheConfigEnvVars } from './config.js';
34
34
  this.allValidators = new Set();
35
35
  this.lastValidatorRefresh = 0;
36
36
  this.log = createLogger('epoch-cache');
37
- this.cache.set(initialEpoch, {
38
- epoch: initialEpoch,
39
- committee: initialValidators,
40
- seed: initialSampleSeed
41
- });
42
- this.log.debug(`Initialized EpochCache with ${initialValidators?.length ?? 'no'} validators`, {
43
- l1constants,
44
- initialValidators,
45
- initialSampleSeed,
46
- initialEpoch
37
+ this.log.debug(`Initialized EpochCache`, {
38
+ l1constants
47
39
  });
48
40
  }
49
- static async create(rollupAddress, config, deps = {}) {
41
+ static async create(rollupOrAddress, config, deps = {}) {
50
42
  config = config ?? getEpochCacheConfigEnvVars();
51
- const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
52
- const publicClient = createPublicClient({
53
- chain: chain.chainInfo,
54
- transport: fallback(config.l1RpcUrls.map((url)=>http(url))),
55
- pollingInterval: config.viemPollingIntervalMS
56
- });
57
- const rollup = new RollupContract(publicClient, rollupAddress.toString());
58
- const [l1StartBlock, l1GenesisTime, initialValidators, sampleSeed, epochNumber, proofSubmissionEpochs] = await Promise.all([
43
+ // Load the rollup contract if we were given an address
44
+ let rollup;
45
+ if ('address' in rollupOrAddress) {
46
+ rollup = rollupOrAddress;
47
+ } else {
48
+ const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
49
+ const publicClient = createPublicClient({
50
+ chain: chain.chainInfo,
51
+ transport: fallback(config.l1RpcUrls.map((url)=>http(url))),
52
+ pollingInterval: config.viemPollingIntervalMS
53
+ });
54
+ rollup = new RollupContract(publicClient, rollupOrAddress.toString());
55
+ }
56
+ const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration] = await Promise.all([
59
57
  rollup.getL1StartBlock(),
60
58
  rollup.getL1GenesisTime(),
61
- rollup.getCurrentEpochCommittee(),
62
- rollup.getCurrentSampleSeed(),
63
- rollup.getEpochNumber(),
64
- rollup.getProofSubmissionEpochs()
59
+ rollup.getProofSubmissionEpochs(),
60
+ rollup.getSlotDuration(),
61
+ rollup.getEpochDuration()
65
62
  ]);
66
63
  const l1RollupConstants = {
67
64
  l1StartBlock,
68
65
  l1GenesisTime,
69
66
  proofSubmissionEpochs: Number(proofSubmissionEpochs),
70
- slotDuration: config.aztecSlotDuration,
71
- epochDuration: config.aztecEpochDuration,
67
+ slotDuration: Number(slotDuration),
68
+ epochDuration: Number(epochDuration),
72
69
  ethereumSlotDuration: config.ethereumSlotDuration
73
70
  };
74
- return new EpochCache(rollup, epochNumber, initialValidators?.map((v)=>EthAddress.fromString(v)), sampleSeed, l1RollupConstants, deps.dateProvider);
71
+ return new EpochCache(rollup, l1RollupConstants, deps.dateProvider);
75
72
  }
76
73
  getL1Constants() {
77
74
  return this.l1constants;
@@ -204,6 +201,14 @@ import { getEpochCacheConfigEnvVars } from './config.js';
204
201
  };
205
202
  }
206
203
  /**
204
+ * Get the proposer attester address in the given L2 slot
205
+ * @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
206
+ * If the committee is empty (i.e. target committee size is 0, and anyone can propose), we return undefined.
207
+ */ getProposerAttesterAddressInSlot(slot) {
208
+ const epochAndSlot = this.getEpochAndSlotAtSlot(slot);
209
+ return this.getProposerAttesterAddressAt(epochAndSlot);
210
+ }
211
+ /**
207
212
  * Get the proposer attester address in the next slot
208
213
  * @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
209
214
  * If the committee is empty (i.e. target committee size is 0, and anyone can propose), we return undefined.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/epoch-cache",
3
- "version": "3.0.0-canary.a9708bd",
3
+ "version": "3.0.0-manual.20251030",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -26,16 +26,16 @@
26
26
  "../package.common.json"
27
27
  ],
28
28
  "dependencies": {
29
- "@aztec/ethereum": "3.0.0-canary.a9708bd",
30
- "@aztec/foundation": "3.0.0-canary.a9708bd",
31
- "@aztec/l1-artifacts": "3.0.0-canary.a9708bd",
32
- "@aztec/stdlib": "3.0.0-canary.a9708bd",
29
+ "@aztec/ethereum": "3.0.0-manual.20251030",
30
+ "@aztec/foundation": "3.0.0-manual.20251030",
31
+ "@aztec/l1-artifacts": "3.0.0-manual.20251030",
32
+ "@aztec/stdlib": "3.0.0-manual.20251030",
33
33
  "@viem/anvil": "^0.0.10",
34
34
  "dotenv": "^16.0.3",
35
35
  "get-port": "^7.1.0",
36
36
  "jest-mock-extended": "^4.0.0",
37
37
  "tslib": "^2.4.0",
38
- "viem": "2.23.7",
38
+ "viem": "npm:@spalladino/viem@2.38.2-eip7594.0",
39
39
  "zod": "^3.23.8"
40
40
  },
41
41
  "devDependencies": {
package/src/config.ts CHANGED
@@ -7,12 +7,7 @@ import {
7
7
 
8
8
  export type EpochCacheConfig = Pick<
9
9
  L1ReaderConfig & L1ContractsConfig,
10
- | 'l1RpcUrls'
11
- | 'l1ChainId'
12
- | 'viemPollingIntervalMS'
13
- | 'aztecSlotDuration'
14
- | 'ethereumSlotDuration'
15
- | 'aztecEpochDuration'
10
+ 'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration'
16
11
  >;
17
12
 
18
13
  export function getEpochCacheConfigEnvVars(): EpochCacheConfig {
@@ -58,71 +58,61 @@ export interface EpochCacheInterface {
58
58
  * Note: This class is very dependent on the system clock being in sync.
59
59
  */
60
60
  export class EpochCache implements EpochCacheInterface {
61
- private cache: Map<bigint, EpochCommitteeInfo> = new Map();
61
+ protected cache: Map<bigint, EpochCommitteeInfo> = new Map();
62
62
  private allValidators: Set<string> = new Set();
63
63
  private lastValidatorRefresh = 0;
64
64
  private readonly log: Logger = createLogger('epoch-cache');
65
65
 
66
66
  constructor(
67
67
  private rollup: RollupContract,
68
- initialEpoch: bigint = 0n,
69
- initialValidators: EthAddress[] | undefined = undefined,
70
- initialSampleSeed: bigint = 0n,
71
68
  private readonly l1constants: L1RollupConstants = EmptyL1RollupConstants,
72
69
  private readonly dateProvider: DateProvider = new DateProvider(),
73
- private readonly config = { cacheSize: 12, validatorRefreshIntervalSeconds: 60 },
70
+ protected readonly config = { cacheSize: 12, validatorRefreshIntervalSeconds: 60 },
74
71
  ) {
75
- this.cache.set(initialEpoch, { epoch: initialEpoch, committee: initialValidators, seed: initialSampleSeed });
76
- this.log.debug(`Initialized EpochCache with ${initialValidators?.length ?? 'no'} validators`, {
72
+ this.log.debug(`Initialized EpochCache`, {
77
73
  l1constants,
78
- initialValidators,
79
- initialSampleSeed,
80
- initialEpoch,
81
74
  });
82
75
  }
83
76
 
84
77
  static async create(
85
- rollupAddress: EthAddress,
78
+ rollupOrAddress: EthAddress | RollupContract,
86
79
  config?: EpochCacheConfig,
87
80
  deps: { dateProvider?: DateProvider } = {},
88
81
  ) {
89
82
  config = config ?? getEpochCacheConfigEnvVars();
90
83
 
91
- const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
92
- const publicClient = createPublicClient({
93
- chain: chain.chainInfo,
94
- transport: fallback(config.l1RpcUrls.map(url => http(url))),
95
- pollingInterval: config.viemPollingIntervalMS,
96
- });
84
+ // Load the rollup contract if we were given an address
85
+ let rollup: RollupContract;
86
+ if ('address' in rollupOrAddress) {
87
+ rollup = rollupOrAddress;
88
+ } else {
89
+ const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
90
+ const publicClient = createPublicClient({
91
+ chain: chain.chainInfo,
92
+ transport: fallback(config.l1RpcUrls.map(url => http(url))),
93
+ pollingInterval: config.viemPollingIntervalMS,
94
+ });
95
+ rollup = new RollupContract(publicClient, rollupOrAddress.toString());
96
+ }
97
97
 
98
- const rollup = new RollupContract(publicClient, rollupAddress.toString());
99
- const [l1StartBlock, l1GenesisTime, initialValidators, sampleSeed, epochNumber, proofSubmissionEpochs] =
100
- await Promise.all([
101
- rollup.getL1StartBlock(),
102
- rollup.getL1GenesisTime(),
103
- rollup.getCurrentEpochCommittee(),
104
- rollup.getCurrentSampleSeed(),
105
- rollup.getEpochNumber(),
106
- rollup.getProofSubmissionEpochs(),
107
- ] as const);
98
+ const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration] = await Promise.all([
99
+ rollup.getL1StartBlock(),
100
+ rollup.getL1GenesisTime(),
101
+ rollup.getProofSubmissionEpochs(),
102
+ rollup.getSlotDuration(),
103
+ rollup.getEpochDuration(),
104
+ ] as const);
108
105
 
109
106
  const l1RollupConstants: L1RollupConstants = {
110
107
  l1StartBlock,
111
108
  l1GenesisTime,
112
109
  proofSubmissionEpochs: Number(proofSubmissionEpochs),
113
- slotDuration: config.aztecSlotDuration,
114
- epochDuration: config.aztecEpochDuration,
110
+ slotDuration: Number(slotDuration),
111
+ epochDuration: Number(epochDuration),
115
112
  ethereumSlotDuration: config.ethereumSlotDuration,
116
113
  };
117
114
 
118
- return new EpochCache(
119
- rollup,
120
- epochNumber,
121
- initialValidators?.map(v => EthAddress.fromString(v)),
122
- sampleSeed,
123
- l1RollupConstants,
124
- deps.dateProvider,
125
- );
115
+ return new EpochCache(rollup, l1RollupConstants, deps.dateProvider);
126
116
  }
127
117
 
128
118
  public getL1Constants(): L1RollupConstants {
@@ -236,7 +226,7 @@ export class EpochCache implements EpochCacheInterface {
236
226
  * We return the next proposer's attester address as the node will check if it is the proposer at the next ethereum block,
237
227
  * which can be the next slot. If this is the case, then it will send proposals early.
238
228
  */
239
- async getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
229
+ public async getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
240
230
  currentSlot: bigint;
241
231
  nextSlot: bigint;
242
232
  currentProposer: EthAddress | undefined;
@@ -253,14 +243,23 @@ export class EpochCache implements EpochCacheInterface {
253
243
  };
254
244
  }
255
245
 
246
+ /**
247
+ * Get the proposer attester address in the given L2 slot
248
+ * @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
249
+ * If the committee is empty (i.e. target committee size is 0, and anyone can propose), we return undefined.
250
+ */
251
+ public getProposerAttesterAddressInSlot(slot: bigint): Promise<EthAddress | undefined> {
252
+ const epochAndSlot = this.getEpochAndSlotAtSlot(slot);
253
+ return this.getProposerAttesterAddressAt(epochAndSlot);
254
+ }
255
+
256
256
  /**
257
257
  * Get the proposer attester address in the next slot
258
258
  * @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
259
259
  * If the committee is empty (i.e. target committee size is 0, and anyone can propose), we return undefined.
260
260
  */
261
- getProposerAttesterAddressInNextSlot(): Promise<EthAddress | undefined> {
261
+ public getProposerAttesterAddressInNextSlot(): Promise<EthAddress | undefined> {
262
262
  const epochAndSlot = this.getEpochAndSlotInNextL1Slot();
263
-
264
263
  return this.getProposerAttesterAddressAt(epochAndSlot);
265
264
  }
266
265