Skip to content

Commit

Permalink
feat: add sequencer address to metrics (#9145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Oct 10, 2024
1 parent e245f83 commit c33d38b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions yarn-project/circuit-types/src/stats/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type L2BlockStats = {

/** Stats logged for each L1 publish tx.*/
export type L1PublishStats = {
/** Address of the sender. */
sender: string;
/** Effective gas price of the tx. */
gasPrice: bigint;
/** Effective gas used in the tx. */
Expand Down Expand Up @@ -177,6 +179,8 @@ export type CircuitVerificationStats = {

/** Stats for an L2 block built by a sequencer. */
export type L2BlockBuiltStats = {
/** The creator of the block */
creator: string;
/** Name of the event. */
eventName: 'l2-block-built';
/** Total duration in ms. */
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/sequencer-client/src/publisher/l1-publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import { prettyLogViemError } from './utils.js';
* Stats for a sent transaction.
*/
export type TransactionStats = {
/** Address of the sender. */
sender: string;
/** Hash of the transaction. */
transactionHash: string;
/** Size in bytes of the tx calldata */
Expand Down Expand Up @@ -327,6 +329,7 @@ export class L1Publisher {
}
const calldata = hexToBytes(tx.input);
return {
sender: tx.from.toString(),
transactionHash: tx.hash,
calldataSize: calldata.length,
calldataGas: getCalldataGasUsage(calldata),
Expand Down Expand Up @@ -403,7 +406,7 @@ export class L1Publisher {
const tx = await this.getTransactionStats(txHash);
const stats: L1PublishBlockStats = {
...pick(receipt, 'gasPrice', 'gasUsed', 'transactionHash'),
...pick(tx!, 'calldataGas', 'calldataSize'),
...pick(tx!, 'calldataGas', 'calldataSize', 'sender'),
...block.getStats(),
eventName: 'rollup-published-to-l1',
};
Expand Down Expand Up @@ -484,7 +487,7 @@ export class L1Publisher {
const tx = await this.getTransactionStats(txHash);
const stats: L1PublishProofStats = {
...pick(receipt, 'gasPrice', 'gasUsed', 'transactionHash'),
...pick(tx!, 'calldataGas', 'calldataSize'),
...pick(tx!, 'calldataGas', 'calldataSize', 'sender'),
eventName: 'proof-published-to-l1',
};
this.log.info(`Published epoch proof to L1 rollup contract`, { ...stats, ...ctx });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('sequencer', () => {
);

publisher = mock<L1Publisher>();
publisher.getSenderAddress.mockImplementation(() => EthAddress.random());
publisher.getCurrentEpochCommittee.mockResolvedValue(committee);
publisher.canProposeAtNextEthBlock.mockResolvedValue([
block.header.globalVariables.slotNumber.toBigInt(),
Expand Down
7 changes: 4 additions & 3 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class Sequencer {
// @note It is very important that the following function will FAIL and not just return early
// if it have made any state changes. If not, we won't rollback the state, and you will
// be in for a world of pain.
await this.buildBlockAndPublish(validTxs, proposalHeader, historicalHeader);
await this.buildBlockAndAttemptToPublish(validTxs, proposalHeader, historicalHeader);
} catch (err) {
if (BlockProofError.isBlockProofError(err)) {
const txHashes = err.txHashes.filter(h => !h.isZero());
Expand Down Expand Up @@ -394,10 +394,10 @@ export class Sequencer {
* @param proposalHeader - The partial header constructed for the proposal
* @param historicalHeader - The historical header of the parent
*/
@trackSpan('Sequencer.buildBlockAndPublish', (_validTxs, proposalHeader, _historicalHeader) => ({
@trackSpan('Sequencer.buildBlockAndAttemptToPublish', (_validTxs, proposalHeader, _historicalHeader) => ({
[Attributes.BLOCK_NUMBER]: proposalHeader.globalVariables.blockNumber.toNumber(),
}))
private async buildBlockAndPublish(
private async buildBlockAndAttemptToPublish(
validTxs: Tx[],
proposalHeader: Header,
historicalHeader: Header | undefined,
Expand Down Expand Up @@ -465,6 +465,7 @@ export class Sequencer {
)})`,
{
eventName: 'l2-block-built',
creator: this.publisher.getSenderAddress().toString(),
duration: workDuration,
publicProcessDuration: publicProcessorDuration,
rollupCircuitsDuration: blockBuildingTimer.ms(),
Expand Down

0 comments on commit c33d38b

Please sign in to comment.