Commit 1904e4ff authored by Maurelian's avatar Maurelian

feat(c-mon): Refactor to clean up network config

parent d6388be4
...@@ -16,6 +16,7 @@ BALANCE_MON__ACCOUNTS= ...@@ -16,6 +16,7 @@ BALANCE_MON__ACCOUNTS=
WALLET_MON__RPC= WALLET_MON__RPC=
# The block number to start monitoring from # The block number to start monitoring from
# Defaults to the first bedrock block if unset.
WALLET_MON__START_BLOCK_NUMBER= WALLET_MON__START_BLOCK_NUMBER=
############################################################################### ###############################################################################
......
...@@ -16,12 +16,10 @@ import l2OutputOracleArtifactsGoerli from '@eth-optimism/contracts-bedrock/deplo ...@@ -16,12 +16,10 @@ import l2OutputOracleArtifactsGoerli from '@eth-optimism/contracts-bedrock/deplo
import { version } from '../../package.json' import { version } from '../../package.json'
const networks = { const networks = {
1: 'mainnet', 1: {
10: 'goerli', name: 'mainnet',
} l1StartingBlockTag: mainnetConfig.l1StartingBlockTag,
accounts: [
const bedrockAccounts = {
mainnet: [
{ {
label: 'Proposer', label: 'Proposer',
wallet: mainnetConfig.l2OutputOracleProposer, wallet: mainnetConfig.l2OutputOracleProposer,
...@@ -33,7 +31,11 @@ const bedrockAccounts = { ...@@ -33,7 +31,11 @@ const bedrockAccounts = {
target: mainnetConfig.batchInboxAddress, target: mainnetConfig.batchInboxAddress,
}, },
], ],
goerli: [ },
10: {
name: 'goerli',
l1StartingBlockTag: goerliConfig.l1StartingBlockTag,
accounts: [
{ {
label: 'Proposer', label: 'Proposer',
wallet: goerliConfig.l2OutputOracleProposer, wallet: goerliConfig.l2OutputOracleProposer,
...@@ -45,33 +47,34 @@ const bedrockAccounts = { ...@@ -45,33 +47,34 @@ const bedrockAccounts = {
target: goerliConfig.batchInboxAddress, target: goerliConfig.batchInboxAddress,
}, },
], ],
},
} }
type TransferMonOptions = { type WalletMonOptions = {
rpc: Provider rpc: Provider
startBlockNumber: number startBlockNumber: number
} }
type TransferMonMetrics = { type WalletMonMetrics = {
validatedCalls: Counter validatedCalls: Counter
unexpectedCalls: Counter unexpectedCalls: Counter
unexpectedRpcErrors: Counter unexpectedRpcErrors: Counter
} }
type TransferMonState = { type WalletMonState = {
chainId: number chainId: number
highestUncheckedBlockNumber: number highestUncheckedBlockNumber: number
} }
export class TransferMonService extends BaseServiceV2< export class WalletMonService extends BaseServiceV2<
TransferMonOptions, WalletMonOptions,
TransferMonMetrics, WalletMonMetrics,
TransferMonState WalletMonState
> { > {
constructor(options?: Partial<TransferMonOptions & StandardOptions>) { constructor(options?: Partial<WalletMonOptions & StandardOptions>) {
super({ super({
version, version,
name: 'transfer-mon', name: 'wallet-mon',
loop: true, loop: true,
options: { options: {
loopIntervalMs: 60_000, loopIntervalMs: 60_000,
...@@ -97,7 +100,7 @@ export class TransferMonService extends BaseServiceV2< ...@@ -97,7 +100,7 @@ export class TransferMonService extends BaseServiceV2<
}, },
unexpectedCalls: { unexpectedCalls: {
type: Counter, type: Counter,
desc: 'Number of unexpected transfers', desc: 'Number of unexpected wallets',
labels: ['wallet', 'target', 'nickname'], labels: ['wallet', 'target', 'nickname'],
}, },
unexpectedRpcErrors: { unexpectedRpcErrors: {
...@@ -117,10 +120,11 @@ export class TransferMonService extends BaseServiceV2< ...@@ -117,10 +120,11 @@ export class TransferMonService extends BaseServiceV2<
}) })
this.state.chainId = await getChainId(this.options.rpc) this.state.chainId = await getChainId(this.options.rpc)
const l1StartingBlockTag = networks[this.state.chainId].l1StartingBlockTag
if (this.options.startBlockNumber === -1) { if (this.options.startBlockNumber === -1) {
this.state.highestUncheckedBlockNumber = const block = await this.options.rpc.getBlock(l1StartingBlockTag)
await this.options.rpc.getBlockNumber() this.state.highestUncheckedBlockNumber = block.number
} else { } else {
this.state.highestUncheckedBlockNumber = this.options.startBlockNumber this.state.highestUncheckedBlockNumber = this.options.startBlockNumber
} }
...@@ -129,14 +133,19 @@ export class TransferMonService extends BaseServiceV2< ...@@ -129,14 +133,19 @@ export class TransferMonService extends BaseServiceV2<
protected async main(): Promise<void> { protected async main(): Promise<void> {
// get the next unchecked block // get the next unchecked block
const network = networks[this.state.chainId] const network = networks[this.state.chainId]
const accounts = bedrockAccounts[network] const accounts = network.accounts
const block = await this.options.rpc.getBlock( const block = await this.options.rpc.getBlock(
this.state.highestUncheckedBlockNumber this.state.highestUncheckedBlockNumber
) )
this.logger.info('Checking block', {
number: block.number,
})
for (const txHash of block.transactions) { for (const txHash of block.transactions) {
console.log('txHash:', txHash)
for (const account of accounts) { for (const account of accounts) {
console.log('account:', account)
const tx = await this.options.rpc.getTransaction(txHash) const tx = await this.options.rpc.getTransaction(txHash)
if (compareAddrs(account.wallet, tx.from)) { if (compareAddrs(account.wallet, tx.from)) {
...@@ -166,10 +175,11 @@ export class TransferMonService extends BaseServiceV2< ...@@ -166,10 +175,11 @@ export class TransferMonService extends BaseServiceV2<
} }
} }
} }
this.state.highestUncheckedBlockNumber++
} }
} }
if (require.main === module) { if (require.main === module) {
const service = new TransferMonService() const service = new WalletMonService()
service.run() service.run()
} }
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