@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.5476d83

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 (110) hide show
  1. package/README.md +27 -6
  2. package/dest/archiver/archiver.d.ts +147 -57
  3. package/dest/archiver/archiver.d.ts.map +1 -1
  4. package/dest/archiver/archiver.js +841 -333
  5. package/dest/archiver/archiver_store.d.ts +85 -50
  6. package/dest/archiver/archiver_store.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
  8. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  9. package/dest/archiver/archiver_store_test_suite.js +708 -213
  10. package/dest/archiver/config.d.ts +5 -21
  11. package/dest/archiver/config.d.ts.map +1 -1
  12. package/dest/archiver/config.js +21 -12
  13. package/dest/archiver/data_retrieval.d.ts +32 -27
  14. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  15. package/dest/archiver/data_retrieval.js +197 -94
  16. package/dest/archiver/errors.d.ts +9 -1
  17. package/dest/archiver/errors.d.ts.map +1 -1
  18. package/dest/archiver/errors.js +12 -0
  19. package/dest/archiver/index.d.ts +3 -4
  20. package/dest/archiver/index.d.ts.map +1 -1
  21. package/dest/archiver/index.js +1 -2
  22. package/dest/archiver/instrumentation.d.ts +12 -6
  23. package/dest/archiver/instrumentation.d.ts.map +1 -1
  24. package/dest/archiver/instrumentation.js +58 -17
  25. package/dest/archiver/kv_archiver_store/block_store.d.ts +48 -11
  26. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  27. package/dest/archiver/kv_archiver_store/block_store.js +216 -63
  28. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +3 -3
  29. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
  30. package/dest/archiver/kv_archiver_store/contract_class_store.js +12 -18
  31. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +11 -8
  32. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
  33. package/dest/archiver/kv_archiver_store/contract_instance_store.js +30 -16
  34. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +50 -35
  35. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  36. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +88 -46
  37. package/dest/archiver/kv_archiver_store/log_store.d.ts +2 -2
  38. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  39. package/dest/archiver/kv_archiver_store/log_store.js +18 -46
  40. package/dest/archiver/kv_archiver_store/message_store.d.ts +23 -17
  41. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  42. package/dest/archiver/kv_archiver_store/message_store.js +150 -48
  43. package/dest/archiver/structs/data_retrieval.d.ts +1 -1
  44. package/dest/archiver/structs/inbox_message.d.ts +15 -0
  45. package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
  46. package/dest/archiver/structs/inbox_message.js +38 -0
  47. package/dest/archiver/structs/published.d.ts +3 -11
  48. package/dest/archiver/structs/published.d.ts.map +1 -1
  49. package/dest/archiver/structs/published.js +1 -1
  50. package/dest/archiver/validation.d.ts +17 -0
  51. package/dest/archiver/validation.d.ts.map +1 -0
  52. package/dest/archiver/validation.js +98 -0
  53. package/dest/factory.d.ts +8 -13
  54. package/dest/factory.d.ts.map +1 -1
  55. package/dest/factory.js +18 -49
  56. package/dest/index.d.ts +2 -2
  57. package/dest/index.d.ts.map +1 -1
  58. package/dest/index.js +1 -1
  59. package/dest/rpc/index.d.ts +2 -3
  60. package/dest/rpc/index.d.ts.map +1 -1
  61. package/dest/rpc/index.js +1 -4
  62. package/dest/test/index.d.ts +1 -1
  63. package/dest/test/mock_archiver.d.ts +2 -2
  64. package/dest/test/mock_archiver.d.ts.map +1 -1
  65. package/dest/test/mock_l1_to_l2_message_source.d.ts +5 -3
  66. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  67. package/dest/test/mock_l1_to_l2_message_source.js +14 -1
  68. package/dest/test/mock_l2_block_source.d.ts +38 -10
  69. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  70. package/dest/test/mock_l2_block_source.js +119 -8
  71. package/dest/test/mock_structs.d.ts +9 -0
  72. package/dest/test/mock_structs.d.ts.map +1 -0
  73. package/dest/test/mock_structs.js +37 -0
  74. package/package.json +28 -30
  75. package/src/archiver/archiver.ts +1087 -410
  76. package/src/archiver/archiver_store.ts +97 -55
  77. package/src/archiver/archiver_store_test_suite.ts +664 -210
  78. package/src/archiver/config.ts +28 -41
  79. package/src/archiver/data_retrieval.ts +279 -125
  80. package/src/archiver/errors.ts +21 -0
  81. package/src/archiver/index.ts +2 -3
  82. package/src/archiver/instrumentation.ts +77 -22
  83. package/src/archiver/kv_archiver_store/block_store.ts +270 -72
  84. package/src/archiver/kv_archiver_store/contract_class_store.ts +13 -23
  85. package/src/archiver/kv_archiver_store/contract_instance_store.ts +35 -27
  86. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +127 -63
  87. package/src/archiver/kv_archiver_store/log_store.ts +24 -62
  88. package/src/archiver/kv_archiver_store/message_store.ts +209 -53
  89. package/src/archiver/structs/inbox_message.ts +41 -0
  90. package/src/archiver/structs/published.ts +2 -11
  91. package/src/archiver/validation.ts +124 -0
  92. package/src/factory.ts +24 -66
  93. package/src/index.ts +1 -1
  94. package/src/rpc/index.ts +1 -5
  95. package/src/test/mock_archiver.ts +1 -1
  96. package/src/test/mock_l1_to_l2_message_source.ts +14 -3
  97. package/src/test/mock_l2_block_source.ts +158 -13
  98. package/src/test/mock_structs.ts +49 -0
  99. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
  100. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
  101. package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
  102. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
  103. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
  104. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
  105. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
  106. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
  107. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
  108. package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
  109. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
  110. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
