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