@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
@@ -3,3 +3,24 @@ export class NoBlobBodiesFoundError extends Error {
3
3
  super(`No blob bodies found for block ${l2BlockNum}`);
4
4
  }
5
5
  }
6
+
7
+ export class InitialBlockNumberNotSequentialError extends Error {
8
+ constructor(
9
+ public readonly newBlockNumber: number,
10
+ public readonly previousBlockNumber: number | undefined,
11
+ ) {
12
+ super(
13
+ `Cannot insert new block ${newBlockNumber} given previous block number in store is ${
14
+ previousBlockNumber ?? 'undefined'
15
+ }`,
16
+ );
17
+ }
18
+ }
19
+
20
+ export class BlockNumberNotSequentialError extends Error {
21
+ constructor(newBlockNumber: number, previous: number | undefined) {
22
+ super(
23
+ `Cannot insert new block ${newBlockNumber} given previous block number in batch is ${previous ?? 'undefined'}`,
24
+ );
25
+ }
26
+ }
@@ -1,7 +1,6 @@
1
1
  export * from './archiver.js';
2
2
  export * from './config.js';
3
- export { type L1Published, type L1PublishedData } from './structs/published.js';
4
- export { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js';
3
+ export { type PublishedL2Block, type L1PublishedData } from './structs/published.js';
5
4
  export type { ArchiverDataStore } from './archiver_store.js';
6
- export { KVArchiverDataStore } from './kv_archiver_store/kv_archiver_store.js';
5
+ export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './kv_archiver_store/kv_archiver_store.js';
7
6
  export { ContractInstanceStore } from './kv_archiver_store/contract_instance_store.js';
@@ -1,5 +1,5 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
- import type { L2Block } from '@aztec/stdlib/block';
2
+ import type { L2BlockNew } from '@aztec/stdlib/block';
3
3
  import {
4
4
  Attributes,
5
5
  type Gauge,
@@ -18,32 +18,43 @@ export class ArchiverInstrumentation {
18
18
 
19
19
  private blockHeight: Gauge;
20
20
  private txCount: UpDownCounter;
21
- private syncDuration: Histogram;
22
- private l1BlocksSynced: UpDownCounter;
23
21
  private l1BlockHeight: Gauge;
24
22
  private proofsSubmittedDelay: Histogram;
25
23
  private proofsSubmittedCount: UpDownCounter;
26
24
  private dbMetrics: LmdbMetrics;
25
+
26
+ private pruneDuration: Histogram;
27
27
  private pruneCount: UpDownCounter;
28
28
 
29
+ private syncDurationPerBlock: Histogram;
30
+ private syncBlockCount: UpDownCounter;
31
+ private manaPerBlock: Histogram;
32
+ private txsPerBlock: Histogram;
33
+
34
+ private syncDurationPerMessage: Histogram;
35
+ private syncMessageCount: UpDownCounter;
36
+
29
37
  private log = createLogger('archiver:instrumentation');
30
38
 
31
- private constructor(private telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
39
+ private constructor(
40
+ private telemetry: TelemetryClient,
41
+ lmdbStats?: LmdbStatsCallback,
42
+ ) {
32
43
  this.tracer = telemetry.getTracer('Archiver');
33
44
  const meter = telemetry.getMeter('Archiver');
45
+
34
46
  this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT, {
35
47
  description: 'The height of the latest block processed by the archiver',
36
48
  valueType: ValueType.INT,
37
49
  });
38
50
 
39
- this.txCount = meter.createUpDownCounter(Metrics.ARCHIVER_TX_COUNT, {
40
- description: 'The total number of transactions',
51
+ this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT, {
52
+ description: 'The height of the latest L1 block processed by the archiver',
41
53
  valueType: ValueType.INT,
42
54
  });
43
55
 
44
- this.syncDuration = meter.createHistogram(Metrics.ARCHIVER_SYNC_DURATION, {
45
- unit: 'ms',
46
- description: 'Duration to sync a block',
56
+ this.txCount = meter.createUpDownCounter(Metrics.ARCHIVER_TOTAL_TXS, {
57
+ description: 'The total number of transactions',
47
58
  valueType: ValueType.INT,
48
59
  });
49
60
 
@@ -58,13 +69,48 @@ export class ArchiverInstrumentation {
58
69
  valueType: ValueType.INT,
59
70
  });
60
71
 
61
- this.l1BlocksSynced = meter.createUpDownCounter(Metrics.ARCHIVER_L1_BLOCKS_SYNCED, {
72
+ this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK, {
73
+ unit: 'ms',
74
+ description: 'Duration to sync a block',
75
+ valueType: ValueType.INT,
76
+ });
77
+
78
+ this.syncBlockCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_BLOCK_COUNT, {
62
79
  description: 'Number of blocks synced from L1',
63
80
  valueType: ValueType.INT,
64
81
  });
65
82
 
66
- this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT, {
67
- description: 'The height of the latest L1 block processed by the archiver',
83
+ this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK, {
84
+ description: 'The mana consumed by blocks',
85
+ valueType: ValueType.DOUBLE,
86
+ unit: 'Mmana',
87
+ });
88
+
89
+ this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK, {
90
+ description: 'The block tx count',
91
+ valueType: ValueType.INT,
92
+ unit: 'tx',
93
+ });
94
+
95
+ this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE, {
96
+ unit: 'ms',
97
+ description: 'Duration to sync a message',
98
+ valueType: ValueType.INT,
99
+ });
100
+
101
+ this.syncMessageCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_MESSAGE_COUNT, {
102
+ description: 'Number of L1 to L2 messages synced',
103
+ valueType: ValueType.INT,
104
+ });
105
+
106
+ this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION, {
107
+ unit: 'ms',
108
+ description: 'Duration to sync a message',
109
+ valueType: ValueType.INT,
110
+ });
111
+
112
+ this.pruneCount = meter.createUpDownCounter(Metrics.ARCHIVER_PRUNE_COUNT, {
113
+ description: 'Number of prunes detected',
68
114
  valueType: ValueType.INT,
69
115
  });
70
116
 
@@ -75,17 +121,14 @@ export class ArchiverInstrumentation {
75
121
  },
76
122
  lmdbStats,
77
123
  );
78
-
79
- this.pruneCount = meter.createUpDownCounter(Metrics.ARCHIVER_PRUNE_COUNT, {
80
- description: 'Number of prunes detected',
81
- valueType: ValueType.INT,
82
- });
83
124
  }
