@aztec/archiver 0.55.1 → 0.57.0

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.
Files changed (78) hide show
  1. package/README.md +1 -1
  2. package/dest/archiver/archiver.d.ts +27 -25
  3. package/dest/archiver/archiver.d.ts.map +1 -1
  4. package/dest/archiver/archiver.js +391 -169
  5. package/dest/archiver/archiver_store.d.ts +47 -23
  6. package/dest/archiver/archiver_store.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  8. package/dest/archiver/archiver_store_test_suite.js +75 -42
  9. package/dest/archiver/config.js +6 -6
  10. package/dest/archiver/data_retrieval.d.ts +32 -5
  11. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  12. package/dest/archiver/data_retrieval.js +126 -16
  13. package/dest/archiver/epoch_helpers.d.ts +15 -0
  14. package/dest/archiver/epoch_helpers.d.ts.map +1 -0
  15. package/dest/archiver/epoch_helpers.js +23 -0
  16. package/dest/archiver/kv_archiver_store/block_store.d.ts +22 -3
  17. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  18. package/dest/archiver/kv_archiver_store/block_store.js +75 -12
  19. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +2 -1
  20. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
  21. package/dest/archiver/kv_archiver_store/contract_class_store.js +11 -4
  22. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +1 -0
  23. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
  24. package/dest/archiver/kv_archiver_store/contract_instance_store.js +4 -1
  25. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +31 -23
  26. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  27. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +65 -38
  28. package/dest/archiver/kv_archiver_store/log_store.d.ts +4 -5
  29. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  30. package/dest/archiver/kv_archiver_store/log_store.js +18 -14
  31. package/dest/archiver/kv_archiver_store/message_store.d.ts +2 -0
  32. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  33. package/dest/archiver/kv_archiver_store/message_store.js +18 -8
  34. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +1 -0
  35. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +1 -1
  36. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +4 -1
  37. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +23 -39
  38. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
  39. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +132 -91
  40. package/dest/index.d.ts +0 -1
  41. package/dest/index.d.ts.map +1 -1
  42. package/dest/index.js +2 -2
  43. package/dest/test/index.d.ts +2 -0
  44. package/dest/test/index.d.ts.map +1 -0
  45. package/dest/test/index.js +2 -0
  46. package/dest/test/mock_l2_block_source.d.ts +73 -0
  47. package/dest/test/mock_l2_block_source.d.ts.map +1 -0
  48. package/dest/test/mock_l2_block_source.js +134 -0
  49. package/package.json +15 -11
  50. package/src/archiver/archiver.ts +531 -248
  51. package/src/archiver/archiver_store.ts +53 -31
  52. package/src/archiver/archiver_store_test_suite.ts +93 -81
  53. package/src/archiver/config.ts +5 -5
  54. package/src/archiver/data_retrieval.ts +189 -30
  55. package/src/archiver/epoch_helpers.ts +26 -0
  56. package/src/archiver/kv_archiver_store/block_store.ts +87 -12
  57. package/src/archiver/kv_archiver_store/contract_class_store.ts +18 -5
  58. package/src/archiver/kv_archiver_store/contract_instance_store.ts +4 -0
  59. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +74 -47
  60. package/src/archiver/kv_archiver_store/log_store.ts +18 -18
  61. package/src/archiver/kv_archiver_store/message_store.ts +18 -5
  62. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +4 -0
  63. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +155 -108
  64. package/src/index.ts +1 -2
  65. package/src/test/index.ts +1 -0
  66. package/src/test/mock_l2_block_source.ts +165 -0
  67. package/dest/archiver/eth_log_handlers.d.ts +0 -59
  68. package/dest/archiver/eth_log_handlers.d.ts.map +0 -1
  69. package/dest/archiver/eth_log_handlers.js +0 -155
  70. package/dest/archiver/kv_archiver_store/block_body_store.d.ts +0 -34
  71. package/dest/archiver/kv_archiver_store/block_body_store.d.ts.map +0 -1
  72. package/dest/archiver/kv_archiver_store/block_body_store.js +0 -65
  73. package/dest/archiver/kv_archiver_store/proven_store.d.ts +0 -14
  74. package/dest/archiver/kv_archiver_store/proven_store.d.ts.map +0 -1
  75. package/dest/archiver/kv_archiver_store/proven_store.js +0 -30
  76. package/src/archiver/eth_log_handlers.ts +0 -213
  77. package/src/archiver/kv_archiver_store/block_body_store.ts +0 -74
  78. package/src/archiver/kv_archiver_store/proven_store.ts +0 -34
