@aztec/end-to-end 5.0.0-rc.2 → 5.0.0

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 (246) hide show
  1. package/README.md +215 -27
  2. package/dest/automine/automine_test_context.d.ts +85 -0
  3. package/dest/automine/automine_test_context.d.ts.map +1 -0
  4. package/dest/automine/automine_test_context.js +98 -0
  5. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts +2 -0
  6. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  7. package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.d.ts +1 -1
  8. package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts.map +1 -0
  9. package/dest/automine/delivery/interactive_handshake_responder.d.ts +48 -0
  10. package/dest/automine/delivery/interactive_handshake_responder.d.ts.map +1 -0
  11. package/dest/automine/delivery/interactive_handshake_responder.js +76 -0
  12. package/dest/automine/delivery/onchain_delivery_harness.d.ts +19 -0
  13. package/dest/automine/delivery/onchain_delivery_harness.d.ts.map +1 -0
  14. package/dest/automine/delivery/onchain_delivery_harness.js +141 -0
  15. package/dest/automine/token/blacklist_token_contract_test.d.ts +49 -0
  16. package/dest/automine/token/blacklist_token_contract_test.d.ts.map +1 -0
  17. package/dest/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.js +17 -24
  18. package/dest/automine/token/token_contract_test.d.ts +40 -0
  19. package/dest/automine/token/token_contract_test.d.ts.map +1 -0
  20. package/dest/{e2e_token_contract → automine/token}/token_contract_test.js +22 -28
  21. package/dest/automine/token/token_test_helpers.d.ts +73 -0
  22. package/dest/automine/token/token_test_helpers.d.ts.map +1 -0
  23. package/dest/automine/token/token_test_helpers.js +97 -0
  24. package/dest/bench/client_flows/benchmark.d.ts +1 -1
  25. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  26. package/dest/bench/client_flows/benchmark.js +3 -1
  27. package/dest/bench/client_flows/client_flows_benchmark.d.ts +1 -1
  28. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.js +16 -4
  30. package/dest/bench/utils.d.ts +1 -1
  31. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  32. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  33. package/dest/composed/ha/ha_full_setup.js +383 -0
  34. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  35. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  36. package/dest/fixtures/e2e_prover_test.d.ts +10 -7
  37. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  38. package/dest/fixtures/e2e_prover_test.js +30 -11
  39. package/dest/fixtures/fixtures.d.ts +7 -5
  40. package/dest/fixtures/fixtures.d.ts.map +1 -1
  41. package/dest/fixtures/fixtures.js +6 -4
  42. package/dest/fixtures/ha_setup.d.ts +3 -3
  43. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  44. package/dest/fixtures/ha_setup.js +4 -1
  45. package/dest/fixtures/index.d.ts +2 -1
  46. package/dest/fixtures/index.d.ts.map +1 -1
  47. package/dest/fixtures/index.js +1 -0
  48. package/dest/fixtures/setup.d.ts +32 -8
  49. package/dest/fixtures/setup.d.ts.map +1 -1
  50. package/dest/fixtures/setup.js +165 -160
  51. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  52. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  53. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  54. package/dest/fixtures/timing.d.ts +42 -0
  55. package/dest/fixtures/timing.d.ts.map +1 -0
  56. package/dest/fixtures/timing.js +72 -0
  57. package/dest/fixtures/wait_helpers.d.ts +135 -0
  58. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  59. package/dest/fixtures/wait_helpers.js +154 -0
  60. package/dest/forward-compatibility/wallet_service.js +1 -1
  61. package/dest/multi-node/block-production/setup.d.ts +97 -0
  62. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  63. package/dest/multi-node/block-production/setup.js +158 -0
  64. package/dest/multi-node/governance/setup.d.ts +67 -0
  65. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  66. package/dest/multi-node/governance/setup.js +126 -0
  67. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  68. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  69. package/dest/multi-node/multi_node_test_context.js +347 -0
  70. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  71. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  72. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  73. package/dest/multi-node/slashing/setup.d.ts +167 -0
  74. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  75. package/dest/multi-node/slashing/setup.js +275 -0
  76. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +9 -1
  77. package/dest/p2p/p2p_network.d.ts.map +1 -0
  78. package/dest/{e2e_p2p → p2p}/p2p_network.js +26 -1
  79. package/dest/p2p/reqresp/utils.d.ts +19 -0
  80. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  81. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +4 -15
  82. package/dest/p2p/shared.d.ts +72 -0
  83. package/dest/p2p/shared.d.ts.map +1 -0
  84. package/dest/p2p/shared.js +212 -0
  85. package/dest/shared/cross_chain_test_harness.d.ts +3 -3
  86. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  87. package/dest/shared/cross_chain_test_harness.js +24 -16
  88. package/dest/shared/gas_portal_test_harness.d.ts +1 -1
  89. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  90. package/dest/shared/gas_portal_test_harness.js +8 -5
  91. package/dest/shared/submit-transactions.d.ts +1 -1
  92. package/dest/shared/submit-transactions.d.ts.map +1 -1
  93. package/dest/shared/submit-transactions.js +12 -5
  94. package/dest/shared/timing_env.d.js +5 -0
  95. package/dest/shared/timing_env.js +158 -47
  96. package/dest/shared/wait_for_l1_to_l2_message.js +1 -1
  97. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  98. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  99. package/dest/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.js +74 -26
  100. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  101. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  102. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  103. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  104. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  105. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +9 -6
  106. package/dest/single-node/fees/fees_test.d.ts +95 -0
  107. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  108. package/dest/{e2e_fees → single-node/fees}/fees_test.js +121 -45
  109. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  110. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  111. package/dest/single-node/l1-reorgs/setup.js +57 -0
  112. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  113. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  114. package/dest/single-node/partial-proofs/setup.js +5 -0
  115. package/dest/single-node/proving/setup.d.ts +5 -0
  116. package/dest/single-node/proving/setup.d.ts.map +1 -0
  117. package/dest/single-node/proving/setup.js +5 -0
  118. package/dest/single-node/recovery/setup.d.ts +5 -0
  119. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  120. package/dest/single-node/recovery/setup.js +5 -0
  121. package/dest/single-node/setup.d.ts +49 -0
  122. package/dest/single-node/setup.d.ts.map +1 -0
  123. package/dest/single-node/setup.js +56 -0
  124. package/dest/single-node/single_node_test_context.d.ts +373 -0
  125. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  126. package/dest/single-node/single_node_test_context.js +845 -0
  127. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  128. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  129. package/dest/spartan/setup_test_wallets.js +13 -7
  130. package/dest/spartan/tx_metrics.d.ts +10 -1
  131. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  132. package/dest/spartan/tx_metrics.js +32 -0
  133. package/dest/test-wallet/test_wallet.d.ts +23 -4
  134. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  135. package/dest/test-wallet/test_wallet.js +20 -4
  136. package/dest/test-wallet/utils.d.ts +36 -1
  137. package/dest/test-wallet/utils.d.ts.map +1 -1
  138. package/dest/test-wallet/utils.js +64 -4
  139. package/dest/test-wallet/wallet_worker_script.js +5 -2
  140. package/dest/test-wallet/worker_wallet.d.ts +5 -5
  141. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  142. package/dest/test-wallet/worker_wallet.js +2 -2
  143. package/dest/test-wallet/worker_wallet_schema.js +2 -1
  144. package/package.json +40 -40
  145. package/src/automine/README.md +60 -0
  146. package/src/automine/automine_test_context.ts +153 -0
  147. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  148. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  149. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +19 -39
  150. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +24 -43
  151. package/src/automine/token/token_test_helpers.ts +138 -0
  152. package/src/bench/client_flows/benchmark.ts +3 -1
  153. package/src/bench/client_flows/client_flows_benchmark.ts +17 -4
  154. package/src/composed/ha/ha_full_setup.ts +466 -0
  155. package/src/fixtures/e2e_prover_test.ts +36 -20
  156. package/src/fixtures/fixtures.ts +6 -4
  157. package/src/fixtures/ha_setup.ts +7 -3
  158. package/src/fixtures/index.ts +1 -0
  159. package/src/fixtures/setup.ts +202 -161
  160. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  161. package/src/fixtures/timing.ts +97 -0
  162. package/src/fixtures/wait_helpers.ts +333 -0
  163. package/src/forward-compatibility/wallet_service.ts +2 -2
  164. package/src/infra/README.md +12 -0
  165. package/src/multi-node/README.md +96 -0
  166. package/src/multi-node/block-production/setup.ts +272 -0
  167. package/src/multi-node/governance/setup.ts +172 -0
  168. package/src/multi-node/multi_node_test_context.ts +447 -0
  169. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  170. package/src/multi-node/slashing/setup.ts +433 -0
  171. package/src/p2p/README.md +78 -0
  172. package/src/{e2e_p2p → p2p}/p2p_network.ts +26 -0
  173. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +5 -14
  174. package/src/p2p/shared.ts +329 -0
  175. package/src/shared/cross_chain_test_harness.ts +22 -13
  176. package/src/shared/gas_portal_test_harness.ts +13 -5
  177. package/src/shared/submit-transactions.ts +13 -5
  178. package/src/shared/timing_env.d.mts +39 -0
  179. package/src/shared/timing_env.mjs +152 -48
  180. package/src/shared/wait_for_l1_to_l2_message.ts +1 -1
  181. package/src/single-node/README.md +66 -0
  182. package/src/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.ts +100 -38
  183. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  184. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +11 -7
  185. package/src/{e2e_fees → single-node/fees}/fees_test.ts +132 -47
  186. package/src/single-node/l1-reorgs/setup.ts +93 -0
  187. package/src/single-node/partial-proofs/setup.ts +8 -0
  188. package/src/single-node/proving/setup.ts +15 -0
  189. package/src/single-node/recovery/setup.ts +8 -0
  190. package/src/single-node/setup.ts +63 -0
  191. package/src/single-node/single_node_test_context.ts +1054 -0
  192. package/src/spartan/setup_test_wallets.ts +19 -7
  193. package/src/spartan/tx_metrics.ts +26 -0
  194. package/src/test-wallet/test_wallet.ts +28 -6
  195. package/src/test-wallet/utils.ts +102 -5
  196. package/src/test-wallet/wallet_worker_script.ts +6 -3
  197. package/src/test-wallet/worker_wallet.ts +5 -9
  198. package/src/test-wallet/worker_wallet_schema.ts +1 -1
  199. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -56
  200. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  201. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -59
  202. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  203. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -36
  204. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  205. package/dest/e2e_deploy_contract/deploy_test.js +0 -42
  206. package/dest/e2e_epochs/epochs_test.d.ts +0 -137
  207. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  208. package/dest/e2e_epochs/epochs_test.js +0 -485
  209. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  210. package/dest/e2e_fees/fees_test.d.ts +0 -89
  211. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  212. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  213. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  214. package/dest/e2e_l1_publisher/write_json.js +0 -57
  215. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  216. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  217. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -22
  218. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  219. package/dest/e2e_nested_contract/nested_contract_test.js +0 -40
  220. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  221. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  222. package/dest/e2e_p2p/inactivity_slash_test.js +0 -138
  223. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  224. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  225. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  226. package/dest/e2e_p2p/shared.d.ts +0 -100
  227. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  228. package/dest/e2e_p2p/shared.js +0 -257
  229. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  230. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  231. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  232. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  233. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  234. package/src/e2e_deploy_contract/deploy_test.ts +0 -73
  235. package/src/e2e_epochs/epochs_test.ts +0 -596
  236. package/src/e2e_l1_publisher/write_json.ts +0 -78
  237. package/src/e2e_nested_contract/nested_contract_test.ts +0 -51
  238. package/src/e2e_p2p/inactivity_slash_test.ts +0 -181
  239. package/src/e2e_p2p/shared.ts +0 -391
  240. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  241. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  242. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  243. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  244. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  245. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  246. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,1054 @@
