@aztec/prover-client 0.0.1-commit.5daedc8 → 0.0.1-commit.6a729f7

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 (107) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +1 -1
  4. package/dest/light/index.d.ts +2 -0
  5. package/dest/light/index.d.ts.map +1 -0
  6. package/dest/light/index.js +1 -0
  7. package/dest/light/lightweight_checkpoint_builder.d.ts +33 -14
  8. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  9. package/dest/light/lightweight_checkpoint_builder.js +116 -23
  10. package/dest/mocks/fixtures.d.ts +1 -1
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +6 -5
  13. package/dest/mocks/test_context.d.ts +5 -3
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +25 -11
  16. package/dest/orchestrator/block-building-helpers.d.ts +4 -4
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +5 -4
  19. package/dest/orchestrator/block-proving-state.d.ts +5 -4
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +1 -1
  22. package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -6
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/checkpoint-proving-state.js +40 -5
  25. package/dest/orchestrator/epoch-proving-state.d.ts +8 -7
  26. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  27. package/dest/orchestrator/epoch-proving-state.js +36 -2
  28. package/dest/orchestrator/orchestrator.d.ts +23 -8
  29. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  30. package/dest/orchestrator/orchestrator.js +540 -137
  31. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  32. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  33. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  34. package/dest/orchestrator/tx-proving-state.d.ts +6 -5
  35. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  36. package/dest/orchestrator/tx-proving-state.js +8 -8
  37. package/dest/prover-client/factory.d.ts +3 -3
  38. package/dest/prover-client/factory.d.ts.map +1 -1
  39. package/dest/prover-client/prover-client.d.ts +3 -3
  40. package/dest/prover-client/prover-client.d.ts.map +1 -1
  41. package/dest/prover-client/prover-client.js +7 -4
  42. package/dest/prover-client/server-epoch-prover.d.ts +5 -5
  43. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  44. package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
  45. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  46. package/dest/proving_broker/broker_prover_facade.js +6 -13
  47. package/dest/proving_broker/config.d.ts +6 -2
  48. package/dest/proving_broker/config.d.ts.map +1 -1
  49. package/dest/proving_broker/config.js +8 -2
  50. package/dest/proving_broker/fixtures.js +1 -1
  51. package/dest/proving_broker/proving_agent.d.ts +5 -9
  52. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  53. package/dest/proving_broker/proving_agent.js +4 -19
  54. package/dest/proving_broker/proving_broker.d.ts +1 -1
  55. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  56. package/dest/proving_broker/proving_broker.js +4 -10
  57. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  58. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  59. package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
  60. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  61. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  62. package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
  63. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  64. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  65. package/dest/proving_broker/proving_job_controller.js +8 -6
  66. package/dest/test/mock_proof_store.d.ts +3 -3
  67. package/dest/test/mock_proof_store.d.ts.map +1 -1
  68. package/dest/test/mock_prover.d.ts +2 -2
  69. package/dest/test/mock_prover.d.ts.map +1 -1
  70. package/dest/test/mock_prover.js +4 -4
  71. package/package.json +20 -19
  72. package/src/config.ts +1 -1
  73. package/src/light/index.ts +1 -0
  74. package/src/light/lightweight_checkpoint_builder.ts +178 -31
  75. package/src/mocks/fixtures.ts +6 -5
  76. package/src/mocks/test_context.ts +25 -10
  77. package/src/orchestrator/block-building-helpers.ts +5 -4
  78. package/src/orchestrator/block-proving-state.ts +3 -2
  79. package/src/orchestrator/checkpoint-proving-state.ts +56 -8
  80. package/src/orchestrator/epoch-proving-state.ts +63 -12
  81. package/src/orchestrator/orchestrator.ts +138 -121
  82. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  83. package/src/orchestrator/tx-proving-state.ts +10 -14
  84. package/src/prover-client/factory.ts +6 -2
  85. package/src/prover-client/prover-client.ts +25 -15
  86. package/src/prover-client/server-epoch-prover.ts +4 -4
  87. package/src/proving_broker/broker_prover_facade.ts +10 -17
  88. package/src/proving_broker/config.ts +10 -1
  89. package/src/proving_broker/fixtures.ts +1 -1
  90. package/src/proving_broker/proving_agent.ts +6 -19
  91. package/src/proving_broker/proving_broker.ts +4 -8
  92. package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
  93. package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
  94. package/src/proving_broker/proving_job_controller.ts +11 -6
  95. package/src/test/mock_prover.ts +2 -14
  96. package/dest/block-factory/index.d.ts +0 -2
  97. package/dest/block-factory/index.d.ts.map +0 -1
  98. package/dest/block-factory/index.js +0 -1
  99. package/dest/block-factory/light.d.ts +0 -38
  100. package/dest/block-factory/light.d.ts.map +0 -1
  101. package/dest/block-factory/light.js +0 -108
  102. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  103. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  104. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  105. package/src/block-factory/index.ts +0 -1
  106. package/src/block-factory/light.ts +0 -137
  107. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1 +0,0 @@
