@aztec/aztec-node 0.0.1-commit.ffe5b04ea → 0.0.1-commit.fff30aa
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/aztec-node/config.d.ts +2 -2
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +1 -1
- package/dest/aztec-node/server.d.ts +15 -18
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +146 -90
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +3 -3
- package/package.json +27 -27
- package/src/aztec-node/config.ts +1 -1
- package/src/aztec-node/server.ts +163 -85
- package/src/sentinel/factory.ts +1 -1
- package/src/sentinel/sentinel.ts +3 -3
package/src/aztec-node/server.ts
CHANGED
|
@@ -5,15 +5,16 @@ import { Blob } from '@aztec/blob-lib';
|
|
|
5
5
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
6
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
7
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
8
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
9
9
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
10
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
11
11
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
12
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
16
16
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
17
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
17
18
|
import { count } from '@aztec/foundation/string';
|
|
18
19
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
19
20
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
@@ -64,6 +65,7 @@ import {
|
|
|
64
65
|
type AztecNodeAdmin,
|
|
65
66
|
type AztecNodeAdminConfig,
|
|
66
67
|
AztecNodeAdminConfigSchema,
|
|
68
|
+
type AztecNodeDebug,
|
|
67
69
|
type GetContractClassLogsResponse,
|
|
68
70
|
type GetPublicLogsResponse,
|
|
69
71
|
} from '@aztec/stdlib/interfaces/client';
|
|
@@ -108,12 +110,13 @@ import {
|
|
|
108
110
|
FullNodeCheckpointsBuilder,
|
|
109
111
|
NodeKeystoreAdapter,
|
|
110
112
|
ValidatorClient,
|
|
111
|
-
|
|
113
|
+
createProposalHandler,
|
|
112
114
|
createValidatorClient,
|
|
113
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
114
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
115
118
|
|
|
116
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
117
120
|
|
|
118
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
119
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -123,7 +126,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
123
126
|
/**
|
|
124
127
|
* The aztec node.
|
|
125
128
|
*/
|
|
126
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
129
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
127
130
|
private metrics: NodeMetrics;
|
|
128
131
|
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
129
132
|
|
|
@@ -195,6 +198,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
195
198
|
dateProvider?: DateProvider;
|
|
196
199
|
p2pClientDeps?: P2PClientDeps;
|
|
197
200
|
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
201
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
198
202
|
} = {},
|
|
199
203
|
options: {
|
|
200
204
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
@@ -257,7 +261,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
257
261
|
|
|
258
262
|
const publicClient = createPublicClient({
|
|
259
263
|
chain: ethereumChain.chainInfo,
|
|
260
|
-
transport:
|
|
264
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
261
265
|
pollingInterval: config.viemPollingIntervalMS,
|
|
262
266
|
});
|
|
263
267
|
|
|
@@ -377,6 +381,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
377
381
|
l1ToL2MessageSource: archiver,
|
|
378
382
|
keyStoreManager,
|
|
379
383
|
blobClient,
|
|
384
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
380
385
|
});
|
|
381
386
|
|
|
382
387
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -390,19 +395,21 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
390
395
|
}
|
|
391
396
|
}
|
|
392
397
|
|
|
393
|
-
// If there's no validator client, create a
|
|
398
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
394
399
|
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
395
400
|
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
401
|
+
// Checkpoint proposals are handled if the blob client can upload blobs.
|
|
396
402
|
if (!validatorClient) {
|
|
397
403
|
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
398
|
-
log.info(`Setting up
|
|
399
|
-
|
|
404
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
405
|
+
createProposalHandler(config, {
|
|
400
406
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
401
407
|
worldState: worldStateSynchronizer,
|
|
402
408
|
epochCache,
|
|
403
409
|
blockSource: archiver,
|
|
404
410
|
l1ToL2MessageSource: archiver,
|
|
405
411
|
p2pClient,
|
|
412
|
+
blobClient,
|
|
406
413
|
dateProvider,
|
|
407
414
|
telemetry,
|
|
408
415
|
}).register(p2pClient, reexecute);
|
|
@@ -455,6 +462,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
455
462
|
})
|
|
456
463
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
457
464
|
|
|
465
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
466
|
+
l1Contracts: config.l1Contracts,
|
|
467
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
468
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
469
|
+
l1GenesisTime,
|
|
470
|
+
slotDuration: Number(slotDuration),
|
|
471
|
+
});
|
|
472
|
+
|
|
458
473
|
// Validator enabled, create/start relevant service
|
|
459
474
|
let sequencer: SequencerClient | undefined;
|
|
460
475
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -517,6 +532,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
517
532
|
dateProvider,
|
|
518
533
|
blobClient,
|
|
519
534
|
nodeKeyStore: keyStoreManager!,
|
|
535
|
+
globalVariableBuilder,
|
|
520
536
|
});
|
|
521
537
|
}
|
|
522
538
|
|
|
@@ -550,13 +566,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
550
566
|
}
|
|
551
567
|
}
|
|
552
568
|
|
|
553
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
554
|
-
...config,
|
|
555
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
556
|
-
l1GenesisTime,
|
|
557
|
-
slotDuration: Number(slotDuration),
|
|
558
|
-
});
|
|
559
|
-
|
|
560
569
|
const node = new AztecNodeService(
|
|
561
570
|
config,
|
|
562
571
|
p2pClient,
|
|
@@ -720,6 +729,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
720
729
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
721
730
|
}
|
|
722
731
|
|
|
732
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
733
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
734
|
+
}
|
|
735
|
+
|
|
723
736
|
/**
|
|
724
737
|
* Method to fetch the current min L2 fees.
|
|
725
738
|
* @returns The current min L2 fees.
|
|
@@ -966,58 +979,64 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
966
979
|
treeId: MerkleTreeId,
|
|
967
980
|
leafValues: Fr[],
|
|
968
981
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
969
|
-
const committedDb = await this
|
|
982
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
970
983
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
971
984
|
treeId,
|
|
972
985
|
leafValues.map(x => x.toBuffer()),
|
|
973
986
|
);
|
|
974
|
-
//
|
|
975
|
-
const
|
|
987
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
988
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
976
989
|
|
|
977
|
-
// Now we find the block numbers for the indices
|
|
978
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
990
|
+
// Now we find the block numbers for the defined indices
|
|
991
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
979
992
|
|
|
980
|
-
//
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
993
|
+
// Build a map from leaf index to block number
|
|
994
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
995
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
996
|
+
const blockNumber = blockNumbers[i];
|
|
997
|
+
if (blockNumber === undefined) {
|
|
998
|
+
throw new Error(
|
|
999
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1000
|
+
);
|
|
984
1001
|
}
|
|
1002
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
985
1003
|
}
|
|
986
1004
|
|
|
987
1005
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
988
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1006
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
989
1007
|
|
|
990
|
-
// Now we obtain the block hashes from the archive tree
|
|
991
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1008
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
992
1009
|
const blockHashes = await Promise.all(
|
|
993
1010
|
uniqueBlockNumbers.map(blockNumber => {
|
|
994
1011
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
995
1012
|
}),
|
|
996
1013
|
);
|
|
997
1014
|
|
|
998
|
-
//
|
|
1015
|
+
// Build a map from block number to block hash
|
|
1016
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
999
1017
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
1000
|
-
|
|
1018
|
+
const blockHash = blockHashes[i];
|
|
1019
|
+
if (blockHash === undefined) {
|
|
1001
1020
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1002
1021
|
}
|
|
1022
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1003
1023
|
}
|
|
1004
1024
|
|
|
1005
1025
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1006
|
-
return maybeIndices.map(
|
|
1026
|
+
return maybeIndices.map(index => {
|
|
1007
1027
|
if (index === undefined) {
|
|
1008
1028
|
return undefined;
|
|
1009
1029
|
}
|
|
1010
|
-
const blockNumber =
|
|
1030
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1011
1031
|
if (blockNumber === undefined) {
|
|
1012
|
-
|
|
1032
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1013
1033
|
}
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
return undefined;
|
|
1034
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1035
|
+
if (blockHash === undefined) {
|
|
1036
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1018
1037
|
}
|
|
1019
1038
|
return {
|
|
1020
|
-
l2BlockNumber:
|
|
1039
|
+
l2BlockNumber: blockNumber,
|
|
1021
1040
|
l2BlockHash: new BlockHash(blockHash),
|
|
1022
1041
|
data: index,
|
|
1023
1042
|
};
|
|
@@ -1028,7 +1047,21 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1028
1047
|
referenceBlock: BlockParameter,
|
|
1029
1048
|
blockHash: BlockHash,
|
|
1030
1049
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1031
|
-
|
|
1050
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1051
|
+
if (referenceBlock === BlockNumber.ZERO) {
|
|
1052
|
+
return undefined;
|
|
1053
|
+
}
|
|
1054
|
+
if (BlockHash.isBlockHash(referenceBlock)) {
|
|
1055
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1056
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1057
|
+
return undefined;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1061
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1062
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1063
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1064
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1032
1065
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1033
1066
|
return pathAndIndex === undefined
|
|
1034
1067
|
? undefined
|
|
@@ -1039,7 +1072,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1039
1072
|
referenceBlock: BlockParameter,
|
|
1040
1073
|
noteHash: Fr,
|
|
1041
1074
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
1042
|
-
const committedDb = await this
|
|
1075
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1043
1076
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
1044
1077
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
1045
1078
|
[noteHash],
|
|
@@ -1053,7 +1086,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1053
1086
|
referenceBlock: BlockParameter,
|
|
1054
1087
|
l1ToL2Message: Fr,
|
|
1055
1088
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
1056
|
-
const db = await this
|
|
1089
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1057
1090
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
1058
1091
|
if (!witness) {
|
|
1059
1092
|
return undefined;
|
|
@@ -1086,19 +1119,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1086
1119
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1087
1120
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1088
1121
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1089
|
-
const blocksInCheckpoints
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1093
|
-
const block = checkpointedBlock.block;
|
|
1094
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1095
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1096
|
-
checkpointIndex++;
|
|
1097
|
-
blocksInCheckpoints.push([]);
|
|
1098
|
-
previousSlotNumber = slotNumber;
|
|
1099
|
-
}
|
|
1100
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1101
|
-
}
|
|
1122
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1123
|
+
group => group.map(cb => cb.block),
|
|
1124
|
+
);
|
|
1102
1125
|
return blocksInCheckpoints.map(blocks =>
|
|
1103
1126
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1104
1127
|
);
|
|
@@ -1108,7 +1131,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1108
1131
|
referenceBlock: BlockParameter,
|
|
1109
1132
|
nullifier: Fr,
|
|
1110
1133
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1111
|
-
const db = await this
|
|
1134
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1112
1135
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1113
1136
|
if (!witness) {
|
|
1114
1137
|
return undefined;
|
|
@@ -1123,33 +1146,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1123
1146
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1124
1147
|
}
|
|
1125
1148
|
|
|
1126
|
-
/**
|
|
1127
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1128
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1129
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1130
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1131
|
-
* @returns The low nullifier membership witness (if found).
|
|
1132
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1133
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1134
|
-
* we are trying to prove non-inclusion for.
|
|
1135
|
-
*
|
|
1136
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1137
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1138
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1139
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1140
|
-
*/
|
|
1141
1149
|
public async getLowNullifierMembershipWitness(
|
|
1142
1150
|
referenceBlock: BlockParameter,
|
|
1143
1151
|
nullifier: Fr,
|
|
1144
1152
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1145
|
-
const committedDb = await this
|
|
1153
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1146
1154
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1147
1155
|
if (!findResult) {
|
|
1148
1156
|
return undefined;
|
|
1149
1157
|
}
|
|
1150
1158
|
const { index, alreadyPresent } = findResult;
|
|
1151
1159
|
if (alreadyPresent) {
|
|
1152
|
-
|
|
1160
|
+
throw new Error(
|
|
1161
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1162
|
+
);
|
|
1153
1163
|
}
|
|
1154
1164
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1155
1165
|
|
|
@@ -1158,7 +1168,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1158
1168
|
}
|
|
1159
1169
|
|
|
1160
1170
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1161
|
-
const committedDb = await this
|
|
1171
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1162
1172
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1163
1173
|
if (!lowLeafResult) {
|
|
1164
1174
|
return undefined;
|
|
@@ -1173,7 +1183,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1173
1183
|
}
|
|
1174
1184
|
|
|
1175
1185
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1176
|
-
const committedDb = await this
|
|
1186
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1177
1187
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1178
1188
|
|
|
1179
1189
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1318,6 +1328,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1318
1328
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1319
1329
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1320
1330
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1331
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1321
1332
|
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1322
1333
|
db,
|
|
1323
1334
|
this.contractDataSource,
|
|
@@ -1334,6 +1345,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1334
1345
|
gasFees: await this.getCurrentMinFees(),
|
|
1335
1346
|
skipFeeEnforcement,
|
|
1336
1347
|
txsPermitted: !this.config.disableTransactions,
|
|
1348
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1349
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1350
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1337
1351
|
},
|
|
1338
1352
|
this.log.getBindings(),
|
|
1339
1353
|
);
|
|
@@ -1588,6 +1602,40 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1588
1602
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1589
1603
|
}
|
|
1590
1604
|
|
|
1605
|
+
public async mineBlock(): Promise<void> {
|
|
1606
|
+
if (!this.sequencer) {
|
|
1607
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1611
|
+
|
|
1612
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1613
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1614
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1615
|
+
|
|
1616
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1617
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1618
|
+
this.sequencer.updateConfig({ minTxsPerBlock: 0 });
|
|
1619
|
+
|
|
1620
|
+
try {
|
|
1621
|
+
// Trigger the sequencer to produce a block immediately
|
|
1622
|
+
void this.sequencer.trigger();
|
|
1623
|
+
|
|
1624
|
+
// Wait for the new L2 block to appear
|
|
1625
|
+
await retryUntil(
|
|
1626
|
+
async () => {
|
|
1627
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1628
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1629
|
+
},
|
|
1630
|
+
'mineBlock',
|
|
1631
|
+
timeoutSeconds,
|
|
1632
|
+
0.1,
|
|
1633
|
+
);
|
|
1634
|
+
} finally {
|
|
1635
|
+
this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1591
1639
|
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1592
1640
|
if (!this.initialHeaderHashPromise) {
|
|
1593
1641
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1600,7 +1648,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1600
1648
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1601
1649
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1602
1650
|
*/
|
|
1603
|
-
async
|
|
1651
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1604
1652
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1605
1653
|
try {
|
|
1606
1654
|
// Attempt to sync the world state if necessary
|
|
@@ -1614,6 +1662,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1614
1662
|
return this.worldStateSynchronizer.getCommitted();
|
|
1615
1663
|
}
|
|
1616
1664
|
|
|
1665
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1666
|
+
let blockNumber: BlockNumber;
|
|
1617
1667
|
if (BlockHash.isBlockHash(block)) {
|
|
1618
1668
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1619
1669
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1627,22 +1677,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1627
1677
|
`Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1628
1678
|
);
|
|
1629
1679
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1680
|
+
|
|
1681
|
+
blockNumber = header.getBlockNumber();
|
|
1682
|
+
} else {
|
|
1683
|
+
blockNumber = block as BlockNumber;
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// Check it's within world state sync range
|
|
1687
|
+
if (blockNumber > blockSyncedTo) {
|
|
1688
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1633
1689
|
}
|
|
1690
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1634
1691
|
|
|
1635
|
-
|
|
1636
|
-
{
|
|
1637
|
-
const blockNumber = block as BlockNumber;
|
|
1692
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1638
1693
|
|
|
1639
|
-
|
|
1640
|
-
|
|
1694
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1695
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1696
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1697
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1700
|
+
);
|
|
1641
1701
|
}
|
|
1702
|
+
}
|
|
1642
1703
|
|
|
1643
|
-
|
|
1644
|
-
|
|
1704
|
+
return snapshot;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
/** Resolves a block parameter to a block number. */
|
|
1708
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1709
|
+
if (block === 'latest') {
|
|
1710
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1711
|
+
}
|
|
1712
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1713
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1714
|
+
if (block.equals(initialBlockHash)) {
|
|
1715
|
+
return BlockNumber.ZERO;
|
|
1716
|
+
}
|
|
1717
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1718
|
+
if (!header) {
|
|
1719
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1720
|
+
}
|
|
1721
|
+
return header.getBlockNumber();
|
|
1645
1722
|
}
|
|
1723
|
+
return block as BlockNumber;
|
|
1646
1724
|
}
|
|
1647
1725
|
|
|
1648
1726
|
/**
|
package/src/sentinel/factory.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
3
4
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
4
5
|
import type { P2PClient } from '@aztec/p2p';
|
|
5
6
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
6
7
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
8
8
|
|
|
9
9
|
import type { SentinelConfig } from './config.js';
|
|
10
10
|
import { Sentinel } from './sentinel.js';
|
package/src/sentinel/sentinel.ts
CHANGED
|
@@ -309,9 +309,9 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
309
309
|
return false;
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
const
|
|
313
|
-
if (
|
|
314
|
-
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, {
|
|
312
|
+
const syncedSlot = await this.archiver.getSyncedL2SlotNumber();
|
|
313
|
+
if (syncedSlot === undefined || syncedSlot < targetSlot) {
|
|
314
|
+
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, { syncedSlot, targetSlot });
|
|
315
315
|
return false;
|
|
316
316
|
}
|
|
317
317
|
|