-
Notifications
You must be signed in to change notification settings - Fork 598
feat: use zod for sequencer config #5419
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
Closed
Closed
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
|
|
@@ -201,6 +201,7 @@ | |
| "SSTORE", | ||
| "staticcall", | ||
| "stdlib", | ||
| "stringly", | ||
| "struct", | ||
| "structs", | ||
| "subarrays", | ||
|
|
||
This file contains hidden or 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 hidden or 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,27 +1,48 @@ | ||
| import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js'; | ||
| import { aztecAddress, ethAddress, fr, stringlyNumber, z } from '@aztec/foundation/zod'; | ||
|
|
||
| /** | ||
| * The sequencer configuration. | ||
| */ | ||
| export interface SequencerConfig { | ||
| export const sequencerConfig = z.object({ | ||
| /** The number of ms to wait between polling for pending txs. */ | ||
| transactionPollingIntervalMS?: number; | ||
| transactionPollingIntervalMS: stringlyNumber.optional().default(1_000), | ||
| /** The maximum number of txs to include in a block. */ | ||
| maxTxsPerBlock?: number; | ||
| maxTxsPerBlock: stringlyNumber.optional().default(32), | ||
| /** The minimum number of txs to include in a block. */ | ||
| minTxsPerBlock?: number; | ||
| minTxsPerBlock: stringlyNumber.optional().default(1), | ||
| /** Recipient of block reward. */ | ||
| coinbase?: EthAddress; | ||
| coinbase: ethAddress.optional(), | ||
| /** Address to receive fees. */ | ||
| feeRecipient?: AztecAddress; | ||
| feeRecipient: aztecAddress.optional(), | ||
| /** The working directory to use for simulation/proving */ | ||
| acvmWorkingDirectory?: string; | ||
| acvmWorkingDirectory: z.string().optional(), | ||
| /** The path to the ACVM binary */ | ||
| acvmBinaryPath?: string; | ||
| acvmBinaryPath: z.string().optional(), | ||
|
|
||
| /** The list of permitted fee payment contract classes */ | ||
| allowedFeePaymentContractClasses?: Fr[]; | ||
|
|
||
| allowedFeePaymentContractClasses: z | ||
| .preprocess(val => { | ||
| if (typeof val === 'string') { | ||
| return val.split(','); | ||
| } else { | ||
| return z.NEVER; | ||
| } | ||
| }, z.array(fr)) | ||
| .or(z.array(fr)) | ||
| .optional() | ||
| .default([]), | ||
| /** The list of permitted fee payment contract instances. Takes precedence over contract classes */ | ||
| allowedFeePaymentContractInstances?: AztecAddress[]; | ||
| } | ||
| allowedFeePaymentContractInstances: z | ||
| .preprocess(val => { | ||
| if (typeof val === 'string') { | ||
| return val.split(','); | ||
| } else { | ||
| return z.NEVER; | ||
| } | ||
| }, z.array(aztecAddress)) | ||
| .or(z.array(aztecAddress)) | ||
| .optional() | ||
| .default([]), | ||
| }); | ||
|
|
||
| /** | ||
| * The sequencer configuration. | ||
| */ | ||
| export type SequencerConfig = z.infer<typeof sequencerConfig>; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| import { AztecAddress } from '../aztec-address/index.js'; | ||
| import { EthAddress } from '../eth-address/index.js'; | ||
| import { Fr } from '../fields/fields.js'; | ||
|
|
||
| export const ethAddress = z | ||
| .custom<`0x${string}` | EthAddress>( | ||
| val => (typeof val === 'string' && EthAddress.isAddress(val)) || EthAddress.isEthAddress(val), | ||
| ) | ||
| .transform(val => (typeof val === 'string' ? EthAddress.fromString(val) : val)); | ||
|
|
||
| export const optionalEthAddress = ethAddress.optional().default(EthAddress.ZERO); | ||
|
|
||
| export const aztecAddress = z | ||
| .custom<`0x${string}` | AztecAddress>( | ||
| val => (typeof val === 'string' && AztecAddress.isAddress(val)) || AztecAddress.isAztecAddress(val), | ||
| ) | ||
| .transform(val => (typeof val === 'string' ? AztecAddress.fromString(val) : val)); | ||
|
|
||
| export const stringlyNumber = z.number().or(z.string()).pipe(z.coerce.number()); | ||
|
|
||
| export const fr = z | ||
| .number() | ||
| .or(z.string()) | ||
| .or(z.bigint()) | ||
| .or(z.instanceof(Fr)) | ||
| .transform(val => (typeof val === 'string' ? Fr.fromString(val) : new Fr(val))); | ||
|
|
||
| export { z }; |
This file contains hidden or 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.
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.
nit: might be safer here to try/catch
fromBuffer. this is making assumptions about the validity checks in the constructor.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.
If I understand correctly, would it look something like:
I think that will work and be safe but we'd be creating objects and discarding them immediately.
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.
That is what I had meant, but perhaps the best approach is to extract the validation code to a function that both this typeguard and the constructor use?