Commit abc7df60 authored by Maurelian's avatar Maurelian

feat(c-mon): Reduce loop time, and return when waiting for new blocks

parent 1904e4ff
...@@ -77,7 +77,7 @@ export class WalletMonService extends BaseServiceV2< ...@@ -77,7 +77,7 @@ export class WalletMonService extends BaseServiceV2<
name: 'wallet-mon', name: 'wallet-mon',
loop: true, loop: true,
options: { options: {
loopIntervalMs: 60_000, loopIntervalMs: 1000,
...options, ...options,
}, },
optionsSpec: { optionsSpec: {
...@@ -120,6 +120,7 @@ export class WalletMonService extends BaseServiceV2< ...@@ -120,6 +120,7 @@ export class WalletMonService 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 const l1StartingBlockTag = networks[this.state.chainId].l1StartingBlockTag
if (this.options.startBlockNumber === -1) { if (this.options.startBlockNumber === -1) {
...@@ -131,7 +132,14 @@ export class WalletMonService extends BaseServiceV2< ...@@ -131,7 +132,14 @@ export class WalletMonService extends BaseServiceV2<
} }
protected async main(): Promise<void> { protected async main(): Promise<void> {
// get the next unchecked block if (
(await this.options.rpc.getBlockNumber()) <
this.state.highestUncheckedBlockNumber
) {
this.logger.info('Waiting for new blocks')
return
}
const network = networks[this.state.chainId] const network = networks[this.state.chainId]
const accounts = network.accounts const accounts = network.accounts
...@@ -142,39 +150,44 @@ export class WalletMonService extends BaseServiceV2< ...@@ -142,39 +150,44 @@ export class WalletMonService extends BaseServiceV2<
number: block.number, number: block.number,
}) })
const transactions = []
for (const txHash of block.transactions) { for (const txHash of block.transactions) {
console.log('txHash:', txHash) const t = await this.options.rpc.getTransaction(txHash)
for (const account of accounts) { transactions.push(t)
console.log('account:', account) }
const tx = await this.options.rpc.getTransaction(txHash)
if (compareAddrs(account.wallet, tx.from)) { for (const transaction of transactions) {
if (compareAddrs(account.target, tx.to)) { for (const account of accounts) {
if (compareAddrs(account.wallet, transaction.from)) {
if (compareAddrs(account.target, transaction.to)) {
this.metrics.validatedCalls.inc({ this.metrics.validatedCalls.inc({
label: account.label, nickname: account.label,
wallet: account.address, wallet: account.address,
target: account.target, target: account.target,
}) })
this.logger.info('validated call', { this.logger.info('validated call', {
label: account.label, nickname: account.label,
wallet: account.address, wallet: account.address,
target: account.target, target: account.target,
}) })
} else { } else {
this.metrics.unexpectedCalls.inc({ this.metrics.unexpectedCalls.inc({
label: account.label, nickname: account.label,
wallet: account.address, wallet: account.address,
target: tx.to, target: transaction.to,
}) })
this.logger.error('Unexpected call detected', { this.logger.error('Unexpected call detected', {
label: account.label, nickname: account.label,
address: account.address, address: account.address,
target: tx.to, target: transaction.to,
}) })
} }
} }
} }
} }
this.logger.info('Checked block', {
number: this.state.highestUncheckedBlockNumber,
})
this.state.highestUncheckedBlockNumber++ this.state.highestUncheckedBlockNumber++
} }
} }
......
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