@aztec/sequencer-client 0.0.1-commit.7b97ef96e → 0.0.1-commit.7cbc774
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.
- package/README.md +282 -21
- package/dest/client/sequencer-client.d.ts +8 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +53 -30
- package/dest/config.d.ts +28 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +62 -27
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +14 -14
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +19 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +25 -5
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +16 -3
- package/dest/publisher/sequencer-publisher.d.ts +83 -65
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +428 -386
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +506 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +54 -11
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +784 -229
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/events.d.ts +47 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +13 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +45 -20
- package/dest/sequencer/sequencer.d.ts +59 -16
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +333 -119
- package/dest/sequencer/timetable.d.ts +17 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +51 -43
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +7 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- package/dest/test/utils.d.ts +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +7 -6
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +72 -33
- package/src/config.ts +76 -27
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +25 -62
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +49 -6
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +18 -6
- package/src/publisher/sequencer-publisher.ts +502 -473
- package/src/sequencer/README.md +152 -450
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +592 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +955 -258
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +50 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +57 -24
- package/src/sequencer/sequencer.ts +414 -132
- package/src/sequencer/timetable.ts +64 -52
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +51 -48
- package/src/test/utils.ts +28 -10
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
3
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
+
import { getNextL1SlotTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import { GasFees, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
7
|
+
import type { FeeProvider } from '@aztec/stdlib/tx';
|
|
8
|
+
|
|
9
|
+
import { FeePredictor } from './fee_predictor.js';
|
|
10
|
+
import type { GlobalVariableBuilderConfig } from './global_builder.js';
|
|
11
|
+
|
|
12
|
+
/** Provides current and predicted fee information based on on-chain state. */
|
|
13
|
+
export class FeeProviderImpl implements FeeProvider {
|
|
14
|
+
private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
|
|
15
|
+
private currentL1BlockNumber: bigint | undefined = undefined;
|
|
16
|
+
|
|
17
|
+
private readonly rollupContract: RollupContract;
|
|
18
|
+
private readonly feePredictor: FeePredictor;
|
|
19
|
+
private readonly ethereumSlotDuration: number;
|
|
20
|
+
private readonly l1GenesisTime: bigint;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly dateProvider: DateProvider,
|
|
24
|
+
private readonly publicClient: ViemPublicClient,
|
|
25
|
+
config: GlobalVariableBuilderConfig,
|
|
26
|
+
) {
|
|
27
|
+
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
28
|
+
this.l1GenesisTime = config.l1GenesisTime;
|
|
29
|
+
|
|
30
|
+
this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
|
|
31
|
+
this.feePredictor = new FeePredictor(this.rollupContract, this.publicClient, this.dateProvider, {
|
|
32
|
+
slotDuration: config.slotDuration,
|
|
33
|
+
l1GenesisTime: config.l1GenesisTime,
|
|
34
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
|
|
40
|
+
* @returns Min fees for the next block
|
|
41
|
+
*/
|
|
42
|
+
private async computeCurrentMinFees(): Promise<GasFees> {
|
|
43
|
+
// Since this might be called in the middle of a slot where a block might have been published,
|
|
44
|
+
// we need to fetch the last block written, and estimate the earliest timestamp for the next block.
|
|
45
|
+
// The timestamp of that last block will act as a lower bound for the next block.
|
|
46
|
+
|
|
47
|
+
const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
|
|
48
|
+
const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
|
|
49
|
+
SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
|
|
50
|
+
);
|
|
51
|
+
const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
|
|
52
|
+
l1GenesisTime: this.l1GenesisTime,
|
|
53
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
54
|
+
});
|
|
55
|
+
const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
|
|
56
|
+
|
|
57
|
+
return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
61
|
+
// Get the current block number
|
|
62
|
+
const blockNumber = await this.publicClient.getBlockNumber();
|
|
63
|
+
|
|
64
|
+
// If the L1 block number has changed then chain a new promise to get the current min fees
|
|
65
|
+
if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
|
|
66
|
+
this.currentL1BlockNumber = blockNumber;
|
|
67
|
+
this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
|
|
68
|
+
}
|
|
69
|
+
return this.currentMinFees;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
|
|
73
|
+
return this.feePredictor.getPredictedMinFees(manaUsage ?? ManaUsageEstimate.Target);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
RollupContract,
|
|
3
|
+
type SimulationOverridesPlan,
|
|
4
|
+
buildSimulationOverridesStateOverride,
|
|
5
|
+
} from '@aztec/ethereum/contracts';
|
|
5
6
|
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
6
7
|
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
9
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
-
import {
|
|
10
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
10
11
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
|
-
import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
+
import { type L1RollupConstants, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
13
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
13
14
|
import type {
|
|
14
15
|
CheckpointGlobalVariables,
|
|
@@ -16,18 +17,18 @@ import type {
|
|
|
16
17
|
} from '@aztec/stdlib/tx';
|
|
17
18
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
/** Configuration for the GlobalVariableBuilder (excludes L1 client config). */
|
|
21
|
+
export type GlobalVariableBuilderConfig = {
|
|
22
|
+
rollupAddress: EthAddress;
|
|
23
|
+
ethereumSlotDuration: number;
|
|
24
|
+
rollupVersion: bigint;
|
|
25
|
+
} & Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'>;
|
|
20
26
|
|
|
21
27
|
/**
|
|
22
28
|
* Simple global variables builder.
|
|
23
29
|
*/
|
|
24
30
|
export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
25
|
-
private log = createLogger('sequencer:global_variable_builder');
|
|
26
|
-
private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
|
|
27
|
-
private currentL1BlockNumber: bigint | undefined = undefined;
|
|
28
|
-
|
|
29
31
|
private readonly rollupContract: RollupContract;
|
|
30
|
-
private readonly publicClient: ViemPublicClient;
|
|
31
32
|
private readonly ethereumSlotDuration: number;
|
|
32
33
|
private readonly aztecSlotDuration: number;
|
|
33
34
|
private readonly l1GenesisTime: bigint;
|
|
@@ -36,59 +37,18 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
36
37
|
private version: Fr;
|
|
37
38
|
|
|
38
39
|
constructor(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
private readonly dateProvider: DateProvider,
|
|
41
|
+
private readonly publicClient: ViemPublicClient,
|
|
42
|
+
config: GlobalVariableBuilderConfig,
|
|
42
43
|
) {
|
|
43
|
-
const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
|
|
44
|
-
|
|
45
|
-
const chain = createEthereumChain(l1RpcUrls, chainId);
|
|
46
|
-
|
|
47
44
|
this.version = new Fr(config.rollupVersion);
|
|
48
|
-
this.chainId = new Fr(
|
|
45
|
+
this.chainId = new Fr(this.publicClient.chain!.id);
|
|
49
46
|
|
|
50
47
|
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
51
48
|
this.aztecSlotDuration = config.slotDuration;
|
|
52
49
|
this.l1GenesisTime = config.l1GenesisTime;
|
|
53
50
|
|
|
54
|
-
this.
|
|
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);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
|
|
65
|
-
* @returns Min fees for the next block
|
|
66
|
-
*/
|
|
67
|
-
private async computeCurrentMinFees(): Promise<GasFees> {
|
|
68
|
-
// Since this might be called in the middle of a slot where a block might have been published,
|
|
69
|
-
// we need to fetch the last block written, and estimate the earliest timestamp for the next block.
|
|
70
|
-
// The timestamp of that last block will act as a lower bound for the next block.
|
|
71
|
-
|
|
72
|
-
const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
|
|
73
|
-
const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
|
|
74
|
-
SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
|
|
75
|
-
);
|
|
76
|
-
const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
|
|
77
|
-
const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
|
|
78
|
-
|
|
79
|
-
return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public async getCurrentMinFees(): Promise<GasFees> {
|
|
83
|
-
// Get the current block number
|
|
84
|
-
const blockNumber = await this.publicClient.getBlockNumber();
|
|
85
|
-
|
|
86
|
-
// If the L1 block number has changed then chain a new promise to get the current min fees
|
|
87
|
-
if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
|
|
88
|
-
this.currentL1BlockNumber = blockNumber;
|
|
89
|
-
this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
|
|
90
|
-
}
|
|
91
|
-
return this.currentMinFees;
|
|
51
|
+
this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
|
|
92
52
|
}
|
|
93
53
|
|
|
94
54
|
/**
|
|
@@ -108,7 +68,10 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
108
68
|
const slot: SlotNumber =
|
|
109
69
|
maybeSlot ??
|
|
110
70
|
(await this.rollupContract.getSlotAt(
|
|
111
|
-
|
|
71
|
+
getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
|
|
72
|
+
l1GenesisTime: this.l1GenesisTime,
|
|
73
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
74
|
+
}),
|
|
112
75
|
));
|
|
113
76
|
|
|
114
77
|
const checkpointGlobalVariables = await this.buildCheckpointGlobalVariables(coinbase, feeRecipient, slot);
|
|
@@ -120,6 +83,7 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
120
83
|
coinbase: EthAddress,
|
|
121
84
|
feeRecipient: AztecAddress,
|
|
122
85
|
slotNumber: SlotNumber,
|
|
86
|
+
simulationOverridesPlan?: SimulationOverridesPlan,
|
|
123
87
|
): Promise<CheckpointGlobalVariables> {
|
|
124
88
|
const { chainId, version } = this;
|
|
125
89
|
|
|
@@ -128,9 +92,8 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
128
92
|
l1GenesisTime: this.l1GenesisTime,
|
|
129
93
|
});
|
|
130
94
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
95
|
+
const stateOverride = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
96
|
+
const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true, stateOverride));
|
|
134
97
|
|
|
135
98
|
return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
|
|
136
99
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
export * from './client/index.js';
|
|
2
2
|
export * from './config.js';
|
|
3
3
|
export * from './publisher/index.js';
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
AutomineSequencer,
|
|
6
|
+
type AutomineSequencerConstants,
|
|
7
|
+
type AutomineSequencerDeps,
|
|
8
|
+
createAutomineSequencer,
|
|
9
|
+
type CreateAutomineSequencerArgs,
|
|
10
|
+
Sequencer,
|
|
11
|
+
SequencerState,
|
|
12
|
+
type SequencerEvents,
|
|
13
|
+
} from './sequencer/index.js';
|
|
5
14
|
|
|
6
15
|
// Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
|
|
7
16
|
// ISSUE(#9832)
|
package/src/publisher/config.ts
CHANGED
|
@@ -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. */
|
|
@@ -48,13 +50,39 @@ export type PublisherConfig = L1TxUtilsConfig &
|
|
|
48
50
|
fishermanMode?: boolean;
|
|
49
51
|
/** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
|
|
50
52
|
publisherForwarderAddress?: EthAddress;
|
|
53
|
+
/** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
|
|
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;
|
|
51
59
|
};
|
|
52
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
|
+
|
|
53
77
|
export type ProverPublisherConfig = L1TxUtilsConfig &
|
|
54
78
|
BlobClientConfig & {
|
|
55
79
|
fishermanMode?: boolean;
|
|
56
80
|
proverPublisherAllowInvalidStates?: boolean;
|
|
57
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;
|
|
58
86
|
};
|
|
59
87
|
|
|
60
88
|
export type SequencerPublisherConfig = L1TxUtilsConfig &
|
|
@@ -62,6 +90,12 @@ export type SequencerPublisherConfig = L1TxUtilsConfig &
|
|
|
62
90
|
fishermanMode?: boolean;
|
|
63
91
|
sequencerPublisherAllowInvalidStates?: boolean;
|
|
64
92
|
sequencerPublisherForwarderAddress?: EthAddress;
|
|
93
|
+
/** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
|
|
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;
|
|
65
99
|
};
|
|
66
100
|
|
|
67
101
|
export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
|
|
@@ -77,15 +111,17 @@ export function getPublisherConfigFromSequencerConfig(config: SequencerPublisher
|
|
|
77
111
|
...config,
|
|
78
112
|
publisherAllowInvalidStates: config.sequencerPublisherAllowInvalidStates,
|
|
79
113
|
publisherForwarderAddress: config.sequencerPublisherForwarderAddress,
|
|
114
|
+
l1TxFailedStore: config.l1TxFailedStore,
|
|
80
115
|
};
|
|
81
116
|
}
|
|
82
117
|
|
|
83
|
-
export const proverTxSenderConfigMappings: ConfigMappingsType<
|
|
118
|
+
export const proverTxSenderConfigMappings: ConfigMappingsType<ProverTxSenderConfig> = {
|
|
84
119
|
...l1ReaderConfigMappings,
|
|
85
120
|
proverPublisherPrivateKeys: {
|
|
86
121
|
env: `PROVER_PUBLISHER_PRIVATE_KEYS`,
|
|
87
122
|
description: 'The private keys to be used by the prover publisher.',
|
|
88
|
-
parseEnv: (val: string) =>
|
|
123
|
+
parseEnv: (val: string) =>
|
|
124
|
+
val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
|
|
89
125
|
defaultValue: [],
|
|
90
126
|
fallback: [`PROVER_PUBLISHER_PRIVATE_KEY`],
|
|
91
127
|
},
|
|
@@ -97,12 +133,13 @@ export const proverTxSenderConfigMappings: ConfigMappingsType<Omit<ProverTxSende
|
|
|
97
133
|
},
|
|
98
134
|
};
|
|
99
135
|
|
|
100
|
-
export const sequencerTxSenderConfigMappings: ConfigMappingsType<
|
|
136
|
+
export const sequencerTxSenderConfigMappings: ConfigMappingsType<SequencerTxSenderConfig> = {
|
|
101
137
|
...l1ReaderConfigMappings,
|
|
102
138
|
sequencerPublisherPrivateKeys: {
|
|
103
139
|
env: `SEQ_PUBLISHER_PRIVATE_KEYS`,
|
|
104
140
|
description: 'The private keys to be used by the sequencer publisher.',
|
|
105
|
-
parseEnv: (val: string) =>
|
|
141
|
+
parseEnv: (val: string) =>
|
|
142
|
+
val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
|
|
106
143
|
defaultValue: [],
|
|
107
144
|
fallback: [`SEQ_PUBLISHER_PRIVATE_KEY`],
|
|
108
145
|
},
|
|
@@ -131,8 +168,13 @@ export const sequencerPublisherConfigMappings: ConfigMappingsType<SequencerPubli
|
|
|
131
168
|
sequencerPublisherForwarderAddress: {
|
|
132
169
|
env: `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
|
|
133
170
|
description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
|
|
134
|
-
parseEnv: (val: string) =>
|
|
171
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
172
|
+
},
|
|
173
|
+
l1TxFailedStore: {
|
|
174
|
+
env: 'L1_TX_FAILED_STORE',
|
|
175
|
+
description: 'Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path',
|
|
135
176
|
},
|
|
177
|
+
...publisherFundingConfigMappings,
|
|
136
178
|
};
|
|
137
179
|
|
|
138
180
|
export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherConfig & L1TxUtilsConfig> = {
|
|
@@ -152,6 +194,7 @@ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherCo
|
|
|
152
194
|
proverPublisherForwarderAddress: {
|
|
153
195
|
env: `PROVER_PUBLISHER_FORWARDER_ADDRESS`,
|
|
154
196
|
description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
|
|
155
|
-
parseEnv: (val: string) =>
|
|
197
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
156
198
|
},
|
|
199
|
+
...publisherFundingConfigMappings,
|
|
157
200
|
};
|
package/src/publisher/index.ts
CHANGED
|
@@ -3,3 +3,6 @@ export { SequencerPublisherFactory } from './sequencer-publisher-factory.js';
|
|
|
3
3
|
|
|
4
4
|
// Used for tests
|
|
5
5
|
export { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
6
|
+
|
|
7
|
+
// Failed L1 tx store (optional, for test networks)
|
|
8
|
+
export { type FailedL1Tx, type FailedL1TxUri, type L1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { createFileStore } from '@aztec/stdlib/file-store';
|
|
3
|
+
|
|
4
|
+
import type { L1TxFailedStore } from './failed_tx_store.js';
|
|
5
|
+
import { FileStoreL1TxFailedStore } from './file_store_failed_tx_store.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates an L1TxFailedStore from a config string.
|
|
9
|
+
* Supports any backend that FileStore supports (GCS, S3, R2, local filesystem).
|
|
10
|
+
* @param config - Config string (e.g., 'gs://bucket/path', 's3://bucket/path', 'file:///path'). If undefined, returns undefined.
|
|
11
|
+
* @param logger - Optional logger.
|
|
12
|
+
* @returns The store instance, or undefined if config is not provided.
|
|
13
|
+
*/
|
|
14
|
+
export async function createL1TxFailedStore(
|
|
15
|
+
config: string | undefined,
|
|
16
|
+
logger: Logger = createLogger('sequencer:l1-tx-failed-store'),
|
|
17
|
+
): Promise<L1TxFailedStore | undefined> {
|
|
18
|
+
if (!config) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const fileStore = await createFileStore(config, logger);
|
|
23
|
+
if (!fileStore) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Failed to create file store from config: '${config}'. ` +
|
|
26
|
+
`Supported formats: 'gs://bucket/path', 's3://bucket/path', 'file:///path'.`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
logger.info(`Created L1 tx failed store`, { config });
|
|
31
|
+
return new FileStoreL1TxFailedStore(fileStore, logger);
|
|
32
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Branded } from '@aztec/foundation/branded-types';
|
|
2
|
+
|
|
3
|
+
import type { Hex } from 'viem';
|
|
4
|
+
|
|
5
|
+
/** URI pointing to a stored failed L1 transaction. */
|
|
6
|
+
export type FailedL1TxUri = Branded<string, 'FailedL1TxUri'>;
|
|
7
|
+
|
|
8
|
+
/** A failed L1 transaction captured for debugging and replay. */
|
|
9
|
+
export type FailedL1Tx = {
|
|
10
|
+
/** Tx hash (for reverts) or keccak256(request.data) (for simulation/send failures). */
|
|
11
|
+
id: Hex;
|
|
12
|
+
/** Unix timestamp (ms) when failure occurred. */
|
|
13
|
+
timestamp: number;
|
|
14
|
+
/** Whether the failure was during simulation or after sending. */
|
|
15
|
+
failureType: 'simulation' | 'revert' | 'send-error';
|
|
16
|
+
/** The actual L1 transaction for replay (multicall-encoded for bundled txs). */
|
|
17
|
+
request: {
|
|
18
|
+
to: Hex;
|
|
19
|
+
data: Hex;
|
|
20
|
+
value?: string; // bigint as string
|
|
21
|
+
};
|
|
22
|
+
/** Raw blob data as hex for replay. */
|
|
23
|
+
blobData?: Hex[];
|
|
24
|
+
/** L1 block number at time of failure (simulation target or receipt block). */
|
|
25
|
+
l1BlockNumber: string; // bigint as string
|
|
26
|
+
/** Receipt info (present only for on-chain reverts). */
|
|
27
|
+
receipt?: {
|
|
28
|
+
transactionHash: Hex;
|
|
29
|
+
blockNumber: string; // bigint as string
|
|
30
|
+
gasUsed: string; // bigint as string
|
|
31
|
+
status: 'reverted';
|
|
32
|
+
};
|
|
33
|
+
/** Error information. */
|
|
34
|
+
error: {
|
|
35
|
+
message: string;
|
|
36
|
+
/** Decoded error name (e.g., 'Rollup__InvalidProposer'). */
|
|
37
|
+
name?: string;
|
|
38
|
+
};
|
|
39
|
+
/** Context metadata. */
|
|
40
|
+
context: {
|
|
41
|
+
/** Actions involved (e.g., ['propose', 'governance-signal']). */
|
|
42
|
+
actions: string[];
|
|
43
|
+
/** Individual request data for each action (metadata, not used for replay). */
|
|
44
|
+
requests?: Array<{ action: string; to: Hex; data: Hex }>;
|
|
45
|
+
checkpointNumber?: number;
|
|
46
|
+
slot?: number;
|
|
47
|
+
sender: Hex;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Store for failed L1 transactions for debugging purposes. */
|
|
52
|
+
export interface L1TxFailedStore {
|
|
53
|
+
/** Saves a failed transaction and returns its URI. */
|
|
54
|
+
saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri>;
|
|
55
|
+
/** Retrieves a failed transaction by its URI. */
|
|
56
|
+
getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { FileStore } from '@aztec/stdlib/file-store';
|
|
3
|
+
|
|
4
|
+
import type { FailedL1Tx, FailedL1TxUri, L1TxFailedStore } from './failed_tx_store.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* L1TxFailedStore implementation using the FileStore abstraction.
|
|
8
|
+
* Supports any backend that FileStore supports (GCS, S3, R2, local filesystem).
|
|
9
|
+
*/
|
|
10
|
+
export class FileStoreL1TxFailedStore implements L1TxFailedStore {
|
|
11
|
+
private readonly log: Logger;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
private readonly fileStore: FileStore,
|
|
15
|
+
logger?: Logger,
|
|
16
|
+
) {
|
|
17
|
+
this.log = logger ?? createLogger('sequencer:l1-tx-failed-store');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public async saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri> {
|
|
21
|
+
const prefix = tx.receipt ? 'tx' : 'data';
|
|
22
|
+
const path = `${tx.failureType}/${prefix}-${tx.id}.json`;
|
|
23
|
+
const json = JSON.stringify(tx, null, 2);
|
|
24
|
+
|
|
25
|
+
const uri = await this.fileStore.save(path, Buffer.from(json), {
|
|
26
|
+
metadata: {
|
|
27
|
+
'content-type': 'application/json',
|
|
28
|
+
actions: tx.context.actions.join(','),
|
|
29
|
+
'failure-type': tx.failureType,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.log.info(`Saved failed L1 tx to ${uri}`, {
|
|
34
|
+
id: tx.id,
|
|
35
|
+
failureType: tx.failureType,
|
|
36
|
+
actions: tx.context.actions.join(','),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return uri as FailedL1TxUri;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public async getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx> {
|
|
43
|
+
const data = await this.fileStore.read(uri);
|
|
44
|
+
return JSON.parse(data.toString()) as FailedL1Tx;
|
|
45
|
+
}
|
|
46
|
+
}
|