@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c

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 (201) hide show
  1. package/README.md +156 -22
  2. package/dest/archiver.d.ts +135 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +768 -0
  5. package/dest/config.d.ts +30 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +21 -5
  8. package/dest/errors.d.ts +41 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +62 -0
  11. package/dest/factory.d.ts +7 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +90 -10
  14. package/dest/index.d.ts +10 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +8 -3
  17. package/dest/interfaces.d.ts +9 -0
  18. package/dest/interfaces.d.ts.map +1 -0
  19. package/dest/interfaces.js +3 -0
  20. package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/l1/bin/retrieve-calldata.js +149 -0
  23. package/dest/l1/calldata_retriever.d.ts +112 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +471 -0
  26. package/dest/l1/data_retrieval.d.ts +88 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver → l1}/data_retrieval.js +76 -150
  29. package/dest/l1/debug_tx.d.ts +19 -0
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/l1/debug_tx.js +73 -0
  32. package/dest/l1/spire_proposer.d.ts +70 -0
  33. package/dest/l1/spire_proposer.d.ts.map +1 -0
  34. package/dest/l1/spire_proposer.js +157 -0
  35. package/dest/l1/trace_tx.d.ts +97 -0
  36. package/dest/l1/trace_tx.d.ts.map +1 -0
  37. package/dest/l1/trace_tx.js +91 -0
  38. package/dest/l1/types.d.ts +12 -0
  39. package/dest/l1/types.d.ts.map +1 -0
  40. package/dest/l1/types.js +3 -0
  41. package/dest/l1/validate_trace.d.ts +29 -0
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/l1/validate_trace.js +150 -0
  44. package/dest/modules/data_source_base.d.ts +84 -0
  45. package/dest/modules/data_source_base.d.ts.map +1 -0
  46. package/dest/modules/data_source_base.js +260 -0
  47. package/dest/modules/data_store_updater.d.ts +73 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +302 -0
  50. package/dest/modules/instrumentation.d.ts +37 -0
  51. package/dest/modules/instrumentation.d.ts.map +1 -0
  52. package/dest/{archiver → modules}/instrumentation.js +22 -59
  53. package/dest/modules/l1_synchronizer.d.ts +75 -0
  54. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  55. package/dest/modules/l1_synchronizer.js +1113 -0
  56. package/dest/modules/validation.d.ts +17 -0
  57. package/dest/modules/validation.d.ts.map +1 -0
  58. package/dest/{archiver → modules}/validation.js +7 -1
  59. package/dest/store/block_store.d.ts +192 -0
  60. package/dest/store/block_store.d.ts.map +1 -0
  61. package/dest/store/block_store.js +721 -0
  62. package/dest/store/contract_class_store.d.ts +18 -0
  63. package/dest/store/contract_class_store.d.ts.map +1 -0
  64. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +2 -2
  65. package/dest/store/contract_instance_store.d.ts +24 -0
  66. package/dest/store/contract_instance_store.d.ts.map +1 -0
  67. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
  68. package/dest/store/kv_archiver_store.d.ts +340 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +447 -0
  71. package/dest/store/log_store.d.ts +54 -0
  72. package/dest/store/log_store.d.ts.map +1 -0
  73. package/dest/store/log_store.js +436 -0
  74. package/dest/store/message_store.d.ts +40 -0
  75. package/dest/store/message_store.d.ts.map +1 -0
  76. package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
  77. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  78. package/dest/structs/data_retrieval.d.ts.map +1 -0
  79. package/dest/structs/inbox_message.d.ts +15 -0
  80. package/dest/structs/inbox_message.d.ts.map +1 -0
  81. package/dest/{archiver/structs → structs}/inbox_message.js +6 -5
  82. package/dest/structs/published.d.ts +2 -0
  83. package/dest/structs/published.d.ts.map +1 -0
  84. package/dest/test/fake_l1_state.d.ts +190 -0
  85. package/dest/test/fake_l1_state.d.ts.map +1 -0
  86. package/dest/test/fake_l1_state.js +383 -0
  87. package/dest/test/index.d.ts +2 -1
  88. package/dest/test/index.d.ts.map +1 -1
  89. package/dest/test/index.js +1 -0
  90. package/dest/test/mock_archiver.d.ts +16 -8
  91. package/dest/test/mock_archiver.d.ts.map +1 -1
  92. package/dest/test/mock_archiver.js +18 -14
  93. package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
  94. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  95. package/dest/test/mock_l1_to_l2_message_source.js +21 -11
  96. package/dest/test/mock_l2_block_source.d.ts +34 -16
  97. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  98. package/dest/test/mock_l2_block_source.js +179 -59
  99. package/dest/test/mock_structs.d.ts +78 -3
  100. package/dest/test/mock_structs.d.ts.map +1 -1
  101. package/dest/test/mock_structs.js +141 -9
  102. package/package.json +19 -20
  103. package/src/archiver.ts +523 -0
  104. package/src/{archiver/config.ts → config.ts} +28 -12
  105. package/src/errors.ts +102 -0
  106. package/src/factory.ts +125 -10
  107. package/src/index.ts +10 -3
  108. package/src/interfaces.ts +9 -0
  109. package/src/l1/README.md +98 -0
  110. package/src/l1/bin/retrieve-calldata.ts +187 -0
  111. package/src/l1/calldata_retriever.ts +641 -0
  112. package/src/{archiver → l1}/data_retrieval.ts +142 -223
  113. package/src/l1/debug_tx.ts +99 -0
  114. package/src/l1/spire_proposer.ts +160 -0
  115. package/src/l1/trace_tx.ts +128 -0
  116. package/src/l1/types.ts +13 -0
  117. package/src/l1/validate_trace.ts +211 -0
  118. package/src/modules/data_source_base.ts +367 -0
  119. package/src/modules/data_store_updater.ts +423 -0
  120. package/src/{archiver → modules}/instrumentation.ts +26 -61
  121. package/src/modules/l1_synchronizer.ts +931 -0
  122. package/src/{archiver → modules}/validation.ts +11 -6
  123. package/src/store/block_store.ts +966 -0
  124. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +2 -2
  125. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
  126. package/src/store/kv_archiver_store.ts +639 -0
  127. package/src/store/log_store.ts +575 -0
  128. package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
  129. package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
  130. package/src/{archiver/structs → structs}/published.ts +0 -1
  131. package/src/test/fake_l1_state.ts +599 -0
  132. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  133. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  134. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  135. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  136. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  137. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  138. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  139. package/src/test/index.ts +1 -0
  140. package/src/test/mock_archiver.ts +22 -16
  141. package/src/test/mock_l1_to_l2_message_source.ts +18 -11
  142. package/src/test/mock_l2_block_source.ts +195 -69
  143. package/src/test/mock_structs.ts +256 -10
  144. package/dest/archiver/archiver.d.ts +0 -287
  145. package/dest/archiver/archiver.d.ts.map +0 -1
  146. package/dest/archiver/archiver.js +0 -1408
  147. package/dest/archiver/archiver_store.d.ts +0 -255
  148. package/dest/archiver/archiver_store.d.ts.map +0 -1
  149. package/dest/archiver/archiver_store.js +0 -4
  150. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  151. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  152. package/dest/archiver/archiver_store_test_suite.js +0 -1289
  153. package/dest/archiver/config.d.ts +0 -21
  154. package/dest/archiver/config.d.ts.map +0 -1
  155. package/dest/archiver/data_retrieval.d.ts +0 -79
  156. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  157. package/dest/archiver/errors.d.ts +0 -12
  158. package/dest/archiver/errors.d.ts.map +0 -1
  159. package/dest/archiver/errors.js +0 -17
  160. package/dest/archiver/index.d.ts +0 -7
  161. package/dest/archiver/index.d.ts.map +0 -1
  162. package/dest/archiver/index.js +0 -4
  163. package/dest/archiver/instrumentation.d.ts +0 -35
  164. package/dest/archiver/instrumentation.d.ts.map +0 -1
  165. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
  166. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  167. package/dest/archiver/kv_archiver_store/block_store.js +0 -370
  168. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  169. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  170. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  171. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  172. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
  173. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  174. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
  175. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  176. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  177. package/dest/archiver/kv_archiver_store/log_store.js +0 -336
  178. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
  179. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  180. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  181. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  182. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  183. package/dest/archiver/structs/published.d.ts +0 -3
  184. package/dest/archiver/structs/published.d.ts.map +0 -1
  185. package/dest/archiver/validation.d.ts +0 -17
  186. package/dest/archiver/validation.d.ts.map +0 -1
  187. package/dest/rpc/index.d.ts +0 -9
  188. package/dest/rpc/index.d.ts.map +0 -1
  189. package/dest/rpc/index.js +0 -15
  190. package/src/archiver/archiver.ts +0 -1858
  191. package/src/archiver/archiver_store.ts +0 -305
  192. package/src/archiver/archiver_store_test_suite.ts +0 -1264
  193. package/src/archiver/errors.ts +0 -26
  194. package/src/archiver/index.ts +0 -6
  195. package/src/archiver/kv_archiver_store/block_store.ts +0 -481
  196. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
  197. package/src/archiver/kv_archiver_store/log_store.ts +0 -406
  198. package/src/rpc/index.ts +0 -16
  199. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  200. /package/dest/{archiver/structs → structs}/published.js +0 -0
  201. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data_source_base.d.ts","sourceRoot":"","sources":["../../src/modules/data_source_base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAwB,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAAE,UAAU,EAAE,mBAA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S,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAErE;IAEM,0BAA0B,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAEzF;IAEM,6BAA6B,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAE1F;IAEY,gBAAgB,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAGzE;IAEY,mBAAmB,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAG1E;CACF"}
