Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions yarn-project/p2p/src/client/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { AttestationPool, type AttestationPoolApi } from '../mem_pools/attestati
import type { MemPools } from '../mem_pools/interface.js';
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
import { AztecKVTxPoolV2 } from '../mem_pools/tx_pool_v2/tx_pool_v2.js';
import { createTxValidatorForTransactionsEnteringPendingTxPool } from '../msg_validators/index.js';
import {
createCheckAllowedSetupCalls,
createTxValidatorForTransactionsEnteringPendingTxPool,
getDefaultAllowedSetupFunctions,
} from '../msg_validators/index.js';
import { DummyP2PService } from '../services/dummy_service.js';
import { LibP2PService } from '../services/index.js';
import { createFileStoreTxSources } from '../services/tx_collection/file_store_tx_source.js';
Expand Down Expand Up @@ -75,6 +79,33 @@ export async function createP2PClient(
const rollupAddress = inputConfig.l1Contracts.rollupAddress.toString().toLowerCase().replace(/^0x/, '');
const txFileStoreBasePath = `aztec-${inputConfig.l1ChainId}-${inputConfig.rollupVersion}-0x${rollupAddress}`;

const allowedInSetup = [
...(await getDefaultAllowedSetupFunctions()),
...(inputConfig.txPublicSetupAllowListExtend ?? []),
];
const checkAllowedSetupCalls = createCheckAllowedSetupCalls(
archiver,
allowedInSetup,
() => epochCache.getEpochAndSlotInNextL1Slot().ts,
);

const createTxValidator = async () => {
// We accept transactions if they are not expired by the next slot and block number (checked based on the ExpirationTimestamp field)
const currentBlockNumber = await archiver.getBlockNumber();
const { ts: nextSlotTimestamp } = epochCache.getEpochAndSlotInNextL1Slot();
const l1Constants = await archiver.getL1Constants();
return createTxValidatorForTransactionsEnteringPendingTxPool(
worldStateSynchronizer,
nextSlotTimestamp,
BlockNumber(currentBlockNumber + 1),
{
rollupManaLimit: l1Constants.rollupManaLimit,
maxBlockL2Gas: config.validateMaxL2BlockGas,
maxBlockDAGas: config.validateMaxDABlockGas,
},
);
};

const txPool =
deps.txPool ??
new AztecKVTxPoolV2(
Expand All @@ -83,22 +114,8 @@ export async function createP2PClient(
{
l2BlockSource: archiver,
worldStateSynchronizer,
createTxValidator: async () => {
// We accept transactions if they are not expired by the next slot and block number (checked based on the ExpirationTimestamp field)
const currentBlockNumber = await archiver.getBlockNumber();
const { ts: nextSlotTimestamp } = epochCache.getEpochAndSlotInNextL1Slot();
const l1Constants = await archiver.getL1Constants();
return createTxValidatorForTransactionsEnteringPendingTxPool(
worldStateSynchronizer,
nextSlotTimestamp,
BlockNumber(currentBlockNumber + 1),
{
rollupManaLimit: l1Constants.rollupManaLimit,
maxBlockL2Gas: config.validateMaxL2BlockGas,
maxBlockDAGas: config.validateMaxDABlockGas,
},
);
},
checkAllowedSetupCalls,
createTxValidator,
},
telemetry,
{
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/p2p/src/mem_pools/tx_pool_v2/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export type TxPoolV2Dependencies = {
worldStateSynchronizer: WorldStateSynchronizer;
/** Factory that creates a validator for re-validating pool transactions using metadata */
createTxValidator: () => Promise<TxValidator<TxMetaData>>;
/** Checks whether a tx's setup-phase calls are on the allow list. Precomputed at receipt time. */
checkAllowedSetupCalls: (tx: Tx) => Promise<boolean>;
};

/**
Expand Down
12 changes: 11 additions & 1 deletion yarn-project/p2p/src/mem_pools/tx_pool_v2/tx_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export type TxMetaData = {
/** Timestamp by which the transaction must be included (for expiration checks) */
readonly expirationTimestamp: bigint;

/** Whether the tx's setup-phase calls pass the allow list check. Computed at receipt time. */
readonly allowedSetupCalls: boolean;

/** Validator-compatible data, providing the same access patterns as Tx.data */
readonly data: TxMetaValidationData;

Expand All @@ -84,8 +87,12 @@ export type TxState = 'pending' | 'protected' | 'mined' | 'deleted';
* Builds TxMetaData from a full Tx object.
* Extracts all relevant fields for efficient in-memory storage and querying.
* Fr values are captured in closures for zero-cost re-validation.
*
* @param allowedSetupCalls - Whether the tx's setup-phase calls pass the allow list.
* For gossip/RPC txs this is always `true` (already validated by PhasesTxValidator).
* For req/resp txs this should be computed by the caller using the phases validator.
*/
export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
export async function buildTxMetaData(tx: Tx, allowedSetupCalls: boolean = true): Promise<TxMetaData> {
const txHashObj = tx.getTxHash();
const txHash = txHashObj.toString();
const txHashBigInt = txHashObj.toBigInt();
Expand All @@ -112,6 +119,7 @@ export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
feeLimit,
nullifiers,
expirationTimestamp,
allowedSetupCalls,
receivedAt: 0,
estimatedSizeBytes,
data: {
Expand Down Expand Up @@ -304,6 +312,7 @@ export function stubTxMetaData(
nullifiers?: string[];
expirationTimestamp?: bigint;
anchorBlockHeaderHash?: string;
allowedSetupCalls?: boolean;
} = {},
): TxMetaData {
const txHashBigInt = Fr.fromHexString(txHash).toBigInt();
Expand All @@ -320,6 +329,7 @@ export function stubTxMetaData(
feeLimit: overrides.feeLimit ?? 100n,
nullifiers: overrides.nullifiers ?? [`0x${normalizedTxHash.slice(2)}null1`],
expirationTimestamp,
allowedSetupCalls: overrides.allowedSetupCalls ?? true,
receivedAt: 0,
estimatedSizeBytes: 0,
data: stubTxMetaValidationData({ expirationTimestamp }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('TxPoolV2 Compatibility Tests', () => {
l2BlockSource: mockL2BlockSource,
worldStateSynchronizer: mockWorldState,
createTxValidator: () => Promise.resolve(alwaysValidValidator),
checkAllowedSetupCalls: () => Promise.resolve(true),
});
await pool.start();
});
Expand Down Expand Up @@ -327,6 +328,7 @@ describe('TxPoolV2 Compatibility Tests', () => {
l2BlockSource: mockL2BlockSource,
worldStateSynchronizer: mockWorldState,
createTxValidator: () => Promise.resolve(alwaysValidValidator),
checkAllowedSetupCalls: () => Promise.resolve(true),
},
undefined, // telemetry
{ archivedTxLimit: 2 },
Expand Down Expand Up @@ -368,6 +370,7 @@ describe('TxPoolV2 Compatibility Tests', () => {
l2BlockSource: mockL2BlockSource,
worldStateSynchronizer: mockWorldState,
createTxValidator: () => Promise.resolve(alwaysValidValidator),
checkAllowedSetupCalls: () => Promise.resolve(true),
},
undefined, // telemetry
{ maxPendingTxCount: 3 },
Expand Down Expand Up @@ -424,6 +427,7 @@ describe('TxPoolV2 Compatibility Tests', () => {
l2BlockSource: mockL2BlockSource,
worldStateSynchronizer: mockWorldState,
createTxValidator: () => Promise.resolve(alwaysValidValidator),
checkAllowedSetupCalls: () => Promise.resolve(true),
},
undefined, // telemetry
{ maxPendingTxCount: 10 },
Expand Down Expand Up @@ -467,6 +471,7 @@ describe('TxPoolV2 Compatibility Tests', () => {
l2BlockSource: mockL2BlockSource,
worldStateSynchronizer: mockWorldState,
createTxValidator: () => Promise.resolve(alwaysValidValidator),
checkAllowedSetupCalls: () => Promise.resolve(true),
},
undefined, // telemetry
{ maxPendingTxCount: 10 },
Expand Down Expand Up @@ -639,6 +644,7 @@ describe('TxPoolV2 Compatibility Tests', () => {
l2BlockSource: mockL2BlockSource,
worldStateSynchronizer: mockWorldState,
createTxValidator: () => Promise.resolve(alwaysValidValidator),
checkAllowedSetupCalls: () => Promise.resolve(true),
},
undefined, // telemetry
{ maxPendingTxCount: 0 },
Expand Down
Loading
Loading