@@ -1,7 +1,4 @@
1
1
  import {
2
- type Body,
3
- type EncryptedL2BlockL2Logs,
4
- type EncryptedNoteL2BlockL2Logs,
5
2
  type FromLogType,
6
3
  type GetUnencryptedLogsResponse,
7
4
  type InboxLeaf,
@@ -12,9 +9,8 @@ import {
12
9
  type TxEffect,
13
10
  type TxHash,
14
11
  type TxReceipt,
15
- type UnencryptedL2BlockL2Logs,
16
12
  } from '@aztec/circuit-types';
17
- import { type Fr } from '@aztec/circuits.js';
13
+ import { type Fr, type Header } from '@aztec/circuits.js';
18
14
  import { type ContractArtifact } from '@aztec/foundation/abi';
19
15
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
20
16
  import {
@@ -24,7 +20,7 @@ import {
24
20
  type UnconstrainedFunctionWithMembershipProof,
25
21
  } from '@aztec/types/contracts';
26
22
 
27
- import { type DataRetrieval, type SingletonDataRetrieval } from './structs/data_retrieval.js';
23
+ import { type DataRetrieval } from './structs/data_retrieval.js';
28
24
  import { type L1Published } from './structs/published.js';
29
25
 
30
26
  /**
@@ -33,8 +29,6 @@ import { type L1Published } from './structs/published.js';
33
29
  export type ArchiverL1SynchPoint = {
34
30
  /** Number of the last L1 block that added a new L2 block metadata. */
35
31
  blocksSynchedTo?: bigint;
36
- /** Number of the last L1 block that added a new L2 block body. */
37
- blockBodiesSynchedTo?: bigint;
38
32
  /** Number of the last L1 block that added L1 -> L2 messages from the Inbox. */
39
33
  messagesSynchedTo?: bigint;
40
34
  /** Number of the last L1 block that added a new proven block. */
@@ -54,19 +48,13 @@ export interface ArchiverDataStore {
54
48
  addBlocks(blocks: L1Published<L2Block>[]): Promise<boolean>;
55
49
 
56
50
  /**
57
- * Append new block bodies to the store's list.
58
- * @param blockBodies - The L2 block bodies to be added to the store.
59
- * @returns True if the operation is successful.
60
- */
61
- addBlockBodies(blockBodies: DataRetrieval<Body>): Promise<boolean>;
62
-
63
- /**
64
- * Gets block bodies that have the same txsEffectsHashes as we supply.
65
- *
66
- * @param txsEffectsHashes - A list of txsEffectsHashes.
67
- * @returns The requested L2 block bodies
51
+ * Unwinds blocks from the database
52
+ * @param from - The tip of the chain, passed for verification purposes,
53
+ * ensuring that we don't end up deleting something we did not intend
54
+ * @param blocksToUnwind - The number of blocks we are to unwind
55
+ * @returns True if the operation is successful
68
56
  */
69
- getBlockBodies(txsEffectsHashes: Buffer[]): Promise<(Body | undefined)[]>;
57
+ unwindBlocks(from: number, blocksToUnwind: number): Promise<boolean>;
70
58
 
71
59
  /**
72
60
  * Gets up to `limit` amount of L2 blocks starting from `from`.
@@ -76,6 +64,14 @@ export interface ArchiverDataStore {
76
64
  */
77
65
  getBlocks(from: number, limit: number): Promise<L1Published<L2Block>[]>;
78
66
 
67
+ /**
68
+ * Gets up to `limit` amount of L2 block headers starting from `from`.
69
+ * @param from - Number of the first block to return (inclusive).
70
+ * @param limit - The number of blocks to return.
71
+ * @returns The requested L2 block headers.
72
+ */
73
+ getBlockHeaders(from: number, limit: number): Promise<Header[]>;
74
+
79
75
  /**
80
76
  * Gets a tx effect.
81
77
  * @param txHash - The txHash of the tx corresponding to the tx effect.
@@ -92,18 +88,11 @@ export interface ArchiverDataStore {
92
88
 
93
89
  /**
94
90
  * Append new logs to the store's list.
95
- * @param noteEncryptedLogs - The note encrypted logs to be added to the store.
96
- * @param encryptedLogs - The encrypted logs to be added to the store.
97
- * @param unencryptedLogs - The unencrypted logs to be added to the store.
98
- * @param blockNumber - The block for which to add the logs.
91
+ * @param blocks - The blocks for which to add the logs.
99
92
  * @returns True if the operation is successful.
100
93
  */
101
- addLogs(
102
- noteEncryptedLogs: EncryptedNoteL2BlockL2Logs | undefined,
103
- encryptedLogs: EncryptedL2BlockL2Logs | undefined,
104
- unencryptedLogs: UnencryptedL2BlockL2Logs | undefined,
105
- blockNumber: number,
106
- ): Promise<boolean>;
94
+ addLogs(blocks: L2Block[]): Promise<boolean>;
95
+ deleteLogs(blocks: L2Block[]): Promise<boolean>;
107
96
 
108
97
  /**
109
98
  * Append L1 to L2 messages to the store.
@@ -127,6 +116,12 @@ export interface ArchiverDataStore {
127
116
  */
128
117
  getL1ToL2MessageIndex(l1ToL2Message: Fr, startIndex: bigint): Promise<bigint | undefined>;
129
118
 
119
+ /**
120
+ * Get the total number of L1 to L2 messages
121
+ * @returns The number of L1 to L2 messages in the store
122
+ */
123
+ getTotalL1ToL2MessageCount(): Promise<bigint>;
124
+
130
125
  /**
131
126
  * Gets up to `limit` amount of logs starting from `from`.
132
127
  * @param from - Number of the L2 block to which corresponds the first logs to be returned.
@@ -159,11 +154,35 @@ export interface ArchiverDataStore {
159
154
  */
160
155
  getProvenL2BlockNumber(): Promise<number>;
161
156
 
157
+ /**
158
+ * Gets the number of the latest proven L2 epoch.
159
+ * @returns The number of the latest proven L2 epoch.
160
+ */
161
+ getProvenL2EpochNumber(): Promise<number | undefined>;
162
+
162
163
  /**
163
164
  * Stores the number of the latest proven L2 block processed.
164
165
  * @param l2BlockNumber - The number of the latest proven L2 block processed.
165
166
  */
166
- setProvenL2BlockNumber(l2BlockNumber: SingletonDataRetrieval<number>): Promise<void>;
167
+ setProvenL2BlockNumber(l2BlockNumber: number): Promise<void>;
168
+
169
+ /**
170
+ * Stores the number of the latest proven L2 epoch.
171
+ * @param l2EpochNumber - The number of the latest proven L2 epoch.
172
+ */
173
+ setProvenL2EpochNumber(l2EpochNumber: number): Promise<void>;
174
+
175
+ /**
176
+ * Stores the l1 block number that blocks have been synched until
177
+ * @param l1BlockNumber - The l1 block number
178
+ */
179
+ setBlockSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
180
+
181
+ /**
182
+ * Stores the l1 block number that messages have been synched until
183
+ * @param l1BlockNumber - The l1 block number
184
+ */
185
+ setMessageSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
167
186
 
168
187
  /**
169
188
  * Gets the synch point of the archiver
@@ -178,6 +197,8 @@ export interface ArchiverDataStore {
178
197
  */
179
198
  addContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean>;
180
199
 
200
+ deleteContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean>;
201
+
181
202
  /**
182
203
  * Returns a contract class given its id, or undefined if not exists.
183
204
  * @param id - Id of the contract class.
@@ -191,6 +212,7 @@ export interface ArchiverDataStore {
191
212
  * @returns True if the operation is successful.
192
213
  */
193
214
  addContractInstances(data: ContractInstanceWithAddress[], blockNumber: number): Promise<boolean>;
215
+ deleteContractInstances(data: ContractInstanceWithAddress[], blockNumber: number): Promise<boolean>;
194
216
 
195
217
  /**
196
218
  * Adds private functions to a contract class.
@@ -1,4 +1,4 @@
1
- import { type Body, InboxLeaf, L2Block, LogId, LogType, TxHash } from '@aztec/circuit-types';
1
+ import { InboxLeaf, L2Block, LogId, LogType, TxHash } from '@aztec/circuit-types';
2
2
  import '@aztec/circuit-types/jest';
3
3
  import { AztecAddress, Fr, INITIAL_L2_BLOCK_NUM, L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/circuits.js';
4
4
  import {
@@ -15,7 +15,6 @@ import {
15
15
  } from '@aztec/types/contracts';
16
16
 
17
17
  import { type ArchiverDataStore, type ArchiverL1SynchPoint } from './archiver_store.js';
18
- import { type DataRetrieval } from './structs/data_retrieval.js';
19
18
  import { type L1Published } from './structs/published.js';
20
19
 
21
20
  /**
@@ -26,7 +25,6 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
26
25
  describe(testName, () => {
27
26
  let store: ArchiverDataStore;
28
27
  let blocks: L1Published<L2Block>[];
29
- let blockBodies: DataRetrieval<Body>;
30
28
  const blockTests: [number, number, () => L1Published<L2Block>[]][] = [
31
29
  [1, 1, () => blocks.slice(0, 1)],
32
30
  [10, 1, () => blocks.slice(9, 10)],
@@ -41,17 +39,9 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
41
39
  data: L2Block.random(i + 1),
42
40
  l1: { blockNumber: BigInt(i + 10), blockHash: `0x${i}`, timestamp: BigInt(i * 1000) },
43
41
  }));
44
- blockBodies = {
45
- retrievedData: blocks.map(block => block.data.body),
46
- lastProcessedL1BlockNumber: 4n,
47
- };
48
42
  });
49
43
 
50
44
  describe('addBlocks', () => {
51
- it('returns success when adding block bodies', async () => {
52
- await expect(store.addBlockBodies(blockBodies)).resolves.toBe(true);
53
- });
54
-
55
45
  it('returns success when adding blocks', async () => {
56
46
  await expect(store.addBlocks(blocks)).resolves.toBe(true);
57
47
  });
@@ -62,10 +52,23 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
62
52
  });
63
53
  });
64
54
 
55
+ describe('unwindBlocks', () => {
56
+ it('unwinding blocks will remove blocks from the chain', async () => {
57
+ await store.addBlocks(blocks);
58
+ const blockNumber = await store.getSynchedL2BlockNumber();
59
+
60
+ expect(await store.getBlocks(blockNumber, 1)).toEqual([blocks[blocks.length - 1]]);
61
+
62
+ await store.unwindBlocks(blockNumber, 1);
63
+
64
+ expect(await store.getSynchedL2BlockNumber()).toBe(blockNumber - 1);
65
+ expect(await store.getBlocks(blockNumber, 1)).toEqual([]);
66
+ });
67
+ });
68
+
65
69
  describe('getBlocks', () => {
66
70
  beforeEach(async () => {
67
71
  await store.addBlocks(blocks);
68
- await store.addBlockBodies(blockBodies);
69
72
  });
70
73
 
71
74
  it.each(blockTests)('retrieves previously stored blocks', async (start, limit, getExpectedBlocks) => {
@@ -80,8 +83,8 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
80
83
  await expect(store.getBlocks(1, 0)).rejects.toThrow('Invalid limit: 0');
81
84
  });
82
85
 
83
- it('resets `from` to the first block if it is out of range', async () => {
84
- await expect(store.getBlocks(INITIAL_L2_BLOCK_NUM - 100, 1)).resolves.toEqual(blocks.slice(0, 1));
86
+ it('throws an error if `from` it is out of range', async () => {
87
+ await expect(store.getBlocks(INITIAL_L2_BLOCK_NUM - 100, 1)).rejects.toThrow('Invalid start: -99');
85
88
  });
86
89
  });
87
90
 
@@ -101,8 +104,6 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
101
104
  await expect(store.getSynchPoint()).resolves.toEqual({
102
105
  blocksSynchedTo: undefined,
103
106
  messagesSynchedTo: undefined,
104
- blockBodiesSynchedTo: undefined,
105
- provenLogsSynchedTo: undefined,
106
107
  } satisfies ArchiverL1SynchPoint);
107
108
  });
108
109
 
@@ -111,18 +112,6 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
111
112
  await expect(store.getSynchPoint()).resolves.toEqual({
112
113
  blocksSynchedTo: 19n,
113
114
  messagesSynchedTo: undefined,
114
- blockBodiesSynchedTo: undefined,
115
- provenLogsSynchedTo: undefined,
116
- } satisfies ArchiverL1SynchPoint);
117
- });
118
-
119
- it('returns the L1 block number in which the most recent L2 block body was published', async () => {
120
- await store.addBlockBodies(blockBodies);
121
- await expect(store.getSynchPoint()).resolves.toEqual({
122
- blocksSynchedTo: undefined,
123
- messagesSynchedTo: undefined,
124
- blockBodiesSynchedTo: blockBodies.lastProcessedL1BlockNumber,
125
- provenLogsSynchedTo: undefined,
126
115
  } satisfies ArchiverL1SynchPoint);
127
116
  });
128
117
 
@@ -134,18 +123,6 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
134
123
  await expect(store.getSynchPoint()).resolves.toEqual({
135
124
  blocksSynchedTo: undefined,
136
125
  messagesSynchedTo: 1n,
137
- blockBodiesSynchedTo: undefined,
138
- provenLogsSynchedTo: undefined,
139
- } satisfies ArchiverL1SynchPoint);
140
- });
141
-
142
- it('returns the L1 block number that most recently logged a proven block', async () => {
143
- await store.setProvenL2BlockNumber({ lastProcessedL1BlockNumber: 3n, retrievedData: 5 });
144
- await expect(store.getSynchPoint()).resolves.toEqual({
145
- blocksSynchedTo: undefined,
146
- messagesSynchedTo: undefined,
147
- blockBodiesSynchedTo: undefined,
148
- provenLogsSynchedTo: 3n,
149
126
  } satisfies ArchiverL1SynchPoint);
150
127
  });
151
128
  });
@@ -153,14 +130,26 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
153
130
  describe('addLogs', () => {
154
131
  it('adds encrypted & unencrypted logs', async () => {
155
132
  const block = blocks[0].data;
156
- await expect(
157
- store.addLogs(
158
- block.body.noteEncryptedLogs,
159
- block.body.encryptedLogs,
160
- block.body.unencryptedLogs,
161
- block.number,
162
- ),
163
- ).resolves.toEqual(true);
133
+ await expect(store.addLogs([block])).resolves.toEqual(true);
134
+ });
135
+ });
136
+
137
+ describe('deleteLogs', () => {
138
+ it('deletes encrypted & unencrypted logs', async () => {
139
+ const block = blocks[0].data;
140
+ await store.addBlocks([blocks[0]]);
141
+ await expect(store.addLogs([block])).resolves.toEqual(true);
142
+
143
+ expect((await store.getLogs(1, 1, LogType.NOTEENCRYPTED))[0]).toEqual(block.body.noteEncryptedLogs);
144
+ expect((await store.getLogs(1, 1, LogType.ENCRYPTED))[0]).toEqual(block.body.encryptedLogs);
145
+ expect((await store.getLogs(1, 1, LogType.UNENCRYPTED))[0]).toEqual(block.body.unencryptedLogs);
146
+
147
+ // This one is a pain for memory as we would never want to just delete memory in the middle.
148
+ await store.deleteLogs([block]);
149
+
150
+ expect((await store.getLogs(1, 1, LogType.NOTEENCRYPTED))[0]).toEqual(undefined);
151
+ expect((await store.getLogs(1, 1, LogType.ENCRYPTED))[0]).toEqual(undefined);
152
+ expect((await store.getLogs(1, 1, LogType.UNENCRYPTED))[0]).toEqual(undefined);
164
153
  });
165
154
  });
166
155
 
@@ -170,16 +159,8 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
170
159
  ['unencrypted', LogType.UNENCRYPTED],
171
160
  ])('getLogs (%s)', (_, logType) => {
172
161
  beforeEach(async () => {
173
- await Promise.all(
174
- blocks.map(block =>
175
- store.addLogs(
176
- block.data.body.noteEncryptedLogs,
177
- block.data.body.encryptedLogs,
178
- block.data.body.unencryptedLogs,
179
- block.data.number,
180
- ),
181
- ),
182
- );
162
+ await store.addBlocks(blocks);
163
+ await store.addLogs(blocks.map(b => b.data));
183
164
  });
184
165
 
185
166
  it.each(blockTests)('retrieves previously stored logs', async (from, limit, getExpectedBlocks) => {
@@ -201,18 +182,8 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
201
182
 
202
183
  describe('getTxEffect', () => {
203
184
  beforeEach(async () => {
204
- await Promise.all(
205
- blocks.map(block =>
206
- store.addLogs(
207
- block.data.body.noteEncryptedLogs,
208
- block.data.body.encryptedLogs,
209
- block.data.body.unencryptedLogs,
210
- block.data.number,
211
- ),
212
- ),
213
- );
185
+ await store.addLogs(blocks.map(b => b.data));
214
186
  await store.addBlocks(blocks);
215
- await store.addBlockBodies(blockBodies);
216
187
  });
217
188
 
218
189
  it.each([
@@ -230,6 +201,24 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
230
201
  it('returns undefined if tx is not found', async () => {
231
202
  await expect(store.getTxEffect(new TxHash(Fr.random().toBuffer()))).resolves.toBeUndefined();
232
203
  });
204
+
205
+ it.each([
206
+ () => blocks[0].data.body.txEffects[0],
207
+ () => blocks[9].data.body.txEffects[3],
208
+ () => blocks[3].data.body.txEffects[1],
209
+ () => blocks[5].data.body.txEffects[2],
210
+ () => blocks[1].data.body.txEffects[0],
211
+ ])('tries to retrieves a previously stored transaction after deleted', async getExpectedTx => {
212
+ await store.unwindBlocks(blocks.length, blocks.length);
213
+
214
+ const expectedTx = getExpectedTx();
215
+ const actualTx = await store.getTxEffect(expectedTx.txHash);
216
+ expect(actualTx).toEqual(undefined);
217
+ });
218
+
219
+ it('returns undefined if tx is not found', async () => {
220
+ await expect(store.getTxEffect(new TxHash(Fr.random().toBuffer()))).resolves.toBeUndefined();
221
+ });
233
222
  });
234
223
 
235
224
  describe('L1 to L2 Messages', () => {
@@ -300,6 +289,11 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
300
289
  it('returns undefined if contract instance is not found', async () => {
301
290
  await expect(store.getContractInstance(AztecAddress.random())).resolves.toBeUndefined();
302
291
  });
292
+
293
+ it('returns undefined if previously stored contract instances was deleted', async () => {
294
+ await store.deleteContractInstances([contractInstance], blockNum);
295
+ await expect(store.getContractInstance(contractInstance.address)).resolves.toBeUndefined();
296
+ });
303
297
  });
304
298
 
305
299
  describe('contractClasses', () => {
@@ -315,6 +309,17 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
315
309
  await expect(store.getContractClass(contractClass.id)).resolves.toMatchObject(contractClass);
316
310
  });
317
311
 
312
+ it('returns undefined if the initial deployed contract class was deleted', async () => {
313
+ await store.deleteContractClasses([contractClass], blockNum);
314
+ await expect(store.getContractClass(contractClass.id)).resolves.toBeUndefined();
315
+ });
316
+
317
+ it('returns contract class if later "deployment" class was deleted', async () => {
318
+ await store.addContractClasses([contractClass], blockNum + 1);
319
+ await store.deleteContractClasses([contractClass], blockNum + 1);
320
+ await expect(store.getContractClass(contractClass.id)).resolves.toMatchObject(contractClass);
321
+ });
322
+
318
323
  it('returns undefined if contract class is not found', async () => {
319
324
  await expect(store.getContractClass(Fr.random())).resolves.toBeUndefined();
320
325
  });
@@ -364,18 +369,25 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
364
369
  }));
365
370
 
366
371
  await store.addBlocks(blocks);
367
- await store.addBlockBodies(blockBodies);
368
-
369
- await Promise.all(
370
- blocks.map(block =>
371
- store.addLogs(
372
- block.data.body.noteEncryptedLogs,
373
- block.data.body.encryptedLogs,
374
- block.data.body.unencryptedLogs,
375
- block.data.number,
376
- ),
377
- ),
378
- );
372
+ await store.addLogs(blocks.map(b => b.data));
373
+ });
374
+
375
+ it('no logs returned if deleted ("txHash" filter param is respected variant)', async () => {
376
+ // get random tx
377
+ const targetBlockIndex = randomInt(numBlocks);
378
+ const targetTxIndex = randomInt(txsPerBlock);
379
+ const targetTxHash = blocks[targetBlockIndex].data.body.txEffects[targetTxIndex].txHash;
380
+
381
+ await Promise.all([
382
+ store.unwindBlocks(blocks.length, blocks.length),
383
+ store.deleteLogs(blocks.map(b => b.data)),
384
+ ]);
385
+
386
+ const response = await store.getUnencryptedLogs({ txHash: targetTxHash });
387
+ const logs = response.logs;
388
+
389
+ expect(response.maxLogsHit).toBeFalsy();
390
+ expect(logs.length).toEqual(0);
379
391
  });
380
392
 
381
393
  it('"txHash" filter param is respected', async () => {
@@ -52,11 +52,6 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
52
52
  description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
53
53
  ...numberConfigHelper(1000),
54
54
  },
55
- viemPollingIntervalMS: {
56
- env: 'ARCHIVER_VIEM_POLLING_INTERVAL_MS',
57
- description: 'The polling interval viem uses in ms',
58
- ...numberConfigHelper(1000),
59
- },
60
55
  dataDirectory: {
61
56
  env: 'DATA_DIRECTORY',
62
57
  description: 'Optional dir to store data. If omitted will store in memory.',
@@ -67,6 +62,11 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
67
62
  ...numberConfigHelper(1_000),
68
63
  },
69
64
  ...l1ReaderConfigMappings,
65
+ viemPollingIntervalMS: {
66
+ env: 'ARCHIVER_VIEM_POLLING_INTERVAL_MS',
67
+ description: 'The polling interval viem uses in ms',
68
+ ...numberConfigHelper(1000),
69
+ },
70
70
  };
71
71
 
72
72
  /**