@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.0b941701
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/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +31 -31
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +82 -60
- package/dest/config.d.ts +15 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +118 -70
- package/dest/global_variable_builder/global_builder.d.ts +26 -15
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +62 -44
- package/dest/global_variable_builder/index.d.ts +1 -1
- package/dest/index.d.ts +2 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -3
- package/dest/publisher/config.d.ts +15 -12
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +32 -19
- package/dest/publisher/index.d.ts +3 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +51 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +26 -62
- package/dest/publisher/sequencer-publisher.d.ts +134 -87
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1146 -249
- package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1165 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/config.d.ts +7 -1
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +48 -12
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +204 -69
- package/dest/sequencer/sequencer.d.ts +144 -137
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +967 -525
- package/dest/sequencer/timetable.d.ts +76 -24
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +177 -61
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +20 -38
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +12 -47
- package/dest/test/index.d.ts +9 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +222 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +103 -0
- package/package.json +47 -45
- package/src/client/sequencer-client.ts +106 -107
- package/src/config.ts +131 -81
- package/src/global_variable_builder/global_builder.ts +84 -55
- package/src/index.ts +1 -3
- package/src/publisher/config.ts +45 -32
- package/src/publisher/index.ts +4 -0
- package/src/publisher/sequencer-publisher-factory.ts +92 -0
- package/src/publisher/sequencer-publisher-metrics.ts +30 -64
- package/src/publisher/sequencer-publisher.ts +967 -295
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +845 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/config.ts +8 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +269 -72
- package/src/sequencer/sequencer.ts +708 -588
- package/src/sequencer/timetable.ts +221 -62
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +28 -60
- package/src/test/index.ts +12 -4
- package/src/test/mock_checkpoint_builder.ts +311 -0
- package/src/test/utils.ts +164 -0
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/nullifier_cache.d.ts +0 -16
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -50
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
- package/src/tx_validator/tx_validator_factory.ts +0 -120
|
@@ -1,69 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '@aztec/
|
|
1
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
2
|
+
import type { L1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
|
|
5
|
+
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
6
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
8
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
9
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
|
-
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
11
10
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
|
+
import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
13
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
CheckpointGlobalVariables,
|
|
15
|
+
GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
16
|
+
} from '@aztec/stdlib/tx';
|
|
14
17
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
15
18
|
|
|
16
|
-
import {
|
|
19
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* Simple global variables builder.
|
|
20
23
|
*/
|
|
21
24
|
export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
22
25
|
private log = createLogger('sequencer:global_variable_builder');
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
|
|
27
|
+
private currentL1BlockNumber: bigint | undefined = undefined;
|
|
28
|
+
|
|
29
|
+
private readonly rollupContract: RollupContract;
|
|
30
|
+
private readonly publicClient: ViemPublicClient;
|
|
31
|
+
private readonly ethereumSlotDuration: number;
|
|
32
|
+
private readonly aztecSlotDuration: number;
|
|
33
|
+
private readonly l1GenesisTime: bigint;
|
|
34
|
+
|
|
35
|
+
private chainId: Fr;
|
|
36
|
+
private version: Fr;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
config: L1ReaderConfig &
|
|
40
|
+
Pick<L1ContractsConfig, 'ethereumSlotDuration'> &
|
|
41
|
+
Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'> & { rollupVersion: bigint },
|
|
42
|
+
) {
|
|
29
43
|
const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
|
|
30
44
|
|
|
31
45
|
const chain = createEthereumChain(l1RpcUrls, chainId);
|
|
32
46
|
|
|
47
|
+
this.version = new Fr(config.rollupVersion);
|
|
48
|
+
this.chainId = new Fr(chainId);
|
|
49
|
+
|
|
33
50
|
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
51
|
+
this.aztecSlotDuration = config.slotDuration;
|
|
52
|
+
this.l1GenesisTime = config.l1GenesisTime;
|
|
34
53
|
|
|
35
54
|
this.publicClient = createPublicClient({
|
|
36
55
|
chain: chain.chainInfo,
|
|
37
|
-
transport: fallback(chain.rpcUrls.map(url => http(url))),
|
|
56
|
+
transport: fallback(chain.rpcUrls.map(url => http(url, { batch: false }))),
|
|
38
57
|
pollingInterval: config.viemPollingIntervalMS,
|
|
39
58
|
});
|
|
40
59
|
|
|
41
|
-
this.rollupContract =
|
|
42
|
-
address: getAddress(l1Contracts.rollupAddress.toString()),
|
|
43
|
-
abi: RollupAbi,
|
|
44
|
-
client: this.publicClient,
|
|
45
|
-
});
|
|
60
|
+
this.rollupContract = new RollupContract(this.publicClient, l1Contracts.rollupAddress);
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
/**
|
|
49
|
-
* Computes the "current"
|
|
50
|
-
* @returns
|
|
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
|
|
51
66
|
*/
|
|
52
|
-
|
|
67
|
+
private async computeCurrentMinFees(): Promise<GasFees> {
|
|
53
68
|
// Since this might be called in the middle of a slot where a block might have been published,
|
|
54
69
|
// we need to fetch the last block written, and estimate the earliest timestamp for the next block.
|
|
55
70
|
// The timestamp of that last block will act as a lower bound for the next block.
|
|
56
71
|
|
|
57
|
-
const
|
|
58
|
-
const earliestTimestamp = await this.rollupContract.
|
|
72
|
+
const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
|
|
73
|
+
const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
|
|
74
|
+
SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
|
|
75
|
+
);
|
|
59
76
|
const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
|
|
60
77
|
const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
|
|
61
78
|
|
|
62
|
-
return new GasFees(
|
|
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;
|
|
63
92
|
}
|
|
64
93
|
|
|
65
94
|
/**
|
|
66
|
-
* Simple builder of global variables
|
|
95
|
+
* Simple builder of global variables.
|
|
67
96
|
* @param blockNumber - The block number to build global variables for.
|
|
68
97
|
* @param coinbase - The address to receive block reward.
|
|
69
98
|
* @param feeRecipient - The address to receive fees.
|
|
@@ -71,38 +100,38 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
71
100
|
* @returns The global variables for the given block number.
|
|
72
101
|
*/
|
|
73
102
|
public async buildGlobalVariables(
|
|
74
|
-
blockNumber:
|
|
103
|
+
blockNumber: BlockNumber,
|
|
75
104
|
coinbase: EthAddress,
|
|
76
105
|
feeRecipient: AztecAddress,
|
|
77
|
-
|
|
106
|
+
maybeSlot?: SlotNumber,
|
|
78
107
|
): Promise<GlobalVariables> {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
108
|
+
const slot: SlotNumber =
|
|
109
|
+
maybeSlot ??
|
|
110
|
+
(await this.rollupContract.getSlotAt(
|
|
111
|
+
BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration)),
|
|
112
|
+
));
|
|
113
|
+
|
|
114
|
+
const checkpointGlobalVariables = await this.buildCheckpointGlobalVariables(coinbase, feeRecipient, slot);
|
|
115
|
+
return GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
|
|
116
|
+
}
|
|
88
117
|
|
|
89
|
-
|
|
90
|
-
|
|
118
|
+
/** Builds global variables that are constant throughout a checkpoint. */
|
|
119
|
+
public async buildCheckpointGlobalVariables(
|
|
120
|
+
coinbase: EthAddress,
|
|
121
|
+
feeRecipient: AztecAddress,
|
|
122
|
+
slotNumber: SlotNumber,
|
|
123
|
+
): Promise<CheckpointGlobalVariables & { timestamp: bigint }> {
|
|
124
|
+
const { chainId, version } = this;
|
|
91
125
|
|
|
92
|
-
|
|
93
|
-
|
|
126
|
+
const timestamp = getTimestampForSlot(slotNumber, {
|
|
127
|
+
slotDuration: this.aztecSlotDuration,
|
|
128
|
+
l1GenesisTime: this.l1GenesisTime,
|
|
129
|
+
});
|
|
94
130
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
blockNumber,
|
|
99
|
-
slotFr,
|
|
100
|
-
timestampFr,
|
|
101
|
-
coinbase,
|
|
102
|
-
feeRecipient,
|
|
103
|
-
gasFees,
|
|
104
|
-
);
|
|
131
|
+
// We can skip much of the logic in getCurrentMinFees since it we already check that we are not within a slot elsewhere.
|
|
132
|
+
// TODO(palla/mbps): Can we use a cached value here?
|
|
133
|
+
const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
105
134
|
|
|
106
|
-
return
|
|
135
|
+
return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
|
|
107
136
|
}
|
|
108
137
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export * from './client/index.js';
|
|
2
2
|
export * from './config.js';
|
|
3
3
|
export * from './publisher/index.js';
|
|
4
|
-
export
|
|
5
|
-
export * from './slasher/index.js';
|
|
6
|
-
export { Sequencer, SequencerState, getDefaultAllowedSetupFunctions } from './sequencer/index.js';
|
|
4
|
+
export { Sequencer, SequencerState, type SequencerEvents } from './sequencer/index.js';
|
|
7
5
|
|
|
8
6
|
// Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
|
|
9
7
|
// ISSUE(#9832)
|
package/src/publisher/config.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type BlobClientConfig, blobClientConfigMapping } from '@aztec/blob-client/client/config';
|
|
2
|
+
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
|
|
3
|
+
import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from '@aztec/ethereum/l1-tx-utils/config';
|
|
2
4
|
import {
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '@aztec/ethereum';
|
|
9
|
-
import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
|
|
5
|
+
type ConfigMappingsType,
|
|
6
|
+
SecretValue,
|
|
7
|
+
booleanConfigHelper,
|
|
8
|
+
getConfigFromMappings,
|
|
9
|
+
} from '@aztec/foundation/config';
|
|
10
10
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -16,40 +16,43 @@ export type TxSenderConfig = L1ReaderConfig & {
|
|
|
16
16
|
/**
|
|
17
17
|
* The private key to be used by the publisher.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
publisherPrivateKeys?: SecretValue<`0x${string}`>[];
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Publisher addresses to be used with a remote signer
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
publisherAddresses?: EthAddress[];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Configuration of the L1Publisher.
|
|
29
29
|
*/
|
|
30
30
|
export type PublisherConfig = L1TxUtilsConfig &
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
BlobClientConfig & {
|
|
32
|
+
/** True to use publishers in invalid states (timed out, cancelled, etc) if no other is available */
|
|
33
|
+
publisherAllowInvalidStates?: boolean;
|
|
34
|
+
/** Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1 */
|
|
35
|
+
fishermanMode?: boolean;
|
|
36
|
+
/** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
|
|
37
|
+
publisherForwarderAddress?: EthAddress;
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
export const getTxSenderConfigMappings: (
|
|
39
41
|
scope: 'PROVER' | 'SEQ',
|
|
40
42
|
) => ConfigMappingsType<Omit<TxSenderConfig, 'l1Contracts'>> = (scope: 'PROVER' | 'SEQ') => ({
|
|
41
43
|
...l1ReaderConfigMappings,
|
|
42
|
-
|
|
43
|
-
env: `
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
defaultValue:
|
|
44
|
+
publisherPrivateKeys: {
|
|
45
|
+
env: scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEYS` : `SEQ_PUBLISHER_PRIVATE_KEYS`,
|
|
46
|
+
description: 'The private keys to be used by the publisher.',
|
|
47
|
+
parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
|
|
48
|
+
defaultValue: [],
|
|
49
|
+
fallback: [scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEY` : `SEQ_PUBLISHER_PRIVATE_KEY`],
|
|
47
50
|
},
|
|
48
|
-
|
|
49
|
-
env: scope === 'PROVER' ? `
|
|
50
|
-
description: 'The
|
|
51
|
-
parseEnv: (val: string) =>
|
|
52
|
-
defaultValue:
|
|
51
|
+
publisherAddresses: {
|
|
52
|
+
env: scope === 'PROVER' ? `PROVER_PUBLISHER_ADDRESSES` : `SEQ_PUBLISHER_ADDRESSES`,
|
|
53
|
+
description: 'The addresses of the publishers to use with remote signers',
|
|
54
|
+
parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
|
|
55
|
+
defaultValue: [],
|
|
53
56
|
},
|
|
54
57
|
});
|
|
55
58
|
|
|
@@ -60,14 +63,24 @@ export function getTxSenderConfigFromEnv(scope: 'PROVER' | 'SEQ'): Omit<TxSender
|
|
|
60
63
|
export const getPublisherConfigMappings: (
|
|
61
64
|
scope: 'PROVER' | 'SEQ',
|
|
62
65
|
) => ConfigMappingsType<PublisherConfig & L1TxUtilsConfig> = scope => ({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
publisherAllowInvalidStates: {
|
|
67
|
+
description: 'True to use publishers in invalid states (timed out, cancelled, etc) if no other is available',
|
|
68
|
+
env: scope === `PROVER` ? `PROVER_PUBLISHER_ALLOW_INVALID_STATES` : `SEQ_PUBLISHER_ALLOW_INVALID_STATES`,
|
|
69
|
+
...booleanConfigHelper(true),
|
|
70
|
+
},
|
|
71
|
+
fishermanMode: {
|
|
72
|
+
env: 'FISHERMAN_MODE',
|
|
73
|
+
description:
|
|
74
|
+
'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
|
|
75
|
+
...booleanConfigHelper(false),
|
|
76
|
+
},
|
|
77
|
+
publisherForwarderAddress: {
|
|
78
|
+
env: scope === `PROVER` ? `PROVER_PUBLISHER_FORWARDER_ADDRESS` : `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
|
|
79
|
+
description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
|
|
80
|
+
parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
|
|
68
81
|
},
|
|
69
82
|
...l1TxUtilsConfigMappings,
|
|
70
|
-
...
|
|
83
|
+
...blobClientConfigMapping,
|
|
71
84
|
});
|
|
72
85
|
|
|
73
86
|
export function getPublisherConfigFromEnv(scope: 'PROVER' | 'SEQ'): PublisherConfig {
|
package/src/publisher/index.ts
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { type Logger, createLogger } from '@aztec/aztec.js/log';
|
|
3
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
4
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
5
|
+
import type { GovernanceProposerContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
6
|
+
import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
|
|
7
|
+
import type { PublisherFilter, PublisherManager } from '@aztec/ethereum/publisher-manager';
|
|
8
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
10
|
+
import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
|
|
11
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
12
|
+
import { NodeKeystoreAdapter } from '@aztec/validator-client';
|
|
13
|
+
|
|
14
|
+
import type { SequencerClientConfig } from '../config.js';
|
|
15
|
+
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
16
|
+
import { type Action, SequencerPublisher } from './sequencer-publisher.js';
|
|
17
|
+
|
|
18
|
+
export type AttestorPublisherPair = {
|
|
19
|
+
attestorAddress: EthAddress;
|
|
20
|
+
publisher: SequencerPublisher;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class SequencerPublisherFactory {
|
|
24
|
+
private publisherMetrics: SequencerPublisherMetrics;
|
|
25
|
+
|
|
26
|
+
/** Stores the last slot in which every action was carried out by a publisher */
|
|
27
|
+
private lastActions: Partial<Record<Action, SlotNumber>> = {};
|
|
28
|
+
|
|
29
|
+
private logger: Logger;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
private sequencerConfig: SequencerClientConfig,
|
|
33
|
+
private deps: {
|
|
34
|
+
telemetry: TelemetryClient;
|
|
35
|
+
publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
|
|
36
|
+
blobClient: BlobClientInterface;
|
|
37
|
+
dateProvider: DateProvider;
|
|
38
|
+
epochCache: EpochCache;
|
|
39
|
+
rollupContract: RollupContract;
|
|
40
|
+
governanceProposerContract: GovernanceProposerContract;
|
|
41
|
+
slashFactoryContract: SlashFactoryContract;
|
|
42
|
+
nodeKeyStore: NodeKeystoreAdapter;
|
|
43
|
+
logger?: Logger;
|
|
44
|
+
},
|
|
45
|
+
) {
|
|
46
|
+
this.publisherMetrics = new SequencerPublisherMetrics(deps.telemetry, 'SequencerPublisher');
|
|
47
|
+
this.logger = deps.logger ?? createLogger('sequencer');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new SequencerPublisher instance.
|
|
51
|
+
* @param _validatorAddress - The address of the validator that will be using the publisher.
|
|
52
|
+
* @returns A new SequencerPublisher instance.
|
|
53
|
+
*/
|
|
54
|
+
public async create(validatorAddress?: EthAddress): Promise<AttestorPublisherPair> {
|
|
55
|
+
// If we have been given an attestor address we must only allow publishers permitted for that attestor
|
|
56
|
+
|
|
57
|
+
const allowedPublishers = !validatorAddress ? [] : this.deps.nodeKeyStore.getPublisherAddresses(validatorAddress);
|
|
58
|
+
const filter: PublisherFilter<L1TxUtilsWithBlobs> = !validatorAddress
|
|
59
|
+
? () => true
|
|
60
|
+
: (utils: L1TxUtilsWithBlobs) => {
|
|
61
|
+
const publisherAddress = utils.getSenderAddress();
|
|
62
|
+
return allowedPublishers.some(allowedPublisher => allowedPublisher.equals(publisherAddress));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const l1Publisher = await this.deps.publisherManager.getAvailablePublisher(filter);
|
|
66
|
+
const attestorAddress =
|
|
67
|
+
validatorAddress ?? this.deps.nodeKeyStore.getAttestorForPublisher(l1Publisher.getSenderAddress());
|
|
68
|
+
|
|
69
|
+
const rollup = this.deps.rollupContract;
|
|
70
|
+
const slashingProposerContract = await rollup.getSlashingProposer();
|
|
71
|
+
|
|
72
|
+
const publisher = new SequencerPublisher(this.sequencerConfig, {
|
|
73
|
+
l1TxUtils: l1Publisher,
|
|
74
|
+
telemetry: this.deps.telemetry,
|
|
75
|
+
blobClient: this.deps.blobClient,
|
|
76
|
+
rollupContract: this.deps.rollupContract,
|
|
77
|
+
epochCache: this.deps.epochCache,
|
|
78
|
+
governanceProposerContract: this.deps.governanceProposerContract,
|
|
79
|
+
slashingProposerContract,
|
|
80
|
+
slashFactoryContract: this.deps.slashFactoryContract,
|
|
81
|
+
dateProvider: this.deps.dateProvider,
|
|
82
|
+
metrics: this.publisherMetrics,
|
|
83
|
+
lastActions: this.lastActions,
|
|
84
|
+
log: this.logger.createChild('publisher'),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
attestorAddress,
|
|
89
|
+
publisher,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/aztec.js';
|
|
2
|
-
import type {
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
+
import type { L1PublishCheckpointStats, L1PublishStats } from '@aztec/stdlib/stats';
|
|
3
3
|
import {
|
|
4
4
|
Attributes,
|
|
5
5
|
type Gauge,
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
Metrics,
|
|
8
8
|
type TelemetryClient,
|
|
9
9
|
type UpDownCounter,
|
|
10
|
-
ValueType,
|
|
11
10
|
} from '@aztec/telemetry-client';
|
|
12
11
|
|
|
13
12
|
import { formatEther } from 'viem/utils';
|
|
@@ -24,6 +23,7 @@ export class SequencerPublisherMetrics {
|
|
|
24
23
|
private txCalldataGas: Histogram;
|
|
25
24
|
private txBlobDataGasUsed: Histogram;
|
|
26
25
|
private txBlobDataGasCost: Histogram;
|
|
26
|
+
private txTotalFee: Histogram;
|
|
27
27
|
|
|
28
28
|
private readonly blobCountHistogram: Histogram;
|
|
29
29
|
private readonly blobInclusionBlocksHistogram: Histogram;
|
|
@@ -39,77 +39,33 @@ export class SequencerPublisherMetrics {
|
|
|
39
39
|
) {
|
|
40
40
|
const meter = client.getMeter(name);
|
|
41
41
|
|
|
42
|
-
this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE
|
|
43
|
-
description: 'The gas price used for transactions',
|
|
44
|
-
unit: 'gwei',
|
|
45
|
-
valueType: ValueType.DOUBLE,
|
|
46
|
-
});
|
|
42
|
+
this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
|
|
47
43
|
|
|
48
|
-
this.txCount = meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT
|
|
49
|
-
description: 'The number of transactions processed',
|
|
50
|
-
});
|
|
44
|
+
this.txCount = meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT);
|
|
51
45
|
|
|
52
|
-
this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION
|
|
53
|
-
description: 'The duration of transaction processing',
|
|
54
|
-
unit: 'ms',
|
|
55
|
-
valueType: ValueType.INT,
|
|
56
|
-
});
|
|
46
|
+
this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
|
|
57
47
|
|
|
58
|
-
this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS
|
|
59
|
-
description: 'The gas consumed by transactions',
|
|
60
|
-
unit: 'gas',
|
|
61
|
-
valueType: ValueType.INT,
|
|
62
|
-
});
|
|
48
|
+
this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS);
|
|
63
49
|
|
|
64
|
-
this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE
|
|
65
|
-
description: 'The size of the calldata in transactions',
|
|
66
|
-
unit: 'By',
|
|
67
|
-
valueType: ValueType.INT,
|
|
68
|
-
});
|
|
50
|
+
this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE);
|
|
69
51
|
|
|
70
|
-
this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS
|
|
71
|
-
description: 'The gas consumed by the calldata in transactions',
|
|
72
|
-
unit: 'gas',
|
|
73
|
-
valueType: ValueType.INT,
|
|
74
|
-
});
|
|
52
|
+
this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS);
|
|
75
53
|
|
|
76
|
-
this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED
|
|
77
|
-
description: 'The amount of blob gas used in transactions',
|
|
78
|
-
unit: 'gas',
|
|
79
|
-
valueType: ValueType.INT,
|
|
80
|
-
});
|
|
54
|
+
this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED);
|
|
81
55
|
|
|
82
|
-
this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST
|
|
83
|
-
description: 'The gas cost of blobs in transactions',
|
|
84
|
-
unit: 'gwei',
|
|
85
|
-
valueType: ValueType.INT,
|
|
86
|
-
});
|
|
56
|
+
this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST);
|
|
87
57
|
|
|
88
|
-
this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT
|
|
89
|
-
description: 'Number of blobs in L1 transactions',
|
|
90
|
-
unit: 'blobs',
|
|
91
|
-
valueType: ValueType.INT,
|
|
92
|
-
});
|
|
58
|
+
this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT);
|
|
93
59
|
|
|
94
|
-
this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS
|
|
95
|
-
description: 'Number of L1 blocks between blob tx submission and inclusion',
|
|
96
|
-
unit: 'blocks',
|
|
97
|
-
valueType: ValueType.INT,
|
|
98
|
-
});
|
|
60
|
+
this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS);
|
|
99
61
|
|
|
100
|
-
this.blobTxSuccessCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS
|
|
101
|
-
description: 'Number of successful L1 transactions with blobs',
|
|
102
|
-
});
|
|
62
|
+
this.blobTxSuccessCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS);
|
|
103
63
|
|
|
104
|
-
this.blobTxFailureCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_FAILURE
|
|
105
|
-
description: 'Number of failed L1 transactions with blobs',
|
|
106
|
-
});
|
|
64
|
+
this.blobTxFailureCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_FAILURE);
|
|
107
65
|
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
valueType: ValueType.DOUBLE,
|
|
112
|
-
});
|
|
66
|
+
this.txTotalFee = meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
|
|
67
|
+
|
|
68
|
+
this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
|
|
113
69
|
}
|
|
114
70
|
|
|
115
71
|
recordFailedTx(txType: L1TxType) {
|
|
@@ -123,7 +79,7 @@ export class SequencerPublisherMetrics {
|
|
|
123
79
|
}
|
|
124
80
|
}
|
|
125
81
|
|
|
126
|
-
recordProcessBlockTx(durationMs: number, stats:
|
|
82
|
+
recordProcessBlockTx(durationMs: number, stats: L1PublishCheckpointStats) {
|
|
127
83
|
this.recordTx('process', durationMs, stats);
|
|
128
84
|
|
|
129
85
|
if (stats.blobCount && stats.blobCount > 0) {
|
|
@@ -169,7 +125,17 @@ export class SequencerPublisherMetrics {
|
|
|
169
125
|
|
|
170
126
|
try {
|
|
171
127
|
this.gasPrice.record(parseInt(formatEther(stats.gasPrice, 'gwei'), 10));
|
|
172
|
-
} catch
|
|
128
|
+
} catch {
|
|
129
|
+
// ignore
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const executionFee = stats.gasUsed * stats.gasPrice;
|
|
133
|
+
const blobFee = stats.blobGasUsed * stats.blobDataGas;
|
|
134
|
+
const totalFee = executionFee + blobFee;
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
this.txTotalFee.record(parseFloat(formatEther(totalFee)));
|
|
138
|
+
} catch {
|
|
173
139
|
// ignore
|
|
174
140
|
}
|
|
175
141
|
}
|