@aztec/prover-node 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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.
- package/README.md +518 -0
- package/dest/actions/download-epoch-proving-job.d.ts +4 -4
- package/dest/actions/download-epoch-proving-job.js +1 -1
- package/dest/actions/index.d.ts +1 -1
- package/dest/actions/rerun-epoch-proving-job.d.ts +6 -4
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
- package/dest/actions/rerun-epoch-proving-job.js +191 -28
- package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
- package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
- package/dest/bin/run-failed-epoch.d.ts +1 -1
- package/dest/bin/run-failed-epoch.js +6 -5
- package/dest/checkpoint-store.d.ts +87 -0
- package/dest/checkpoint-store.d.ts.map +1 -0
- package/dest/checkpoint-store.js +186 -0
- package/dest/config.d.ts +10 -10
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +27 -22
- package/dest/factory.d.ts +23 -16
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +49 -68
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/job/checkpoint-prover.d.ts +134 -0
- package/dest/job/checkpoint-prover.d.ts.map +1 -0
- package/dest/job/checkpoint-prover.js +353 -0
- package/dest/job/epoch-proving-job-data.d.ts +8 -6
- package/dest/job/epoch-proving-job-data.d.ts.map +1 -1
- package/dest/job/epoch-proving-job-data.js +25 -18
- package/dest/job/epoch-session.d.ts +146 -0
- package/dest/job/epoch-session.d.ts.map +1 -0
- package/dest/job/epoch-session.js +720 -0
- package/dest/job/top-tree-job.d.ts +82 -0
- package/dest/job/top-tree-job.d.ts.map +1 -0
- package/dest/job/top-tree-job.js +152 -0
- package/dest/metrics.d.ts +42 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +128 -99
- package/dest/monitors/epoch-monitor.d.ts +3 -2
- package/dest/monitors/epoch-monitor.d.ts.map +1 -1
- package/dest/monitors/epoch-monitor.js +14 -20
- package/dest/monitors/index.d.ts +1 -1
- package/dest/proof-publishing-service.d.ts +161 -0
- package/dest/proof-publishing-service.d.ts.map +1 -0
- package/dest/proof-publishing-service.js +335 -0
- package/dest/prover-node-publisher.d.ts +36 -23
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +244 -98
- package/dest/prover-node.d.ts +122 -71
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +872 -226
- package/dest/prover-publisher-factory.d.ts +12 -6
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +8 -5
- package/dest/session-manager.d.ts +158 -0
- package/dest/session-manager.d.ts.map +1 -0
- package/dest/session-manager.js +452 -0
- package/dest/test/index.d.ts +7 -6
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +28 -25
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +120 -30
- package/src/actions/upload-epoch-proof-failure.ts +1 -1
- package/src/bin/run-failed-epoch.ts +5 -3
- package/src/checkpoint-store.ts +218 -0
- package/src/config.ts +39 -34
- package/src/factory.ts +86 -111
- package/src/index.ts +2 -0
- package/src/job/checkpoint-prover.ts +468 -0
- package/src/job/epoch-proving-job-data.ts +31 -25
- package/src/job/epoch-session.ts +436 -0
- package/src/job/top-tree-job.ts +227 -0
- package/src/metrics.ts +146 -84
- package/src/monitors/epoch-monitor.ts +10 -17
- package/src/proof-publishing-service.ts +427 -0
- package/src/prover-node-publisher.ts +300 -129
- package/src/prover-node.ts +569 -254
- package/src/prover-publisher-factory.ts +22 -11
- package/src/session-manager.ts +552 -0
- package/src/test/index.ts +6 -6
- package/dest/job/epoch-proving-job.d.ts +0 -69
- package/dest/job/epoch-proving-job.d.ts.map +0 -1
- package/dest/job/epoch-proving-job.js +0 -354
- package/src/job/epoch-proving-job.ts +0 -420
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
2
|
-
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
3
|
-
import { type EpochProver, type EpochProvingJobState, EpochProvingJobTerminalState, type ForkMerkleTreeOperations } from '@aztec/stdlib/interfaces/server';
|
|
4
|
-
import { type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
5
|
-
import type { ProverNodeJobMetrics } from '../metrics.js';
|
|
6
|
-
import type { ProverNodePublisher } from '../prover-node-publisher.js';
|
|
7
|
-
import { type EpochProvingJobData } from './epoch-proving-job-data.js';
|
|
8
|
-
export type EpochProvingJobOptions = {
|
|
9
|
-
parallelBlockLimit?: number;
|
|
10
|
-
skipEpochCheck?: boolean;
|
|
11
|
-
skipSubmitProof?: boolean;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Job that grabs a range of blocks from the unfinalized chain from L1, gets their txs given their hashes,
|
|
15
|
-
* re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
|
|
16
|
-
* world state as part of public call execution via the public processor.
|
|
17
|
-
*/
|
|
18
|
-
export declare class EpochProvingJob implements Traceable {
|
|
19
|
-
private data;
|
|
20
|
-
private dbProvider;
|
|
21
|
-
private prover;
|
|
22
|
-
private publicProcessorFactory;
|
|
23
|
-
private publisher;
|
|
24
|
-
private l2BlockSource;
|
|
25
|
-
private metrics;
|
|
26
|
-
private deadline;
|
|
27
|
-
private config;
|
|
28
|
-
private state;
|
|
29
|
-
private log;
|
|
30
|
-
private uuid;
|
|
31
|
-
private runPromise;
|
|
32
|
-
private epochCheckPromise;
|
|
33
|
-
private deadlineTimeoutHandler;
|
|
34
|
-
readonly tracer: Tracer;
|
|
35
|
-
constructor(data: EpochProvingJobData, dbProvider: Pick<ForkMerkleTreeOperations, 'fork'>, prover: EpochProver, publicProcessorFactory: PublicProcessorFactory, publisher: Pick<ProverNodePublisher, 'submitEpochProof'>, l2BlockSource: L2BlockSource | undefined, metrics: ProverNodeJobMetrics, deadline: Date | undefined, config: EpochProvingJobOptions);
|
|
36
|
-
getId(): string;
|
|
37
|
-
getState(): EpochProvingJobState;
|
|
38
|
-
getEpochNumber(): bigint;
|
|
39
|
-
getDeadline(): Date | undefined;
|
|
40
|
-
getProvingData(): EpochProvingJobData;
|
|
41
|
-
private get epochNumber();
|
|
42
|
-
private get blocks();
|
|
43
|
-
private get txs();
|
|
44
|
-
private get attestations();
|
|
45
|
-
/**
|
|
46
|
-
* Proves the given epoch and submits the proof to L1.
|
|
47
|
-
*/
|
|
48
|
-
run(): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Create a new db fork for tx processing, inserting all L1 to L2.
|
|
51
|
-
* REFACTOR: The prover already spawns a db fork of its own for each block, so we may be able to do away with just one fork.
|
|
52
|
-
*/
|
|
53
|
-
private createFork;
|
|
54
|
-
private progressState;
|
|
55
|
-
private checkState;
|
|
56
|
-
stop(state?: EpochProvingJobTerminalState): Promise<void>;
|
|
57
|
-
private scheduleDeadlineStop;
|
|
58
|
-
/**
|
|
59
|
-
* Kicks off a running promise that queries the archiver for the set of L2 blocks of the current epoch.
|
|
60
|
-
* If those change, stops the proving job with a `rerun` state, so the node re-enqueues it.
|
|
61
|
-
*/
|
|
62
|
-
private scheduleEpochCheck;
|
|
63
|
-
private getBlockHeader;
|
|
64
|
-
private getTxs;
|
|
65
|
-
private getL1ToL2Messages;
|
|
66
|
-
private processTxs;
|
|
67
|
-
}
|
|
68
|
-
export { type EpochProvingJobState };
|
|
69
|
-
//# sourceMappingURL=epoch-proving-job.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"epoch-proving-job.d.ts","sourceRoot":"","sources":["../../src/job/epoch-proving-job.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAmB,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,KAAK,EAAW,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,4BAA4B,EAC5B,KAAK,wBAAwB,EAC9B,MAAM,iCAAiC,CAAC;AAIzC,OAAO,EAAc,KAAK,SAAS,EAAE,KAAK,MAAM,EAAa,MAAM,yBAAyB,CAAC;AAI7F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,KAAK,mBAAmB,EAA+B,MAAM,6BAA6B,CAAC;AAEpG,MAAM,MAAM,sBAAsB,GAAG;IACnC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,SAAS;IAY7C,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,sBAAsB;IAC9B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,MAAM;IAnBhB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,GAAG,CAAiD;IAC5D,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,sBAAsB,CAA6B;IAE3D,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAGrB,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,EAClD,MAAM,EAAE,WAAW,EACnB,sBAAsB,EAAE,sBAAsB,EAC9C,SAAS,EAAE,IAAI,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,EACxD,aAAa,EAAE,aAAa,GAAG,SAAS,EACxC,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,IAAI,GAAG,SAAS,EAC1B,MAAM,EAAE,sBAAsB;IAOjC,KAAK,IAAI,MAAM;IAIf,QAAQ,IAAI,oBAAoB;IAIhC,cAAc,IAAI,MAAM;IAIxB,WAAW,IAAI,IAAI,GAAG,SAAS;IAI/B,cAAc,IAAI,mBAAmB;IAI5C,OAAO,KAAK,WAAW,GAEtB;IAED,OAAO,KAAK,MAAM,GAEjB;IAED,OAAO,KAAK,GAAG,GAEd;IAED,OAAO,KAAK,YAAY,GAEvB;IAED;;OAEG;IAIU,GAAG;IAiKhB;;;OAGG;YACW,UAAU;IAgBxB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,UAAU;IAML,IAAI,CAAC,KAAK,GAAE,4BAAwC;IAQjE,OAAO,CAAC,oBAAoB;IAoB5B;;;OAGG;YACW,kBAAkB;IAiChC,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,iBAAiB;YAIX,UAAU;CAmBzB;AASD,OAAO,EAAE,KAAK,oBAAoB,EAAE,CAAC"}
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
8
|
-
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
9
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
10
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
11
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
12
|
-
import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
13
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
14
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
15
|
-
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
16
|
-
import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
|
|
17
|
-
import { EpochProvingJobTerminalState } from '@aztec/stdlib/interfaces/server';
|
|
18
|
-
import { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
19
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
20
|
-
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
21
|
-
import * as crypto from 'node:crypto';
|
|
22
|
-
import { validateEpochProvingJobData } from './epoch-proving-job-data.js';
|
|
23
|
-
/**
|
|
24
|
-
* Job that grabs a range of blocks from the unfinalized chain from L1, gets their txs given their hashes,
|
|
25
|
-
* re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
|
|
26
|
-
* world state as part of public call execution via the public processor.
|
|
27
|
-
*/ export class EpochProvingJob {
|
|
28
|
-
data;
|
|
29
|
-
dbProvider;
|
|
30
|
-
prover;
|
|
31
|
-
publicProcessorFactory;
|
|
32
|
-
publisher;
|
|
33
|
-
l2BlockSource;
|
|
34
|
-
metrics;
|
|
35
|
-
deadline;
|
|
36
|
-
config;
|
|
37
|
-
state;
|
|
38
|
-
log;
|
|
39
|
-
uuid;
|
|
40
|
-
runPromise;
|
|
41
|
-
epochCheckPromise;
|
|
42
|
-
deadlineTimeoutHandler;
|
|
43
|
-
tracer;
|
|
44
|
-
constructor(data, dbProvider, prover, publicProcessorFactory, publisher, l2BlockSource, metrics, deadline, config){
|
|
45
|
-
this.data = data;
|
|
46
|
-
this.dbProvider = dbProvider;
|
|
47
|
-
this.prover = prover;
|
|
48
|
-
this.publicProcessorFactory = publicProcessorFactory;
|
|
49
|
-
this.publisher = publisher;
|
|
50
|
-
this.l2BlockSource = l2BlockSource;
|
|
51
|
-
this.metrics = metrics;
|
|
52
|
-
this.deadline = deadline;
|
|
53
|
-
this.config = config;
|
|
54
|
-
this.state = 'initialized';
|
|
55
|
-
this.log = createLogger('prover-node:epoch-proving-job');
|
|
56
|
-
validateEpochProvingJobData(data);
|
|
57
|
-
this.uuid = crypto.randomUUID();
|
|
58
|
-
this.tracer = metrics.tracer;
|
|
59
|
-
}
|
|
60
|
-
getId() {
|
|
61
|
-
return this.uuid;
|
|
62
|
-
}
|
|
63
|
-
getState() {
|
|
64
|
-
return this.state;
|
|
65
|
-
}
|
|
66
|
-
getEpochNumber() {
|
|
67
|
-
return this.data.epochNumber;
|
|
68
|
-
}
|
|
69
|
-
getDeadline() {
|
|
70
|
-
return this.deadline;
|
|
71
|
-
}
|
|
72
|
-
getProvingData() {
|
|
73
|
-
return this.data;
|
|
74
|
-
}
|
|
75
|
-
get epochNumber() {
|
|
76
|
-
return this.data.epochNumber;
|
|
77
|
-
}
|
|
78
|
-
get blocks() {
|
|
79
|
-
return this.data.blocks;
|
|
80
|
-
}
|
|
81
|
-
get txs() {
|
|
82
|
-
return this.data.txs;
|
|
83
|
-
}
|
|
84
|
-
get attestations() {
|
|
85
|
-
return this.data.attestations;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Proves the given epoch and submits the proof to L1.
|
|
89
|
-
*/ async run() {
|
|
90
|
-
this.scheduleDeadlineStop();
|
|
91
|
-
if (!this.config.skipEpochCheck) {
|
|
92
|
-
await this.scheduleEpochCheck();
|
|
93
|
-
}
|
|
94
|
-
const attestations = this.attestations.map((attestation)=>attestation.toViem());
|
|
95
|
-
const epochNumber = Number(this.epochNumber);
|
|
96
|
-
const epochSizeBlocks = this.blocks.length;
|
|
97
|
-
const epochSizeTxs = this.blocks.reduce((total, current)=>total + current.body.txEffects.length, 0);
|
|
98
|
-
const [fromBlock, toBlock] = [
|
|
99
|
-
this.blocks[0].number,
|
|
100
|
-
this.blocks.at(-1).number
|
|
101
|
-
];
|
|
102
|
-
this.log.info(`Starting epoch ${epochNumber} proving job with blocks ${fromBlock} to ${toBlock}`, {
|
|
103
|
-
fromBlock,
|
|
104
|
-
toBlock,
|
|
105
|
-
epochSizeBlocks,
|
|
106
|
-
epochNumber,
|
|
107
|
-
uuid: this.uuid
|
|
108
|
-
});
|
|
109
|
-
this.progressState('processing');
|
|
110
|
-
const timer = new Timer();
|
|
111
|
-
const { promise, resolve } = promiseWithResolvers();
|
|
112
|
-
this.runPromise = promise;
|
|
113
|
-
try {
|
|
114
|
-
const blobFieldsPerCheckpoint = this.blocks.map((block)=>block.getCheckpointBlobFields());
|
|
115
|
-
const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
|
|
116
|
-
// TODO(#17027): Enable multiple blocks per checkpoint.
|
|
117
|
-
// Total number of checkpoints equals number of blocks because we currently build a checkpoint with only one block.
|
|
118
|
-
const totalNumCheckpoints = epochSizeBlocks;
|
|
119
|
-
this.prover.startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges);
|
|
120
|
-
await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
|
|
121
|
-
await asyncPool(this.config.parallelBlockLimit ?? 32, this.blocks, async (block)=>{
|
|
122
|
-
this.checkState();
|
|
123
|
-
const globalVariables = block.header.globalVariables;
|
|
124
|
-
const txs = this.getTxs(block);
|
|
125
|
-
const l1ToL2Messages = this.getL1ToL2Messages(block);
|
|
126
|
-
const previousHeader = this.getBlockHeader(block.number - 1);
|
|
127
|
-
this.log.verbose(`Starting processing block ${block.number}`, {
|
|
128
|
-
number: block.number,
|
|
129
|
-
blockHash: (await block.hash()).toString(),
|
|
130
|
-
lastArchive: block.header.lastArchive.root,
|
|
131
|
-
noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
|
|
132
|
-
nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
|
|
133
|
-
publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
|
|
134
|
-
previousHeader: previousHeader.hash(),
|
|
135
|
-
uuid: this.uuid,
|
|
136
|
-
...globalVariables
|
|
137
|
-
});
|
|
138
|
-
const checkpointConstants = CheckpointConstantData.from({
|
|
139
|
-
chainId: globalVariables.chainId,
|
|
140
|
-
version: globalVariables.version,
|
|
141
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
142
|
-
protocolContractsHash: protocolContractsHash,
|
|
143
|
-
proverId: this.prover.getProverId().toField(),
|
|
144
|
-
slotNumber: globalVariables.slotNumber,
|
|
145
|
-
coinbase: globalVariables.coinbase,
|
|
146
|
-
feeRecipient: globalVariables.feeRecipient,
|
|
147
|
-
gasFees: globalVariables.gasFees
|
|
148
|
-
});
|
|
149
|
-
// TODO(#17027): Enable multiple blocks per checkpoint.
|
|
150
|
-
// Each checkpoint has only one block.
|
|
151
|
-
const totalNumBlocks = 1;
|
|
152
|
-
const checkpointIndex = block.number - fromBlock;
|
|
153
|
-
await this.prover.startNewCheckpoint(checkpointIndex, checkpointConstants, l1ToL2Messages, totalNumBlocks, blobFieldsPerCheckpoint[checkpointIndex].length, previousHeader);
|
|
154
|
-
// Start block proving
|
|
155
|
-
await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
|
|
156
|
-
// Process public fns
|
|
157
|
-
const db = await this.createFork(block.number - 1, l1ToL2Messages);
|
|
158
|
-
const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, {
|
|
159
|
-
skipFeeEnforcement: true,
|
|
160
|
-
clientInitiatedSimulation: false,
|
|
161
|
-
proverId: this.prover.getProverId().toField()
|
|
162
|
-
});
|
|
163
|
-
const processed = await this.processTxs(publicProcessor, txs);
|
|
164
|
-
await this.prover.addTxs(processed);
|
|
165
|
-
await db.close();
|
|
166
|
-
this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
|
|
167
|
-
blockNumber: block.number,
|
|
168
|
-
blockHash: (await block.hash()).toString(),
|
|
169
|
-
uuid: this.uuid
|
|
170
|
-
});
|
|
171
|
-
// Mark block as completed to pad it
|
|
172
|
-
const expectedBlockHeader = block.getBlockHeader();
|
|
173
|
-
await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
|
|
174
|
-
});
|
|
175
|
-
const executionTime = timer.ms();
|
|
176
|
-
this.progressState('awaiting-prover');
|
|
177
|
-
const { publicInputs, proof, batchedBlobInputs } = await this.prover.finalizeEpoch();
|
|
178
|
-
this.log.info(`Finalized proof for epoch ${epochNumber}`, {
|
|
179
|
-
epochNumber,
|
|
180
|
-
uuid: this.uuid,
|
|
181
|
-
duration: timer.ms()
|
|
182
|
-
});
|
|
183
|
-
this.progressState('publishing-proof');
|
|
184
|
-
if (this.config.skipSubmitProof) {
|
|
185
|
-
this.log.info(`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (blocks ${fromBlock} to ${toBlock})`);
|
|
186
|
-
this.state = 'completed';
|
|
187
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const success = await this.publisher.submitEpochProof({
|
|
191
|
-
fromBlock,
|
|
192
|
-
toBlock,
|
|
193
|
-
epochNumber,
|
|
194
|
-
publicInputs,
|
|
195
|
-
proof,
|
|
196
|
-
batchedBlobInputs,
|
|
197
|
-
attestations
|
|
198
|
-
});
|
|
199
|
-
if (!success) {
|
|
200
|
-
throw new Error('Failed to submit epoch proof to L1');
|
|
201
|
-
}
|
|
202
|
-
this.log.info(`Submitted proof for epoch ${epochNumber} (blocks ${fromBlock} to ${toBlock})`, {
|
|
203
|
-
epochNumber,
|
|
204
|
-
uuid: this.uuid
|
|
205
|
-
});
|
|
206
|
-
this.state = 'completed';
|
|
207
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
|
|
208
|
-
} catch (err) {
|
|
209
|
-
if (err && err.name === 'HaltExecutionError') {
|
|
210
|
-
this.log.warn(`Halted execution of epoch ${epochNumber} prover job`, {
|
|
211
|
-
uuid: this.uuid,
|
|
212
|
-
epochNumber,
|
|
213
|
-
details: err.message
|
|
214
|
-
});
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
this.log.error(`Error running epoch ${epochNumber} prover job`, err, {
|
|
218
|
-
uuid: this.uuid,
|
|
219
|
-
epochNumber
|
|
220
|
-
});
|
|
221
|
-
if (this.state === 'processing' || this.state === 'awaiting-prover' || this.state === 'publishing-proof') {
|
|
222
|
-
this.state = 'failed';
|
|
223
|
-
}
|
|
224
|
-
} finally{
|
|
225
|
-
clearTimeout(this.deadlineTimeoutHandler);
|
|
226
|
-
await this.epochCheckPromise?.stop();
|
|
227
|
-
await this.prover.stop();
|
|
228
|
-
resolve();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Create a new db fork for tx processing, inserting all L1 to L2.
|
|
233
|
-
* REFACTOR: The prover already spawns a db fork of its own for each block, so we may be able to do away with just one fork.
|
|
234
|
-
*/ async createFork(blockNumber, l1ToL2Messages) {
|
|
235
|
-
const db = await this.dbProvider.fork(blockNumber);
|
|
236
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
|
|
237
|
-
this.log.verbose(`Creating fork at ${blockNumber} with ${l1ToL2Messages.length} L1 to L2 messages`, {
|
|
238
|
-
blockNumber,
|
|
239
|
-
l1ToL2Messages: l1ToL2MessagesPadded.map((m)=>m.toString())
|
|
240
|
-
});
|
|
241
|
-
await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
242
|
-
return db;
|
|
243
|
-
}
|
|
244
|
-
progressState(state) {
|
|
245
|
-
this.checkState();
|
|
246
|
-
this.state = state;
|
|
247
|
-
}
|
|
248
|
-
checkState() {
|
|
249
|
-
if (this.state === 'timed-out' || this.state === 'stopped' || this.state === 'failed' || this.state === 'reorg') {
|
|
250
|
-
throw new HaltExecutionError(this.state);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async stop(state = 'stopped') {
|
|
254
|
-
this.state = state;
|
|
255
|
-
this.prover.cancel();
|
|
256
|
-
if (this.runPromise) {
|
|
257
|
-
await this.runPromise;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
scheduleDeadlineStop() {
|
|
261
|
-
const deadline = this.deadline;
|
|
262
|
-
if (deadline) {
|
|
263
|
-
const timeout = deadline.getTime() - Date.now();
|
|
264
|
-
if (timeout <= 0) {
|
|
265
|
-
throw new Error('Cannot start job with deadline in the past');
|
|
266
|
-
}
|
|
267
|
-
this.deadlineTimeoutHandler = setTimeout(()=>{
|
|
268
|
-
if (EpochProvingJobTerminalState.includes(this.state)) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
this.log.warn('Stopping job due to deadline hit', {
|
|
272
|
-
uuid: this.uuid,
|
|
273
|
-
epochNumber: this.epochNumber
|
|
274
|
-
});
|
|
275
|
-
this.stop('timed-out').catch((err)=>{
|
|
276
|
-
this.log.error('Error stopping job', err, {
|
|
277
|
-
uuid: this.uuid,
|
|
278
|
-
epochNumber: this.epochNumber
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
}, timeout);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Kicks off a running promise that queries the archiver for the set of L2 blocks of the current epoch.
|
|
286
|
-
* If those change, stops the proving job with a `rerun` state, so the node re-enqueues it.
|
|
287
|
-
*/ async scheduleEpochCheck() {
|
|
288
|
-
const l2BlockSource = this.l2BlockSource;
|
|
289
|
-
if (!l2BlockSource) {
|
|
290
|
-
this.log.warn(`No L2 block source available, skipping epoch check`);
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
|
|
294
|
-
this.epochCheckPromise = new RunningPromise(async ()=>{
|
|
295
|
-
const blocks = await l2BlockSource.getBlockHeadersForEpoch(this.epochNumber);
|
|
296
|
-
const blockHashes = await Promise.all(blocks.map((block)=>block.hash()));
|
|
297
|
-
const thisBlockHashes = await Promise.all(this.blocks.map((block)=>block.hash()));
|
|
298
|
-
if (blocks.length !== this.blocks.length || !blockHashes.every((block, i)=>block.equals(thisBlockHashes[i]))) {
|
|
299
|
-
this.log.warn('Epoch blocks changed underfoot', {
|
|
300
|
-
uuid: this.uuid,
|
|
301
|
-
epochNumber: this.epochNumber,
|
|
302
|
-
oldBlockHashes: thisBlockHashes,
|
|
303
|
-
newBlockHashes: blockHashes
|
|
304
|
-
});
|
|
305
|
-
void this.stop('reorg');
|
|
306
|
-
}
|
|
307
|
-
}, this.log, intervalMs).start();
|
|
308
|
-
this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
|
|
309
|
-
}
|
|
310
|
-
/* Returns the header for the given block number based on the epoch proving job data. */ getBlockHeader(blockNumber) {
|
|
311
|
-
const block = this.blocks.find((b)=>b.number === blockNumber);
|
|
312
|
-
if (block) {
|
|
313
|
-
return block.getBlockHeader();
|
|
314
|
-
}
|
|
315
|
-
if (blockNumber === Number(this.data.previousBlockHeader.getBlockNumber())) {
|
|
316
|
-
return this.data.previousBlockHeader;
|
|
317
|
-
}
|
|
318
|
-
throw new Error(`Block header not found for block number ${blockNumber} (got ${this.blocks.map((b)=>b.number).join(', ')} and previous header ${this.data.previousBlockHeader.getBlockNumber()})`);
|
|
319
|
-
}
|
|
320
|
-
getTxs(block) {
|
|
321
|
-
return block.body.txEffects.map((txEffect)=>this.txs.get(txEffect.txHash.toString()));
|
|
322
|
-
}
|
|
323
|
-
getL1ToL2Messages(block) {
|
|
324
|
-
return this.data.l1ToL2Messages[block.number];
|
|
325
|
-
}
|
|
326
|
-
async processTxs(publicProcessor, txs) {
|
|
327
|
-
const { deadline } = this;
|
|
328
|
-
const [processedTxs, failedTxs] = await publicProcessor.process(txs, {
|
|
329
|
-
deadline
|
|
330
|
-
});
|
|
331
|
-
if (failedTxs.length) {
|
|
332
|
-
const failedTxHashes = await Promise.all(failedTxs.map(({ tx })=>tx.getTxHash()));
|
|
333
|
-
throw new Error(`Txs failed processing: ${failedTxs.map(({ error }, index)=>`${failedTxHashes[index]} (${error})`).join(', ')}`);
|
|
334
|
-
}
|
|
335
|
-
if (processedTxs.length !== txs.length) {
|
|
336
|
-
throw new Error(`Failed to process all txs: processed ${processedTxs.length} out of ${txs.length}`);
|
|
337
|
-
}
|
|
338
|
-
return processedTxs;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
_ts_decorate([
|
|
342
|
-
trackSpan('EpochProvingJob.run', function() {
|
|
343
|
-
return {
|
|
344
|
-
[Attributes.EPOCH_NUMBER]: Number(this.data.epochNumber)
|
|
345
|
-
};
|
|
346
|
-
})
|
|
347
|
-
], EpochProvingJob.prototype, "run", null);
|
|
348
|
-
class HaltExecutionError extends Error {
|
|
349
|
-
state;
|
|
350
|
-
constructor(state){
|
|
351
|
-
super(`Halted execution due to state ${state}`), this.state = state;
|
|
352
|
-
this.name = 'HaltExecutionError';
|
|
353
|
-
}
|
|
354
|
-
}
|