@aztec/sequencer-client 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7
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.d.ts +12 -12
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +32 -25
- package/dest/config.d.ts +12 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +75 -30
- package/dest/global_variable_builder/global_builder.d.ts +22 -13
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +51 -41
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/publisher/config.d.ts +7 -4
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +9 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +15 -86
- package/dest/publisher/sequencer-publisher.d.ts +49 -41
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +566 -114
- package/dest/sequencer/block_builder.d.ts +4 -5
- package/dest/sequencer/block_builder.d.ts.map +1 -1
- package/dest/sequencer/block_builder.js +9 -14
- package/dest/sequencer/checkpoint_proposal_job.d.ts +77 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1089 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +85 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -0
- package/dest/sequencer/metrics.d.ts +22 -2
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +125 -62
- package/dest/sequencer/sequencer.d.ts +98 -130
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +636 -603
- package/dest/sequencer/timetable.d.ts +54 -14
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +148 -59
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +4 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +91 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +202 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +103 -0
- package/package.json +29 -29
- package/src/client/sequencer-client.ts +30 -41
- package/src/config.ts +80 -34
- package/src/global_variable_builder/global_builder.ts +65 -61
- package/src/index.ts +0 -1
- package/src/publisher/config.ts +12 -9
- package/src/publisher/sequencer-publisher-factory.ts +5 -4
- package/src/publisher/sequencer-publisher-metrics.ts +16 -72
- package/src/publisher/sequencer-publisher.ts +269 -146
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/block_builder.ts +12 -18
- package/src/sequencer/checkpoint_proposal_job.ts +742 -0
- package/src/sequencer/checkpoint_voter.ts +105 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -0
- package/src/sequencer/metrics.ts +164 -70
- package/src/sequencer/sequencer.ts +364 -811
- package/src/sequencer/timetable.ts +173 -79
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +3 -2
- package/src/test/mock_checkpoint_builder.ts +279 -0
- package/src/test/utils.ts +157 -0
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Body } from '@aztec/aztec.js/block';
|
|
2
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { times } from '@aztec/foundation/collection';
|
|
4
|
+
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import type { P2P } from '@aztec/p2p';
|
|
9
|
+
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
10
|
+
import { CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
|
|
11
|
+
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
|
+
import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
|
|
14
|
+
import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
|
|
15
|
+
|
|
16
|
+
import type { MockProxy } from 'jest-mock-extended';
|
|
17
|
+
|
|
18
|
+
// Re-export mock classes from their dedicated file
|
|
19
|
+
export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a mock transaction with a specific seed for deterministic testing
|
|
23
|
+
*/
|
|
24
|
+
export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
|
|
25
|
+
const tx = await mockTxForRollup(seed);
|
|
26
|
+
if (chainId) {
|
|
27
|
+
tx.data.constants.txContext.chainId = chainId;
|
|
28
|
+
}
|
|
29
|
+
return tx;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates an L2BlockNew from transactions and global variables
|
|
34
|
+
*/
|
|
35
|
+
export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2BlockNew> {
|
|
36
|
+
const processedTxs = await Promise.all(
|
|
37
|
+
txs.map(tx =>
|
|
38
|
+
makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
const body = new Body(processedTxs.map(tx => tx.txEffect));
|
|
42
|
+
const header = BlockHeader.empty({ globalVariables });
|
|
43
|
+
const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
|
|
44
|
+
return new L2BlockNew(archive, header, body, CheckpointNumber(globalVariables.blockNumber), 0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Mocks the P2P client to return specific pending transactions
|
|
49
|
+
*/
|
|
50
|
+
export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
|
|
51
|
+
p2p.getPendingTxCount.mockResolvedValue(txs.length);
|
|
52
|
+
p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates an async iterator for transactions
|
|
57
|
+
*/
|
|
58
|
+
export async function* mockTxIterator(txs: Promise<Tx[]>): AsyncIterableIterator<Tx> {
|
|
59
|
+
for (const tx of await txs) {
|
|
60
|
+
yield tx;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates mock committee attestations from a signer
|
|
66
|
+
*/
|
|
67
|
+
export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestation[] {
|
|
68
|
+
const mockedSig = Signature.random();
|
|
69
|
+
return [new CommitteeAttestation(signer.address, mockedSig)];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Creates a CheckpointHeader from an L2BlockNew for testing purposes.
|
|
74
|
+
* Uses mock values for blockHeadersHash, blobsHash and inHash since L2BlockNew doesn't have these fields.
|
|
75
|
+
*/
|
|
76
|
+
function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
|
|
77
|
+
const gv = block.header.globalVariables;
|
|
78
|
+
return new CheckpointHeader(
|
|
79
|
+
block.header.lastArchive.root,
|
|
80
|
+
Fr.random(), // blockHeadersHash - mock value for testing
|
|
81
|
+
Fr.random(), // blobsHash - mock value for testing
|
|
82
|
+
Fr.random(), // inHash - mock value for testing
|
|
83
|
+
gv.slotNumber,
|
|
84
|
+
gv.timestamp,
|
|
85
|
+
gv.coinbase,
|
|
86
|
+
gv.feeRecipient,
|
|
87
|
+
gv.gasFees,
|
|
88
|
+
block.header.totalManaUsed,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Creates a block proposal from a block and signature
|
|
94
|
+
*/
|
|
95
|
+
export function createBlockProposal(block: L2BlockNew, signature: Signature): BlockProposal {
|
|
96
|
+
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
97
|
+
return new BlockProposal(
|
|
98
|
+
block.header,
|
|
99
|
+
block.indexWithinCheckpoint,
|
|
100
|
+
Fr.ZERO, // inHash - using zero for testing
|
|
101
|
+
block.archive.root,
|
|
102
|
+
txHashes,
|
|
103
|
+
signature,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Creates a checkpoint proposal from a block and signature
|
|
109
|
+
*/
|
|
110
|
+
export function createCheckpointProposal(
|
|
111
|
+
block: L2BlockNew,
|
|
112
|
+
checkpointSignature: Signature,
|
|
113
|
+
blockSignature?: Signature,
|
|
114
|
+
): CheckpointProposal {
|
|
115
|
+
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
116
|
+
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
117
|
+
return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
|
|
118
|
+
blockHeader: block.header,
|
|
119
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
120
|
+
txHashes,
|
|
121
|
+
signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Creates a checkpoint attestation from a block and signature.
|
|
127
|
+
* Note: We manually set the sender since we use random signatures in tests.
|
|
128
|
+
* In production, the sender is recovered from the signature.
|
|
129
|
+
*/
|
|
130
|
+
export function createCheckpointAttestation(
|
|
131
|
+
block: L2BlockNew,
|
|
132
|
+
signature: Signature,
|
|
133
|
+
sender: EthAddress,
|
|
134
|
+
): CheckpointAttestation {
|
|
135
|
+
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
136
|
+
const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
|
|
137
|
+
const attestation = new CheckpointAttestation(payload, signature, signature);
|
|
138
|
+
// Set sender directly for testing (bypasses signature recovery)
|
|
139
|
+
(attestation as any).sender = sender;
|
|
140
|
+
return attestation;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Creates transactions and a block, and mocks P2P to return them.
|
|
145
|
+
* Helper for tests that need to set up a block with transactions.
|
|
146
|
+
*/
|
|
147
|
+
export async function setupTxsAndBlock(
|
|
148
|
+
p2p: MockProxy<P2P>,
|
|
149
|
+
globalVariables: GlobalVariables,
|
|
150
|
+
txCount: number,
|
|
151
|
+
chainId: Fr,
|
|
152
|
+
): Promise<{ txs: Tx[]; block: L2BlockNew }> {
|
|
153
|
+
const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
|
|
154
|
+
const block = await makeBlock(txs, globalVariables);
|
|
155
|
+
mockPendingTxs(p2p, txs);
|
|
156
|
+
return { txs, block };
|
|
157
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NullifierSource } from '@aztec/p2p';
|
|
2
|
-
import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
/**
|
|
4
|
-
* Implements a nullifier source by checking a DB and an in-memory collection.
|
|
5
|
-
* Intended for validating transactions as they are added to a block.
|
|
6
|
-
*/
|
|
7
|
-
export declare class NullifierCache implements NullifierSource {
|
|
8
|
-
private db;
|
|
9
|
-
nullifiers: Set<string>;
|
|
10
|
-
constructor(db: MerkleTreeReadOperations);
|
|
11
|
-
nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]>;
|
|
12
|
-
addNullifiers(nullifiers: Buffer[]): void;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnVsbGlmaWVyX2NhY2hlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHhfdmFsaWRhdG9yL251bGxpZmllcl9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFDbEQsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUdoRjs7O0dBR0c7QUFDSCxxQkFBYSxjQUFlLFlBQVcsZUFBZTtJQUd4QyxPQUFPLENBQUMsRUFBRTtJQUZ0QixVQUFVLEVBQUUsR0FBRyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXhCLFlBQW9CLEVBQUUsRUFBRSx3QkFBd0IsRUFFL0M7SUFFWSxlQUFlLENBQUMsVUFBVSxFQUFFLE1BQU0sRUFBRSxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQU9yRTtJQUVNLGFBQWEsQ0FBQyxVQUFVLEVBQUUsTUFBTSxFQUFFLFFBSXhDO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nullifier_cache.d.ts","sourceRoot":"","sources":["../../src/tx_validator/nullifier_cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAGhF;;;GAGG;AACH,qBAAa,cAAe,YAAW,eAAe;IAGxC,OAAO,CAAC,EAAE;IAFtB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAExB,YAAoB,EAAE,EAAE,wBAAwB,EAE/C;IAEY,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAOrE;IAEM,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,QAIxC;CACF"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
2
|
-
/**
|
|
3
|
-
* Implements a nullifier source by checking a DB and an in-memory collection.
|
|
4
|
-
* Intended for validating transactions as they are added to a block.
|
|
5
|
-
*/ export class NullifierCache {
|
|
6
|
-
db;
|
|
7
|
-
nullifiers;
|
|
8
|
-
constructor(db){
|
|
9
|
-
this.db = db;
|
|
10
|
-
this.nullifiers = new Set();
|
|
11
|
-
}
|
|
12
|
-
async nullifiersExist(nullifiers) {
|
|
13
|
-
const cacheResults = nullifiers.map((n)=>this.nullifiers.has(n.toString()));
|
|
14
|
-
const toCheckDb = nullifiers.filter((_n, index)=>!cacheResults[index]);
|
|
15
|
-
const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
|
|
16
|
-
let dbIndex = 0;
|
|
17
|
-
return nullifiers.map((_n, index)=>cacheResults[index] || dbHits[dbIndex++] !== undefined);
|
|
18
|
-
}
|
|
19
|
-
addNullifiers(nullifiers) {
|
|
20
|
-
for (const nullifier of nullifiers){
|
|
21
|
-
this.nullifiers.add(nullifier.toString());
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
2
|
-
import type { GasFees } from '@aztec/stdlib/gas';
|
|
3
|
-
import type { AllowedElement, ClientProtocolCircuitVerifier, MerkleTreeReadOperations, PublicProcessorValidator } from '@aztec/stdlib/interfaces/server';
|
|
4
|
-
import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
5
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
6
|
-
export declare function createValidatorForAcceptingTxs(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, verifier: ClientProtocolCircuitVerifier | undefined, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }: {
|
|
7
|
-
l1ChainId: number;
|
|
8
|
-
rollupVersion: number;
|
|
9
|
-
setupAllowList: AllowedElement[];
|
|
10
|
-
gasFees: GasFees;
|
|
11
|
-
skipFeeEnforcement?: boolean;
|
|
12
|
-
timestamp: UInt64;
|
|
13
|
-
blockNumber: number;
|
|
14
|
-
txsPermitted: boolean;
|
|
15
|
-
}): TxValidator<Tx>;
|
|
16
|
-
export declare function createValidatorForBlockBuilding(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, globalVariables: GlobalVariables, setupAllowList: AllowedElement[]): PublicProcessorValidator;
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfdmFsaWRhdG9yX2ZhY3RvcnkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eF92YWxpZGF0b3IvdHhfdmFsaWRhdG9yX2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBZ0JBLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDakUsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDakQsT0FBTyxLQUFLLEVBQ1YsY0FBYyxFQUNkLDZCQUE2QixFQUM3Qix3QkFBd0IsRUFDeEIsd0JBQXdCLEVBQ3pCLE1BQU0saUNBQWlDLENBQUM7QUFFekMsT0FBTyxFQUFFLGVBQWUsRUFBRSxLQUFLLEVBQUUsRUFBRSxLQUFLLFdBQVcsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBQzlFLE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBSWxELHdCQUFnQiw4QkFBOEIsQ0FDNUMsRUFBRSxFQUFFLHdCQUF3QixFQUM1QixrQkFBa0IsRUFBRSxrQkFBa0IsRUFDdEMsUUFBUSxFQUFFLDZCQUE2QixHQUFHLFNBQVMsRUFDbkQsRUFDRSxTQUFTLEVBQ1QsYUFBYSxFQUNiLGNBQWMsRUFDZCxPQUFPLEVBQ1Asa0JBQWtCLEVBQ2xCLFNBQVMsRUFDVCxXQUFXLEVBQ1gsWUFBWSxFQUNiLEVBQUU7SUFDRCxTQUFTLEVBQUUsTUFBTSxDQUFDO0lBQ2xCLGFBQWEsRUFBRSxNQUFNLENBQUM7SUFDdEIsY0FBYyxFQUFFLGNBQWMsRUFBRSxDQUFDO0lBQ2pDLE9BQU8sRUFBRSxPQUFPLENBQUM7SUFDakIsa0JBQWtCLENBQUMsRUFBRSxPQUFPLENBQUM7SUFDN0IsU0FBUyxFQUFFLE1BQU0sQ0FBQztJQUNsQixXQUFXLEVBQUUsTUFBTSxDQUFDO0lBQ3BCLFlBQVksRUFBRSxPQUFPLENBQUM7Q0FDdkIsR0FDQSxXQUFXLENBQUMsRUFBRSxDQUFDLENBNEJqQjtBQUVELHdCQUFnQiwrQkFBK0IsQ0FDN0MsRUFBRSxFQUFFLHdCQUF3QixFQUM1QixrQkFBa0IsRUFBRSxrQkFBa0IsRUFDdEMsZUFBZSxFQUFFLGVBQWUsRUFDaEMsY0FBYyxFQUFFLGNBQWMsRUFBRSxHQUMvQix3QkFBd0IsQ0FnQjFCIn0=
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tx_validator_factory.d.ts","sourceRoot":"","sources":["../../src/tx_validator/tx_validator_factory.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EACV,cAAc,EACd,6BAA6B,EAC7B,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,wBAAgB,8BAA8B,CAC5C,EAAE,EAAE,wBAAwB,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,6BAA6B,GAAG,SAAS,EACnD,EACE,SAAS,EACT,aAAa,EACb,cAAc,EACd,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,YAAY,EACb,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;CACvB,GACA,WAAW,CAAC,EAAE,CAAC,CA4BjB;AAED,wBAAgB,+BAA+B,CAC7C,EAAE,EAAE,wBAAwB,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,cAAc,EAAE,GAC/B,wBAAwB,CAgB1B"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
3
|
-
import { AggregateTxValidator, ArchiveCache, BlockHeaderTxValidator, DataTxValidator, DoubleSpendTxValidator, GasTxValidator, MetadataTxValidator, PhasesTxValidator, TimestampTxValidator, TxPermittedValidator, TxProofValidator } from '@aztec/p2p';
|
|
4
|
-
import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
|
|
5
|
-
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
6
|
-
import { NullifierCache } from './nullifier_cache.js';
|
|
7
|
-
export function createValidatorForAcceptingTxs(db, contractDataSource, verifier, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }) {
|
|
8
|
-
const validators = [
|
|
9
|
-
new TxPermittedValidator(txsPermitted),
|
|
10
|
-
new DataTxValidator(),
|
|
11
|
-
new MetadataTxValidator({
|
|
12
|
-
l1ChainId: new Fr(l1ChainId),
|
|
13
|
-
rollupVersion: new Fr(rollupVersion),
|
|
14
|
-
protocolContractsHash,
|
|
15
|
-
vkTreeRoot: getVKTreeRoot()
|
|
16
|
-
}),
|
|
17
|
-
new TimestampTxValidator({
|
|
18
|
-
timestamp,
|
|
19
|
-
blockNumber
|
|
20
|
-
}),
|
|
21
|
-
new DoubleSpendTxValidator(new NullifierCache(db)),
|
|
22
|
-
new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
|
|
23
|
-
new BlockHeaderTxValidator(new ArchiveCache(db))
|
|
24
|
-
];
|
|
25
|
-
if (!skipFeeEnforcement) {
|
|
26
|
-
validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
|
|
27
|
-
}
|
|
28
|
-
if (verifier) {
|
|
29
|
-
validators.push(new TxProofValidator(verifier));
|
|
30
|
-
}
|
|
31
|
-
return new AggregateTxValidator(...validators);
|
|
32
|
-
}
|
|
33
|
-
export function createValidatorForBlockBuilding(db, contractDataSource, globalVariables, setupAllowList) {
|
|
34
|
-
const nullifierCache = new NullifierCache(db);
|
|
35
|
-
const archiveCache = new ArchiveCache(db);
|
|
36
|
-
const publicStateSource = new DatabasePublicStateSource(db);
|
|
37
|
-
return {
|
|
38
|
-
preprocessValidator: preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList),
|
|
39
|
-
nullifierCache
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList) {
|
|
43
|
-
// We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
|
|
44
|
-
return new AggregateTxValidator(new MetadataTxValidator({
|
|
45
|
-
l1ChainId: globalVariables.chainId,
|
|
46
|
-
rollupVersion: globalVariables.version,
|
|
47
|
-
protocolContractsHash,
|
|
48
|
-
vkTreeRoot: getVKTreeRoot()
|
|
49
|
-
}), new TimestampTxValidator({
|
|
50
|
-
timestamp: globalVariables.timestamp,
|
|
51
|
-
blockNumber: globalVariables.blockNumber
|
|
52
|
-
}), new DoubleSpendTxValidator(nullifierCache), new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp), new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees), new BlockHeaderTxValidator(archiveCache));
|
|
53
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { NullifierSource } from '@aztec/p2p';
|
|
2
|
-
import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Implements a nullifier source by checking a DB and an in-memory collection.
|
|
7
|
-
* Intended for validating transactions as they are added to a block.
|
|
8
|
-
*/
|
|
9
|
-
export class NullifierCache implements NullifierSource {
|
|
10
|
-
nullifiers: Set<string>;
|
|
11
|
-
|
|
12
|
-
constructor(private db: MerkleTreeReadOperations) {
|
|
13
|
-
this.nullifiers = new Set();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public async nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]> {
|
|
17
|
-
const cacheResults = nullifiers.map(n => this.nullifiers.has(n.toString()));
|
|
18
|
-
const toCheckDb = nullifiers.filter((_n, index) => !cacheResults[index]);
|
|
19
|
-
const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
|
|
20
|
-
|
|
21
|
-
let dbIndex = 0;
|
|
22
|
-
return nullifiers.map((_n, index) => cacheResults[index] || dbHits[dbIndex++] !== undefined);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public addNullifiers(nullifiers: Buffer[]) {
|
|
26
|
-
for (const nullifier of nullifiers) {
|
|
27
|
-
this.nullifiers.add(nullifier.toString());
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
3
|
-
import {
|
|
4
|
-
AggregateTxValidator,
|
|
5
|
-
ArchiveCache,
|
|
6
|
-
BlockHeaderTxValidator,
|
|
7
|
-
DataTxValidator,
|
|
8
|
-
DoubleSpendTxValidator,
|
|
9
|
-
GasTxValidator,
|
|
10
|
-
MetadataTxValidator,
|
|
11
|
-
PhasesTxValidator,
|
|
12
|
-
TimestampTxValidator,
|
|
13
|
-
TxPermittedValidator,
|
|
14
|
-
TxProofValidator,
|
|
15
|
-
} from '@aztec/p2p';
|
|
16
|
-
import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
|
|
17
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
18
|
-
import type { GasFees } from '@aztec/stdlib/gas';
|
|
19
|
-
import type {
|
|
20
|
-
AllowedElement,
|
|
21
|
-
ClientProtocolCircuitVerifier,
|
|
22
|
-
MerkleTreeReadOperations,
|
|
23
|
-
PublicProcessorValidator,
|
|
24
|
-
} from '@aztec/stdlib/interfaces/server';
|
|
25
|
-
import { DatabasePublicStateSource, type PublicStateSource } from '@aztec/stdlib/trees';
|
|
26
|
-
import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
27
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
28
|
-
|
|
29
|
-
import { NullifierCache } from './nullifier_cache.js';
|
|
30
|
-
|
|
31
|
-
export function createValidatorForAcceptingTxs(
|
|
32
|
-
db: MerkleTreeReadOperations,
|
|
33
|
-
contractDataSource: ContractDataSource,
|
|
34
|
-
verifier: ClientProtocolCircuitVerifier | undefined,
|
|
35
|
-
{
|
|
36
|
-
l1ChainId,
|
|
37
|
-
rollupVersion,
|
|
38
|
-
setupAllowList,
|
|
39
|
-
gasFees,
|
|
40
|
-
skipFeeEnforcement,
|
|
41
|
-
timestamp,
|
|
42
|
-
blockNumber,
|
|
43
|
-
txsPermitted,
|
|
44
|
-
}: {
|
|
45
|
-
l1ChainId: number;
|
|
46
|
-
rollupVersion: number;
|
|
47
|
-
setupAllowList: AllowedElement[];
|
|
48
|
-
gasFees: GasFees;
|
|
49
|
-
skipFeeEnforcement?: boolean;
|
|
50
|
-
timestamp: UInt64;
|
|
51
|
-
blockNumber: number;
|
|
52
|
-
txsPermitted: boolean;
|
|
53
|
-
},
|
|
54
|
-
): TxValidator<Tx> {
|
|
55
|
-
const validators: TxValidator<Tx>[] = [
|
|
56
|
-
new TxPermittedValidator(txsPermitted),
|
|
57
|
-
new DataTxValidator(),
|
|
58
|
-
new MetadataTxValidator({
|
|
59
|
-
l1ChainId: new Fr(l1ChainId),
|
|
60
|
-
rollupVersion: new Fr(rollupVersion),
|
|
61
|
-
protocolContractsHash,
|
|
62
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
63
|
-
}),
|
|
64
|
-
new TimestampTxValidator({
|
|
65
|
-
timestamp,
|
|
66
|
-
blockNumber,
|
|
67
|
-
}),
|
|
68
|
-
new DoubleSpendTxValidator(new NullifierCache(db)),
|
|
69
|
-
new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
|
|
70
|
-
new BlockHeaderTxValidator(new ArchiveCache(db)),
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
if (!skipFeeEnforcement) {
|
|
74
|
-
validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (verifier) {
|
|
78
|
-
validators.push(new TxProofValidator(verifier));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return new AggregateTxValidator(...validators);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function createValidatorForBlockBuilding(
|
|
85
|
-
db: MerkleTreeReadOperations,
|
|
86
|
-
contractDataSource: ContractDataSource,
|
|
87
|
-
globalVariables: GlobalVariables,
|
|
88
|
-
setupAllowList: AllowedElement[],
|
|
89
|
-
): PublicProcessorValidator {
|
|
90
|
-
const nullifierCache = new NullifierCache(db);
|
|
91
|
-
const archiveCache = new ArchiveCache(db);
|
|
92
|
-
const publicStateSource = new DatabasePublicStateSource(db);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
preprocessValidator: preprocessValidator(
|
|
96
|
-
nullifierCache,
|
|
97
|
-
archiveCache,
|
|
98
|
-
publicStateSource,
|
|
99
|
-
contractDataSource,
|
|
100
|
-
globalVariables,
|
|
101
|
-
setupAllowList,
|
|
102
|
-
),
|
|
103
|
-
nullifierCache,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function preprocessValidator(
|
|
108
|
-
nullifierCache: NullifierCache,
|
|
109
|
-
archiveCache: ArchiveCache,
|
|
110
|
-
publicStateSource: PublicStateSource,
|
|
111
|
-
contractDataSource: ContractDataSource,
|
|
112
|
-
globalVariables: GlobalVariables,
|
|
113
|
-
setupAllowList: AllowedElement[],
|
|
114
|
-
): TxValidator<Tx> {
|
|
115
|
-
// We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
|
|
116
|
-
return new AggregateTxValidator(
|
|
117
|
-
new MetadataTxValidator({
|
|
118
|
-
l1ChainId: globalVariables.chainId,
|
|
119
|
-
rollupVersion: globalVariables.version,
|
|
120
|
-
protocolContractsHash,
|
|
121
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
122
|
-
}),
|
|
123
|
-
new TimestampTxValidator({
|
|
124
|
-
timestamp: globalVariables.timestamp,
|
|
125
|
-
blockNumber: globalVariables.blockNumber,
|
|
126
|
-
}),
|
|
127
|
-
new DoubleSpendTxValidator(nullifierCache),
|
|
128
|
-
new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp),
|
|
129
|
-
new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees),
|
|
130
|
-
new BlockHeaderTxValidator(archiveCache),
|
|
131
|
-
);
|
|
132
|
-
}
|