Commit 453ebf04 authored by Liam Horne's avatar Liam Horne

fix: prevent batch submitter from submitting batches if low on ETH

parent 154aab39
...@@ -3,7 +3,7 @@ import { Contract, Signer, utils, providers } from 'ethers' ...@@ -3,7 +3,7 @@ import { Contract, Signer, utils, providers } from 'ethers'
import { TransactionReceipt } from '@ethersproject/abstract-provider' import { TransactionReceipt } from '@ethersproject/abstract-provider'
import { Gauge, Histogram, Counter } from 'prom-client' import { Gauge, Histogram, Counter } from 'prom-client'
import * as ynatm from '@eth-optimism/ynatm' import * as ynatm from '@eth-optimism/ynatm'
import { RollupInfo } from '@eth-optimism/core-utils' import { RollupInfo, sleep } from '@eth-optimism/core-utils'
import { Logger, Metrics } from '@eth-optimism/common-ts' import { Logger, Metrics } from '@eth-optimism/common-ts'
import { getContractFactory } from 'old-contracts' import { getContractFactory } from 'old-contracts'
...@@ -73,7 +73,11 @@ export abstract class BatchSubmitter { ...@@ -73,7 +73,11 @@ export abstract class BatchSubmitter {
this.l2ChainId = await this._getL2ChainId() this.l2ChainId = await this._getL2ChainId()
} }
await this._updateChainInfo() await this._updateChainInfo()
await this._checkBalance()
if (!(await this._hasEnoughETHToCoverGasCosts())) {
await sleep(this.resubmissionTimeout)
return
}
this.logger.info('Readying to submit next batch...', { this.logger.info('Readying to submit next batch...', {
l2ChainId: this.l2ChainId, l2ChainId: this.l2ChainId,
...@@ -94,7 +98,7 @@ export abstract class BatchSubmitter { ...@@ -94,7 +98,7 @@ export abstract class BatchSubmitter {
return this._submitBatch(range.start, range.end) return this._submitBatch(range.start, range.end)
} }
protected async _checkBalance(): Promise<void> { protected async _hasEnoughETHToCoverGasCosts(): Promise<boolean> {
const address = await this.signer.getAddress() const address = await this.signer.getAddress()
const balance = await this.signer.getBalance() const balance = await this.signer.getBalance()
const ether = utils.formatEther(balance) const ether = utils.formatEther(balance)
...@@ -104,6 +108,7 @@ export abstract class BatchSubmitter { ...@@ -104,6 +108,7 @@ export abstract class BatchSubmitter {
address, address,
ether, ether,
}) })
this.metrics.batchSubmitterETHBalance.set(num) this.metrics.batchSubmitterETHBalance.set(num)
if (num < this.minBalanceEther) { if (num < this.minBalanceEther) {
...@@ -111,7 +116,10 @@ export abstract class BatchSubmitter { ...@@ -111,7 +116,10 @@ export abstract class BatchSubmitter {
current: num, current: num,
safeBalance: this.minBalanceEther, safeBalance: this.minBalanceEther,
}) })
return false
} }
return true
} }
protected async _getRollupInfo(): Promise<RollupInfo> { protected async _getRollupInfo(): Promise<RollupInfo> {
......
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