Commit 55d34935 authored by Mark Tyneway's avatar Mark Tyneway

batch-submitter: add typed batch support

Enable typed batch support in the batch submitter.
Type 0 batches (zlib compressed) can be enabled with
the env var `BATCH_SUBMITTER_SEQUENCER_BATCH_TYPE=zlib`
or via the flag `--sequencer-batch-type zlib`.
parent 27d8942e
---
'@eth-optimism/batch-submitter': patch
---
Update to allow for zlib compressed batches
......@@ -12,6 +12,7 @@ import {
BatchElement,
Batch,
QueueOrigin,
BatchType,
} from '@eth-optimism/core-utils'
import { Logger, Metrics } from '@eth-optimism/common-ts'
......@@ -39,6 +40,7 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
private validateBatch: boolean
private transactionSubmitter: TransactionSubmitter
private gasThresholdInGwei: number
private batchType: BatchType
constructor(
signer: Signer,
......@@ -61,7 +63,8 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
fixDoublePlayedDeposits: false,
fixMonotonicity: false,
fixSkippedDeposits: false,
} // TODO: Remove this
}, // TODO: Remove this
batchType: string
) {
super(
signer,
......@@ -84,9 +87,18 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
this.gasThresholdInGwei = gasThresholdInGwei
this.transactionSubmitter = transactionSubmitter
this.logger.info('Batch validation options', {
if (batchType === 'legacy') {
this.batchType = BatchType.LEGACY
} else if (batchType === 'zlib') {
this.batchType = BatchType.ZLIB
} else {
throw new Error(`Invalid batch type: ${batchType}`)
}
this.logger.info('Batch options', {
autoFixBatchOptions,
validateBatch,
batchType: BatchType[this.batchType],
})
}
......@@ -295,6 +307,7 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
startBlock,
batch
)
let wasBatchTruncated = false
let encoded = encodeAppendSequencerBatch(sequencerBatchParams)
while (encoded.length / 2 > this.maxTxSize) {
......@@ -313,10 +326,14 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
wasBatchTruncated = true
}
// Set the batch type so that it is serialized correctly
sequencerBatchParams.type = this.batchType
this.logger.info('Generated sequencer batch params', {
contexts: sequencerBatchParams.contexts,
transactions: sequencerBatchParams.transactions,
wasBatchTruncated,
type: BatchType[sequencerBatchParams.type],
})
return [sequencerBatchParams, wasBatchTruncated]
}
......
......@@ -250,6 +250,11 @@ export const run = async () => {
env.VALIDATE_TX_BATCH ? env.VALIDATE_TX_BATCH === 'true' : false
)
const SEQUENCER_BATCH_TYPE = config.str(
'sequencer-batch-type',
env.SEQUENCER_BATCH_TYPE || 'legacy'
)
// Auto fix batch options -- TODO: Remove this very hacky config
const AUTO_FIX_BATCH_OPTIONS_CONF = config.str(
'auto-fix-batch-conf',
......@@ -402,7 +407,8 @@ export const run = async () => {
VALIDATE_TX_BATCH,
logger.child({ name: TX_BATCH_SUBMITTER_LOG_TAG }),
metrics,
autoFixBatchOptions
autoFixBatchOptions,
SEQUENCER_BATCH_TYPE
)
const stateBatchTxSubmitter: TransactionSubmitter =
......
......@@ -4,12 +4,11 @@ import {
TransactionResponse,
TransactionRequest,
} from '@ethersproject/abstract-provider'
import { keccak256 } from 'ethers/lib/utils'
import {
AppendSequencerBatchParams,
BatchContext,
encodeAppendSequencerBatch,
remove0x,
sequencerBatch,
} from '@eth-optimism/core-utils'
export { encodeAppendSequencerBatch, BatchContext, AppendSequencerBatchParams }
......@@ -52,10 +51,6 @@ export class CanonicalTransactionChainContract extends Contract {
* Internal Functions *
*********************/
const APPEND_SEQUENCER_BATCH_METHOD_ID = keccak256(
Buffer.from('appendSequencerBatch()')
).slice(2, 10)
const appendSequencerBatch = async (
OVM_CanonicalTransactionChain: Contract,
batch: AppendSequencerBatchParams,
......@@ -68,8 +63,6 @@ const appendSequencerBatch = async (
})
}
const getEncodedCalldata = (batch: AppendSequencerBatchParams): string => {
const methodId = APPEND_SEQUENCER_BATCH_METHOD_ID
const calldata = encodeAppendSequencerBatch(batch)
return '0x' + remove0x(methodId) + remove0x(calldata)
const getEncodedCalldata = (params: AppendSequencerBatchParams): string => {
return sequencerBatch.encode(params)
}
......@@ -226,7 +226,13 @@ describe('BatchSubmitter', () => {
1,
false,
new Logger({ name: TX_BATCH_SUBMITTER_LOG_TAG }),
testMetrics
testMetrics,
{
fixDoublePlayedDeposits: false,
fixMonotonicity: false,
fixSkippedDeposits: false,
},
'legacy'
)
}
......
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