84
125
 
85
126
  public static async new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
86
127
  const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
87
128
 
88
- instance.l1BlocksSynced.add(0);
129
+ instance.syncBlockCount.add(0);
130
+ instance.syncMessageCount.add(0);
131
+ instance.pruneCount.add(0);
89
132
 
90
133
  await instance.telemetry.flush();
91
134
 
@@ -96,17 +139,29 @@ export class ArchiverInstrumentation {
96
139
  return this.telemetry.isEnabled();
97
140
  }
98
141
 
99
- public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) {
100
- this.syncDuration.record(Math.ceil(syncTimePerBlock));
142
+ public processNewBlocks(syncTimePerBlock: number, blocks: L2BlockNew[]) {
143
+ this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
101
144
  this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
102
- this.l1BlocksSynced.add(blocks.length);
145
+ this.syncBlockCount.add(blocks.length);
146
+
103
147
  for (const block of blocks) {
104
148
  this.txCount.add(block.body.txEffects.length);
149
+ this.txsPerBlock.record(block.body.txEffects.length);
150
+ this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
151
+ }
152
+ }
153
+
154
+ public processNewMessages(count: number, syncPerMessageMs: number) {
155
+ if (count === 0) {
156
+ return;
105
157
  }
158
+ this.syncMessageCount.add(count);
159
+ this.syncDurationPerMessage.record(Math.ceil(syncPerMessageMs));
106
160
  }
107
161
 
108
- public processPrune() {
162
+ public processPrune(duration: number) {
109
163
  this.pruneCount.add(1);
164
+ this.pruneDuration.record(Math.ceil(duration));
110
165
  }
111
166
 
112
167
  public updateLastProvenBlock(blockNumber: number) {