From 0c6a72228761b0ba1feb625d6c603459e78cf211 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:33:04 +0000 Subject: [PATCH 1/5] feat: add sequencer address to metrics --- yarn-project/circuit-types/src/stats/stats.ts | 2 ++ .../sequencer-client/src/publisher/l1-publisher.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/yarn-project/circuit-types/src/stats/stats.ts b/yarn-project/circuit-types/src/stats/stats.ts index ac2c0ed60a9..2fb82d2ea88 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. */ diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index a0a40a3bc0f..dc206c55dba 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 */ @@ -326,6 +328,7 @@ export class L1Publisher { } const calldata = hexToBytes(tx.input); return { + sender: tx.from.toString(), transactionHash: tx.hash, calldataSize: calldata.length, calldataGas: getCalldataGasUsage(calldata), @@ -402,7 +405,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', }; @@ -483,8 +486,9 @@ 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', + sender: this.account.address, }; this.log.info(`Published epoch proof to L1 rollup contract`, { ...stats, ...ctx }); this.metrics.recordSubmitProof(timer.ms(), stats); From 904e220ff26c7c56ecf781a4442692e15f0f4172 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:04:54 +0000 Subject: [PATCH 2/5] chore: add creator to l2 block built stats --- yarn-project/circuit-types/src/stats/stats.ts | 2 ++ yarn-project/sequencer-client/src/sequencer/sequencer.ts | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/yarn-project/circuit-types/src/stats/stats.ts b/yarn-project/circuit-types/src/stats/stats.ts index 2fb82d2ea88..95e3da32682 100644 --- a/yarn-project/circuit-types/src/stats/stats.ts +++ b/yarn-project/circuit-types/src/stats/stats.ts @@ -179,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/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 7710e9a1f21..7c3cfb4ab2b 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(), From 8e59a51dd5fd25d624781ed479207364b82632ec Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:32:23 +0000 Subject: [PATCH 3/5] fix: mock getSenderAddress --- yarn-project/sequencer-client/src/sequencer/sequencer.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index 7844d04a9b8..3e70b3a6196 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.mockResolvedValue(EthAddress.random()); publisher.getCurrentEpochCommittee.mockResolvedValue(committee); publisher.canProposeAtNextEthBlock.mockResolvedValue([ block.header.globalVariables.slotNumber.toBigInt(), From a9aee4f6ac099d6b1ed6596a4369bb036297afc9 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:34:40 +0000 Subject: [PATCH 4/5] fix --- yarn-project/sequencer-client/src/sequencer/sequencer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index 3e70b3a6196..7493c01cb33 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts @@ -107,7 +107,7 @@ describe('sequencer', () => { ); publisher = mock(); - publisher.getSenderAddress.mockResolvedValue(EthAddress.random()); + publisher.getSenderAddress.mockImplementation(() => EthAddress.random()); publisher.getCurrentEpochCommittee.mockResolvedValue(committee); publisher.canProposeAtNextEthBlock.mockResolvedValue([ block.header.globalVariables.slotNumber.toBigInt(), From 1e2caaa0edaf38e2bc5ac48a8413349cead215ac Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:53:24 +0000 Subject: [PATCH 5/5] fix: duplicate setup --- yarn-project/sequencer-client/src/publisher/l1-publisher.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index ad7758b11a2..f728470a089 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -489,7 +489,6 @@ export class L1Publisher { ...pick(receipt, 'gasPrice', 'gasUsed', 'transactionHash'), ...pick(tx!, 'calldataGas', 'calldataSize', 'sender'), eventName: 'proof-published-to-l1', - sender: this.account.address, }; this.log.info(`Published epoch proof to L1 rollup contract`, { ...stats, ...ctx }); this.metrics.recordSubmitProof(timer.ms(), stats);