From 71f8de9c8fd8cdcf46a2f45f1ca79bd3fed73f39 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Fri, 15 Oct 2021 17:08:52 -0700 Subject: [PATCH] batch-submitter: handle error case explicitly It was possible to return from a function directly into destructuring an array when the return value was polymorphic in either being an array or undefined. The undefined case is handled explicitly now and an error is thrown with a useful error message instead of something that would require looking at the source code and knowing nodejs error types to find out what the problem was. --- .changeset/great-buckets-bow.md | 5 +++++ .../src/batch-submitter/tx-batch-submitter.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/great-buckets-bow.md diff --git a/.changeset/great-buckets-bow.md b/.changeset/great-buckets-bow.md new file mode 100644 index 000000000000..3f21e6481fde --- /dev/null +++ b/.changeset/great-buckets-bow.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/batch-submitter': patch +--- + +Handle error case more explicity when creating invalid batch diff --git a/packages/batch-submitter/src/batch-submitter/tx-batch-submitter.ts b/packages/batch-submitter/src/batch-submitter/tx-batch-submitter.ts index 3fbfed818d84..8945c3991505 100644 --- a/packages/batch-submitter/src/batch-submitter/tx-batch-submitter.ts +++ b/packages/batch-submitter/src/batch-submitter/tx-batch-submitter.ts @@ -195,8 +195,12 @@ export class TransactionBatchSubmitter extends BatchSubmitter { return } - const [batchParams, wasBatchTruncated] = - await this._generateSequencerBatchParams(startBlock, endBlock) + const params = await this._generateSequencerBatchParams(startBlock, endBlock) + if (!params) { + throw new Error(`Cannot create sequencer batch with params start ${startBlock} and end ${endBlock}`) + } + + const [batchParams, wasBatchTruncated] = params const batchSizeInBytes = encodeAppendSequencerBatch(batchParams).length / 2 this.logger.debug('Sequencer batch generated', { batchSizeInBytes,