Commit a2f6e839 authored by Annie Ke's avatar Annie Ke Committed by GitHub

feat: add default metrics tracking to batch-submitter (#551)

* export metrics in core-utils

* initialize metrics in batch submitters

* add changeset

* fix unit tests
parent 1746244b
---
"@eth-optimism/batch-submitter": patch
---
add default metrics to all batch submitters
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { Contract, Signer, utils, providers } from 'ethers' import { Contract, Signer, utils, providers } from 'ethers'
import { TransactionReceipt } from '@ethersproject/abstract-provider' import { TransactionReceipt } from '@ethersproject/abstract-provider'
import * as ynatm from '@eth-optimism/ynatm' import * as ynatm from '@eth-optimism/ynatm'
import { Logger } from '@eth-optimism/core-utils' import { Logger, Metrics } from '@eth-optimism/core-utils'
import { getContractFactory } from 'old-contracts' import { getContractFactory } from 'old-contracts'
export interface RollupInfo { export interface RollupInfo {
...@@ -51,7 +51,8 @@ export abstract class BatchSubmitter { ...@@ -51,7 +51,8 @@ export abstract class BatchSubmitter {
readonly maxGasPriceInGwei: number, readonly maxGasPriceInGwei: number,
readonly gasRetryIncrement: number, readonly gasRetryIncrement: number,
readonly gasThresholdInGwei: number, readonly gasThresholdInGwei: number,
readonly log: Logger readonly log: Logger,
readonly metrics: Metrics
) {} ) {}
public abstract _submitBatch( public abstract _submitBatch(
......
...@@ -2,8 +2,8 @@ export * from './batch-submitter' ...@@ -2,8 +2,8 @@ export * from './batch-submitter'
export * from './tx-batch-submitter' export * from './tx-batch-submitter'
export * from './state-batch-submitter' export * from './state-batch-submitter'
export const TX_BATCH_SUBMITTER_LOG_TAG = 'oe:batch-submitter:tx-chain' export const TX_BATCH_SUBMITTER_LOG_TAG = 'oe:batch_submitter:tx_chain'
export const STATE_BATCH_SUBMITTER_LOG_TAG = 'oe:batch-submitter:state-chain' export const STATE_BATCH_SUBMITTER_LOG_TAG = 'oe:batch_submitter:state_chain'
// BLOCK_OFFSET is the number of L2 blocks we need to skip for the // BLOCK_OFFSET is the number of L2 blocks we need to skip for the
// batch submitter. // batch submitter.
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
Bytes32, Bytes32,
remove0x, remove0x,
toRpcHexString, toRpcHexString,
Metrics,
} from '@eth-optimism/core-utils' } from '@eth-optimism/core-utils'
/* Internal Imports */ /* Internal Imports */
...@@ -41,6 +42,7 @@ export class StateBatchSubmitter extends BatchSubmitter { ...@@ -41,6 +42,7 @@ export class StateBatchSubmitter extends BatchSubmitter {
gasRetryIncrement: number, gasRetryIncrement: number,
gasThresholdInGwei: number, gasThresholdInGwei: number,
log: Logger, log: Logger,
metrics: Metrics,
fraudSubmissionAddress: string fraudSubmissionAddress: string
) { ) {
super( super(
...@@ -59,7 +61,8 @@ export class StateBatchSubmitter extends BatchSubmitter { ...@@ -59,7 +61,8 @@ export class StateBatchSubmitter extends BatchSubmitter {
maxGasPriceInGwei, maxGasPriceInGwei,
gasRetryIncrement, gasRetryIncrement,
gasThresholdInGwei, gasThresholdInGwei,
log log,
metrics
) )
this.fraudSubmissionAddress = fraudSubmissionAddress this.fraudSubmissionAddress = fraudSubmissionAddress
} }
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
} from '@ethersproject/abstract-provider' } from '@ethersproject/abstract-provider'
import { getContractInterface, getContractFactory } from 'old-contracts' import { getContractInterface, getContractFactory } from 'old-contracts'
import { getContractInterface as getNewContractInterface } from '@eth-optimism/contracts' import { getContractInterface as getNewContractInterface } from '@eth-optimism/contracts'
import { Logger, ctcCoder } from '@eth-optimism/core-utils' import { Logger, Metrics, ctcCoder } from '@eth-optimism/core-utils'
/* Internal Imports */ /* Internal Imports */
import { import {
...@@ -48,6 +48,7 @@ export class TransactionBatchSubmitter extends BatchSubmitter { ...@@ -48,6 +48,7 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
gasRetryIncrement: number, gasRetryIncrement: number,
gasThresholdInGwei: number, gasThresholdInGwei: number,
log: Logger, log: Logger,
metrics: Metrics,
disableQueueBatchAppend: boolean, disableQueueBatchAppend: boolean,
autoFixBatchOptions: AutoFixBatchOptions = { autoFixBatchOptions: AutoFixBatchOptions = {
fixDoublePlayedDeposits: false, fixDoublePlayedDeposits: false,
...@@ -70,7 +71,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter { ...@@ -70,7 +71,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
maxGasPriceInGwei, maxGasPriceInGwei,
gasRetryIncrement, gasRetryIncrement,
gasThresholdInGwei, gasThresholdInGwei,
log log,
metrics
) )
this.disableQueueBatchAppend = disableQueueBatchAppend this.disableQueueBatchAppend = disableQueueBatchAppend
this.autoFixBatchOptions = autoFixBatchOptions this.autoFixBatchOptions = autoFixBatchOptions
......
/* External Imports */ /* External Imports */
import { Logger, injectL2Context } from '@eth-optimism/core-utils' import { Logger, Metrics, injectL2Context } from '@eth-optimism/core-utils'
import { exit } from 'process' import { exit } from 'process'
import { Signer, Wallet } from 'ethers' import { Signer, Wallet } from 'ethers'
import { JsonRpcProvider, TransactionReceipt } from '@ethersproject/providers' import { JsonRpcProvider, TransactionReceipt } from '@ethersproject/providers'
...@@ -16,14 +16,19 @@ import { ...@@ -16,14 +16,19 @@ import {
} from '..' } from '..'
/* Logger */ /* Logger */
const name = 'oe:batch_submitter:init'
const log = new Logger({ const log = new Logger({
name: 'oe:batch-submitter:init', name,
sentryOptions: { sentryOptions: {
release: `@eth-optimism/batch-submitter@${process.env.npm_package_version}`, release: `@eth-optimism/batch-submitter@${process.env.npm_package_version}`,
dsn: process.env.SENTRY_DSN, dsn: process.env.SENTRY_DSN,
tracesSampleRate: 0.05, tracesSampleRate: 0.05,
}, },
}) })
/* Metrics */
const metrics = new Metrics({
prefix: name,
})
interface RequiredEnvVars { interface RequiredEnvVars {
// The HTTP provider URL for L1. // The HTTP provider URL for L1.
...@@ -159,6 +164,7 @@ export const run = async () => { ...@@ -159,6 +164,7 @@ export const run = async () => {
GAS_RETRY_INCREMENT, GAS_RETRY_INCREMENT,
GAS_THRESHOLD_IN_GWEI, GAS_THRESHOLD_IN_GWEI,
new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }), new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }),
new Metrics({ prefix: TX_BATCH_SUBMITTER_LOG_TAG }),
DISABLE_QUEUE_BATCH_APPEND, DISABLE_QUEUE_BATCH_APPEND,
autoFixBatchOptions autoFixBatchOptions
) )
...@@ -180,6 +186,7 @@ export const run = async () => { ...@@ -180,6 +186,7 @@ export const run = async () => {
GAS_RETRY_INCREMENT, GAS_RETRY_INCREMENT,
GAS_THRESHOLD_IN_GWEI, GAS_THRESHOLD_IN_GWEI,
new Logger({ name: STATE_BATCH_SUBMITTER_LOG_TAG }), new Logger({ name: STATE_BATCH_SUBMITTER_LOG_TAG }),
new Metrics({ prefix: STATE_BATCH_SUBMITTER_LOG_TAG }),
FRAUD_SUBMISSION_ADDRESS FRAUD_SUBMISSION_ADDRESS
) )
......
...@@ -37,6 +37,7 @@ import { ...@@ -37,6 +37,7 @@ import {
ctcCoder, ctcCoder,
remove0x, remove0x,
Logger, Logger,
Metrics,
} from '@eth-optimism/core-utils' } from '@eth-optimism/core-utils'
const DECOMPRESSION_ADDRESS = '0x4200000000000000000000000000000000000008' const DECOMPRESSION_ADDRESS = '0x4200000000000000000000000000000000000008'
...@@ -78,6 +79,7 @@ class TransactionBatchSubmitter extends RealTransactionBatchSubmitter { ...@@ -78,6 +79,7 @@ class TransactionBatchSubmitter extends RealTransactionBatchSubmitter {
return true return true
} }
} }
const testMetrics = new Metrics({ prefix: 'bs_test' })
describe('BatchSubmitter', () => { describe('BatchSubmitter', () => {
let signer: Signer let signer: Signer
...@@ -217,6 +219,7 @@ describe('BatchSubmitter', () => { ...@@ -217,6 +219,7 @@ describe('BatchSubmitter', () => {
GAS_RETRY_INCREMENT, GAS_RETRY_INCREMENT,
GAS_THRESHOLD_IN_GWEI, GAS_THRESHOLD_IN_GWEI,
new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }), new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }),
testMetrics,
false false
) )
...@@ -432,6 +435,7 @@ describe('BatchSubmitter', () => { ...@@ -432,6 +435,7 @@ describe('BatchSubmitter', () => {
GAS_RETRY_INCREMENT, GAS_RETRY_INCREMENT,
GAS_THRESHOLD_IN_GWEI, GAS_THRESHOLD_IN_GWEI,
new Logger({ name: STATE_BATCH_SUBMITTER_LOG_TAG }), new Logger({ name: STATE_BATCH_SUBMITTER_LOG_TAG }),
testMetrics,
'0x' + '01'.repeat(20) // placeholder for fraudSubmissionAddress '0x' + '01'.repeat(20) // placeholder for fraudSubmissionAddress
) )
}) })
......
...@@ -33,6 +33,7 @@ import { ...@@ -33,6 +33,7 @@ import {
ctcCoder, ctcCoder,
remove0x, remove0x,
Logger, Logger,
Metrics,
} from '@eth-optimism/core-utils' } from '@eth-optimism/core-utils'
const DECOMPRESSION_ADDRESS = '0x4200000000000000000000000000000000000008' const DECOMPRESSION_ADDRESS = '0x4200000000000000000000000000000000000008'
...@@ -71,6 +72,7 @@ class TransactionBatchSubmitter extends RealTransactionBatchSubmitter { ...@@ -71,6 +72,7 @@ class TransactionBatchSubmitter extends RealTransactionBatchSubmitter {
return true return true
} }
} }
const testMetrics = new Metrics({ prefix: 'tx_bs_test' })
describe('TransactionBatchSubmitter', () => { describe('TransactionBatchSubmitter', () => {
let signer: Signer let signer: Signer
...@@ -189,6 +191,7 @@ describe('TransactionBatchSubmitter', () => { ...@@ -189,6 +191,7 @@ describe('TransactionBatchSubmitter', () => {
GAS_RETRY_INCREMENT, GAS_RETRY_INCREMENT,
GAS_THRESHOLD_IN_GWEI, GAS_THRESHOLD_IN_GWEI,
new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }), new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }),
testMetrics,
false false
) )
}) })
...@@ -309,6 +312,7 @@ describe('TransactionBatchSubmitter', () => { ...@@ -309,6 +312,7 @@ describe('TransactionBatchSubmitter', () => {
GAS_RETRY_INCREMENT, GAS_RETRY_INCREMENT,
GAS_THRESHOLD_IN_GWEI, GAS_THRESHOLD_IN_GWEI,
new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }), new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }),
testMetrics,
false false
) )
......
export * from './addresses' export * from './addresses'
export * from './hex-strings' export * from './hex-strings'
export * from './logger' export * from './logger'
export * from './metrics'
export * from './misc' export * from './misc'
export * from './common' export * from './common'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment