@aztec/sequencer-client 0.0.1-commit.f504929 → 0.0.1-commit.f650c0a5c

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.
Files changed (59) hide show
  1. package/dest/client/sequencer-client.d.ts +4 -1
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +46 -27
  4. package/dest/config.d.ts +25 -5
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +21 -12
  7. package/dest/global_variable_builder/global_builder.d.ts +15 -9
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +29 -25
  10. package/dest/global_variable_builder/index.d.ts +2 -2
  11. package/dest/global_variable_builder/index.d.ts.map +1 -1
  12. package/dest/publisher/config.d.ts +13 -1
  13. package/dest/publisher/config.d.ts.map +1 -1
  14. package/dest/publisher/config.js +17 -2
  15. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
  16. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  17. package/dest/publisher/sequencer-publisher-factory.js +2 -3
  18. package/dest/publisher/sequencer-publisher.d.ts +58 -32
  19. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  20. package/dest/publisher/sequencer-publisher.js +132 -89
  21. package/dest/sequencer/checkpoint_proposal_job.d.ts +36 -9
  22. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  23. package/dest/sequencer/checkpoint_proposal_job.js +302 -180
  24. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  25. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  26. package/dest/sequencer/checkpoint_voter.js +2 -5
  27. package/dest/sequencer/events.d.ts +2 -1
  28. package/dest/sequencer/events.d.ts.map +1 -1
  29. package/dest/sequencer/metrics.d.ts +5 -1
  30. package/dest/sequencer/metrics.d.ts.map +1 -1
  31. package/dest/sequencer/metrics.js +11 -0
  32. package/dest/sequencer/sequencer.d.ts +23 -10
  33. package/dest/sequencer/sequencer.d.ts.map +1 -1
  34. package/dest/sequencer/sequencer.js +130 -71
  35. package/dest/sequencer/timetable.d.ts +7 -3
  36. package/dest/sequencer/timetable.d.ts.map +1 -1
  37. package/dest/sequencer/timetable.js +21 -12
  38. package/dest/sequencer/types.d.ts +2 -2
  39. package/dest/sequencer/types.d.ts.map +1 -1
  40. package/dest/test/mock_checkpoint_builder.d.ts +7 -9
  41. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  42. package/dest/test/mock_checkpoint_builder.js +39 -30
  43. package/package.json +27 -28
  44. package/src/client/sequencer-client.ts +56 -28
  45. package/src/config.ts +28 -14
  46. package/src/global_variable_builder/global_builder.ts +37 -26
  47. package/src/global_variable_builder/index.ts +1 -1
  48. package/src/publisher/config.ts +32 -0
  49. package/src/publisher/sequencer-publisher-factory.ts +3 -6
  50. package/src/publisher/sequencer-publisher.ts +205 -127
  51. package/src/sequencer/README.md +81 -12
  52. package/src/sequencer/checkpoint_proposal_job.ts +385 -199
  53. package/src/sequencer/checkpoint_voter.ts +1 -12
  54. package/src/sequencer/events.ts +1 -1
  55. package/src/sequencer/metrics.ts +14 -0
  56. package/src/sequencer/sequencer.ts +186 -80
  57. package/src/sequencer/timetable.ts +26 -15
  58. package/src/sequencer/types.ts +1 -1
  59. package/src/test/mock_checkpoint_builder.ts +51 -48
@@ -1,22 +1,27 @@
1
- import { createEthereumChain } from '@aztec/ethereum/chain';
2
- import type { L1ContractsConfig } from '@aztec/ethereum/config';
3
1
  import { RollupContract } from '@aztec/ethereum/contracts';
4
- import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
2
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
5
3
  import type { ViemPublicClient } from '@aztec/ethereum/types';
6
4
  import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
7
5
  import { Fr } from '@aztec/foundation/curves/bn254';
8
6
  import type { EthAddress } from '@aztec/foundation/eth-address';
9
7
  import { createLogger } from '@aztec/foundation/log';