@@ -1,97 +0,0 @@
1
- import { MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
2
- import type { Fr } from '@aztec/foundation/fields';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
5
- import type { InBlock, L2Block } from '@aztec/stdlib/block';
6
-
7
- export class NullifierStore {
8
- #nullifiersToBlockNumber: AztecAsyncMap<string, number>;
9
- #nullifiersToBlockHash: AztecAsyncMap<string, string>;
10
- #nullifiersToIndex: AztecAsyncMap<string, number>;
11
- #log = createLogger('archiver:log_store');
12
-
13
- constructor(private db: AztecAsyncKVStore) {
14
- this.#nullifiersToBlockNumber = db.openMap('archiver_nullifiers_to_block_number');
15
- this.#nullifiersToBlockHash = db.openMap('archiver_nullifiers_to_block_hash');
16
- this.#nullifiersToIndex = db.openMap('archiver_nullifiers_to_index');
17
- }
18
-
19
- async addNullifiers(blocks: L2Block[]): Promise<boolean> {
20
- const blockHashes = await Promise.all(blocks.map(block => block.hash()));
21
- await this.db.transactionAsync(async () => {
22
- await Promise.all(
23
- blocks.map((block, i) => {
24
- const dataStartIndexForBlock =
25
- block.header.state.partial.nullifierTree.nextAvailableLeafIndex -
26
- block.body.txEffects.length * MAX_NULLIFIERS_PER_TX;
27
- return Promise.all(
28
- block.body.txEffects.map((txEffects, txIndex) => {
29
- const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NULLIFIERS_PER_TX;
30
- return Promise.all(
31
- txEffects.nullifiers.map(async (nullifier, nullifierIndex) => {
32
- await this.#nullifiersToBlockNumber.set(nullifier.toString(), block.number);
33
- await this.#nullifiersToBlockHash.set(nullifier.toString(), blockHashes[i].toString());
34
- await this.#nullifiersToIndex.set(nullifier.toString(), dataStartIndexForTx + nullifierIndex);
35
- }),
36
- );
37
- }),
38
- );
39
- }),
40
- );
41
- });
42
- return true;
43
- }
44
-
45
- async deleteNullifiers(blocks: L2Block[]): Promise<boolean> {
46
- await this.db.transactionAsync(async () => {
47
- for (const block of blocks) {
48
- for (const nullifier of block.body.txEffects.flatMap(tx => tx.nullifiers)) {
49
- await Promise.all([
50
- this.#nullifiersToBlockNumber.delete(nullifier.toString()),
51
- this.#nullifiersToBlockHash.delete(nullifier.toString()),
52
- this.#nullifiersToIndex.delete(nullifier.toString()),
53
- ]);
54
- }
55
- }
56
- });
57
- return true;
58
- }
59
-
60
- async findNullifiersIndexesWithBlock(
61
- blockNumber: number,
62
- nullifiers: Fr[],
63
- ): Promise<(InBlock<bigint> | undefined)[]> {
64
- const asStrings = nullifiers.map(x => x.toString());
65
-
66
- const maybeNullifiers = await Promise.all(
67
- asStrings.map(async nullifier => {
68
- const [data, l2BlockNumber, l2BlockHash] = await Promise.all([
69
- this.#nullifiersToIndex.getAsync(nullifier),
70
- this.#nullifiersToBlockNumber.getAsync(nullifier),
71
- this.#nullifiersToBlockHash.getAsync(nullifier),
72
- ]);
73
- return {
74
- data,
75
- l2BlockNumber,
76
- l2BlockHash,
77
- };
78
- }),
79
- );
80
- return maybeNullifiers.map(({ data, l2BlockNumber, l2BlockHash }) => {
81
- if (
82
- data === undefined ||
83
- l2BlockNumber === undefined ||
84
- l2BlockHash === undefined ||
85
- l2BlockNumber > blockNumber
86
- ) {
87
- return undefined;
88
- } else {
89
- return {
90
- data: BigInt(data),
91
- l2BlockNumber,
92
- l2BlockHash,
93
- } as InBlock<bigint>;
94
- }
95
- });
96
- }
97
- }
@@ -1,61 +0,0 @@
1
- import { L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/constants';
2
- import type { Fr } from '@aztec/foundation/fields';
3
- import { InboxLeaf } from '@aztec/stdlib/messaging';
4
-
5
- /**
6
- * A simple in-memory implementation of an L1 to L2 message store.
7
- */
8
- export class L1ToL2MessageStore {
9
- /**
10
- * A map pointing from a key in a "messageIndex" format to the corresponding L1 to L2 message hash.
11
- */
12
- protected store: Map<string, Fr> = new Map();
13
-
14
- #l1ToL2MessagesSubtreeSize = 2 ** L1_TO_L2_MSG_SUBTREE_HEIGHT;
15
-
16
- constructor() {}
17
-
18
- getTotalL1ToL2MessageCount(): bigint {
19
- return BigInt(this.store.size);
20
- }
21
-
22
- addMessage(message: InboxLeaf) {
23
- this.store.set(`${message.index}`, message.leaf);
24
- }
25
-
26
- getMessages(blockNumber: bigint): Fr[] {
27
- const messages: Fr[] = [];
28
- let undefinedMessageFound = false;
29
- const startIndex = Number(InboxLeaf.smallestIndexFromL2Block(blockNumber));
30
-
31
- for (let i = startIndex; i < startIndex + this.#l1ToL2MessagesSubtreeSize; i++) {
32
- // This is inefficient but probably fine for now.
33
- const message = this.store.get(`${i}`);
34
- if (message) {
35
- if (undefinedMessageFound) {
36
- throw new Error(`L1 to L2 message gap found in block ${blockNumber}`);
37
- }
38
- messages.push(message);
39
- } else {
40
- undefinedMessageFound = true;
41
- // We continue iterating over messages here to verify that there are no more messages after the undefined one.
42
- // --> If this was the case this would imply there is some issue with log fetching.
43
- }
44
- }
45
- return messages;
46
- }
47
-
48
- /**
49
- * Gets the L1 to L2 message index in the L1 to L2 message tree.
50
- * @param l1ToL2Message - The L1 to L2 message.
51
- * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
52
- */
53
- getMessageIndex(l1ToL2Message: Fr): bigint | undefined {
54
- for (const [key, message] of this.store.entries()) {
55
- if (message.equals(l1ToL2Message)) {
56
- return BigInt(key);
57
- }
58
- }
59
- return undefined;
60
- }
61
- }