Commit 5bcd7c96 authored by Liam Horne's avatar Liam Horne

refactor: rename Range to BlockRange

parent e5383c30
......@@ -7,7 +7,7 @@ import { RollupInfo, sleep } from '@eth-optimism/core-utils'
import { Logger, Metrics } from '@eth-optimism/common-ts'
import { getContractFactory } from 'old-contracts'
export interface Range {
export interface BlockRange {
start: number
end: number
}
......@@ -65,7 +65,7 @@ export abstract class BatchSubmitter {
endBlock: number
): Promise<TransactionReceipt>
public abstract _onSync(): Promise<TransactionReceipt>
public abstract _getBatchStartAndEnd(): Promise<Range>
public abstract _getBatchStartAndEnd(): Promise<BlockRange>
public abstract _updateChainInfo(): Promise<void>
public async submitNextBatch(): Promise<TransactionReceipt> {
......
......@@ -12,7 +12,7 @@ import {
import { Logger, Metrics } from '@eth-optimism/common-ts'
/* Internal Imports */
import { Range, BatchSubmitter } from '.'
import { BlockRange, BatchSubmitter } from '.'
export class StateBatchSubmitter extends BatchSubmitter {
// TODO: Change this so that we calculate start = scc.totalElements() and end = ctc.totalElements()!
......@@ -116,7 +116,7 @@ export class StateBatchSubmitter extends BatchSubmitter {
return
}
public async _getBatchStartAndEnd(): Promise<Range> {
public async _getBatchStartAndEnd(): Promise<BlockRange> {
this.logger.info('Getting batch start and end for state batch submitter...')
const startBlock: number =
(await this.chainContract.getTotalElements()).toNumber() +
......
......@@ -21,7 +21,7 @@ import {
AppendSequencerBatchParams,
} from '../transaction-chain-contract'
import { Range, BatchSubmitter } from '.'
import { BlockRange, BatchSubmitter } from '.'
export interface AutoFixBatchOptions {
fixDoublePlayedDeposits: boolean
......@@ -127,7 +127,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
}
public async _onSync(): Promise<TransactionReceipt> {
const pendingQueueElements = await this.chainContract.getNumPendingQueueElements()
const pendingQueueElements =
await this.chainContract.getNumPendingQueueElements()
this.logger.debug('Got number of pending queue elements', {
pendingQueueElements,
})
......@@ -173,7 +174,7 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
return
}
public async _getBatchStartAndEnd(): Promise<Range> {
public async _getBatchStartAndEnd(): Promise<BlockRange> {
this.logger.info(
'Getting batch start and end for transaction batch submitter...'
)
......@@ -228,10 +229,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
return
}
const [
batchParams,
wasBatchTruncated,
] = await this._generateSequencerBatchParams(startBlock, endBlock)
const [batchParams, wasBatchTruncated] =
await this._generateSequencerBatchParams(startBlock, endBlock)
const batchSizeInBytes = encodeAppendSequencerBatch(batchParams).length / 2
this.logger.debug('Sequencer batch generated', {
batchSizeInBytes,
......@@ -390,11 +389,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
}
let isEqual = true
const [
queueEleHash,
timestamp,
blockNumber,
] = await this.chainContract.getQueueElement(queueIndex)
const [queueEleHash, timestamp, blockNumber] =
await this.chainContract.getQueueElement(queueIndex)
// TODO: Verify queue element hash equality. The queue element hash can be computed with:
// keccak256( abi.encode( msg.sender, _target, _gasLimit, _data))
......@@ -458,19 +454,18 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
for (const ele of b) {
// Look for skipped deposits
while (true) {
const pendingQueueElements = await this.chainContract.getNumPendingQueueElements()
const nextRemoteQueueElements = await this.chainContract.getNextQueueIndex()
const pendingQueueElements =
await this.chainContract.getNumPendingQueueElements()
const nextRemoteQueueElements =
await this.chainContract.getNextQueueIndex()
const totalQueueElements =
pendingQueueElements + nextRemoteQueueElements
// No more queue elements so we clearly haven't skipped anything
if (nextQueueIndex >= totalQueueElements) {
break
}
const [
queueEleHash,
timestamp,
blockNumber,
] = await this.chainContract.getQueueElement(nextQueueIndex)
const [queueEleHash, timestamp, blockNumber] =
await this.chainContract.getQueueElement(nextQueueIndex)
if (timestamp < ele.timestamp || blockNumber < ele.blockNumber) {
this.logger.warn('Fixing skipped deposit', {
......@@ -506,10 +501,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
const fixMonotonicity = async (b: Batch): Promise<Batch> => {
this.logger.debug('Fixing monotonicity...')
// The earliest allowed timestamp/blockNumber is the last timestamp submitted on chain.
const {
lastTimestamp,
lastBlockNumber,
} = await this._getLastTimestampAndBlockNumber()
const { lastTimestamp, lastBlockNumber } =
await this._getLastTimestampAndBlockNumber()
let earliestTimestamp = lastTimestamp
let earliestBlockNumber = lastBlockNumber
this.logger.debug('Determined earliest timestamp and blockNumber', {
......@@ -525,16 +518,15 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
// updateLatestTimestampAndBlockNumber is a helper which updates
// the latest timestamp and block number based on the pending queue elements.
const updateLatestTimestampAndBlockNumber = async () => {
const pendingQueueElements = await this.chainContract.getNumPendingQueueElements()
const nextRemoteQueueElements = await this.chainContract.getNextQueueIndex()
const pendingQueueElements =
await this.chainContract.getNumPendingQueueElements()
const nextRemoteQueueElements =
await this.chainContract.getNextQueueIndex()
const totalQueueElements =
pendingQueueElements + nextRemoteQueueElements
if (nextQueueIndex < totalQueueElements) {
const [
queueEleHash,
queueTimestamp,
queueBlockNumber,
] = await this.chainContract.getQueueElement(nextQueueIndex)
const [queueEleHash, queueTimestamp, queueBlockNumber] =
await this.chainContract.getQueueElement(nextQueueIndex)
latestTimestamp = queueTimestamp
latestBlockNumber = queueBlockNumber
} else {
......@@ -652,11 +644,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
queueIndex: number,
queueElement: BatchElement
): Promise<BatchElement> {
const [
queueEleHash,
timestamp,
blockNumber,
] = await this.chainContract.getQueueElement(queueIndex)
const [queueEleHash, timestamp, blockNumber] =
await this.chainContract.getQueueElement(queueIndex)
if (
timestamp > queueElement.timestamp &&
......
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