8
+ import type { DateProvider } from '@aztec/foundation/timer';
10
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
11
- import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
10
+ import { type L1RollupConstants, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
12
11
  import { GasFees } from '@aztec/stdlib/gas';
13
12
  import type {
13
+ BuildCheckpointGlobalVariablesOpts,
14
14
  CheckpointGlobalVariables,
15
15
  GlobalVariableBuilder as GlobalVariableBuilderInterface,
16
16
  } from '@aztec/stdlib/tx';
17
17
  import { GlobalVariables } from '@aztec/stdlib/tx';
18
18
 
19
- import { createPublicClient, fallback, http } from 'viem';
19
+ /** Configuration for the GlobalVariableBuilder (excludes L1 client config). */
20
+ export type GlobalVariableBuilderConfig = {
21
+ l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
22
+ ethereumSlotDuration: number;
23
+ rollupVersion: bigint;
24
+ } & Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'>;
20
25
 
21
26
  /**
22
27
  * Simple global variables builder.
@@ -27,7 +32,6 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
27
32
  private currentL1BlockNumber: bigint | undefined = undefined;
28
33
 
29
34
  private readonly rollupContract: RollupContract;
30
- private readonly publicClient: ViemPublicClient;
31
35
  private readonly ethereumSlotDuration: number;
32
36
  private readonly aztecSlotDuration: number;
33
37
  private readonly l1GenesisTime: bigint;
@@ -36,28 +40,18 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
36
40
  private version: Fr;
37
41
 
38
42
  constructor(
39
- config: L1ReaderConfig &
40
- Pick<L1ContractsConfig, 'ethereumSlotDuration'> &
41
- Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'> & { rollupVersion: bigint },
43
+ private readonly dateProvider: DateProvider,
44
+ private readonly publicClient: ViemPublicClient,
45
+ config: GlobalVariableBuilderConfig,
42
46
  ) {
43
- const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
44
-
45
- const chain = createEthereumChain(l1RpcUrls, chainId);
46
-
47
47
  this.version = new Fr(config.rollupVersion);
48
- this.chainId = new Fr(chainId);
48
+ this.chainId = new Fr(this.publicClient.chain!.id);
49
49
 
50
50
  this.ethereumSlotDuration = config.ethereumSlotDuration;
51
51
  this.aztecSlotDuration = config.slotDuration;
52
52
  this.l1GenesisTime = config.l1GenesisTime;
53
53
 
54
- this.publicClient = createPublicClient({
55
- chain: chain.chainInfo,
56
- transport: fallback(chain.rpcUrls.map(url => http(url, { batch: false }))),
57
- pollingInterval: config.viemPollingIntervalMS,
58
- });
59
-
60
- this.rollupContract = new RollupContract(this.publicClient, l1Contracts.rollupAddress);
54
+ this.rollupContract = new RollupContract(this.publicClient, config.l1Contracts.rollupAddress);
61
55
  }
62
56
 
63
57
  /**
@@ -73,7 +67,10 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
73
67
  const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
74
68
  SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
75
69
  );
76
- const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
70
+ const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
71
+ l1GenesisTime: this.l1GenesisTime,
72
+ ethereumSlotDuration: this.ethereumSlotDuration,
73
+ });
77
74
  const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
78
75
 
79
76
  return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
@@ -108,7 +105,10 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
108
105
  const slot: SlotNumber =
109
106
  maybeSlot ??
110
107
  (await this.rollupContract.getSlotAt(
111
- BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration)),
108
+ getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
109
+ l1GenesisTime: this.l1GenesisTime,
110
+ ethereumSlotDuration: this.ethereumSlotDuration,
111
+ }),
112
112
  ));
113
113
 
114
114
  const checkpointGlobalVariables = await this.buildCheckpointGlobalVariables(coinbase, feeRecipient, slot);
@@ -120,6 +120,7 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
120
120
  coinbase: EthAddress,
121
121
  feeRecipient: AztecAddress,
122
122
  slotNumber: SlotNumber,
123
+ opts?: BuildCheckpointGlobalVariablesOpts,
123
124
  ): Promise<CheckpointGlobalVariables> {
124
125
  const { chainId, version } = this;
125
126
 
@@ -128,9 +129,19 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
128
129
  l1GenesisTime: this.l1GenesisTime,
129
130
  });
130
131
 
131
- // We can skip much of the logic in getCurrentMinFees since it we already check that we are not within a slot elsewhere.
132
- // TODO(palla/mbps): Can we use a cached value here?
133
- const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
132
+ // When pipelining, force the proposed checkpoint number and fee header to the parent so that
133
+ // the fee computation matches what L1 will see when the previous pipelined checkpoint has landed.
134
+ const pendingNumberOverride = await this.rollupContract.makePendingCheckpointNumberOverride(
135
+ opts?.forcePendingCheckpointNumber,
136
+ );
137
+ const feeHeaderOverride = opts?.forceProposedFeeHeader
138
+ ? await this.rollupContract.makeFeeHeaderOverride(
139
+ opts.forceProposedFeeHeader.checkpointNumber,
140
+ opts.forceProposedFeeHeader.feeHeader,
141
+ )
142
+ : [];
143
+ const stateOverride = RollupContract.mergeStateOverrides(pendingNumberOverride, feeHeaderOverride);
144
+ const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true, stateOverride));
134
145
 
135
146
  return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
136
147
  }
@@ -1 +1 @@
1
- export { GlobalVariableBuilder } from './global_builder.js';
1
+ export { GlobalVariableBuilder, type GlobalVariableBuilderConfig } from './global_builder.js';
@@ -4,6 +4,8 @@ import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from '@aztec/ethereum/l
4
4
  import { type ConfigMappingsType, SecretValue, booleanConfigHelper } from '@aztec/foundation/config';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
6
 
7
+ import { parseEther } from 'viem';
8
+
7
9
  /** Configuration of the transaction publisher. */
8
10
  export type TxSenderConfig = L1ReaderConfig & {
9
11
  /** The private key to be used by the publisher. */
@@ -50,13 +52,37 @@ export type PublisherConfig = L1TxUtilsConfig &
50
52
  publisherForwarderAddress?: EthAddress;
51
53
  /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
52
54
  l1TxFailedStore?: string;
55
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
56
+ publisherFundingThreshold?: bigint;
57
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
58
+ publisherFundingAmount?: bigint;
53
59
  };
54
60
 
61
+ /** Shared config mappings for publisher funding, used by both sequencer and prover publisher configs. */
62
+ const publisherFundingConfigMappings = {
63
+ publisherFundingThreshold: {
64
+ env: 'PUBLISHER_FUNDING_THRESHOLD' as const,
65
+ description:
66
+ 'Min ETH balance below which a publisher gets funded. Specified in ether (e.g. 0.1). Unset = funding disabled.',
67
+ parseEnv: (val: string) => parseEther(val),
68
+ },
69
+ publisherFundingAmount: {
70
+ env: 'PUBLISHER_FUNDING_AMOUNT' as const,
71
+ description:
72
+ 'Amount of ETH to send when funding a publisher. Specified in ether (e.g. 0.5). Unset = funding disabled.',
73
+ parseEnv: (val: string) => parseEther(val),
74
+ },
75
+ };
76
+
55
77
  export type ProverPublisherConfig = L1TxUtilsConfig &
56
78
  BlobClientConfig & {
57
79
  fishermanMode?: boolean;
58
80
  proverPublisherAllowInvalidStates?: boolean;
59
81
  proverPublisherForwarderAddress?: EthAddress;
82
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
83
+ publisherFundingThreshold?: bigint;
84
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
85
+ publisherFundingAmount?: bigint;
60
86
  };
61
87
 
62
88
  export type SequencerPublisherConfig = L1TxUtilsConfig &
@@ -66,6 +92,10 @@ export type SequencerPublisherConfig = L1TxUtilsConfig &
66
92
  sequencerPublisherForwarderAddress?: EthAddress;
67
93
  /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
68
94
  l1TxFailedStore?: string;
95
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
96
+ publisherFundingThreshold?: bigint;
97
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
98
+ publisherFundingAmount?: bigint;
69
99
  };
