-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Validate block proposal txs iteratively #10921
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf2d14a
feat: Validate block proposal txs iteratively
spalladino dcae49f
Do not throw on invalid sendTx for now
spalladino f6449d2
Fix phases validator for received txs
spalladino 8e5a7fd
Lint
spalladino 16b4eba
Facepalm
spalladino b887301
Nullifier cache only hits db if needed
spalladino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use constants or enums here so we don't end up with string literals around the codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen most discriminated unions use just string literals (see the typescript handbook for an example). But after some googling it seems that enums vs string literals is actually a hot topic. I personally prefer string literals for their simplicity, and because tsc guards you against any typos, but this is not a hill I'm willing to die on.