1
+ import type { InitialAccountData } from '@aztec/accounts/testing';
2
+ import type { Archiver } from '@aztec/archiver';
3
+ import { type AztecNodeConfig, AztecNodeService, createAztecNodeService } from '@aztec/aztec-node';
4
+ import { getAccountContractAddress } from '@aztec/aztec.js/account';
5
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
6
+ import { getTimestampRangeForEpoch } from '@aztec/aztec.js/block';
7
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
8
+ import { Fr } from '@aztec/aztec.js/fields';
9
+ import type { Logger } from '@aztec/aztec.js/log';
10
+ import { MerkleTreeId } from '@aztec/aztec.js/trees';
11
+ import type { Wallet } from '@aztec/aztec.js/wallet';
12
+ import type { CheatCodes } from '@aztec/aztec/testing';
13
+ import { EpochCache } from '@aztec/epoch-cache';
14
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
15
+ import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
16
+ import { RollupContract } from '@aztec/ethereum/contracts';
17
+ import { Delayer, createDelayer, waitUntilL1Timestamp, wrapClientWithDelayer } from '@aztec/ethereum/l1-tx-utils';
18
+ import { ChainMonitor } from '@aztec/ethereum/test';
19
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
20
+ import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
21
+ import { SecretValue } from '@aztec/foundation/config';
22
+ import { randomBytes } from '@aztec/foundation/crypto/random';
23
+ import { withLoggerBindings } from '@aztec/foundation/log/server';
24
+ import { retryUntil } from '@aztec/foundation/retry';
25
+ import { sleep } from '@aztec/foundation/sleep';
26
+ import { executeTimeout } from '@aztec/foundation/timer';
27
+ import { SpamContract } from '@aztec/noir-test-contracts.js/Spam';
28
+ import { TestContract } from '@aztec/noir-test-contracts.js/Test';
29
+ import { getMockPubSubP2PServiceFactory } from '@aztec/p2p/test-helpers';
30
+ import type { ProverNodeConfig } from '@aztec/prover-node';
31
+ import type { PXEConfig } from '@aztec/pxe/config';
32
+ import { type Sequencer, type SequencerClient, type SequencerEvents, SequencerState } from '@aztec/sequencer-client';
33
+ import { type BlockParameter, EthAddress } from '@aztec/stdlib/block';
34
+ import {
35
+ type L1RollupConstants,
36
+ getProofSubmissionDeadlineTimestamp,
37
+ getTimestampForSlot,
38
+ } from '@aztec/stdlib/epoch-helpers';
39
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
40
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
41
+
42
+ import { join } from 'path';
43
+ import type { Hex } from 'viem';
44
+ import { privateKeyToAccount } from 'viem/accounts';
45
+
46
+ import {
47
+ SCHNORR_HARDCODED_PRIVATE_KEY,
48
+ SchnorrHardcodedKeyAccountContract,
49
+ } from '../fixtures/schnorr_hardcoded_account_contract.js';
50
+ import { testSpan } from '../fixtures/timing.js';
51
+ import {
52
+ type EndToEndContext,
53
+ type SetupOptions,
54
+ createAndSyncProverNode,
55
+ getPrivateKeyFromIndex,
56
+ setup,
57
+ } from '../fixtures/utils.js';
58
+ import type { TestWallet } from '../test-wallet/test_wallet.js';
59
+
60
+ export const WORLD_STATE_CHECKPOINT_HISTORY = 2;
61
+ export const WORLD_STATE_BLOCK_CHECK_INTERVAL = 50;
62
+ export const ARCHIVER_POLL_INTERVAL = 50;
63
+ /**
64
+ * Default L1 (ethereum) slot duration in seconds for single-node e2e tests. Kept at 8s, the fast-profile
65
+ * boundary (`FAST_PROFILE_ETHEREUM_SLOT_DURATION`): at 8s the proposer still uses the production operational
66
+ * budgets (fast-profile clamping only kicks in strictly below 8s), so the default single-node L2 slot is
67
+ * `2 x 8 = 16s`. CI previously ran at 12s (24s L2 slots); unifying it with the local value removes a
68
+ * CI-vs-local cadence asymmetry and cuts every default-cadence single-node suite by a third.
69
+ */
70
+ export const DEFAULT_L1_BLOCK_TIME = 8;
71
+
72
+ export type SingleNodeTestOpts = Partial<SetupOptions> & {
73
+ numberOfAccounts?: number;
74
+ pxeOpts?: Partial<PXEConfig>;
75
+ aztecSlotDurationInL1Slots?: number;
76
+ /** Skip creating/registering the hardcoded account during setup (for tests that handle accounts themselves). */
77
+ skipHardcodedAccount?: boolean;
78
+ /**
79
+ * Force the hardcoded-account fast-path even when an initial sequencer is running. Useful for
80
+ * tests with tight per-block gas budgets that can't fit a full account-deploy tx.
81
+ */
82
+ useHardcodedAccount?: boolean;
83
+ };
84
+
85
+ export type TrackedSequencerEvent = {
86
+ [K in keyof SequencerEvents]: Parameters<SequencerEvents[K]>[0] & {
87
+ type: K;
88
+ sequencerIndex: number;
89
+ validator: EthAddress;
90
+ };
91
+ }[keyof SequencerEvents];
92
+
93
+ /** A `block-proposed` sequencer event captured for the pipelining-offset assertion. */
94
+ export type BlockProposedEvent = { blockNumber: BlockNumber; slot: SlotNumber; buildSlot: SlotNumber };
95
+
96
+ /**
97
+ * The 24s-slot reorg cadence shared by every reorg/prune/HA test, regardless of single-node vs
98
+ * multi-validator topology: a 24s L2 slot, 5s blocks, and a 4-slot epoch. The 5s block duration is chosen
99
+ * so the fast-profile budgets both reorg profiles run under (eth < 8s: p2p 0.5s, prepare 0.5s, init 1s)
100
+ * still fit ~3 full block sub-slots per checkpoint — `floor((24 - 1 - 5 - 2*0.5 - 0.5) / 5) = 3` — which
101
+ * the l1-reorgs suites' `assertMultipleBlocksPerSlot(2)` assertions require. The two concrete reorg
102
+ * profiles ({@link FAST_REORG_TIMING}, {@link MULTI_VALIDATOR_REORG_TIMING}) extend this with their topology's L1
103
+ * slot duration and any extra knobs. Kept timing-only — `maxSpeedUpAttempts`, `cancelTxOnTimeout`, and
104
+ * `aztecProofSubmissionEpochs` encode per-test scenario intent and stay explicit at the call site.
105
+ */
106
+ export const REORG_TIMING_BASE = {
107
+ aztecSlotDuration: 24,
108
+ blockDurationMs: 5000,
109
+ aztecEpochDuration: 4,
110
+ } as const;
111
+
112
+ /**
113
+ * Timing-only profile shared by the fast single-node L1-reorg tests (`proving/optimistic`'s reorg
114
+ * cases and `l1-reorgs/`). Extends {@link REORG_TIMING_BASE} with mainnet-style 32-slot anvil epochs
115
+ * and a 4s L1 slot. Note: `ethereumSlotDuration` stays at 4 here (not unified to
116
+ * {@link MULTI_VALIDATOR_REORG_TIMING}'s 6) — at eth=6 the proof-submission-window timing in the
117
+ * proof-removal/proof-restore reorg assertions in `l1-reorgs/blocks` starves and times out, so the 4s
118
+ * L1 slot is required for the single-node reorg path. Tests that need a different epoch length (e.g. 8
119
+ * for the "with replacement" case) override `aztecEpochDuration` after the spread.
120
+ */
121
+ export const FAST_REORG_TIMING = {
122
+ ...REORG_TIMING_BASE,
123
+ ethereumSlotDuration: 4,
124
+ anvilSlotsInAnEpoch: 32,
125
+ } as const;
126
+
127
+ /**
128
+ * Timing-only profile naming the 24s/6s reorg-and-prune cadence copied verbatim across the
129
+ * multi-validator recovery and high-availability tests (`recovery/proposal_failure_recovery`,
130
+ * `recovery/equivocation_recovery`, `high-availability/ha_sync`,
131
+ * `high-availability/ha_checkpoint_handoff`). The multi-validator analogue of
132
+ * {@link FAST_REORG_TIMING}, adding the 0.5s attestation-propagation budget those committee tests
133
+ * need. Timing-only: committee size, `aztecProofSubmissionEpochs`, and the slasher block stay
134
+ * per-test. Spread BEFORE per-test overrides so a test can still bump e.g. `aztecEpochDuration`.
135
+ */
136
+ export const MULTI_VALIDATOR_REORG_TIMING = {
137
+ ...REORG_TIMING_BASE,
138
+ ethereumSlotDuration: 6,
139
+ attestationPropagationTime: 0.5,
140
+ } as const;
141
+
142
+ /**
143
+ * Timing-only profile naming the 24s/12s multi-validator block-production cadence copied across
144
+ * `block-production/` (`simple`, `first_slot`, and `proof_boundary`). Uses `aztecSlotDurationInL1Slots: 2`
145
+ * rather than an explicit `aztecSlotDuration: 24` so the L2 slot stays coupled to `ethereumSlotDuration`
146
+ * if a test overrides eth. The 4s block duration keeps enough full block sub-slots per checkpoint under
147
+ * the production budgets these eth=12 tests run with (init 1s, prepare 1s, min-block 2s, p2p =
148
+ * attestationPropagationTime): `floor((24 - 1 - 4 - 2P - 1) / 4)` = 4 blocks at P<=1, 3 blocks at P=2
149
+ * (the default). Deliberately omits `attestationPropagationTime` (per-scenario: default 2, 0.5, or 1) —
150
+ * set it per test. `high_tps` pins the old 36s/6s cadence at its own call site because its 2-txs-x-2.5s
151
+ * per-block budget does not fit a 4s block. Spread BEFORE per-test overrides.
152
+ */
153
+ export const MULTI_VALIDATOR_BLOCK_PRODUCTION_TIMING = {
154
+ ethereumSlotDuration: 12,
155
+ aztecSlotDurationInL1Slots: 2,
156
+ blockDurationMs: 4000,
157
+ } as const;
158
+
159
+ /**
160
+ * Timing-only profile naming the 72s wide-slot multiple-blocks-per-slot cadence copied across the
161
+ * block-production and recovery tests (`block-production/`'s `setupBlockProductionWithProver`, `block-production/blob_promotion`,
162
+ * `recovery/pipeline_prune`). A-914:
163
+ * pipelined multiple-blocks-per-slot needs this 72s/12s cadence (not the tighter 36s/4s), otherwise non-proposer nodes hit
164
+ * `CheckpointNumberNotSequentialError` when the pipelined proposer races ahead of L1 confirmation. The
165
+ * larger `perBlockAllocationMultiplier` lets each of the several blocks per slot fit non-trivial txs.
166
+ * Spread BEFORE per-test overrides (e.g. `mockGossipSubNetworkLatency`, `maxTxsPerCheckpoint`).
167
+ */
168
+ export const WIDE_SLOT_TIMING = {
169
+ ethereumSlotDuration: 12,
170
+ aztecSlotDuration: 72,
171
+ blockDurationMs: 5500,
172
+ aztecEpochDuration: 4,
173
+ perBlockAllocationMultiplier: 8,
174
+ aztecTargetCommitteeSize: 3,
175
+ } as const;
176
+
177
+ /**
178
+ * Base class for the prod-sequencer single-node test topology: one node running the production
179
+ * sequencer with fast block times and short epochs, an optional fake-proof prover node, and the
180
+ * environment it runs in (in-proc anvil + L1 deploy). Owns node spawning
181
+ * (`createNonValidatorNode` / `createProverNode` incl. the mock-gossip `p2pServiceFactory` wiring,
182
+ * which is harmless with a single node), the `ChainMonitor`, and the epoch / proof-window / reorg
183
+ * waiters and assertion helpers shared by every test in the category.
184
+ *
185
+ * {@link MultiNodeTestContext} extends this with the N-validator topology (validator-node spawning,
186
+ * committee/proposal/attestation convergence helpers). Single-node-topology tests use this base
187
+ * directly from the sibling `single-node/` category.
188
+ */
189
+ export class SingleNodeTestContext {
190
+ public context!: EndToEndContext;
191
+ public l1Client!: ExtendedViemWalletClient;
192
+ public rollup!: RollupContract;
193
+ public constants!: L1RollupConstants;
194
+ public logger!: Logger;
195
+ public monitor!: ChainMonitor;
196
+ public epochCache!: EpochCache;
197
+ public proverDelayer!: Delayer;
198
+ public sequencerDelayer!: Delayer;
199
+
200
+ public proverNodes: AztecNodeService[] = [];
201
+ public nodes: AztecNodeService[] = [];
202
+
203
+ public epochDuration!: number;
204
+
205
+ public L1_BLOCK_TIME_IN_S!: number;
206
+ public L2_SLOT_DURATION_IN_S!: number;
207
+
208
+ public static async setup<T extends SingleNodeTestContext>(this: new () => T, opts: SingleNodeTestOpts = {}) {
209
+ const test = new this();
210
+ await test.setup(opts);
211
+ return test;
212
+ }
213
+
214
+ public static getSlotDurations(opts: SingleNodeTestOpts = {}) {
215
+ const envEthereumSlotDuration = process.env.L1_BLOCK_TIME
216
+ ? parseInt(process.env.L1_BLOCK_TIME)
217
+ : DEFAULT_L1_BLOCK_TIME;
218
+ const ethereumSlotDuration = opts.ethereumSlotDuration ?? envEthereumSlotDuration;
219
+ const aztecSlotDuration = opts.aztecSlotDuration ?? (opts.aztecSlotDurationInL1Slots ?? 2) * ethereumSlotDuration;
220
+ const aztecEpochDuration = opts.aztecEpochDuration ?? 6;
221
+ const aztecProofSubmissionEpochs = opts.aztecProofSubmissionEpochs ?? 1;
222
+ return {
223
+ ethereumSlotDuration,
224
+ aztecSlotDuration,
225
+ aztecEpochDuration,
226
+ aztecProofSubmissionEpochs,
227
+ };
228
+ }
229
+
230
+ public async setup(opts: SingleNodeTestOpts = {}) {
231
+ const { ethereumSlotDuration, aztecSlotDuration, aztecEpochDuration, aztecProofSubmissionEpochs } =
232
+ SingleNodeTestContext.getSlotDurations(opts);
233
+
234
+ // Auto-create a hardcoded account funded via genesis when:
235
+ // - skipInitialSequencer is set (no sequencer to deploy on-chain), or
236
+ // - useHardcodedAccount is explicitly requested (e.g. tight per-block gas budgets that
237
+ // can't fit a full account-deploy tx).
238
+ const useHardcodedAccount = (opts.skipInitialSequencer || opts.useHardcodedAccount) && !opts.skipHardcodedAccount;
239
+ let hardcodedAccountData: InitialAccountData | undefined;
240
+ if (useHardcodedAccount) {
241
+ hardcodedAccountData = await SingleNodeTestContext.getHardcodedAccountData(Fr.random(), Fr.random());
242
+ }
243
+
244
+ // Set up system without any account nor protocol contracts
245
+ // and with faster block times and shorter epochs.
246
+ const context = await setup(
247
+ useHardcodedAccount ? 0 : (opts.numberOfAccounts ?? 0),
248
+ {
249
+ automineL1Setup: true,
250
+ checkIntervalMs: 50,
251
+ archiverPollingIntervalMS: ARCHIVER_POLL_INTERVAL,
252
+ worldStateBlockCheckIntervalMS: WORLD_STATE_BLOCK_CHECK_INTERVAL,
253
+ aztecEpochDuration,
254
+ aztecSlotDuration,
255
+ ethereumSlotDuration,
256
+ aztecProofSubmissionEpochs,
257
+ aztecTargetCommitteeSize: opts.initialValidators?.length ?? 0,
258
+ minTxsPerBlock: 0,
259
+ realProofs: false,
260
+ startProverNode: true,
261
+ proverTestDelayMs: opts.proverTestDelayMs ?? 0,
262
+ proverId: EthAddress.fromNumber(1),
263
+ worldStateCheckpointHistory: WORLD_STATE_CHECKPOINT_HISTORY,
264
+ exitDelaySeconds: DefaultL1ContractsConfig.exitDelaySeconds,
265
+ slasherEnabled: false,
266
+ // `inboxLag: 2` is the intended value when running with pipelining (the production config
267
+ // default of 1 is a separate bug). Set before `...opts` so tests can still override.
268
+ inboxLag: 2,
269
+ ...opts,
270
+ ...(hardcodedAccountData ? { additionallyFundedAccounts: [hardcodedAccountData], numberOfAccounts: 0 } : {}),
271
+ },
272
+ // Use checkpointed chain tip for PXE by default to avoid issues with blocks being dropped due to pruned anchor blocks.
273
+ // Can be overridden via opts.pxeOpts.
274
+ { syncChainTip: 'checkpointed', ...opts.pxeOpts },
275
+ );
276
+
277
+ // Register the hardcoded account in PXE (local only, no on-chain deployment needed).
278
+ if (hardcodedAccountData) {
279
+ this.context = context;
280
+ await this.registerHardcodedAccount(hardcodedAccountData);
281
+ }
282
+
283
+ await this.hydrateFromContext(context);
284
+ }
285
+
286
+ /**
287
+ * Populates the context-derived state (tracked nodes, L1 client, rollup, epoch cache, chain
288
+ * monitor, delayers, timing constants) from an already-built {@link EndToEndContext}. Split out of
289
+ * {@link setup} so prover-specific subclasses that build the environment with their own bespoke
290
+ * `setup(...)` opts (e.g. `FullProverTest`) can still reuse the base node/teardown machinery
291
+ * without inheriting the base's default node config. Slot/epoch durations are read from the
292
+ * resolved `context.config` so the recorded constants match whatever the environment was deployed
293
+ * with.
294
+ */
295
+ protected async hydrateFromContext(context: EndToEndContext): Promise<void> {
296
+ this.context = context;
297
+
298
+ const { ethereumSlotDuration, aztecSlotDuration, aztecEpochDuration } = context.config;
299
+
300
+ this.L1_BLOCK_TIME_IN_S = ethereumSlotDuration;
301
+ this.L2_SLOT_DURATION_IN_S = aztecSlotDuration;
302
+
303
+ this.proverNodes = context.proverNode ? [context.proverNode] : [];
304
+ this.nodes = context.aztecNode ? [context.aztecNode as AztecNodeService] : [];
305
+ this.logger = context.logger;
306
+ this.l1Client = context.deployL1ContractsValues.l1Client;
307
+ this.rollup = RollupContract.getFromConfig(context.config);
308
+ this.epochCache = await EpochCache.create(this.rollup, context.config, { dateProvider: context.dateProvider });
309
+
310
+ // Loop that tracks L1 and L2 block numbers and logs whenever there's a new one.
311
+ this.monitor = new ChainMonitor(this.rollup, context.dateProvider, this.logger).start();
312
+
313
+ this.proverDelayer = context.proverDelayer!;
314
+ this.sequencerDelayer = context.sequencerDelayer!;
315
+
316
+ if ((context.proverNode && !this.proverDelayer) || (context.sequencer && !this.sequencerDelayer)) {
317
+ throw new Error(`Could not find prover or sequencer delayer`);
318
+ }
319
+
320
+ // Constants used for time calculation
321
+ this.epochDuration = aztecEpochDuration;
322
+ this.constants = {
323
+ epochDuration: aztecEpochDuration,
324
+ slotDuration: aztecSlotDuration,
325
+ l1StartBlock: await this.rollup.getL1StartBlock(),
326
+ l1GenesisTime: await this.rollup.getL1GenesisTime(),
327
+ ethereumSlotDuration,
328
+ proofSubmissionEpochs: Number(await this.rollup.getProofSubmissionEpochs()),
329
+ targetCommitteeSize: await this.rollup.getTargetCommitteeSize(),
330
+ rollupManaLimit: Number(await this.rollup.getManaLimit()),
331
+ };
332
+
333
+ this.logger.info(
334
+ `L2 genesis at L1 block ${this.constants.l1StartBlock} (timestamp ${this.constants.l1GenesisTime})`,
335
+ );
336
+ }
337
+
338
+ public async teardown() {
339
+ await this.monitor.stop();
340
+ await Promise.all(this.proverNodes.map(node => tryStop(node, this.logger)));
341
+ await Promise.all(this.nodes.map(node => tryStop(node, this.logger)));
342
+ await this.context.teardown();
343
+ }
344
+
345
+ /**
346
+ * Computes InitialAccountData for a SchnorrHardcodedKeyAccountContract.
347
+ * This contract has a hardcoded signing key and no initializer, so it can be used without
348
+ * on-chain deployment. Pass the returned data in `additionallyFundedAccounts` so the address
349
+ * gets funded with fee juice in genesis.
350
+ */
351
+ public static async getHardcodedAccountData(secret: Fr, salt: Fr): Promise<InitialAccountData> {
352
+ const contract = new SchnorrHardcodedKeyAccountContract();
353
+ const address = await getAccountContractAddress(contract, secret, salt);
354
+ const signingKey = SCHNORR_HARDCODED_PRIVATE_KEY;
355
+ return { secret, salt, signingKey, address };
356
+ }
357
+
358
+ /**
359
+ * Registers a SchnorrHardcodedKeyAccountContract in PXE. The account must have been funded
360
+ * at genesis (via getHardcodedAccountData). No on-chain deployment or block mining needed.
361
+ */
362
+ public async registerHardcodedAccount(accountData: InitialAccountData): Promise<AztecAddress> {
363
+ const contract = new SchnorrHardcodedKeyAccountContract();
364
+ const wallet = this.context.wallet;
365
+ const accountManager = await (wallet as TestWallet).createAccount({
366
+ secret: accountData.secret,
367
+ salt: accountData.salt,
368
+ contract,
369
+ });
370
+ this.context.accounts = [accountManager.address];
371
+ return accountManager.address;
372
+ }
373
+
374
+ public async createProverNode(opts: { dontStart?: boolean } & Partial<ProverNodeConfig> = {}) {
375
+ this.logger.warn('Creating and syncing a simulated prover node...');
376
+ const proverNodePrivateKey = this.getNextPrivateKey();
377
+ const proverIndex = this.proverNodes.length + 1;
378
+ const { mockGossipSubNetwork } = this.context;
379
+ const { proverNode } = await testSpan('setup:node', () =>
380
+ withLoggerBindings({ actor: `prover-${proverIndex}` }, () =>
381
+ createAndSyncProverNode(
382
+ proverNodePrivateKey,
383
+ {
384
+ ...this.context.config,
385
+ p2pEnabled: this.context.config.p2pEnabled || mockGossipSubNetwork !== undefined,
386
+ proverId: EthAddress.fromNumber(proverIndex),
387
+ dontStart: opts.dontStart,
388
+ ...opts,
389
+ },
390
+ {
391
+ dataDirectory: join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
392
+ },
393
+ {
394
+ dateProvider: this.context.dateProvider,
395
+ p2pClientDeps: {
396
+ p2pServiceFactory: mockGossipSubNetwork
397
+ ? getMockPubSubP2PServiceFactory(mockGossipSubNetwork)
398
+ : undefined,
399
+ rpcTxProviders: [this.context.aztecNode],
400
+ },
401
+ },
402
+ {
403
+ genesis: this.context.genesis,
404
+ dontStart: opts.dontStart,
405
+ },
406
+ ),
407
+ ),
408
+ );
409
+ this.proverNodes.push(proverNode);
410
+ return proverNode;
411
+ }
412
+
413
+ public createNonValidatorNode(opts: Partial<AztecNodeConfig> = {}) {
414
+ this.logger.warn('Creating and syncing a node without a validator...');
415
+ return this.createNode({ ...opts, disableValidator: true });
416
+ }
417
+
418
+ protected async createNode(
419
+ opts: Partial<AztecNodeConfig> & {
420
+ dontStartSequencer?: boolean;
421
+ slashingProtectionDb?: SlashingProtectionDatabase;
422
+ } = {},
423
+ ) {
424
+ const nodeIndex = this.nodes.length + 1;
425
+ const actorPrefix = opts.disableValidator ? 'node' : 'validator';
426
+ const { mockGossipSubNetwork } = this.context;
427
+ const resolvedConfig = { ...this.context.config, ...opts };
428
+ const p2pEnabled = resolvedConfig.p2pEnabled || mockGossipSubNetwork !== undefined;
429
+ const p2pIp = resolvedConfig.p2pIp ?? (p2pEnabled ? '127.0.0.1' : undefined);
430
+ const node = await testSpan('setup:node', () =>
431
+ withLoggerBindings({ actor: `${actorPrefix}-${nodeIndex}` }, () =>
432
+ createAztecNodeService(
433
+ {
434
+ ...resolvedConfig,
435
+ dataDirectory: join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
436
+ validatorPrivateKeys: opts.validatorPrivateKeys ?? new SecretValue([]),
437
+ nodeId: resolvedConfig.nodeId || `${actorPrefix}-${nodeIndex}`,
438
+ p2pEnabled,
439
+ p2pIp,
440
+ },
441
+ {
442
+ dateProvider: this.context.dateProvider,
443
+ p2pClientDeps: {
444
+ p2pServiceFactory: mockGossipSubNetwork
445
+ ? getMockPubSubP2PServiceFactory(mockGossipSubNetwork)
446
+ : undefined,
447
+ },
448
+ slashingProtectionDb: opts.slashingProtectionDb,
449
+ },
450
+ {
451
+ genesis: this.context.genesis,
452
+ ...opts,
453
+ },
454
+ ),
455
+ ),
456
+ );
457
+
458
+ this.nodes.push(node);
459
+ return node;
460
+ }
461
+
462
+ protected getNextPrivateKey(): Hex {
463
+ const key = getPrivateKeyFromIndex(this.nodes.length + this.proverNodes.length + 1);
464
+ return `0x${key!.toString('hex')}`;
465
+ }
466
+
467
+ /** Waits until the epoch begins (ie until the immediately previous L1 block is mined). */
468
+ public async waitUntilEpochStarts(epoch: number) {
469
+ const [start] = getTimestampRangeForEpoch(EpochNumber(epoch), this.constants);
470
+ this.logger.info(`Waiting until L1 timestamp ${start} is reached as the start of epoch ${epoch}`);
471
+ // Cover at least two full epochs of wall time so callers issuing the wait mid-epoch
472
+ // still have headroom — the prior `30 * epochDuration` mixed units (slots vs seconds)
473
+ // and timed out at 120s for configs whose epoch wall time is 144s+.
474
+ await testSpan('wait:epoch', () =>
475
+ waitUntilL1Timestamp(
476
+ this.l1Client,
477
+ start - BigInt(this.L1_BLOCK_TIME_IN_S),
478
+ undefined,
479
+ 2 * this.epochDuration * this.L2_SLOT_DURATION_IN_S,
480
+ ),
481
+ );
482
+ return start;
483
+ }
484
+
485
+ /**
486
+ * Waits until the next epoch boundary and returns that epoch's number. Anchors tests
487
+ * on a guaranteed-fresh epoch regardless of how much wall time `beforeEach` consumed —
488
+ * `waitUntilEpochStarts(1)` returns immediately when the chain has already advanced past
489
+ * slot 4, which under CI load can leave only seconds of the target epoch remaining.
490
+ *
491
+ * If the chain has more than two slots of headroom before the target boundary, warps
492
+ * the L1 clock to within two slots of the boundary instead of waiting in wall-clock.
493
+ * The two-slot tail is intentional — it lets the sequencer/builder settle so the first
494
+ * checkpoint of the target epoch lands correctly.
495
+ */
496
+ public async waitUntilNextEpochStarts(): Promise<EpochNumber> {
497
+ const { epoch } = this.epochCache.getEpochAndSlotNow();
498
+ const target = EpochNumber(Number(epoch) + 1);
499
+ const [targetTs] = getTimestampRangeForEpoch(target, this.constants);
500
+ const safeTs = targetTs - BigInt(2 * this.L2_SLOT_DURATION_IN_S);
501
+ const currentTs = BigInt(await this.context.cheatCodes.eth.lastBlockTimestamp());
502
+ if (currentTs < safeTs) {
503
+ this.logger.info(`Warping L1 from ${currentTs} to ${safeTs} (2 slots before epoch ${target})`);
504
+ await this.context.cheatCodes.eth.warp(Number(safeTs), { resetBlockInterval: true });
505
+ }
506
+ await this.waitUntilEpochStarts(Number(target));
507
+ return target;
508
+ }
509
+
510
+ /**
511
+ * Warps the L1 clock to within `leadSlots` slots of the start of `epoch`, then waits for that boundary in
512
+ * wall-clock, skipping the dead stretch where the chain just advances one L1 block per slot until an epoch
513
+ * ends. Anything the post-warp assertions depend on must already be produced before calling this — warping
514
+ * the tail away does not change what gets proven, and the shared `TestDateProvider` moves the
515
+ * prover/node/sequencer clocks together so the epoch finalizes right after the warp. The `leadSlots` tail
516
+ * (default 2) is left in real time so the sequencer can publish the epoch's final checkpoint before the
517
+ * boundary, and so any post-warp sampler observes an in-epoch slot rather than the epoch's last slot.
518
+ * Forward-only, so a no-op when already within `leadSlots` of the boundary.
519
+ */
520
+ public async warpToEpochStart(epoch: number, opts: { leadSlots?: number } = {}): Promise<bigint> {
521
+ const leadSlots = opts.leadSlots ?? 2;
522
+ const [targetTs] = getTimestampRangeForEpoch(EpochNumber(epoch), this.constants);
523
+ const safeTs = targetTs - BigInt(leadSlots * this.L2_SLOT_DURATION_IN_S);
524
+ const currentTs = BigInt(await this.context.cheatCodes.eth.lastBlockTimestamp());
525
+ if (currentTs < safeTs) {
526
+ this.logger.info(`Warping L1 from ${currentTs} to ${safeTs} (${leadSlots} slots before epoch ${epoch})`);
527
+ await this.context.cheatCodes.eth.warp(Number(safeTs), { resetBlockInterval: true });
528
+ }
529
+ return this.waitUntilEpochStarts(epoch);
530
+ }
531
+
532
+ /**
533
+ * Most of a proof-submission window is dead wall-clock time, so warp the L1 clock forward to `leadSlots`
534
+ * (default 2) L2 slots before the window's last slot. A subsequent
535
+ * {@link waitUntilLastSlotOfProofSubmissionWindow} then only sleeps out the few remaining real slots,
536
+ * leaving enough real time for any in-flight proving, pruning, and recovery to happen organically. Only
537
+ * warps forward, so it is a no-op when the chain is already within `leadSlots`+1 slots of the window end.
538
+ */
539
+ public async warpNearSubmissionWindowEnd(epoch: number, opts: { leadSlots?: number } = {}): Promise<void> {
540
+ const leadSlots = opts.leadSlots ?? 2;
541
+ const { slotDuration } = this.constants;
542
+ const deadline = getProofSubmissionDeadlineTimestamp(EpochNumber(epoch), this.constants);
543
+ // Mirror waitUntilLastSlotOfProofSubmissionWindow's target (one slot before the deadline).
544
+ const lastSlotTs = deadline - BigInt(slotDuration);
545
+ const target = lastSlotTs - BigInt(leadSlots * slotDuration);
546
+ const currentTs = BigInt(await this.context.cheatCodes.eth.lastBlockTimestamp());
547
+ if (currentTs < target) {
548
+ this.logger.warn(`Warping L1 to ${leadSlots} slots before end of epoch ${epoch} submission window`, {
549
+ currentTs,
550
+ target,
551
+ epoch,
552
+ });
553
+ await this.context.cheatCodes.eth.warp(Number(target), { resetBlockInterval: true });
554
+ }
555
+ }
556
+
557
+ /** Waits until the given checkpoint number is mined. */
558
+ public async waitUntilCheckpointNumber(target: CheckpointNumber, timeout = 120) {
559
+ await testSpan('wait:checkpoint', () =>
560
+ retryUntil(
561
+ () => Promise.resolve(target <= this.monitor.checkpointNumber),
562
+ `Wait until checkpoint ${target}`,
563
+ timeout,
564
+ 0.1,
565
+ ),
566
+ );
567
+ }
568
+
569
+ /** Waits until the given checkpoint number is marked as proven. */
570
+ public async waitUntilProvenCheckpointNumber(target: CheckpointNumber, timeout = 120) {
571
+ await testSpan('wait:proven-checkpoint', () =>
572
+ retryUntil(
573
+ () => Promise.resolve(target <= this.monitor.provenCheckpointNumber),
574
+ `Wait proven checkpoint ${target}`,
575
+ timeout,
576
+ 0.1,
577
+ ),
578
+ );
579
+ return this.monitor.provenCheckpointNumber;
580
+ }
581
+
582
+ /** Waits until the last slot of the proof submission window for a given epoch. */
583
+ public async waitUntilLastSlotOfProofSubmissionWindow(epochNumber: number | bigint) {
584
+ const deadline = getProofSubmissionDeadlineTimestamp(EpochNumber.fromBigInt(BigInt(epochNumber)), this.constants);
585
+ const oneSlotBefore = deadline - BigInt(this.constants.slotDuration);
586
+ const date = new Date(Number(oneSlotBefore) * 1000);
587
+ this.logger.info(`Waiting until last slot of submission window for epoch ${epochNumber} at ${date}`, {
588
+ oneSlotBefore,
589
+ });
590
+ // Use a timeout that accounts for the full proof submission window
591
+ const proofSubmissionWindowDuration =
592
+ this.constants.proofSubmissionEpochs * this.epochDuration * this.L2_SLOT_DURATION_IN_S;
593
+ await testSpan('wait:proof-window', () =>
594
+ waitUntilL1Timestamp(this.l1Client, oneSlotBefore, undefined, proofSubmissionWindowDuration * 2),
595
+ );
596
+ }
597
+
598
+ /**
599
+ * Timestamp one L1 block before L2 `slot` begins — the instant a pipelined proposer starts
600
+ * building for that slot. `opts.lead` overrides the default one-L1-block lead (e.g. when a test
601
+ * needs an extra block-duration margin to guarantee sub-slot 1 is reachable).
602
+ */
603
+ public buildWindowTimestampForSlot(slot: SlotNumber, opts: { lead?: number } = {}): bigint {
604
+ const lead = opts.lead ?? this.L1_BLOCK_TIME_IN_S;
605
+ return getTimestampForSlot(slot, this.constants) - BigInt(lead);
606
+ }
607
+
608
+ /**
609
+ * Warps the L1 clock to the build window of `slot` (one L1 block before the slot begins) with
610
+ * `resetBlockInterval`, so a pipelined proposer engages cleanly when its sequencer starts.
611
+ * @returns The slot warped to.
612
+ */
613
+ public async warpToBuildWindowForSlot(slot: SlotNumber): Promise<SlotNumber> {
614
+ const target = this.buildWindowTimestampForSlot(slot);
615
+ this.logger.info(`Warping L1 to build window of slot ${slot}`, { slot, target });
616
+ await this.context.cheatCodes.eth.warp(Number(target), { resetBlockInterval: true });
617
+ return slot;
618
+ }
619
+
620
+ /**
621
+ * Waits (in wall-clock, without warping) until the L1 clock reaches the build window of `slot`.
622
+ * For production-sequencer tests that can't warp. `opts.lead` extends the lead beyond the default
623
+ * one L1 block; `opts.timeout` bounds the wait (defaults to three L2 slots).
624
+ * @returns The slot waited for.
625
+ */
626
+ public async waitForBuildWindowForSlot(
627
+ slot: SlotNumber,
628
+ opts: { lead?: number; timeout?: number } = {},
629
+ ): Promise<SlotNumber> {
630
+ const target = this.buildWindowTimestampForSlot(slot, { lead: opts.lead });
631
+ const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 3;
632
+ this.logger.info(`Waiting until L1 reaches build window of slot ${slot}`, { slot, target });
633
+ await testSpan('wait:slot', () => waitUntilL1Timestamp(this.l1Client, target, undefined, timeout));
634
+ return slot;
635
+ }
636
+
637
+ /** Waits for the aztec node to sync to the target block number. */
638
+ public async waitForNodeToSync(blockNumber: BlockNumber, type: 'proven' | 'finalized' | 'historic') {
639
+ const waitTime = ARCHIVER_POLL_INTERVAL + WORLD_STATE_BLOCK_CHECK_INTERVAL;
640
+ await testSpan('wait:node-sync', async () => {
641
+ let synched = false;
642
+ while (!synched) {
643
+ await sleep(waitTime);
644
+ const [syncState, tips] = await Promise.all([
645
+ this.context.aztecNode.getWorldStateSyncStatus(),
646
+ await this.context.aztecNode.getChainTips(),
647
+ ]);
648
+ this.logger.info(`Wait for node synch ${blockNumber} ${type}`, { blockNumber, type, syncState, tips });
649
+ if (type === 'proven') {
650
+ synched = tips.proven.block.number >= blockNumber && syncState.latestBlockNumber >= blockNumber;
651
+ } else if (type === 'finalized') {
652
+ synched = syncState.finalizedBlockNumber >= blockNumber;
653
+ } else {
654
+ synched = syncState.oldestHistoricBlockNumber >= blockNumber;
655
+ }
656
+ }
657
+ });
658
+ }
659
+
660
+ /**
661
+ * Waits until every prover node has submitted a proof for `epoch` (of length `epochLength`
662
+ * checkpoints) on L1. Polls `rollup.getHasSubmittedProof` for each prover registered in
663
+ * {@link proverNodes}.
664
+ */
665
+ public async waitForAllProversToSubmit(
666
+ epoch: EpochNumber,
667
+ epochLength: number,
668
+ opts: { timeout?: number } = {},
669
+ ): Promise<void> {
670
+ const proverIds = this.proverNodes.map(node => node.getProverNode()!.getProverId());
671
+ await testSpan('wait:proof-submitted', () =>
672
+ retryUntil(
673
+ async () => {
674
+ const haveSubmitted = await Promise.all(
675
+ proverIds.map(proverId => this.rollup.getHasSubmittedProof(epoch, epochLength, proverId)),
676
+ );
677
+ this.logger.info(`Proof submissions: ${haveSubmitted.join(', ')}`);
678
+ return haveSubmitted.every(submitted => submitted);
679
+ },
680
+ 'Provers have submitted proofs',
681
+ opts.timeout ?? 120,
682
+ ),
683
+ );
684
+ }
685
+
686
+ /** Registers the SpamContract on the given wallet. */
687
+ public async registerSpamContract(wallet: Wallet, salt = Fr.ZERO) {
688
+ const instance = await getContractInstanceFromInstantiationParams(SpamContract.artifact, {
689
+ constructorArgs: [],
690
+ constructorArtifact: undefined,
691
+ salt,
692
+ publicKeys: undefined,
693
+ deployer: undefined,
694
+ });
695
+ await wallet.registerContract(instance, SpamContract.artifact);
696
+ return SpamContract.at(instance.address, wallet);
697
+ }
698
+
699
+ /** Registers the TestContract on the given wallet. */
700
+ public async registerTestContract(wallet: Wallet, salt = Fr.ZERO) {
701
+ const instance = await getContractInstanceFromInstantiationParams(TestContract.artifact, {
702
+ constructorArgs: [],
703
+ constructorArtifact: undefined,
704
+ salt,
705
+ publicKeys: undefined,
706
+ deployer: undefined,
707
+ });
708
+ await wallet.registerContract(instance, TestContract.artifact);
709
+ return TestContract.at(instance.address, wallet);
710
+ }
711
+
712
+ /** Creates an L1 client using a fresh account with funds from anvil, with a tx delayer already set up. */
713
+ public async createL1Client() {
714
+ const rawClient = createExtendedL1Client(
715
+ [...this.l1Client.chain.rpcUrls.default.http],
716
+ privateKeyToAccount(this.getNextPrivateKey()),
717
+ this.l1Client.chain,
718
+ );
719
+ const delayer = createDelayer(this.context.dateProvider, { ethereumSlotDuration: this.L1_BLOCK_TIME_IN_S }, {});
720
+ const client = wrapClientWithDelayer(rawClient, delayer);
721
+ expect(await client.getBalance({ address: client.account.address })).toBeGreaterThan(0n);
722
+ return { client, delayer };
723
+ }
724
+
725
+ /** Verifies whether the given block number is found on the aztec node. */
726
+ public async verifyHistoricBlock(blockNumber: BlockParameter, expectedSuccess: boolean) {
727
+ // We use `findLeavesIndexes` here, but could use any function that queries the world-state
728
+ // at a particular block, so we know whether that historic block is available or has been
729
+ // pruned. Note that `getBlock` would not work here, since it only hits the archiver.
730
+ const result = await this.context.aztecNode
731
+ .findLeavesIndexes(blockNumber, MerkleTreeId.NULLIFIER_TREE, [Fr.ZERO])
732
+ .then(_ => true)
733
+ .catch(_ => false);
734
+ expect(result).toBe(expectedSuccess);
735
+ }
736
+
737
+ /**
738
+ * Verifies that at least one checkpoint has `targetBlockCount` blocks and that block numbering is
739
+ * contiguous within every checkpoint (MBPS validation).
740
+ *
741
+ * Two optional wait modes (both poll before reading checkpoints):
742
+ * - `opts.wait`: waits until some checkpoint reaches `targetBlockCount` blocks (the proposed-tip
743
+ * MBPS setup case), and
744
+ * - `opts.targetBlock`: waits until the archiver's checkpointed tip reaches that block number
745
+ * (the pipeline-prune recovery case).
746
+ *
747
+ * Reads from `opts.archiver` when given (e.g. a specific validator node's block source); otherwise
748
+ * from the initial node's archiver.
749
+ * @returns The number of the first checkpoint with at least `targetBlockCount` blocks.
750
+ */
751
+ public async assertMultipleBlocksPerSlot(
752
+ targetBlockCount: number,
753
+ opts: { wait?: boolean; targetBlock?: BlockNumber; archiver?: Archiver; timeout?: number } = {},
754
+ ): Promise<CheckpointNumber> {
755
+ const archiver = opts.archiver ?? ((this.context.aztecNode as AztecNodeService).getBlockSource() as Archiver);
756
+ const waitTimeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 3;
757
+
758
+ if (opts.targetBlock !== undefined) {
759
+ const targetBlock = opts.targetBlock;
760
+ await retryUntil(
761
+ async () => {
762
+ const checkpointed = await archiver.getBlockNumber({ tag: 'checkpointed' });
763
+ return checkpointed !== undefined && checkpointed >= targetBlock;
764
+ },
765
+ `archiver checkpointed block ${targetBlock}`,
766
+ 10,
767
+ 0.1,
768
+ );
769
+ }
770
+
771
+ if (opts.wait) {
772
+ await retryUntil(
773
+ async () => {
774
+ const found = await archiver.getCheckpoints({ from: CheckpointNumber(1), limit: 50 });
775
+ return found.some(pc => pc.checkpoint.blocks.length >= targetBlockCount) || undefined;
776
+ },
777
+ `checkpoint with at least ${targetBlockCount} blocks`,
778
+ waitTimeout,
779
+ 0.5,
780
+ );
781
+ }
782
+
783
+ const checkpoints = await archiver.getCheckpoints({ from: CheckpointNumber(1), limit: 50 });
784
+
785
+ this.logger.warn(`Retrieved ${checkpoints.length} checkpoints from archiver`, {
786
+ checkpoints: checkpoints.map(pc => pc.checkpoint.getStats()),
787
+ });
788
+
789
+ let expectedBlockNumber = checkpoints[0].checkpoint.blocks[0].number;
790
+ let multiBlockCheckpointNumber: CheckpointNumber | undefined;
791
+
792
+ for (const checkpoint of checkpoints) {
793
+ const blockCount = checkpoint.checkpoint.blocks.length;
794
+ if (blockCount >= targetBlockCount && multiBlockCheckpointNumber === undefined) {
795
+ multiBlockCheckpointNumber = checkpoint.checkpoint.number;
796
+ }
797
+
798
+ this.logger.verbose(`Checkpoint ${checkpoint.checkpoint.number} has ${blockCount} blocks`, {
799
+ checkpoint: checkpoint.checkpoint.getStats(),
800
+ });
801
+
802
+ for (let i = 0; i < blockCount; i++) {
803
+ const block = checkpoint.checkpoint.blocks[i];
804
+ expect(block.indexWithinCheckpoint).toBe(i);
805
+ expect(block.checkpointNumber).toBe(checkpoint.checkpoint.number);
806
+ expect(block.number).toBe(expectedBlockNumber);
807
+ expectedBlockNumber++;
808
+ }
809
+ }
810
+
811
+ expect(multiBlockCheckpointNumber).toBeDefined();
812
+ return multiBlockCheckpointNumber!;
813
+ }
814
+
815
+ /**
816
+ * Asserts pipelining by comparing the build slot (from block-proposed events) against the
817
+ * submission slot (from block headers). With pipelining, the block is built in slot N but its
818
+ * header carries submission slot N+1. Also checks each block's coinbase matches the expected
819
+ * proposer for its submission slot. Reads checkpoints from `archiver` (typically a validator
820
+ * node's block source).
821
+ */
822
+ public async assertProposerPipelining(
823
+ archiver: Archiver,
824
+ blockProposedEvents: BlockProposedEvent[],
825
+ logger: Logger,
826
+ ): Promise<void> {
827
+ const checkpoints = await archiver.getCheckpoints({ from: CheckpointNumber(1), limit: 50 });
828
+ const allBlocks = checkpoints.flatMap(pc => pc.checkpoint.blocks);
829
+
830
+ logger.warn(`assertProposerPipelining: ${allBlocks.length} blocks, ${blockProposedEvents.length} events`, {
831
+ blockNumbers: allBlocks.map(b => b.number),
832
+ eventBlockNumbers: blockProposedEvents.map(e => e.blockNumber),
833
+ });
834
+
835
+ let foundPipelining = false;
836
+
837
+ for (const block of allBlocks) {
838
+ const headerSlot = block.header.globalVariables.slotNumber; // submission slot (N+1)
839
+ const coinbase = block.header.globalVariables.coinbase;
840
+
841
+ // Find the block-proposed event for this block (use Number() for safe comparison)
842
+ const event = blockProposedEvents.find(e => Number(e.blockNumber) === Number(block.number));
843
+ // if there is no event, then it was probably block number one - which was proposed in setup
844
+ if (!event) {
845
+ continue;
846
+ }
847
+
848
+ const buildSlot = event.buildSlot; // build slot (N)
849
+
850
+ // Verify the pipelining offset: block built in slot N, submitted in slot N+1
851
+ expect(Number(headerSlot)).toBe(Number(buildSlot) + 1);
852
+ foundPipelining = true;
853
+
854
+ // Verify coinbase matches the expected proposer for the submission slot
855
+ const expectedProposer = await this.rollup.getProposerAt(getTimestampForSlot(headerSlot, this.constants));
856
+ expect(coinbase).toEqual(expectedProposer);
857
+
858
+ logger.warn(`Block ${block.number}: buildSlot=${buildSlot}, submissionSlot=${headerSlot}, coinbase=${coinbase}`, {
859
+ blockNumber: block.number,
860
+ buildSlot,
861
+ headerSlot,
862
+ coinbase: coinbase.toString(),
863
+ expectedProposer: expectedProposer.toString(),
864
+ });
865
+ }
866
+
867
+ expect(foundPipelining).toBe(true);
868
+ logger.warn(`Pipelining assertion passed for ${allBlocks.length} blocks`);
869
+ }
870
+
871
+ public watchSequencerEvents(
872
+ sequencers: SequencerClient[],
873
+ getMetadata: (i: number) => Record<string, any> = () => ({}),
874
+ additionalFailEventKeys: (keyof SequencerEvents)[] = [],
875
+ ) {
876
+ const stateChanges: TrackedSequencerEvent[] = [];
877
+ const failEvents: TrackedSequencerEvent[] = [];
878
+
879
+ // Note we do not include the 'block-tx-count-check-failed' event here, since it is fine if we dont build
880
+ // due to lack of txs available.
881
+ const failEventsKeys: (keyof SequencerEvents)[] = [
882
+ 'block-build-failed',
883
+ 'checkpoint-publish-failed',
884
+ 'proposer-rollup-check-failed',
885
+ 'checkpoint-error',
886
+ 'checkpoint-publish-failed',
887
+ 'header-validation-failed',
888
+ 'pipelined-checkpoint-discarded',
889
+ ...additionalFailEventKeys,
890
+ ];
891
+
892
+ const makeEvent = (
893
+ i: number,
894
+ eventName: keyof SequencerEvents,
895
+ args: Parameters<SequencerEvents[keyof SequencerEvents]>[0],
896
+ ) =>
897
+ ({
898
+ ...args,
899
+ type: eventName,
900
+ sequencerIndex: i + 2,
901
+ ...getMetadata(i),
902
+ }) as TrackedSequencerEvent;
903
+
904
+ sequencers.forEach((sequencer, i) => {
905
+ const sequencerIndex = i + 2;
906
+ sequencer.getSequencer().on('state-changed', (args: Parameters<SequencerEvents['state-changed']>[0]) => {
907
+ const noisyStates = [SequencerState.IDLE, SequencerState.PROPOSER_CHECK, SequencerState.SYNCHRONIZING];
908
+ if (!noisyStates.includes(args.newState)) {
909
+ const evt = makeEvent(i, 'state-changed', args);
910
+ stateChanges.push(evt);
911
+ this.logger.verbose(
912
+ `Sequencer ${sequencerIndex} transitioned from state ${args.oldState} to state ${args.newState}`,
913
+ evt,
914
+ );
915
+ }
916
+ });
917
+ failEventsKeys.forEach(eventName => {
918
+ sequencer.getSequencer().on(eventName, (args: Parameters<SequencerEvents[typeof eventName]>[0]) => {
919
+ // Skip benign block-build-failed events where the builder rejected the block because it
920
+ // could not collect enough valid txs. This is the same "not enough txs" case as
921
+ // block-tx-count-check-failed (which is already excluded above), just detected after we
922
+ // started processing txs rather than before.
923
+ if (eventName === 'block-build-failed' && (args as { reason?: string }).reason === 'Insufficient valid txs') {
924
+ return;
925
+ }
926
+ const evt = makeEvent(i, eventName, args);
927
+ failEvents.push(evt);
928
+ this.logger.error(`Failed event ${eventName} from sequencer ${sequencerIndex}`, undefined, evt);
929
+ });
930
+ });
931
+ });
932
+
933
+ return { failEvents, stateChanges };
934
+ }
935
+
936
+ /**
937
+ * Resolves with the event args the first time `sequencer` emits `event` with args matching
938
+ * `match`. Rejects after `opts.timeout` ms (default 60s). Wraps the
939
+ * `executeTimeout(signal => new Promise(...))` one-shot subscription boilerplate, cleaning up
940
+ * the listener on both the resolve and the abort paths.
941
+ */
942
+ public waitForSequencerEvent<E extends keyof SequencerEvents>(
943
+ sequencer: Sequencer,
944
+ event: E,
945
+ match: (args: Parameters<SequencerEvents[E]>[0]) => boolean = () => true,
946
+ opts: { timeout?: number } = {},
947
+ ): Promise<Parameters<SequencerEvents[E]>[0]> {
948
+ const timeout = opts.timeout ?? 60_000;
949
+ return testSpan('wait:sequencer-state', () =>
950
+ executeTimeout(
951
+ signal =>
952
+ new Promise<Parameters<SequencerEvents[E]>[0]>(resolve => {
953
+ const listener = (args: Parameters<SequencerEvents[E]>[0]) => {
954
+ if (match(args)) {
955
+ sequencer.off(event, listener as SequencerEvents[E]);
956
+ resolve(args);
957
+ }
958
+ };
959
+ signal.addEventListener('abort', () => sequencer.off(event, listener as SequencerEvents[E]), {
960
+ once: true,
961
+ });
962
+ sequencer.on(event, listener as SequencerEvents[E]);
963
+ }),
964
+ timeout,
965
+ `wait for sequencer event ${String(event)}`,
966
+ ),
967
+ );
968
+ }
969
+
970
+ /** Returns the {@link SequencerClient} of each given node, throwing if any node has no sequencer. */
971
+ public getSequencers(nodes: AztecNodeService[]): SequencerClient[] {
972
+ return nodes.map(node => {
973
+ const sequencer = node.getSequencer();
974
+ if (!sequencer) {
975
+ throw new Error('Node has no sequencer');
976
+ }
977
+ return sequencer;
978
+ });
979
+ }
980
+
981
+ /** Starts the sequencer on each given node in parallel. */
982
+ public async startSequencers(nodes: AztecNodeService[]): Promise<void> {
983
+ await Promise.all(this.getSequencers(nodes).map(sequencer => sequencer.start()));
984
+ }
985
+
986
+ /**
987
+ * Resolves once `sequencer` is in `state`, returning immediately if it is already there. Use to
988
+ * flush in-flight work (e.g. wait for `IDLE` so pending L1 publishes have been issued) before
989
+ * sampling chain state. Builds on {@link waitForSequencerEvent} for the not-yet-there path.
990
+ */
991
+ public async waitForSequencerState(
992
+ sequencer: Sequencer,
993
+ state: SequencerState,
994
+ opts: { timeout?: number } = {},
995
+ ): Promise<void> {
996
+ if (sequencer.status().state === state) {
997
+ return;
998
+ }
999
+ await this.waitForSequencerEvent(sequencer, 'state-changed', args => args.newState === state, opts);
1000
+ }
1001
+
1002
+ public assertNoFailuresFromSequencers(failEvents: TrackedSequencerEvent[]) {
1003
+ if (failEvents.length > 0) {
1004
+ this.logger.error(`Failed events from sequencers`, failEvents);
1005
+ }
1006
+ expect(failEvents).toEqual([]);
1007
+ }
1008
+
1009
+ /**
1010
+ * Warps the L1 clock to `target` with every given node's sequencer paused, then resumes them
1011
+ * (pass `restart: false` to leave them paused, e.g. until some clock-driven effect is confirmed).
1012
+ *
1013
+ * Warping the shared date provider under live sequencers interrupts whatever iteration is mid-build,
1014
+ * producing spurious `block-build-failed` / `checkpoint-error` events and dropped checkpoints. The
1015
+ * sequencers are therefore paused first: the poll loop halts and the in-flight iteration, its pending L1
1016
+ * submission, and any pending fallback vote all finish untouched before the warp, so nothing fires with a
1017
+ * stale slot afterwards. Pausing leaves the validator clients (and their slashing-protection stores) and
1018
+ * publishers running, so a later {@link SequencerClient.start} cleanly resumes; archivers, provers, and
1019
+ * the chain monitor keep running throughout, so clock-driven effects of the warp (e.g. an orphan-block
1020
+ * prune) still fire.
1021
+ *
1022
+ * The warp is performed here (rather than via a caller-supplied callback) so it happens only after the
1023
+ * pause has drained. Draining can take several slots, so a `target` computed before the pause may already
1024
+ * lie in the past by the time the sequencers are down. The warp is therefore skipped when the L1 clock has
1025
+ * already reached or passed `target` — `evm_setNextBlockTimestamp` rejects a non-advancing timestamp, so
1026
+ * warping there would throw "timestamp in the past".
1027
+ */
1028
+ public async warpWithSequencersPaused(
1029
+ nodes: AztecNodeService[],
1030
+ cheatCodes: CheatCodes,
1031
+ target: bigint,
1032
+ opts: { restart?: boolean } = {},
1033
+ ): Promise<void> {
1034
+ const sequencers = this.getSequencers(nodes);
1035
+ await testSpan('warp:sequencers-paused', async () => {
1036
+ this.logger.warn(`Pausing ${sequencers.length} sequencers before warp`);
1037
+ await Promise.all(sequencers.map(sequencer => sequencer.pause()));
1038
+ const currentTs = BigInt(await cheatCodes.eth.lastBlockTimestamp());
1039
+ if (currentTs < target) {
1040
+ this.logger.warn(`Warping L1 to ${target} with all sequencers paused`, { currentTs, target });
1041
+ await cheatCodes.eth.warp(Number(target), { resetBlockInterval: true });
1042
+ } else {
1043
+ this.logger.verbose(`Skipping warp: L1 clock ${currentTs} already at or past target ${target}`, {
1044
+ currentTs,
1045
+ target,
1046
+ });
1047
+ }
1048
+ if (opts.restart ?? true) {
1049
+ this.logger.warn(`Resuming ${sequencers.length} sequencers after warp`);
1050
+ await Promise.all(sequencers.map(sequencer => sequencer.start()));
1051
+ }
1052
+ });
1053
+ }
1054
+ }