70
100
 
71
101
  export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
@@ -142,6 +172,7 @@ export const sequencerPublisherConfigMappings: ConfigMappingsType<SequencerPubli
142
172
  env: 'L1_TX_FAILED_STORE',
143
173
  description: 'Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path',
144
174
  },
175
+ ...publisherFundingConfigMappings,
145
176
  };
146
177
 
147
178
  export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherConfig & L1TxUtilsConfig> = {
@@ -163,4 +194,5 @@ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherCo
163
194
  description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
164
195
  parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
165
196
  },
197
+ ...publisherFundingConfigMappings,
166
198
  };
@@ -7,7 +7,6 @@ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
7
7
  import type { PublisherFilter, PublisherManager } from '@aztec/ethereum/publisher-manager';
8
8
  import { SlotNumber } from '@aztec/foundation/branded-types';
9
9
  import type { DateProvider } from '@aztec/foundation/timer';
10
- import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
11
10
  import type { TelemetryClient } from '@aztec/telemetry-client';
12
11
  import { NodeKeystoreAdapter } from '@aztec/validator-client';
13
12
 
@@ -40,7 +39,6 @@ export class SequencerPublisherFactory {
40
39
  epochCache: EpochCache;
41
40
  rollupContract: RollupContract;
42
41
  governanceProposerContract: GovernanceProposerContract;
43
- slashFactoryContract: SlashFactoryContract;
44
42
  nodeKeyStore: NodeKeystoreAdapter;
45
43
  logger?: Logger;
46
44
  },
@@ -104,7 +102,6 @@ export class SequencerPublisherFactory {
104
102
  epochCache: this.deps.epochCache,
105
103
  governanceProposerContract: this.deps.governanceProposerContract,
106
104
  slashingProposerContract,
107
- slashFactoryContract: this.deps.slashFactoryContract,
108
105
  dateProvider: this.deps.dateProvider,
109
106
  metrics: this.publisherMetrics,
110
107
  lastActions: this.lastActions,
@@ -117,8 +114,8 @@ export class SequencerPublisherFactory {
117
114
  };
118
115
  }
119
116
 
120
- /** Interrupts all publishers managed by this factory. Used during sequencer shutdown. */
121
- public interruptAll(): void {
122
- this.deps.publisherManager.interrupt();
117
+ /** Stops all publishers managed by this factory. Used during sequencer shutdown. */
118
+ public async stopAll(): Promise<void> {
119
+ await this.deps.publisherManager.stop();
123
120
  }
124
121
  }