Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/contracts/tasks/fetch-batches.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes'
import { SequencerBatch } from '@eth-optimism/core-utils'
import { BatchType, SequencerBatch } from '@eth-optimism/core-utils'

import { names } from '../src/address-names'
import { getContractFromArtifact } from '../src/deploy-utils'
Expand Down Expand Up @@ -51,7 +51,31 @@ task('fetch-batches')
for (const event of events) {
const tx = await provider.getTransaction(event.transactionHash)
const batch = (SequencerBatch as any).fromHex(tx.data)
batches.push(batch.toJSON())

// Add an extra field to the resulting json
// so that the serialization sizes can be observed
const json = batch.toJSON()
json.sizes = {
legacy: 0,
zlib: 0,
}

// Create a copy of the batch to serialize in
// the alternative format
const copy = (SequencerBatch as any).fromHex(tx.data)
if (batch.type === BatchType.ZLIB) {
copy.type = BatchType.LEGACY
json.sizes.legacy = copy.encode().length
json.sizes.zlib = batch.encode().length
} else {
copy.type = BatchType.ZLIB
json.sizes.zlib = copy.encode().length
json.sizes.legacy = batch.encode().length
}

json.compressionRatio = json.sizes.zlib / json.sizes.legacy

batches.push(json)
}
}

Expand Down