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