Skip to content

Commit

Permalink
[monitor] Support Rinkeby and increase time interval (#66)
Browse files Browse the repository at this point in the history
* Support Rinkeby and increase time interval

* Fix yarn.lock

* Remove more logs

Co-authored-by: CAPtheorem <79423264+CAPtheorem@users.noreply.github.com>
(cherry picked from commit 5fbcb50)
  • Loading branch information
boyuan-chen authored and InoMurko committed Jun 17, 2022
1 parent 2127cea commit d64cad9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
51 changes: 33 additions & 18 deletions ops_boba/monitor/exec/run-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const configs = require('../services/utilities/configs')
const { sleep } = require('@eth-optimism/core-utils')
const { logger } = require('../services/utilities/logger')
require('dotenv').config()

const loop = async (func) => {
while (true) {
Expand Down Expand Up @@ -80,26 +81,40 @@ const main = async () => {
loop(() => blockService.startTransactionMonitor()).catch()
loop(() => blockService.startCrossDomainMessageMonitor()).catch()

if (configs.enableTxResponseTime) {
loop(() => loopLogTx()).catch()
}
// enable the periodic transaction and check on Mainnet
if (process.env.STAGE === 'mainnet') {
if (configs.enableTxResponseTime) {
loop(() => loopLogTx()).catch()
}

const {
setupProvider,
validateMonitoring,
} = require('../services/monitoring')

if (validateMonitoring()) {
logger.info('Start addresses monitoring service!')
setupProvider(configs.OMGXNetwork.L1, configs.l1Url, 5).catch()
setupProvider(configs.OMGXNetwork.L2, configs.l2Url, 15).catch()
} else {
logger.error(
'Addresses Monitoring: Env variables for monitoring is missing!'
)
}
const L1_MONITOR_INTERVAL = process.env.L1_MONITOR_INTERVAL || 5 * 60
const L2_MONITOR_INTERVAL = process.env.L2_MONITOR_INTERVAL || 5 * 60

const {
setupProvider,
validateMonitoring,
} = require('../services/monitoring')

if (validateMonitoring()) {
logger.info('Start addresses monitoring service!')
setupProvider(
configs.OMGXNetwork.L1,
configs.l1Url,
L1_MONITOR_INTERVAL
).catch()
setupProvider(
configs.OMGXNetwork.L2,
configs.l2Url,
L2_MONITOR_INTERVAL
).catch()
} else {
logger.error(
'Addresses Monitoring: Env variables for monitoring is missing!'
)
}

loop(() => loopTransferTx()).catch()
loop(() => loopTransferTx()).catch()
}
}

;(async () => {
Expand Down
1 change: 1 addition & 0 deletions ops_boba/monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@eth-optimism/core-utils": "0.8.1",
"@eth-optimism/common-ts": "0.2.2",
"@ethersproject/providers": "5.4.5",
"axios": "0.26.0",
"async-mutex": "^0.3.1",
"dotenv": "^9.0.0",
"ethers": "^5.1.4",
Expand Down
16 changes: 8 additions & 8 deletions ops_boba/monitor/services/blockMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BlockMonitorService extends OptimismEnv {
const latestSQLBlock = latestSQLBlockQuery[0]['MAX(blockNumber)']

// get the blocks, transactions and receipts
this.logger.info('Fetching the block data...')
// this.logger.info('Fetching the block data...')
const [blocksData, receiptsData] = await this.getChainData(
latestSQLBlock,
Math.min(this.latestBlock, latestSQLBlock + 1000)
Expand All @@ -91,7 +91,7 @@ class BlockMonitorService extends OptimismEnv {
}

// write the block data into MySQL
this.logger.info('Writing the block data...')
// this.logger.info('Writing the block data...')
for (const blockData of blocksData) {
await this.databaseService.insertBlockData(blockData)
// write the transaction data into MySQL
Expand All @@ -105,7 +105,7 @@ class BlockMonitorService extends OptimismEnv {
}

// write the receipt data into MySQL
this.logger.info('Writing the receipt data...')
// this.logger.info('Writing the receipt data...')
for (let receiptData of receiptsData) {
const correspondingBlock = blocksData.filter(
(i) => i && i.hash === receiptData.blockHash
Expand Down Expand Up @@ -136,11 +136,11 @@ class BlockMonitorService extends OptimismEnv {
const latestBlock = await this.L2Provider.getBlockNumber()

if (latestBlock > this.latestBlock) {
this.logger.info('Finding new blocks...')
// this.logger.info('Finding new blocks...')
this.latestBlock = latestBlock

// get the blocks, transactions and receipts
this.logger.info('Fetching the block data...')
// this.logger.info('Fetching the block data...')
const [blocksData, receiptsData] = await this.getChainData(
this.scannedLastBlock,
Math.min(latestBlock, this.latestBlock + 1000)
Expand All @@ -154,7 +154,7 @@ class BlockMonitorService extends OptimismEnv {
}

// write the block data into MySQL
this.logger.info('Writing the block data...')
// this.logger.info('Writing the block data...')
for (const blockData of blocksData) {
if (!blockData) {
continue
Expand All @@ -171,7 +171,7 @@ class BlockMonitorService extends OptimismEnv {
}

// write the receipt data into MySQL
this.logger.info('Writing the receipt data...')
// this.logger.info('Writing the receipt data...')
for (let receiptData of receiptsData) {
const correspondingBlock = blocksData.filter(
(i) => i && i.hash === receiptData.blockHash
Expand Down Expand Up @@ -264,7 +264,7 @@ class BlockMonitorService extends OptimismEnv {
const promisesReceipt = []
for (let i = startingBlock; i <= endingBlock; i++) {
promisesBlock.push(this.L2Provider.getBlockWithTransactions(i))
this.logger.info(`Pushing block`)
// this.logger.info(`Pushing block`)
}
const blocksData = await Promise.all(promisesBlock)
for (const blockData of blocksData) {
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5948,6 +5948,13 @@ axe-core@^4.3.5:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.1.tgz#7dbdc25989298f9ad006645cd396782443757413"
integrity sha512-gd1kmb21kwNuWr6BQz8fv6GNECPBnUasepcoLbekws23NVBLODdsClRZ+bQ8+9Uomf3Sm3+Vwn0oYG9NvwnJCw==

axios@0.26.0:
version "0.26.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928"
integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==
dependencies:
follow-redirects "^1.14.8"

axios@^0.21.1, axios@^0.21.4:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
Expand Down Expand Up @@ -11616,6 +11623,11 @@ follow-redirects@^1.0.0, follow-redirects@^1.12.1, follow-redirects@^1.14.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685"
integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==

follow-redirects@^1.14.8:
version "1.14.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==

for-each@^0.3.3, for-each@~0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
Expand Down

0 comments on commit d64cad9

Please sign in to comment.