@aztec/sequencer-client 0.0.1-commit.6d3c34e → 0.0.1-commit.7cf39cb55
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/dest/client/sequencer-client.js +1 -1
- package/dest/config.d.ts +1 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -11
- package/dest/global_variable_builder/global_builder.js +2 -2
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +1 -2
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +39 -18
- package/dest/sequencer/checkpoint_proposal_job.d.ts +34 -9
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +136 -34
- package/dest/sequencer/checkpoint_voter.d.ts +3 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +34 -10
- package/dest/sequencer/index.d.ts +1 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -1
- package/dest/sequencer/metrics.d.ts +5 -2
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +52 -17
- package/dest/sequencer/sequencer.d.ts +19 -9
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +73 -12
- package/dest/sequencer/timetable.d.ts +1 -4
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +1 -4
- package/dest/test/mock_checkpoint_builder.d.ts +17 -13
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +28 -10
- package/dest/test/utils.d.ts +8 -8
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +8 -7
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +1 -1
- package/src/config.ts +10 -14
- package/src/global_variable_builder/global_builder.ts +2 -2
- package/src/index.ts +1 -6
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +34 -18
- package/src/sequencer/checkpoint_proposal_job.ts +189 -54
- package/src/sequencer/checkpoint_voter.ts +32 -7
- package/src/sequencer/index.ts +0 -1
- package/src/sequencer/metrics.ts +60 -18
- package/src/sequencer/sequencer.ts +90 -11
- package/src/sequencer/timetable.ts +6 -5
- package/src/test/mock_checkpoint_builder.ts +64 -34
- package/src/test/utils.ts +20 -12
- package/dest/sequencer/block_builder.d.ts +0 -26
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -129
- package/src/sequencer/block_builder.ts +0 -216
package/src/test/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Body } from '@aztec/aztec.js/block';
|
|
2
|
-
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { times } from '@aztec/foundation/collection';
|
|
4
4
|
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -7,7 +7,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
7
7
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
8
|
import type { P2P } from '@aztec/p2p';
|
|
9
9
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
10
|
-
import { CommitteeAttestation,
|
|
10
|
+
import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
11
11
|
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
12
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
13
|
import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
|
|
@@ -30,9 +30,9 @@ export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Creates an
|
|
33
|
+
* Creates an L2Block from transactions and global variables
|
|
34
34
|
*/
|
|
35
|
-
export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<
|
|
35
|
+
export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2Block> {
|
|
36
36
|
const processedTxs = await Promise.all(
|
|
37
37
|
txs.map(tx =>
|
|
38
38
|
makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
|
|
@@ -41,7 +41,13 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
|
|
|
41
41
|
const body = new Body(processedTxs.map(tx => tx.txEffect));
|
|
42
42
|
const header = BlockHeader.empty({ globalVariables });
|
|
43
43
|
const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
|
|
44
|
-
return new
|
|
44
|
+
return new L2Block(
|
|
45
|
+
archive,
|
|
46
|
+
header,
|
|
47
|
+
body,
|
|
48
|
+
CheckpointNumber.fromBlockNumber(globalVariables.blockNumber),
|
|
49
|
+
IndexWithinCheckpoint(0),
|
|
50
|
+
);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -50,6 +56,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
|
|
|
50
56
|
export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
|
|
51
57
|
p2p.getPendingTxCount.mockResolvedValue(txs.length);
|
|
52
58
|
p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
59
|
+
p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
/**
|
|
@@ -70,16 +77,17 @@ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestat
|
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
|
-
* Creates a CheckpointHeader from an
|
|
74
|
-
* Uses mock values for blockHeadersHash, blobsHash and inHash since
|
|
80
|
+
* Creates a CheckpointHeader from an L2Block for testing purposes.
|
|
81
|
+
* Uses mock values for blockHeadersHash, blobsHash and inHash since L2Block doesn't have these fields.
|
|
75
82
|
*/
|
|
76
|
-
function createCheckpointHeaderFromBlock(block:
|
|
83
|
+
function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
|
|
77
84
|
const gv = block.header.globalVariables;
|
|
78
85
|
return new CheckpointHeader(
|
|
79
86
|
block.header.lastArchive.root,
|
|
80
87
|
Fr.random(), // blockHeadersHash - mock value for testing
|
|
81
88
|
Fr.random(), // blobsHash - mock value for testing
|
|
82
89
|
Fr.random(), // inHash - mock value for testing
|
|
90
|
+
Fr.random(), // outHash - mock value for testing
|
|
83
91
|
gv.slotNumber,
|
|
84
92
|
gv.timestamp,
|
|
85
93
|
gv.coinbase,
|
|
@@ -92,7 +100,7 @@ function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
|
|
|
92
100
|
/**
|
|
93
101
|
* Creates a block proposal from a block and signature
|
|
94
102
|
*/
|
|
95
|
-
export function createBlockProposal(block:
|
|
103
|
+
export function createBlockProposal(block: L2Block, signature: Signature): BlockProposal {
|
|
96
104
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
97
105
|
return new BlockProposal(
|
|
98
106
|
block.header,
|
|
@@ -108,7 +116,7 @@ export function createBlockProposal(block: L2BlockNew, signature: Signature): Bl
|
|
|
108
116
|
* Creates a checkpoint proposal from a block and signature
|
|
109
117
|
*/
|
|
110
118
|
export function createCheckpointProposal(
|
|
111
|
-
block:
|
|
119
|
+
block: L2Block,
|
|
112
120
|
checkpointSignature: Signature,
|
|
113
121
|
blockSignature?: Signature,
|
|
114
122
|
): CheckpointProposal {
|
|
@@ -128,7 +136,7 @@ export function createCheckpointProposal(
|
|
|
128
136
|
* In production, the sender is recovered from the signature.
|
|
129
137
|
*/
|
|
130
138
|
export function createCheckpointAttestation(
|
|
131
|
-
block:
|
|
139
|
+
block: L2Block,
|
|
132
140
|
signature: Signature,
|
|
133
141
|
sender: EthAddress,
|
|
134
142
|
): CheckpointAttestation {
|
|
@@ -149,7 +157,7 @@ export async function setupTxsAndBlock(
|
|
|
149
157
|
globalVariables: GlobalVariables,
|
|
150
158
|
txCount: number,
|
|
151
159
|
chainId: Fr,
|
|
152
|
-
): Promise<{ txs: Tx[]; block:
|
|
160
|
+
): Promise<{ txs: Tx[]; block: L2Block }> {
|
|
153
161
|
const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
|
|
154
162
|
const block = await makeBlock(txs, globalVariables);
|
|
155
163
|
mockPendingTxs(p2p, txs);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
-
import { PublicProcessor } from '@aztec/simulator/server';
|
|
5
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
6
|
-
import type { BuildBlockResult, FullNodeBlockBuilderConfig, IFullNodeBlockBuilder, MerkleTreeWriteOperations, PublicProcessorLimits, PublicProcessorValidator, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
8
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
9
|
-
export declare class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
|
|
10
|
-
private config;
|
|
11
|
-
private worldState;
|
|
12
|
-
private contractDataSource;
|
|
13
|
-
private dateProvider;
|
|
14
|
-
private telemetryClient;
|
|
15
|
-
constructor(config: FullNodeBlockBuilderConfig, worldState: WorldStateSynchronizer, contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient?: TelemetryClient);
|
|
16
|
-
getConfig(): FullNodeBlockBuilderConfig;
|
|
17
|
-
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
|
|
18
|
-
makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations): Promise<{
|
|
19
|
-
processor: PublicProcessor;
|
|
20
|
-
validator: PublicProcessorValidator;
|
|
21
|
-
}>;
|
|
22
|
-
private syncToPreviousBlock;
|
|
23
|
-
buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], globalVariables: GlobalVariables, opts: PublicProcessorLimits, suppliedFork?: MerkleTreeWriteOperations): Promise<BuildBlockResult>;
|
|
24
|
-
getFork(blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfYnVpbGRlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NlcXVlbmNlci9ibG9ja19idWlsZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU5RCxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUl6RCxPQUFPLEVBQUUsWUFBWSxFQUFrQixNQUFNLHlCQUF5QixDQUFDO0FBR3ZFLE9BQU8sRUFHTCxlQUFlLEVBRWhCLE1BQU0seUJBQXlCLENBQUM7QUFDakMsT0FBTyxLQUFLLEV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C7D;IAEG,SAAS,IAAI,0BAA0B,CAE7C;IAEM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,0BAA0B,CAAC,QAE9D;IAEY,oBAAoB,CAAC,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,yBAAyB;;;OAkClG;YAEa,mBAAmB;IAU3B,UAAU,CACd,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,qBAAqB,EAC3B,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,gBAAgB,CAAC,CAsC3B;IAED,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAEpE;CACF"}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { MerkleTreeId } from '@aztec/aztec.js/trees';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
6
|
-
import { bufferToHex } from '@aztec/foundation/string';
|
|
7
|
-
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
8
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
9
|
-
import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
|
|
10
|
-
import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, createPublicTxSimulatorForBlockBuilding } from '@aztec/simulator/server';
|
|
11
|
-
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
13
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
|
-
import { createValidatorForBlockBuilding } from '@aztec/validator-client';
|
|
15
|
-
const log = createLogger('block-builder');
|
|
16
|
-
/** Builds a block out of pending txs */ async function buildBlock(pendingTxs, l1ToL2Messages, newGlobalVariables, opts = {}, worldStateFork, processor, validator, l1Constants, dateProvider, telemetryClient = getTelemetryClient()) {
|
|
17
|
-
const blockBuildingTimer = new Timer();
|
|
18
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
19
|
-
const slot = newGlobalVariables.slotNumber;
|
|
20
|
-
const msgCount = l1ToL2Messages.length;
|
|
21
|
-
const stateReference = await worldStateFork.getStateReference();
|
|
22
|
-
const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
23
|
-
log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
|
|
24
|
-
slot,
|
|
25
|
-
slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
|
|
26
|
-
now: new Date(dateProvider.now()),
|
|
27
|
-
blockNumber,
|
|
28
|
-
msgCount,
|
|
29
|
-
initialStateReference: stateReference.toInspect(),
|
|
30
|
-
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
31
|
-
opts
|
|
32
|
-
});
|
|
33
|
-
const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
|
|
34
|
-
await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
|
|
35
|
-
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(()=>processor.process(pendingTxs, opts, validator));
|
|
36
|
-
// All real transactions have been added, set the block as full and pad if needed
|
|
37
|
-
await blockFactory.addTxs(processedTxs);
|
|
38
|
-
const block = await blockFactory.setBlockCompleted();
|
|
39
|
-
// How much public gas was processed
|
|
40
|
-
const publicGas = processedTxs.reduce((acc, tx)=>acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
41
|
-
const res = {
|
|
42
|
-
block,
|
|
43
|
-
publicGas,
|
|
44
|
-
publicProcessorDuration,
|
|
45
|
-
numMsgs: l1ToL2Messages.length,
|
|
46
|
-
numTxs: processedTxs.length,
|
|
47
|
-
failedTxs: failedTxs,
|
|
48
|
-
blockBuildingTimer,
|
|
49
|
-
usedTxs
|
|
50
|
-
};
|
|
51
|
-
log.trace('Built block', res.block.header);
|
|
52
|
-
return res;
|
|
53
|
-
}
|
|
54
|
-
const FullNodeBlockBuilderConfigKeys = [
|
|
55
|
-
'l1GenesisTime',
|
|
56
|
-
'slotDuration',
|
|
57
|
-
'l1ChainId',
|
|
58
|
-
'rollupVersion',
|
|
59
|
-
'txPublicSetupAllowList',
|
|
60
|
-
'fakeProcessingDelayPerTxMs',
|
|
61
|
-
'fakeThrowAfterProcessingTxCount'
|
|
62
|
-
];
|
|
63
|
-
// TODO(palla/mbps): Try killing this in favor of the CheckpointsBuilder
|
|
64
|
-
export class FullNodeBlockBuilder {
|
|
65
|
-
config;
|
|
66
|
-
worldState;
|
|
67
|
-
contractDataSource;
|
|
68
|
-
dateProvider;
|
|
69
|
-
telemetryClient;
|
|
70
|
-
constructor(config, worldState, contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
|
|
71
|
-
this.config = config;
|
|
72
|
-
this.worldState = worldState;
|
|
73
|
-
this.contractDataSource = contractDataSource;
|
|
74
|
-
this.dateProvider = dateProvider;
|
|
75
|
-
this.telemetryClient = telemetryClient;
|
|
76
|
-
}
|
|
77
|
-
getConfig() {
|
|
78
|
-
return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
|
|
79
|
-
}
|
|
80
|
-
updateConfig(config) {
|
|
81
|
-
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
82
|
-
}
|
|
83
|
-
async makeBlockBuilderDeps(globalVariables, fork) {
|
|
84
|
-
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
85
|
-
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
86
|
-
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
87
|
-
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(guardedFork, contractsDB, globalVariables, this.telemetryClient);
|
|
88
|
-
const processor = new PublicProcessor(globalVariables, guardedFork, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient, undefined, this.config);
|
|
89
|
-
const validator = createValidatorForBlockBuilding(fork, this.contractDataSource, globalVariables, txPublicSetupAllowList);
|
|
90
|
-
return {
|
|
91
|
-
processor,
|
|
92
|
-
validator
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
async syncToPreviousBlock(parentBlockNumber, timeout) {
|
|
96
|
-
await retryUntil(()=>this.worldState.syncImmediate(parentBlockNumber, true).then((syncedTo)=>syncedTo >= parentBlockNumber), 'sync to previous block', timeout, 0.1);
|
|
97
|
-
log.debug(`Synced to previous block ${parentBlockNumber}`);
|
|
98
|
-
}
|
|
99
|
-
async buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, suppliedFork) {
|
|
100
|
-
const parentBlockNumber = BlockNumber(globalVariables.blockNumber - 1);
|
|
101
|
-
const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
|
|
102
|
-
await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
|
|
103
|
-
const fork = suppliedFork ?? await this.worldState.fork(parentBlockNumber);
|
|
104
|
-
try {
|
|
105
|
-
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
|
|
106
|
-
const res = await buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, fork, processor, validator, this.config, this.dateProvider, this.telemetryClient);
|
|
107
|
-
return res;
|
|
108
|
-
} finally{
|
|
109
|
-
// If the fork was supplied, we don't close it.
|
|
110
|
-
// Otherwise, we wait a bit to close the fork we just created,
|
|
111
|
-
// since the processor may still be working on a dangling tx
|
|
112
|
-
// which was interrupted due to the processingDeadline being hit.
|
|
113
|
-
if (!suppliedFork) {
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
115
|
-
setTimeout(async ()=>{
|
|
116
|
-
try {
|
|
117
|
-
await fork.close();
|
|
118
|
-
} catch (err) {
|
|
119
|
-
// This can happen if the sequencer is stopped before we hit this timeout.
|
|
120
|
-
log.warn(`Error closing forks for block processing`, err);
|
|
121
|
-
}
|
|
122
|
-
}, 5000);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
getFork(blockNumber) {
|
|
127
|
-
return this.worldState.fork(blockNumber);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { MerkleTreeId } from '@aztec/aztec.js/trees';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
-
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
|
-
import { bufferToHex } from '@aztec/foundation/string';
|
|
8
|
-
import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
|
|
9
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
10
|
-
import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
|
|
11
|
-
import {
|
|
12
|
-
GuardedMerkleTreeOperations,
|
|
13
|
-
PublicContractsDB,
|
|
14
|
-
PublicProcessor,
|
|
15
|
-
createPublicTxSimulatorForBlockBuilding,
|
|
16
|
-
} from '@aztec/simulator/server';
|
|
17
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
18
|
-
import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
19
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
20
|
-
import type {
|
|
21
|
-
BuildBlockResult,
|
|
22
|
-
FullNodeBlockBuilderConfig,
|
|
23
|
-
IFullNodeBlockBuilder,
|
|
24
|
-
MerkleTreeWriteOperations,
|
|
25
|
-
PublicProcessorLimits,
|
|
26
|
-
PublicProcessorValidator,
|
|
27
|
-
WorldStateSynchronizer,
|
|
28
|
-
} from '@aztec/stdlib/interfaces/server';
|
|
29
|
-
import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
30
|
-
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
31
|
-
import { createValidatorForBlockBuilding } from '@aztec/validator-client';
|
|
32
|
-
|
|
33
|
-
const log = createLogger('block-builder');
|
|
34
|
-
|
|
35
|
-
/** Builds a block out of pending txs */
|
|
36
|
-
async function buildBlock(
|
|
37
|
-
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
38
|
-
l1ToL2Messages: Fr[],
|
|
39
|
-
newGlobalVariables: GlobalVariables,
|
|
40
|
-
opts: PublicProcessorLimits = {},
|
|
41
|
-
worldStateFork: MerkleTreeWriteOperations,
|
|
42
|
-
processor: PublicProcessor,
|
|
43
|
-
validator: PublicProcessorValidator,
|
|
44
|
-
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>,
|
|
45
|
-
dateProvider: DateProvider,
|
|
46
|
-
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
47
|
-
): Promise<BuildBlockResult> {
|
|
48
|
-
const blockBuildingTimer = new Timer();
|
|
49
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
50
|
-
const slot = newGlobalVariables.slotNumber;
|
|
51
|
-
const msgCount = l1ToL2Messages.length;
|
|
52
|
-
const stateReference = await worldStateFork.getStateReference();
|
|
53
|
-
const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
54
|
-
|
|
55
|
-
log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
|
|
56
|
-
slot,
|
|
57
|
-
slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
|
|
58
|
-
now: new Date(dateProvider.now()),
|
|
59
|
-
blockNumber,
|
|
60
|
-
msgCount,
|
|
61
|
-
initialStateReference: stateReference.toInspect(),
|
|
62
|
-
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
63
|
-
opts,
|
|
64
|
-
});
|
|
65
|
-
const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
|
|
66
|
-
await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
|
|
67
|
-
|
|
68
|
-
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
69
|
-
processor.process(pendingTxs, opts, validator),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
// All real transactions have been added, set the block as full and pad if needed
|
|
73
|
-
await blockFactory.addTxs(processedTxs);
|
|
74
|
-
const block = await blockFactory.setBlockCompleted();
|
|
75
|
-
|
|
76
|
-
// How much public gas was processed
|
|
77
|
-
const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
78
|
-
|
|
79
|
-
const res = {
|
|
80
|
-
block,
|
|
81
|
-
publicGas,
|
|
82
|
-
publicProcessorDuration,
|
|
83
|
-
numMsgs: l1ToL2Messages.length,
|
|
84
|
-
numTxs: processedTxs.length,
|
|
85
|
-
failedTxs: failedTxs,
|
|
86
|
-
blockBuildingTimer,
|
|
87
|
-
usedTxs,
|
|
88
|
-
};
|
|
89
|
-
log.trace('Built block', res.block.header);
|
|
90
|
-
return res;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const FullNodeBlockBuilderConfigKeys = [
|
|
94
|
-
'l1GenesisTime',
|
|
95
|
-
'slotDuration',
|
|
96
|
-
'l1ChainId',
|
|
97
|
-
'rollupVersion',
|
|
98
|
-
'txPublicSetupAllowList',
|
|
99
|
-
'fakeProcessingDelayPerTxMs',
|
|
100
|
-
'fakeThrowAfterProcessingTxCount',
|
|
101
|
-
] as const;
|
|
102
|
-
|
|
103
|
-
// TODO(palla/mbps): Try killing this in favor of the CheckpointsBuilder
|
|
104
|
-
export class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
|
|
105
|
-
constructor(
|
|
106
|
-
private config: FullNodeBlockBuilderConfig,
|
|
107
|
-
private worldState: WorldStateSynchronizer,
|
|
108
|
-
private contractDataSource: ContractDataSource,
|
|
109
|
-
private dateProvider: DateProvider,
|
|
110
|
-
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
111
|
-
) {}
|
|
112
|
-
|
|
113
|
-
public getConfig(): FullNodeBlockBuilderConfig {
|
|
114
|
-
return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public updateConfig(config: Partial<FullNodeBlockBuilderConfig>) {
|
|
118
|
-
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
|
|
122
|
-
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
123
|
-
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
124
|
-
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
125
|
-
|
|
126
|
-
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
127
|
-
guardedFork,
|
|
128
|
-
contractsDB,
|
|
129
|
-
globalVariables,
|
|
130
|
-
this.telemetryClient,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const processor = new PublicProcessor(
|
|
134
|
-
globalVariables,
|
|
135
|
-
guardedFork,
|
|
136
|
-
contractsDB,
|
|
137
|
-
publicTxSimulator,
|
|
138
|
-
this.dateProvider,
|
|
139
|
-
this.telemetryClient,
|
|
140
|
-
undefined,
|
|
141
|
-
this.config,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const validator = createValidatorForBlockBuilding(
|
|
145
|
-
fork,
|
|
146
|
-
this.contractDataSource,
|
|
147
|
-
globalVariables,
|
|
148
|
-
txPublicSetupAllowList,
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
processor,
|
|
153
|
-
validator,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private async syncToPreviousBlock(parentBlockNumber: BlockNumber, timeout: number | undefined) {
|
|
158
|
-
await retryUntil(
|
|
159
|
-
() => this.worldState.syncImmediate(parentBlockNumber, true).then(syncedTo => syncedTo >= parentBlockNumber),
|
|
160
|
-
'sync to previous block',
|
|
161
|
-
timeout,
|
|
162
|
-
0.1,
|
|
163
|
-
);
|
|
164
|
-
log.debug(`Synced to previous block ${parentBlockNumber}`);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async buildBlock(
|
|
168
|
-
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
169
|
-
l1ToL2Messages: Fr[],
|
|
170
|
-
globalVariables: GlobalVariables,
|
|
171
|
-
opts: PublicProcessorLimits,
|
|
172
|
-
suppliedFork?: MerkleTreeWriteOperations,
|
|
173
|
-
): Promise<BuildBlockResult> {
|
|
174
|
-
const parentBlockNumber = BlockNumber(globalVariables.blockNumber - 1);
|
|
175
|
-
const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
|
|
176
|
-
await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
|
|
177
|
-
const fork = suppliedFork ?? (await this.worldState.fork(parentBlockNumber));
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
|
|
181
|
-
const res = await buildBlock(
|
|
182
|
-
pendingTxs,
|
|
183
|
-
l1ToL2Messages,
|
|
184
|
-
globalVariables,
|
|
185
|
-
opts,
|
|
186
|
-
fork,
|
|
187
|
-
processor,
|
|
188
|
-
validator,
|
|
189
|
-
this.config,
|
|
190
|
-
this.dateProvider,
|
|
191
|
-
this.telemetryClient,
|
|
192
|
-
);
|
|
193
|
-
return res;
|
|
194
|
-
} finally {
|
|
195
|
-
// If the fork was supplied, we don't close it.
|
|
196
|
-
// Otherwise, we wait a bit to close the fork we just created,
|
|
197
|
-
// since the processor may still be working on a dangling tx
|
|
198
|
-
// which was interrupted due to the processingDeadline being hit.
|
|
199
|
-
if (!suppliedFork) {
|
|
200
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
201
|
-
setTimeout(async () => {
|
|
202
|
-
try {
|
|
203
|
-
await fork.close();
|
|
204
|
-
} catch (err) {
|
|
205
|
-
// This can happen if the sequencer is stopped before we hit this timeout.
|
|
206
|
-
log.warn(`Error closing forks for block processing`, err);
|
|
207
|
-
}
|
|
208
|
-
}, 5000);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
getFork(blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
|
|
214
|
-
return this.worldState.fork(blockNumber);
|
|
215
|
-
}
|
|
216
|
-
}
|