1
- export * from './light.js';
@@ -1,38 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { L2Block } from '@aztec/stdlib/block';
3
- import type { IBlockFactory, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
4
- import { type GlobalVariables, type ProcessedTx } from '@aztec/stdlib/tx';
5
- import { type TelemetryClient } from '@aztec/telemetry-client';
6
- /**
7
- * Builds a block and its header from a set of processed tx without running any circuits.
8
- *
9
- * NOTE: the onus is ON THE CALLER to update the db that is passed in with the notes hashes, nullifiers, etc
10
- * PRIOR to calling `buildBlock`.
11
- *
12
- * Why? Because if you are, e.g. building a block in practice from TxObjects, you are using the
13
- * PublicProcessor which will do this for you as it processes transactions.
14
- *
15
- * If you haven't already inserted the side effects, e.g. because you are in a testing context, you can use the helper
16
- * function `buildBlockWithCleanDB`, which calls `insertSideEffects` for you.
17
- *
18
- * @deprecated Use LightweightCheckpointBuilder instead. This only works for one block per checkpoint.
19
- */
20
- export declare class LightweightBlockFactory implements IBlockFactory {
21
- private db;
22
- private telemetry;
23
- private globalVariables?;
24
- private l1ToL2Messages?;
25
- private txs;
26
- private readonly logger;
27
- constructor(db: MerkleTreeWriteOperations, telemetry?: TelemetryClient);
28
- startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[]): Promise<void>;
29
- addTxs(txs: ProcessedTx[]): Promise<void>;
30
- setBlockCompleted(): Promise<L2Block>;
31
- private buildBlock;
32
- }
33
- /**
34
- * Inserts the processed transactions into the DB, then creates a block.
35
- * @param db - A db fork to use for block building which WILL BE MODIFIED.
36
- */
37
- export declare function buildBlockWithCleanDB(txs: ProcessedTx[], globalVariables: GlobalVariables, l1ToL2Messages: Fr[], db: MerkleTreeWrite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,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAOzF;IAED,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CASxC;IAED,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAEpC;YAEa,UAAU;CA8CzB;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,WAAW,EAAE,EAClB,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,EAAE,EAAE,EACpB,EAAE,EAAE,yBAAyB,EAC7B,SAAS,GAAE,eAAsC,oBAWlD"}
@@ -1,108 +0,0 @@
1
- import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
2
- import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
3
- import { padArrayEnd } from '@aztec/foundation/collection';
4
- import { Fr } from '@aztec/foundation/fields';
5
- import { createLogger } from '@aztec/foundation/log';
6
- import { L2Block, L2BlockHeader } from '@aztec/stdlib/block';
7
- import { computeBlockOutHash, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
8
- import { MerkleTreeId } from '@aztec/stdlib/trees';
9
- import { ContentCommitment } from '@aztec/stdlib/tx';
10
- import { getTelemetryClient } from '@aztec/telemetry-client';
11
- import { buildHeaderAndBodyFromTxs, getTreeSnapshot, insertSideEffects } from '../orchestrator/block-building-helpers.js';
12
- /**
13
- * Builds a block and its header from a set of processed tx without running any circuits.
14
- *
15
- * NOTE: the onus is ON THE CALLER to update the db that is passed in with the notes hashes, nullifiers, etc
16
- * PRIOR to calling `buildBlock`.
17
- *
18
- * Why? Because if you are, e.g. building a block in practice from TxObjects, you are using the
19
- * PublicProcessor which will do this for you as it processes transactions.
20
- *
21
- * If you haven't already inserted the side effects, e.g. because you are in a testing context, you can use the helper
22
- * function `buildBlockWithCleanDB`, which calls `insertSideEffects` for you.
23
- *
24
- * @deprecated Use LightweightCheckpointBuilder instead. This only works for one block per checkpoint.
25
- */ export class LightweightBlockFactory {
26
- db;
27
- telemetry;
28
- globalVariables;
29
- l1ToL2Messages;
30
- txs;
31
- logger;
32
- constructor(db, telemetry = getTelemetryClient()){
33
- this.db = db;
34
- this.telemetry = telemetry;
35
- this.logger = createLogger('lightweight-block-factory');
36
- }
37
- async startNewBlock(globalVariables, l1ToL2Messages) {
38
- this.logger.debug('Starting new block', {
39
- globalVariables: globalVariables.toInspect(),
40
- l1ToL2Messages
41
- });
42
- this.globalVariables = globalVariables;
43
- this.l1ToL2Messages = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
44
- this.txs = undefined;
45
- // Update L1 to L2 tree
46
- await this.db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, this.l1ToL2Messages);
47
- }
48
- addTxs(txs) {
49
- // Most times, `addTxs` is only called once per block.
50
- // So avoid copies.
51
- if (this.txs === undefined) {
52
- this.txs = txs;
53
- } else {
54
- this.txs.push(...txs);
55
- }
56
- return Promise.resolve();
57
- }
58
- setBlockCompleted() {
59
- return this.buildBlock();
60
- }
61
- async buildBlock() {
62
- const lastArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
63
- const state = await this.db.getStateReference();
64
- const txs = this.txs ?? [];
65
- const startSpongeBlob = SpongeBlob.init();
66
- const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(txs, lastArchive, state, this.globalVariables, startSpongeBlob, true);
67
- header.state.validate();
68
- await this.db.updateArchive(header);
69
- const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
70
- const outHash = computeBlockOutHash(txs.map((tx)=>tx.txEffect.l2ToL1Msgs));
71
- const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
72
- const numBlobFields = blockBlobFields.length + 1;
73
- const blobFields = blockBlobFields.concat([
74
- encodeCheckpointEndMarker({
75
- numBlobFields
76
- })
77
- ]);
78
- const blobsHash = computeBlobsHashFromBlobs(getBlobsPerL1Block(blobFields));
79
- const blockHeaderHash = await header.hash();
80
- const contentCommitment = new ContentCommitment(blobsHash, inHash, outHash);
81
- const l2BlockHeader = L2BlockHeader.from({
82
- ...header,
83
- blockHeadersHash: blockHeaderHash,
84
- contentCommitment
85
- });
86
- const block = new L2Block(newArchive, l2BlockHeader, body);
87
- this.logger.debug(`Built block ${block.number}`, {
88
- globalVariables: this.globalVariables?.toInspect(),
89
- archiveRoot: newArchive.root.toString(),
90
- stateReference: header.state.toInspect(),
91
- blockHash: (await block.hash()).toString(),
92
- txs: block.body.txEffects.map((tx)=>tx.txHash.toString())
93
- });
94
- return block;
95
- }
96
- }
97
- /**
98
- * Inserts the processed transactions into the DB, then creates a block.
99
- * @param db - A db fork to use for block building which WILL BE MODIFIED.
100
- */ export async function buildBlockWithCleanDB(txs, globalVariables, l1ToL2Messages, db, telemetry = getTelemetryClient()) {
101
- const builder = new LightweightBlockFactory(db, telemetry);
102
- await builder.startNewBlock(globalVariables, l1ToL2Messages);
103
- for (const tx of txs){
104
- await insertSideEffects(tx, db);
105
- }
106
- await builder.addTxs(txs);
107
- return await builder.setBlockCompleted();
108
- }
@@ -1,8 +0,0 @@
1
- import type { Timer } from '@aztec/foundation/timer';
2
- import { type TelemetryClient } from '@aztec/telemetry-client';
3
- export declare class ProvingAgentInstrumentation {
4
- private idleTime;
5
- constructor(client: TelemetryClient, name?: string);
6
- recordIdleTime(msOrTimer: Timer | number): void;
7
- }
8
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvdmluZ19hZ2VudF9pbnN0cnVtZW50YXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcm92aW5nX2Jyb2tlci9wcm92aW5nX2FnZW50X2luc3RydW1lbnRhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxLQUFLLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUNyRCxPQUFPLEVBQTJCLEtBQUssZUFBZSxFQUFhLE1BQU0seUJBQXlCLENBQUM7QUFFbkcscUJBQWEsMkJBQTJCO0lBQ3RDLE9BQU8sQ0FBQyxRQUFRLENBQVk7SUFFNUIsWUFBWSxNQUFNLEVBQUUsZUFBZSxFQUFFLElBQUksU0FBaUIsRUFRekQ7SUFFRCxjQUFjLENBQUMsU0FBUyxFQUFFLEtBQUssR0FBRyxNQUFNLFFBR3ZDO0NBQ0YifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"proving_agent_instrumentation.d.ts","sourceRoot":"","sources":["../../src/proving_broker/proving_agent_instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAA2B,KAAK,eAAe,EAAa,MAAM,yBAAyB,CAAC;AAEnG,qBAAa,2BAA2B;IACtC,OAAO,CAAC,QAAQ,CAAY;IAE5B,YAAY,MAAM,EAAE,eAAe,EAAE,IAAI,SAAiB,EAQzD;IAED,cAAc,CAAC,SAAS,EAAE,KAAK,GAAG,MAAM,QAGvC;CACF"}
@@ -1,16 +0,0 @@
1
- import { Metrics, ValueType } from '@aztec/telemetry-client';
2
- export class ProvingAgentInstrumentation {
3
- idleTime;
4
- constructor(client, name = 'ProvingAgent'){
5
- const meter = client.getMeter(name);
6
- this.idleTime = meter.createHistogram(Metrics.PROVING_AGENT_IDLE, {
7
- description: 'Records how long an agent was idle',
8
- unit: 's',
9
- valueType: ValueType.DOUBLE
10
- });
11
- }
12
- recordIdleTime(msOrTimer) {
13
- const duration = typeof msOrTimer === 'number' ? msOrTimer : msOrTimer.ms();
14
- this.idleTime.record(duration / 1000);
15
- }
16
- }
@@ -1 +0,0 @@
1
- export * from './light.js';
@@ -1,137 +0,0 @@
1
- import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
2
- import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
3
- import { padArrayEnd } from '@aztec/foundation/collection';
4
- import { Fr } from '@aztec/foundation/fields';
5
- import { createLogger } from '@aztec/foundation/log';
6
- import { L2Block, L2BlockHeader } from '@aztec/stdlib/block';
7
- import type { IBlockFactory, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
8
- import { computeBlockOutHash, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
9
- import { MerkleTreeId } from '@aztec/stdlib/trees';
10
- import { ContentCommitment, type GlobalVariables, type ProcessedTx } from '@aztec/stdlib/tx';
11
- import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
12
-
13
- import {
14
- buildHeaderAndBodyFromTxs,
15
- getTreeSnapshot,
16
- insertSideEffects,
17
- } from '../orchestrator/block-building-helpers.js';
18
-
19
- /**
20
- * Builds a block and its header from a set of processed tx without running any circuits.
21
- *
22
- * NOTE: the onus is ON THE CALLER to update the db that is passed in with the notes hashes, nullifiers, etc
23
- * PRIOR to calling `buildBlock`.
24
- *
25
- * Why? Because if you are, e.g. building a block in practice from TxObjects, you are using the
26
- * PublicProcessor which will do this for you as it processes transactions.
27
- *
28
- * If you haven't already inserted the side effects, e.g. because you are in a testing context, you can use the helper
29
- * function `buildBlockWithCleanDB`, which calls `insertSideEffects` for you.
30
- *
31
- * @deprecated Use LightweightCheckpointBuilder instead. This only works for one block per checkpoint.
32
- */
33
- export class LightweightBlockFactory implements IBlockFactory {
34
- private globalVariables?: GlobalVariables;
35
- private l1ToL2Messages?: Fr[];
36
- private txs: ProcessedTx[] | undefined;
37
-
38
- private readonly logger = createLogger('lightweight-block-factory');
39
-
40
- constructor(
41
- private db: MerkleTreeWriteOperations,
42
- private telemetry: TelemetryClient = getTelemetryClient(),
43
- ) {}
44
-
45
- async startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[]): Promise<void> {
46
- this.logger.debug('Starting new block', { globalVariables: globalVariables.toInspect(), l1ToL2Messages });
47
- this.globalVariables = globalVariables;
48
- this.l1ToL2Messages = padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
49
- this.txs = undefined;
50
- // Update L1 to L2 tree
51
- await this.db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, this.l1ToL2Messages!);
52
- }
53
-
54
- addTxs(txs: ProcessedTx[]): Promise<void> {
55
- // Most times, `addTxs` is only called once per block.
56
- // So avoid copies.
57
- if (this.txs === undefined) {
58
- this.txs = txs;
59
- } else {
60
- this.txs.push(...txs);
61
- }
62
- return Promise.resolve();
63
- }
64
-
65
- setBlockCompleted(): Promise<L2Block> {
66
- return this.buildBlock();
67
- }
68
-
69
- private async buildBlock(): Promise<L2Block> {
70
- const lastArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
71
- const state = await this.db.getStateReference();
72
-
73
- const txs = this.txs ?? [];
74
- const startSpongeBlob = SpongeBlob.init();
75
-
76
- const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(
77
- txs,
78
- lastArchive,
79
- state,
80
- this.globalVariables!,
81
- startSpongeBlob,
82
- true,
83
- );
84
-
85
- header.state.validate();
86
-
87
- await this.db.updateArchive(header);
88
- const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
89
-
90
- const outHash = computeBlockOutHash(txs.map(tx => tx.txEffect.l2ToL1Msgs));
91
- const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages!);
92
- const numBlobFields = blockBlobFields.length + 1;
93
- const blobFields = blockBlobFields.concat([encodeCheckpointEndMarker({ numBlobFields })]);
94
- const blobsHash = computeBlobsHashFromBlobs(getBlobsPerL1Block(blobFields));
95
- const blockHeaderHash = await header.hash();
96
- const contentCommitment = new ContentCommitment(blobsHash, inHash, outHash);
97
- const l2BlockHeader = L2BlockHeader.from({
98
- ...header,
99
- blockHeadersHash: blockHeaderHash,
100
- contentCommitment,
101
- });
102
-
103
- const block = new L2Block(newArchive, l2BlockHeader, body);
104
-
105
- this.logger.debug(`Built block ${block.number}`, {
106
- globalVariables: this.globalVariables?.toInspect(),
107
- archiveRoot: newArchive.root.toString(),
108
- stateReference: header.state.toInspect(),
109
- blockHash: (await block.hash()).toString(),
110
- txs: block.body.txEffects.map(tx => tx.txHash.toString()),
111
- });
112
-
113
- return block;
114
- }
115
- }
116
-
117
- /**
118
- * Inserts the processed transactions into the DB, then creates a block.
119
- * @param db - A db fork to use for block building which WILL BE MODIFIED.
120
- */
121
- export async function buildBlockWithCleanDB(
122
- txs: ProcessedTx[],
123
- globalVariables: GlobalVariables,
124
- l1ToL2Messages: Fr[],
125
- db: MerkleTreeWriteOperations,
126
- telemetry: TelemetryClient = getTelemetryClient(),
127
- ) {
128
- const builder = new LightweightBlockFactory(db, telemetry);
129
- await builder.startNewBlock(globalVariables, l1ToL2Messages);
130
-
131
- for (const tx of txs) {
132
- await insertSideEffects(tx, db);
133
- }
134
- await builder.addTxs(txs);
135
-
136
- return await builder.setBlockCompleted();
137
- }
@@ -1,21 +0,0 @@
1
- import type { Timer } from '@aztec/foundation/timer';
2
- import { type Histogram, Metrics, type TelemetryClient, ValueType } from '@aztec/telemetry-client';
3
-
4
- export class ProvingAgentInstrumentation {
5
- private idleTime: Histogram;
6
-
7
- constructor(client: TelemetryClient, name = 'ProvingAgent') {
8
- const meter = client.getMeter(name);
9
-
10
- this.idleTime = meter.createHistogram(Metrics.PROVING_AGENT_IDLE, {
11
- description: 'Records how long an agent was idle',
12
- unit: 's',
13
- valueType: ValueType.DOUBLE,
14
- });
15
- }
16
-
17
- recordIdleTime(msOrTimer: Timer | number) {
18
- const duration = typeof msOrTimer === 'number' ? msOrTimer : msOrTimer.ms();
19
- this.idleTime.record(duration / 1000);
20
- }
21
- }