Skip to content

Commit

Permalink
Fix small bugs & improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
karlfloersch committed Oct 24, 2020
1 parent 64a9b23 commit ea3f9c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
27 changes: 13 additions & 14 deletions packages/batch-submitter/src/batch-submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class BatchSubmitter {
readonly l2Provider: OptimismProvider,
readonly l2ChainId: number,
readonly maxTxSize: number,
readonly numConfirmations: number,
readonly numConfirmations: number
) {}

public async submitNextBatch(): Promise<void> {
Expand Down Expand Up @@ -63,7 +63,7 @@ export class BatchSubmitter {
const blocks: Batch = []
for (let i = startBlock; i < endBlock; i++) {
if (!this.blockCache.hasOwnProperty(i)) {
this.blockCache[i] = await this._getL2Block(i)
this.blockCache[i] = await this._getL2BatchElement(i)
}
blocks.push(this.blockCache[i])
}
Expand Down Expand Up @@ -154,17 +154,17 @@ export class BatchSubmitter {
}
}

public async _getL2Block(blockNumber: number): Promise<BatchElement> {
public async _getL2BatchElement(blockNumber: number): Promise<BatchElement> {
const block = (await this.l2Provider.getBlockWithTransactions(
blockNumber
)) as L2Block
const txType = block.transactions[0].meta.txType

if (this._isSequencerTx(block)) {
if (txType === TxType.EIP155) {
return this._getEIP155L2Block(block)
if (txType === TxType.EIP155 || txType === TxType.EthSign) {
return this._getDefaultEcdsaTxBatchElement(block)
} else if (txType === TxType.createEOA) {
return this._getCreateEOAL2Block(block)
return this._getCreateEoaBatchElement(block)
} else {
throw new Error('Unsupported Tx Type!')
}
Expand All @@ -175,12 +175,12 @@ export class BatchSubmitter {
sequencerTxType: undefined,
txData: undefined,
timestamp: block.timestamp,
blockNumber: block.number,
blockNumber: block.transactions[0].meta.l1BlockNumber,
}
}
}

private _getEIP155L2Block(block: L2Block): BatchElement {
private _getDefaultEcdsaTxBatchElement(block: L2Block): BatchElement {
const tx: TransactionResponse = block.transactions[0]
const txData: EIP155TxData = {
sig: {
Expand All @@ -200,29 +200,28 @@ export class BatchSubmitter {
sequencerTxType: block.transactions[0].meta.txType,
txData,
timestamp: block.timestamp,
blockNumber: block.number,
blockNumber: block.transactions[0].meta.l1BlockNumber,
}
}

private _getCreateEOAL2Block(block: L2Block): BatchElement {
private _getCreateEoaBatchElement(block: L2Block): BatchElement {
const tx: TransactionResponse = block.transactions[0]
// Call decode on the data field to get sig and messageHash
const txData: CreateEOATxData = {
sig: {
// TODO: Update v value to strip the chainID
v: remove0x(BigNumber.from(tx.v).toHexString()).padStart(2, '0'),
v: '0' + (tx.v - this.l2ChainId * 2 - 8 - 27).toString(),
r: tx.r,
s: tx.s,
},
messageHash: tx.data, // TODO: Parse this more
messageHash: tx.data,
}
return {
stateRoot: block.stateRoot,
isSequencerTx: true,
sequencerTxType: block.transactions[0].meta.txType,
txData,
timestamp: block.timestamp,
blockNumber: block.number,
blockNumber: block.transactions[0].meta.l1BlockNumber,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/batch-submitter/src/exec/run-batch-submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const run = async () => {
l2Provider,
parseInt(requiredEnvVars.L2_CHAIN_ID, 10),
parseInt(requiredEnvVars.MAX_TX_SIZE, 10),
parseInt(requiredEnvVars.NUM_CONFIRMATIONS, 10),
parseInt(requiredEnvVars.NUM_CONFIRMATIONS, 10)
)

// Run batch submitter!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,5 @@ describe('BatchSubmitter', () => {
)
await batchSubmitter.submitNextBatch()
})

it.skip('should allow me to console.log a bunch of blocks', async () => {
for (let i = 1; i < 7; i++) {
await OVM_CanonicalTransactionChain.enqueue(
'0x' + '01'.repeat(20),
50_000,
'0x' + i.toString().repeat(64),
{
gasLimit: 1_000_000,
}
)
}
const totalBlocks = await await signer.provider.getBlockNumber()
const blocks = []
for (let i = 0; i < totalBlocks; i++) {
blocks.push(await signer.provider.getBlockWithTransactions(i))
}
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -918,4 +918,4 @@ const BLOCKS = JSON.parse(`
]
}
]
`)
`)

0 comments on commit ea3f9c7

Please sign in to comment.