-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Validate block proposal txs iteratively (#10921)
Instead of loading all txs from the p2p pool and validating them all, we now get an iterator to the p2p pool and iteratively run through them and validate them as we go. This ensures we only load and validate strictly the txs we need. This also makes it easy to enforce new block constraints such as gas limits, which we add as two new env vars. As part of this PR, we also change the interface of validators. Since there is no point anymore in validating txs in bulk, we drop the `validateTxs` method in favor of just `validateTx`. And since we're at it, we enrich `validateTx` to return `valid/invalid/skip` and to include the failure reason. Fixes #10869
- Loading branch information
1 parent
1cb7cd7
commit c92129e
Showing
44 changed files
with
911 additions
and
931 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
yarn-project/circuit-types/src/tx/validator/empty_validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import { type AnyTx, type TxValidator } from './tx_validator.js'; | ||
import { type AnyTx, type TxValidationResult, type TxValidator } from './tx_validator.js'; | ||
|
||
export class EmptyTxValidator<T extends AnyTx = AnyTx> implements TxValidator<T> { | ||
public validateTxs(txs: T[]): Promise<[validTxs: T[], invalidTxs: T[], skippedTxs: T[]]> { | ||
return Promise.resolve([txs, [], []]); | ||
} | ||
|
||
public validateTx(_tx: T): Promise<boolean> { | ||
return Promise.resolve(true); | ||
public validateTx(_tx: T): Promise<TxValidationResult> { | ||
return Promise.resolve({ result: 'valid' }); | ||
} | ||
} |
18 changes: 16 additions & 2 deletions
18
yarn-project/circuit-types/src/tx/validator/tx_validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import { type ZodFor } from '@aztec/foundation/schemas'; | ||
|
||
import { z } from 'zod'; | ||
|
||
import { type ProcessedTx } from '../processed_tx.js'; | ||
import { type Tx } from '../tx.js'; | ||
|
||
export type AnyTx = Tx | ProcessedTx; | ||
|
||
export type TxValidationResult = | ||
| { result: 'valid' } | ||
| { result: 'invalid'; reason: string[] } | ||
| { result: 'skipped'; reason: string[] }; | ||
|
||
export interface TxValidator<T extends AnyTx = AnyTx> { | ||
validateTx(tx: T): Promise<boolean>; | ||
validateTxs(txs: T[]): Promise<[validTxs: T[], invalidTxs: T[], skippedTxs?: T[]]>; | ||
validateTx(tx: T): Promise<TxValidationResult>; | ||
} | ||
|
||
export const TxValidationResultSchema = z.discriminatedUnion('result', [ | ||
z.object({ result: z.literal('valid'), reason: z.array(z.string()).optional() }), | ||
z.object({ result: z.literal('invalid'), reason: z.array(z.string()) }), | ||
z.object({ result: z.literal('skipped'), reason: z.array(z.string()) }), | ||
]) satisfies ZodFor<TxValidationResult>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.