@@ -0,0 +1,260 @@
1
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import { isDefined } from '@aztec/foundation/types';
3
+ import { CommitteeAttestation } from '@aztec/stdlib/block';
4
+ import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
5
+ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
6
+ /**
7
+ * Abstract base class implementing ArchiverDataSource using a KVArchiverDataStore.
8
+ * Provides implementations for all store-delegating methods and declares abstract methods
9
+ * for L1-dependent functionality that subclasses must implement.
10
+ */ export class ArchiverDataSourceBase {
11
+ store;
12
+ l1Constants;
13
+ constructor(store, l1Constants){
14
+ this.store = store;
15
+ this.l1Constants = l1Constants;
16
+ }
17
+ getCheckpointNumber() {
18
+ return this.store.getSynchedCheckpointNumber();
19
+ }
20
+ getSynchedCheckpointNumber() {
21
+ return this.store.getSynchedCheckpointNumber();
22
+ }
23
+ getProvenCheckpointNumber() {
24
+ return this.store.getProvenCheckpointNumber();
25
+ }
26
+ getBlockNumber() {
27
+ return this.store.getLatestBlockNumber();
28
+ }
29
+ getProvenBlockNumber() {
30
+ return this.store.getProvenBlockNumber();
31
+ }
32
+ async getBlockHeader(number) {
33
+ const blockNumber = number === 'latest' ? await this.store.getLatestBlockNumber() : number;
34
+ if (blockNumber === 0) {
35
+ return undefined;
36
+ }
37
+ const headers = await this.store.getBlockHeaders(blockNumber, 1);
38
+ return headers.length === 0 ? undefined : headers[0];
39
+ }
40
+ getCheckpointedBlock(number) {
41
+ return this.store.getCheckpointedBlock(number);
42
+ }
43
+ getCheckpointedL2BlockNumber() {
44
+ return this.store.getCheckpointedL2BlockNumber();
45
+ }
46
+ getFinalizedL2BlockNumber() {
47
+ return this.store.getFinalizedL2BlockNumber();
48
+ }
49
+ async getCheckpointHeader(number) {
50
+ if (number === 'latest') {
51
+ number = await this.store.getSynchedCheckpointNumber();
52
+ }
53
+ if (number === 0) {
54
+ return undefined;
55
+ }
56
+ const checkpoint = await this.store.getCheckpointData(number);
57
+ if (!checkpoint) {
58
+ return undefined;
59
+ }
60
+ return checkpoint.header;
61
+ }
62
+ async getLastBlockNumberInCheckpoint(checkpointNumber) {
63
+ const checkpointData = await this.store.getCheckpointData(checkpointNumber);
64
+ if (!checkpointData) {
65
+ return undefined;
66
+ }
67
+ return BlockNumber(checkpointData.startBlock + checkpointData.numBlocks - 1);
68
+ }
69
+ getCheckpointedBlocks(from, limit) {
70
+ return this.store.getCheckpointedBlocks(from, limit);
71
+ }
72
+ getBlockHeaderByHash(blockHash) {
73
+ return this.store.getBlockHeaderByHash(blockHash);
74
+ }
75
+ getBlockHeaderByArchive(archive) {
76
+ return this.store.getBlockHeaderByArchive(archive);
77
+ }
78
+ async getL2Block(number) {
79
+ // If the number provided is -ve, then return the latest block.
80
+ if (number < 0) {
81
+ number = await this.store.getLatestBlockNumber();
82
+ }
83
+ if (number === 0) {
84
+ return undefined;
85
+ }
86
+ const publishedBlock = await this.store.getBlock(number);
87
+ return publishedBlock;
88
+ }
89
+ getTxEffect(txHash) {
90
+ return this.store.getTxEffect(txHash);
91
+ }
92
+ getSettledTxReceipt(txHash) {
93
+ return this.store.getSettledTxReceipt(txHash);
94
+ }
95
+ isPendingChainInvalid() {
96
+ return this.getPendingChainValidationStatus().then((status)=>!status.valid);
97
+ }
98
+ async getPendingChainValidationStatus() {
99
+ return await this.store.getPendingChainValidationStatus() ?? {
100
+ valid: true
101
+ };
102
+ }
103
+ getPrivateLogsByTags(tags, page) {
104
+ return this.store.getPrivateLogsByTags(tags, page);
105
+ }
106
+ getPublicLogsByTagsFromContract(contractAddress, tags, page) {
107
+ return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
108
+ }
109
+ getPublicLogs(filter) {
110
+ return this.store.getPublicLogs(filter);
111
+ }
112
+ getContractClassLogs(filter) {
113
+ return this.store.getContractClassLogs(filter);
114
+ }
115
+ getContractClass(id) {
116
+ return this.store.getContractClass(id);
117
+ }
118
+ getBytecodeCommitment(id) {
119
+ return this.store.getBytecodeCommitment(id);
120
+ }
121
+ async getContract(address, maybeTimestamp) {
122
+ let timestamp;
123
+ if (maybeTimestamp === undefined) {
124
+ const latestBlockHeader = await this.getBlockHeader('latest');
125
+ // If we get undefined block header, it means that the archiver has not yet synced any block so we default to 0.
126
+ timestamp = latestBlockHeader ? latestBlockHeader.globalVariables.timestamp : 0n;
127
+ } else {
128
+ timestamp = maybeTimestamp;
129
+ }
130
+ return this.store.getContractInstance(address, timestamp);
131
+ }
132
+ getContractClassIds() {
133
+ return this.store.getContractClassIds();
134
+ }
135
+ getDebugFunctionName(address, selector) {
136
+ return this.store.getDebugFunctionName(address, selector);
137
+ }
138
+ registerContractFunctionSignatures(signatures) {
139
+ return this.store.registerContractFunctionSignatures(signatures);
140
+ }
141
+ getL1ToL2Messages(checkpointNumber) {
142
+ return this.store.getL1ToL2Messages(checkpointNumber);
143
+ }
144
+ getL1ToL2MessageIndex(l1ToL2Message) {
145
+ return this.store.getL1ToL2MessageIndex(l1ToL2Message);
146
+ }
147
+ async getCheckpoints(checkpointNumber, limit) {
148
+ const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
149
+ const blocks = (await Promise.all(checkpoints.map((ch)=>this.store.getBlocksForCheckpoint(ch.checkpointNumber)))).filter(isDefined);
150
+ const fullCheckpoints = [];
151
+ for(let i = 0; i < checkpoints.length; i++){
152
+ const blocksForCheckpoint = blocks[i];
153
+ const checkpoint = checkpoints[i];
154
+ const fullCheckpoint = new Checkpoint(checkpoint.archive, checkpoint.header, blocksForCheckpoint, checkpoint.checkpointNumber);
155
+ const publishedCheckpoint = new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations.map((x)=>CommitteeAttestation.fromBuffer(x)));
156
+ fullCheckpoints.push(publishedCheckpoint);
157
+ }
158
+ return fullCheckpoints;
159
+ }
160
+ getBlocksForSlot(slotNumber) {
161
+ return this.store.getBlocksForSlot(slotNumber);
162
+ }
163
+ async getCheckpointedBlocksForEpoch(epochNumber) {
164
+ if (!this.l1Constants) {
165
+ throw new Error('L1 constants not set');
166
+ }
167
+ const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
168
+ const blocks = [];
169
+ // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
170
+ // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
171
+ let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
172
+ const slot = (b)=>b.header.slotNumber;
173
+ while(checkpoint && slot(checkpoint) >= start){
174
+ if (slot(checkpoint) <= end) {
175
+ // push the blocks on backwards
176
+ const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
177
+ for(let i = endBlock; i >= checkpoint.startBlock; i--){
178
+ const checkpointedBlock = await this.getCheckpointedBlock(BlockNumber(i));
179
+ if (checkpointedBlock) {
180
+ blocks.push(checkpointedBlock);
181
+ }
182
+ }
183
+ }
184
+ checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
185
+ }
186
+ return blocks.reverse();
187
+ }
188
+ async getCheckpointedBlockHeadersForEpoch(epochNumber) {
189
+ if (!this.l1Constants) {
190
+ throw new Error('L1 constants not set');
191
+ }
192
+ const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
193
+ const blocks = [];
194
+ // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
195
+ // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
196
+ let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
197
+ const slot = (b)=>b.header.slotNumber;
198
+ while(checkpoint && slot(checkpoint) >= start){
199
+ if (slot(checkpoint) <= end) {
200
+ // push the blocks on backwards
201
+ const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
202
+ for(let i = endBlock; i >= checkpoint.startBlock; i--){
203
+ const block = await this.getBlockHeader(BlockNumber(i));
204
+ if (block) {
205
+ blocks.push(block);
206
+ }
207
+ }
208
+ }
209
+ checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
210
+ }
211
+ return blocks.reverse();
212
+ }
213
+ async getCheckpointsForEpoch(epochNumber) {
214
+ if (!this.l1Constants) {
215
+ throw new Error('L1 constants not set');
216
+ }
217
+ const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
218
+ const checkpoints = [];
219
+ // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
220
+ // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
221
+ let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
222
+ const slot = (b)=>b.header.slotNumber;
223
+ while(checkpointData && slot(checkpointData) >= start){
224
+ if (slot(checkpointData) <= end) {
225
+ // push the checkpoints on backwards
226
+ const [checkpoint] = await this.getCheckpoints(checkpointData.checkpointNumber, 1);
227
+ checkpoints.push(checkpoint.checkpoint);
228
+ }
229
+ checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
230
+ }
231
+ return checkpoints.reverse();
232
+ }
233
+ async getBlock(number) {
234
+ // If the number provided is -ve, then return the latest block.
235
+ if (number < 0) {
236
+ number = await this.store.getLatestBlockNumber();
237
+ }
238
+ if (number === 0) {
239
+ return undefined;
240
+ }
241
+ return this.store.getBlock(number);
242
+ }
243
+ getBlocks(from, limit) {
244
+ return this.store.getBlocks(from, limit);
245
+ }
246
+ getCheckpointedBlockByHash(blockHash) {
247
+ return this.store.getCheckpointedBlockByHash(blockHash);
248
+ }
249
+ getCheckpointedBlockByArchive(archive) {
250
+ return this.store.getCheckpointedBlockByArchive(archive);
251
+ }
252
+ async getL2BlockByHash(blockHash) {
253
+ const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
254
+ return checkpointedBlock?.block;
255
+ }
256
+ async getL2BlockByArchive(archive) {
257
+ const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
258
+ return checkpointedBlock?.block;
259
+ }
260
+ }
@@ -0,0 +1,73 @@
1
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
3
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
4
+ import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
5
+ /** Result of adding checkpoints with information about any pruned blocks. */
6
+ type ReconcileCheckpointsResult = {
7
+ /** Blocks that were pruned due to conflict with L1 checkpoints. */
8
+ prunedBlocks: L2Block[] | undefined;
9
+ /** Last block number that was already inserted locally, or undefined if none. */
10
+ lastAlreadyInsertedBlockNumber: BlockNumber | undefined;
11
+ };
12
+ /** Archiver helper module to handle updates to the data store. */
13
+ export declare class ArchiverDataStoreUpdater {
14
+ private store;
15
+ private readonly log;
16
+ constructor(store: KVArchiverDataStore);
17
+ /**
18
+ * Adds proposed blocks to the store with contract class/instance extraction from logs.
19
+ * These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
20
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
21
+ * and individually broadcasted functions from the block logs.
22
+ *
23
+ * @param blocks - The proposed L2 blocks to add.
24
+ * @param pendingChainValidationStatus - Optional validation status to set.
25
+ * @returns True if the operation is successful.
26
+ */
27
+ addProposedBlocks(blocks: L2Block[], pendingChainValidationStatus?: ValidateCheckpointResult): Promise<boolean>;
28
+ /**
29
+ * Reconciles local blocks with incoming checkpoints from L1.
30
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
31
+ * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
32
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
33
+ * and individually broadcasted functions from the checkpoint block logs.
34
+ *
35
+ * @param checkpoints - The published checkpoints to add.
36
+ * @param pendingChainValidationStatus - Optional validation status to set.
37
+ * @returns Result with information about any pruned blocks.
38
+ */
39
+ addCheckpoints(checkpoints: PublishedCheckpoint[], pendingChainValidationStatus?: ValidateCheckpointResult): Promise<ReconcileCheckpointsResult>;
40
+ private pruneMismatchingLocalBlocks;
41
+ /**
42
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
43
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
44
+ * Verifies that each block being removed is not part of a stored checkpoint.
45
+ *
46
+ * @param blockNumber - Remove all blocks with number greater than this.
47
+ * @returns The removed blocks.
48
+ * @throws Error if any block to be removed is checkpointed.
49
+ */
50
+ removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]>;
51
+ private removeBlocksAfter;
52
+ /**
53
+ * Removes all checkpoints after the given checkpoint number.
54
+ * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
55
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
56
+ * and uncheckpointed) after the last block of the given checkpoint.
57
+ *
58
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
59
+ * @returns True if the operation is successful.
60
+ */
61
+ removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean>;
62
+ /** Extracts and stores contract data from a single block. */
63
+ private addContractDataToDb;
64
+ /** Removes contract data associated with a block. */
65
+ private removeContractDataFromDb;
66
+ private updateContractDataOnDb;
67
+ private updatePublishedContractClasses;
68
+ private updateDeployedContractInstances;
69
+ private updateUpdatedContractInstances;
70
+ private storeBroadcastedIndividualFunctions;
71
+ }
72
+ export {};
73
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV9zdG9yZV91cGRhdGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9kYXRhX3N0b3JlX3VwZGF0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBWWhGLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQzdFLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFhcEUsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQVF6RSw2RUFBNkU7QUFDN0UsS0FBSywwQkFBMEIsR0FBRztJQUNoQyxtRUFBbUU7SUFDbkUsWUFBWSxFQUFFLE9BQU8sRUFBRSxHQUFHLFNBQVMsQ0FBQztJQUNwQyxpRkFBaUY7SUFDakYsOEJBQThCLEVBQUUsV0FBVyxHQUFHLFNBQVMsQ0FBQztDQUN6RCxDQUFDO0FBRUYsa0VBQWtFO0FBQ2xFLHFCQUFhLHdCQUF3QjtJQUd2QixPQUFPLENBQUMsS0FBSztJQUZ6QixPQUFPLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBMEM7SUFFOUQsWUFBb0IsS0FBSyxFQUFFLG1CQUFtQixFQUFJO0lBRWxEOzs7Ozs7Ozs7T0FTRztJQUNJLGlCQUFpQixDQUN0QixNQUFNLEVBQUUsT0FBTyxFQUFFLEVBQ2pCLDRCQUE0QixDQUF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nE,YAAY,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IACpC,iFAAiF;IACjF,8BAA8B,EAAE,WAAW,GAAG,SAAS,CAAC;CACzD,CAAC;AAEF,kEAAkE;AAClE,qBAAa,wBAAwB;IAGvB,OAAO,CAAC,KAAK;IAFzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0C;IAE9D,YAAoB,KAAK,EAAE,mBAAmB,EAAI;IAElD;;;;;;;;;OASG;IACI,iBAAiB,CACtB,MAAM,EAAE,OAAO,EAAE,EACjB,4BAA4B,CAAC,EAAE,wBAAwB,GACtD,OAAO,CAAC,OAAO,CAAC,CAelB;IAED;;;;;;;;;;OAUG;IACI,cAAc,CACnB,WAAW,EAAE,mBAAmB,EAAE,EAClC,4BAA4B,CAAC,EAAE,wBAAwB,GACtD,OAAO,CAAC,0BAA0B,CAAC,CAuBrC;YAQa,2BAA2B;IAmEzC;;;;;;;;OAQG;IACI,+BAA+B,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAYnF;YAMa,iBAAiB;IAa/B;;;;;;;;OAQG;IACU,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAYxF;IAED,6DAA6D;IAC7D,OAAO,CAAC,mBAAmB;IAI3B,qDAAqD;IACrD,OAAO,CAAC,wBAAwB;YAKlB,sBAAsB;YAoBtB,8BAA8B;YA4B9B,+BAA+B;YAyB/B,8BAA8B;YA6B9B,mCAAmC;CAwDlD"}
@@ -0,0 +1,302 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { ContractClassPublishedEvent, PrivateFunctionBroadcastedEvent, UtilityFunctionBroadcastedEvent } from '@aztec/protocol-contracts/class-registry';
5
+ import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
6
+ import { computePublicBytecodeCommitment, isValidPrivateFunctionMembershipProof, isValidUtilityFunctionMembershipProof } from '@aztec/stdlib/contract';
7
+ import groupBy from 'lodash.groupby';
8
+ /** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
9
+ Operation[Operation["Store"] = 0] = "Store";
10
+ Operation[Operation["Delete"] = 1] = "Delete";
11
+ return Operation;
12
+ }(Operation || {});
13
+ /** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
14
+ store;
15
+ log;
16
+ constructor(store){
17
+ this.store = store;
18
+ this.log = createLogger('archiver:store_updater');
19
+ }
20
+ /**
21
+ * Adds proposed blocks to the store with contract class/instance extraction from logs.
22
+ * These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
23
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
24
+ * and individually broadcasted functions from the block logs.
25
+ *
26
+ * @param blocks - The proposed L2 blocks to add.
27
+ * @param pendingChainValidationStatus - Optional validation status to set.
28
+ * @returns True if the operation is successful.
29
+ */ addProposedBlocks(blocks, pendingChainValidationStatus) {
30
+ return this.store.transactionAsync(async ()=>{
31
+ await this.store.addProposedBlocks(blocks);
32
+ const opResults = await Promise.all([
33
+ // Update the pending chain validation status if provided
34
+ pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
35
+ // Add any logs emitted during the retrieved blocks
36
+ this.store.addLogs(blocks),
37
+ // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
38
+ ...blocks.map((block)=>this.addContractDataToDb(block))
39
+ ]);
40
+ return opResults.every(Boolean);
41
+ });
42
+ }
43
+ /**
44
+ * Reconciles local blocks with incoming checkpoints from L1.
45
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
46
+ * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
47
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
48
+ * and individually broadcasted functions from the checkpoint block logs.
49
+ *
50
+ * @param checkpoints - The published checkpoints to add.
51
+ * @param pendingChainValidationStatus - Optional validation status to set.
52
+ * @returns Result with information about any pruned blocks.
53
+ */ addCheckpoints(checkpoints, pendingChainValidationStatus) {
54
+ return this.store.transactionAsync(async ()=>{
55
+ // Before adding checkpoints, check for conflicts with local blocks if any
56
+ const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
57
+ await this.store.addCheckpoints(checkpoints);
58
+ // Filter out blocks that were already inserted via addProposedBlocks() to avoid duplicating logs/contract data
59
+ const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
60
+ await Promise.all([
61
+ // Update the pending chain validation status if provided
62
+ pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
63
+ // Add any logs emitted during the retrieved blocks
64
+ this.store.addLogs(newBlocks),
65
+ // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
66
+ ...newBlocks.map((block)=>this.addContractDataToDb(block))
67
+ ]);
68
+ return {
69
+ prunedBlocks,
70
+ lastAlreadyInsertedBlockNumber
71
+ };
72
+ });
73
+ }
74
+ /**
75
+ * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
76
+ * This method handles multiple checkpoints but returns after pruning the first conflict found.
77
+ * This is correct because pruning from the first conflict point removes all subsequent blocks,
78
+ * and when checkpoints are added afterward, they include all the correct blocks.
79
+ */ async pruneMismatchingLocalBlocks(checkpoints) {
80
+ const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
81
+ this.store.getCheckpointedL2BlockNumber(),
82
+ this.store.getLatestBlockNumber()
83
+ ]);
84
+ // Exit early if there are no local uncheckpointed blocks
85
+ if (lastBlockNumber === lastCheckpointedBlockNumber) {
86
+ return {
87
+ prunedBlocks: undefined,
88
+ lastAlreadyInsertedBlockNumber: undefined
89
+ };
90
+ }
91
+ // Get all uncheckpointed local blocks
92
+ const uncheckpointedLocalBlocks = await this.store.getBlocks(BlockNumber.add(lastCheckpointedBlockNumber, 1), lastBlockNumber - lastCheckpointedBlockNumber);
93
+ let lastAlreadyInsertedBlockNumber;
94
+ for (const publishedCheckpoint of checkpoints){
95
+ const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
96
+ const slot = publishedCheckpoint.checkpoint.slot;
97
+ const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.slot === slot);
98
+ if (checkpointBlocks.length === 0) {
99
+ this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
100
+ continue;
101
+ }
102
+ // Find the first checkpoint block that conflicts with an existing local block and prune local afterwards
103
+ for (const checkpointBlock of checkpointBlocks){
104
+ const blockNumber = checkpointBlock.number;
105
+ const existingBlock = localBlocksInSlot.find((b)=>b.number === blockNumber);
106
+ const blockInfos = {
107
+ existingBlock: existingBlock?.toBlockInfo(),
108
+ checkpointBlock: checkpointBlock.toBlockInfo()
109
+ };
110
+ if (!existingBlock) {
111
+ this.log.verbose(`No local block found for checkpointed block number ${blockNumber}`, blockInfos);
112
+ } else if (existingBlock.archive.root.equals(checkpointBlock.archive.root)) {
113
+ this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
114
+ lastAlreadyInsertedBlockNumber = blockNumber;
115
+ } else {
116
+ this.log.warn(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
117
+ const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
118
+ return {
119
+ prunedBlocks,
120
+ lastAlreadyInsertedBlockNumber
121
+ };
122
+ }
123
+ }
124
+ // If local has more blocks than the checkpoint (e.g., local has [2,3,4] but checkpoint has [2,3]),
125
+ // we need to prune the extra local blocks so they match what was checkpointed
126
+ const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
127
+ const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.number;
128
+ if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
129
+ this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
130
+ const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
131
+ return {
132
+ prunedBlocks,
133
+ lastAlreadyInsertedBlockNumber
134
+ };
135
+ }
136
+ }
137
+ return {
138
+ prunedBlocks: undefined,
139
+ lastAlreadyInsertedBlockNumber
140
+ };
141
+ }
142
+ /**
143
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
144
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
145
+ * Verifies that each block being removed is not part of a stored checkpoint.
146
+ *
147
+ * @param blockNumber - Remove all blocks with number greater than this.
148
+ * @returns The removed blocks.
149
+ * @throws Error if any block to be removed is checkpointed.
150
+ */ removeUncheckpointedBlocksAfter(blockNumber) {
151
+ return this.store.transactionAsync(async ()=>{
152
+ // Verify we're only removing uncheckpointed blocks
153
+ const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
154
+ if (blockNumber < lastCheckpointedBlockNumber) {
155
+ throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
156
+ }
157
+ return await this.removeBlocksAfter(blockNumber);
158
+ });
159
+ }
160
+ /**
161
+ * Removes all blocks strictly after the given block number along with any logs and contract data.
162
+ * Does not remove their checkpoints.
163
+ */ async removeBlocksAfter(blockNumber) {
164
+ // First get the blocks to be removed so we can clean up contract data
165
+ const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
166
+ // Clean up contract data and logs for the removed blocks
167
+ await Promise.all([
168
+ this.store.deleteLogs(removedBlocks),
169
+ ...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
170
+ ]);
171
+ return removedBlocks;
172
+ }
173
+ /**
174
+ * Removes all checkpoints after the given checkpoint number.
175
+ * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
176
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
177
+ * and uncheckpointed) after the last block of the given checkpoint.
178
+ *
179
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
180
+ * @returns True if the operation is successful.
181
+ */ async removeCheckpointsAfter(checkpointNumber) {
182
+ const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
183
+ const opResults = await Promise.all([
184
+ // Prune rolls back to the last proven block, which is by definition valid
185
+ this.store.setPendingChainValidationStatus({
186
+ valid: true
187
+ }),
188
+ // Remove contract data for all blocks being removed
189
+ ...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
190
+ this.store.deleteLogs(blocksRemoved)
191
+ ]);
192
+ return opResults.every(Boolean);
193
+ }
194
+ /** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
195
+ return this.updateContractDataOnDb(block, 0);
196
+ }
197
+ /** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
198
+ return this.updateContractDataOnDb(block, 1);
199
+ }
200
+ /** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
201
+ const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
202
+ const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
203
+ const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
204
+ return (await Promise.all([
205
+ this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
206
+ this.updateDeployedContractInstances(privateLogs, block.number, operation),
207
+ this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation),
208
+ operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
209
+ ])).every(Boolean);
210
+ }
211
+ /**
212
+ * Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
213
+ */ async updatePublishedContractClasses(allLogs, blockNum, operation) {
214
+ const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
215
+ const contractClasses = await Promise.all(contractClassPublishedEvents.map((e)=>e.toContractClassPublic()));
216
+ if (contractClasses.length > 0) {
217
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
218
+ if (operation == 0) {
219
+ // TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
220
+ const commitments = await Promise.all(contractClasses.map((c)=>computePublicBytecodeCommitment(c.packedBytecode)));
221
+ return await this.store.addContractClasses(contractClasses, commitments, blockNum);
222
+ } else if (operation == 1) {
223
+ return await this.store.deleteContractClasses(contractClasses, blockNum);
224
+ }
225
+ }
226
+ return true;
227
+ }
228
+ /**
229
+ * Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
230
+ */ async updateDeployedContractInstances(allLogs, blockNum, operation) {
231
+ const contractInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
232
+ if (contractInstances.length > 0) {
233
+ contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
234
+ if (operation == 0) {
235
+ return await this.store.addContractInstances(contractInstances, blockNum);
236
+ } else if (operation == 1) {
237
+ return await this.store.deleteContractInstances(contractInstances, blockNum);
238
+ }
239
+ }
240
+ return true;
241
+ }
242
+ /**
243
+ * Extracts and stores contract instance updates out of ContractInstanceUpdated events.
244
+ */ async updateUpdatedContractInstances(allLogs, timestamp, operation) {
245
+ const contractUpdates = allLogs.filter((log)=>ContractInstanceUpdatedEvent.isContractInstanceUpdatedEvent(log)).map((log)=>ContractInstanceUpdatedEvent.fromLog(log)).map((e)=>e.toContractInstanceUpdate());
246
+ if (contractUpdates.length > 0) {
247
+ contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
248
+ if (operation == 0) {
249
+ return await this.store.addContractInstanceUpdates(contractUpdates, timestamp);
250
+ } else if (operation == 1) {
251
+ return await this.store.deleteContractInstanceUpdates(contractUpdates, timestamp);
252
+ }
253
+ }
254
+ return true;
255
+ }
256
+ /**
257
+ * Stores the functions that were broadcasted individually.
258
+ *
259
+ * @dev Beware that there is not a delete variant of this, since they are added to contract classes
260
+ * and will be deleted as part of the class if needed.
261
+ */ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
262
+ // Filter out private and utility function broadcast events
263
+ const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
264
+ const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
265
+ // Group all events by contract class id
266
+ for (const [classIdString, classEvents] of Object.entries(groupBy([
267
+ ...privateFnEvents,
268
+ ...utilityFnEvents
269
+ ], (e)=>e.contractClassId.toString()))){
270
+ const contractClassId = Fr.fromHexString(classIdString);
271
+ const contractClass = await this.store.getContractClass(contractClassId);
272
+ if (!contractClass) {
273
+ this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
274
+ continue;
275
+ }
276
+ // Split private and utility functions, and filter out invalid ones
277
+ const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
278
+ const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
279
+ const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
280
+ const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
281
+ fn,
282
+ valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
283
+ })));
284
+ const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
285
+ const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
286
+ fn,
287
+ valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
288
+ })));
289
+ const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
290
+ const validFnCount = validPrivateFns.length + validUtilityFns.length;
291
+ if (validFnCount !== allFns.length) {
292
+ this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
293
+ }
294
+ // Store the functions in the contract class in a single operation
295
+ if (validFnCount > 0) {
296
+ this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
297
+ }
298
+ return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
299
+ }
300
+ return true;
301
+ }
302
+ }