From c33d38b68a8c109e138a2809b530f7fdb1abb122 Mon Sep 17 00:00:00 2001 From: Maddiaa <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:23:17 +0100 Subject: [PATCH] feat: add sequencer address to metrics (#9145) --- yarn-project/circuit-types/src/stats/stats.ts | 4 ++++ .../sequencer-client/src/publisher/l1-publisher.ts | 7 +++++-- .../sequencer-client/src/sequencer/sequencer.test.ts | 1 + yarn-project/sequencer-client/src/sequencer/sequencer.ts | 7 ++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/yarn-project/circuit-types/src/stats/stats.ts b/yarn-project/circuit-types/src/stats/stats.ts index ac2c0ed60a9..95e3da32682 100644 --- a/yarn-project/circuit-types/src/stats/stats.ts +++ b/yarn-project/circuit-types/src/stats/stats.ts @@ -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. */ @@ -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. */ diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index 3f76c7aa51b..f728470a089 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -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 */ @@ -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), @@ -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', }; @@ -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 }); diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index 7844d04a9b8..7493c01cb33 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts @@ -107,6 +107,7 @@ describe('sequencer', () => { ); publisher = mock(); + publisher.getSenderAddress.mockImplementation(() => EthAddress.random()); publisher.getCurrentEpochCommittee.mockResolvedValue(committee); publisher.canProposeAtNextEthBlock.mockResolvedValue([ block.header.globalVariables.slotNumber.toBigInt(), diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 6e3ac4f1618..8da14b955f9 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -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()); @@ -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, @@ -465,6 +465,7 @@ export class Sequencer { )})`, { eventName: 'l2-block-built', + creator: this.publisher.getSenderAddress().toString(), duration: workDuration, publicProcessDuration: publicProcessorDuration, rollupCircuitsDuration: blockBuildingTimer.ms(),