Commit a75f05b7 authored by smartcontracts's avatar smartcontracts Committed by GitHub

fix[dtl]: fix dtl bug breaking verifiers (#1011)

* fix[dtl]: fix dtl bug breaking verifiers

* tweaks so tests pass

* chore: add changeset
parent e3dc90cb
---
'@eth-optimism/data-transport-layer': patch
---
Fixes a bug that prevented verifiers from syncing properly with the DTL
...@@ -20,6 +20,7 @@ import { ...@@ -20,6 +20,7 @@ import {
import { import {
SEQUENCER_ENTRYPOINT_ADDRESS, SEQUENCER_ENTRYPOINT_ADDRESS,
SEQUENCER_GAS_LIMIT, SEQUENCER_GAS_LIMIT,
parseSignatureVParam,
} from '../../../utils' } from '../../../utils'
export const handleEventsSequencerBatchAppended: EventHandlerSet< export const handleEventsSequencerBatchAppended: EventHandlerSet<
...@@ -76,7 +77,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet< ...@@ -76,7 +77,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet<
batchExtraData: batchSubmissionEvent.args._extraData, batchExtraData: batchSubmissionEvent.args._extraData,
} }
}, },
parseEvent: (event, extraData) => { parseEvent: (event, extraData, l2ChainId) => {
const transactionEntries: TransactionEntry[] = [] const transactionEntries: TransactionEntry[] = []
// It's easier to deal with this data if it's a Buffer. // It's easier to deal with this data if it's a Buffer.
...@@ -103,7 +104,8 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet< ...@@ -103,7 +104,8 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet<
) )
const decoded = maybeDecodeSequencerBatchTransaction( const decoded = maybeDecodeSequencerBatchTransaction(
sequencerTransaction sequencerTransaction,
l2ChainId
) )
transactionEntries.push({ transactionEntries.push({
...@@ -234,7 +236,8 @@ const parseSequencerBatchTransaction = ( ...@@ -234,7 +236,8 @@ const parseSequencerBatchTransaction = (
} }
const maybeDecodeSequencerBatchTransaction = ( const maybeDecodeSequencerBatchTransaction = (
transaction: Buffer transaction: Buffer,
l2ChainId: number
): DecodedSequencerBatchTransaction | null => { ): DecodedSequencerBatchTransaction | null => {
try { try {
const decodedTx = ethers.utils.parseTransaction(transaction) const decodedTx = ethers.utils.parseTransaction(transaction)
...@@ -247,7 +250,7 @@ const maybeDecodeSequencerBatchTransaction = ( ...@@ -247,7 +250,7 @@ const maybeDecodeSequencerBatchTransaction = (
target: toHexString(decodedTx.to), // Maybe null this out for creations? target: toHexString(decodedTx.to), // Maybe null this out for creations?
data: toHexString(decodedTx.data), data: toHexString(decodedTx.data),
sig: { sig: {
v: BigNumber.from(decodedTx.v).toNumber(), v: parseSignatureVParam(decodedTx.v, l2ChainId),
r: toHexString(decodedTx.r), r: toHexString(decodedTx.r),
s: toHexString(decodedTx.s), s: toHexString(decodedTx.s),
}, },
......
...@@ -3,6 +3,7 @@ import { fromHexString, EventArgsAddressSet } from '@eth-optimism/core-utils' ...@@ -3,6 +3,7 @@ import { fromHexString, EventArgsAddressSet } from '@eth-optimism/core-utils'
import { BaseService } from '@eth-optimism/common-ts' import { BaseService } from '@eth-optimism/common-ts'
import { JsonRpcProvider } from '@ethersproject/providers' import { JsonRpcProvider } from '@ethersproject/providers'
import { LevelUp } from 'levelup' import { LevelUp } from 'levelup'
import { ethers, constants } from 'ethers'
/* Imports: Internal */ /* Imports: Internal */
import { TransportDB } from '../../db/transport-db' import { TransportDB } from '../../db/transport-db'
...@@ -18,7 +19,6 @@ import { handleEventsTransactionEnqueued } from './handlers/transaction-enqueued ...@@ -18,7 +19,6 @@ import { handleEventsTransactionEnqueued } from './handlers/transaction-enqueued
import { handleEventsSequencerBatchAppended } from './handlers/sequencer-batch-appended' import { handleEventsSequencerBatchAppended } from './handlers/sequencer-batch-appended'
import { handleEventsStateBatchAppended } from './handlers/state-batch-appended' import { handleEventsStateBatchAppended } from './handlers/state-batch-appended'
import { L1DataTransportServiceOptions } from '../main/service' import { L1DataTransportServiceOptions } from '../main/service'
import { constants } from 'ethers'
export interface L1IngestionServiceOptions export interface L1IngestionServiceOptions
extends L1DataTransportServiceOptions { extends L1DataTransportServiceOptions {
...@@ -65,6 +65,7 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> { ...@@ -65,6 +65,7 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
contracts: OptimismContracts contracts: OptimismContracts
l1RpcProvider: JsonRpcProvider l1RpcProvider: JsonRpcProvider
startingL1BlockNumber: number startingL1BlockNumber: number
l2ChainId: number
} = {} as any } = {} as any
protected async _init(): Promise<void> { protected async _init(): Promise<void> {
...@@ -114,6 +115,10 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> { ...@@ -114,6 +115,10 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
this.options.addressManager this.options.addressManager
) )
this.state.l2ChainId = ethers.BigNumber.from(
await this.state.contracts.OVM_ExecutionManager.ovmCHAINID()
).toNumber()
const startingL1BlockNumber = await this.state.db.getStartingL1Block() const startingL1BlockNumber = await this.state.db.getStartingL1Block()
if (startingL1BlockNumber) { if (startingL1BlockNumber) {
this.state.startingL1BlockNumber = startingL1BlockNumber this.state.startingL1BlockNumber = startingL1BlockNumber
...@@ -295,7 +300,11 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> { ...@@ -295,7 +300,11 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
event, event,
this.state.l1RpcProvider this.state.l1RpcProvider
) )
const parsedEvent = await handlers.parseEvent(event, extraData) const parsedEvent = await handlers.parseEvent(
event,
extraData,
this.state.l2ChainId
)
await handlers.storeEvent(parsedEvent, this.state.db) await handlers.storeEvent(parsedEvent, this.state.db)
} }
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
padHexString, padHexString,
SEQUENCER_ENTRYPOINT_ADDRESS, SEQUENCER_ENTRYPOINT_ADDRESS,
SEQUENCER_GAS_LIMIT, SEQUENCER_GAS_LIMIT,
parseSignatureVParam,
} from '../../../utils' } from '../../../utils'
export const handleSequencerBlock = { export const handleSequencerBlock = {
...@@ -43,7 +44,7 @@ export const handleSequencerBlock = { ...@@ -43,7 +44,7 @@ export const handleSequencerBlock = {
if (transaction.queueOrigin === 'sequencer') { if (transaction.queueOrigin === 'sequencer') {
const decodedTransaction: DecodedSequencerBatchTransaction = { const decodedTransaction: DecodedSequencerBatchTransaction = {
sig: { sig: {
v: BigNumber.from(transaction.v).toNumber() - 2 * chainId - 35, v: parseSignatureVParam(transaction.v, chainId),
r: padHexString(transaction.r, 32), r: padHexString(transaction.r, 32),
s: padHexString(transaction.s, 32), s: padHexString(transaction.s, 32),
}, },
......
...@@ -20,7 +20,8 @@ export type GetExtraDataHandler<TEventArgs, TExtraData> = ( ...@@ -20,7 +20,8 @@ export type GetExtraDataHandler<TEventArgs, TExtraData> = (
export type ParseEventHandler<TEventArgs, TExtraData, TParsedEvent> = ( export type ParseEventHandler<TEventArgs, TExtraData, TParsedEvent> = (
event: TypedEthersEvent<TEventArgs>, event: TypedEthersEvent<TEventArgs>,
extraData: TExtraData extraData: TExtraData,
l2ChainId: number
) => TParsedEvent ) => TParsedEvent
export type StoreEventHandler<TParsedEvent> = ( export type StoreEventHandler<TParsedEvent> = (
......
/* Imports: External */
import { ethers } from 'ethers'
export const parseSignatureVParam = (
v: number | ethers.BigNumber,
chainId: number
): number => {
return ethers.BigNumber.from(v).toNumber() - 2 * chainId - 35
}
...@@ -2,3 +2,4 @@ export * from './common' ...@@ -2,3 +2,4 @@ export * from './common'
export * from './constants' export * from './constants'
export * from './contracts' export * from './contracts'
export * from './validation' export * from './validation'
export * from './eth-tx'
import { BigNumber, ethers } from 'ethers' import { BigNumber, ethers } from 'ethers'
/* Imports: Internal */
import { expect } from '../../../../setup' import { expect } from '../../../../setup'
import { handleEventsSequencerBatchAppended } from '../../../../../src/services/l1-ingestion/handlers/sequencer-batch-appended' import { handleEventsSequencerBatchAppended } from '../../../../../src/services/l1-ingestion/handlers/sequencer-batch-appended'
import { SequencerBatchAppendedExtraData } from '../../../../../src/types' import { SequencerBatchAppendedExtraData } from '../../../../../src/types'
import { l1TransactionData } from '../../../examples/l1-data'
import { blocksOnL2 } from '../../../examples/l2-data'
describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended', () => { describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended', () => {
describe('handleEventsSequencerBatchAppended.parseEvent', () => { describe('handleEventsSequencerBatchAppended.parseEvent', () => {
...@@ -28,7 +28,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended', ...@@ -28,7 +28,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended',
} }
it('should error on malformed transaction data', async () => { it('should error on malformed transaction data', async () => {
const input1: [any, SequencerBatchAppendedExtraData] = [ const input1: [any, SequencerBatchAppendedExtraData, number] = [
{ {
args: { args: {
_startingQueueIndex: ethers.constants.Zero, _startingQueueIndex: ethers.constants.Zero,
...@@ -40,6 +40,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended', ...@@ -40,6 +40,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended',
l1TransactionData: '0x00000', l1TransactionData: '0x00000',
...exampleExtraData, ...exampleExtraData,
}, },
0,
] ]
expect(() => { expect(() => {
......
import { expect } from '../../../../setup'
/* Imports: External */
import { BigNumber } from 'ethers' import { BigNumber } from 'ethers'
import { Block } from '@ethersproject/abstract-provider' import { Block } from '@ethersproject/abstract-provider'
import { expect } from '../../../../setup' /* Imports: Internal */
import { handleEventsStateBatchAppended } from '../../../../../src/services/l1-ingestion/handlers/state-batch-appended' import { handleEventsStateBatchAppended } from '../../../../../src/services/l1-ingestion/handlers/state-batch-appended'
import { StateBatchAppendedExtraData } from '../../../../../src/types' import { StateBatchAppendedExtraData } from '../../../../../src/types'
import { l1StateBatchData } from '../../../examples/l1-data' import { l1StateBatchData } from '../../../examples/l1-data'
...@@ -73,7 +76,11 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.StateBatchAppended', () ...@@ -73,7 +76,11 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.StateBatchAppended', ()
l1TransactionHash: l1TransactionHash:
'0x4ca72484e93cdb50fe1089984db152258c2bbffc2534dcafbfe032b596bd5b49', '0x4ca72484e93cdb50fe1089984db152258c2bbffc2534dcafbfe032b596bd5b49',
} }
const input1: [any, StateBatchAppendedExtraData] = [event, extraData] const input1: [any, StateBatchAppendedExtraData, number] = [
event,
extraData,
0,
]
const output1 = handleEventsStateBatchAppended.parseEvent(...input1) const output1 = handleEventsStateBatchAppended.parseEvent(...input1)
......
import { expect } from '../../../../setup'
/* Imports: External */
import { ethers, BigNumber } from 'ethers' import { ethers, BigNumber } from 'ethers'
import { expect } from '../../../../setup' /* Imports: Internal */
import { handleEventsTransactionEnqueued } from '../../../../../src/services/l1-ingestion/handlers/transaction-enqueued' import { handleEventsTransactionEnqueued } from '../../../../../src/services/l1-ingestion/handlers/transaction-enqueued'
const MAX_ITERATIONS = 128 const MAX_ITERATIONS = 128
...@@ -22,7 +25,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -22,7 +25,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
// but it's probably better to get wider test coverage first. // but it's probably better to get wider test coverage first.
it('should have a ctcIndex equal to null', () => { it('should have a ctcIndex equal to null', () => {
const input1: [any, any] = [ const input1: [any, any, number] = [
{ {
blockNumber: 0, blockNumber: 0,
args: { args: {
...@@ -32,6 +35,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -32,6 +35,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
}, },
}, },
null, null,
0,
] ]
const output1 = handleEventsTransactionEnqueued.parseEvent(...input1) const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
...@@ -47,7 +51,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -47,7 +51,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER; i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS) i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) { ) {
const input1: [any, any] = [ const input1: [any, any, number] = [
{ {
blockNumber: i, blockNumber: i,
args: { args: {
...@@ -57,6 +61,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -57,6 +61,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
}, },
}, },
null, null,
0,
] ]
const output1 = handleEventsTransactionEnqueued.parseEvent(...input1) const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
...@@ -73,7 +78,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -73,7 +78,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER; i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS) i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) { ) {
const input1: [any, any] = [ const input1: [any, any, number] = [
{ {
blockNumber: 0, blockNumber: 0,
args: { args: {
...@@ -83,6 +88,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -83,6 +88,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
}, },
}, },
null, null,
0,
] ]
const output1 = handleEventsTransactionEnqueued.parseEvent(...input1) const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
...@@ -99,7 +105,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -99,7 +105,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER; i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS) i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) { ) {
const input1: [any, any] = [ const input1: [any, any, number] = [
{ {
blockNumber: 0, blockNumber: 0,
args: { args: {
...@@ -109,6 +115,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -109,6 +115,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
}, },
}, },
null, null,
0,
] ]
const output1 = handleEventsTransactionEnqueued.parseEvent(...input1) const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
...@@ -125,7 +132,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -125,7 +132,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER; i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS) i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) { ) {
const input1: [any, any] = [ const input1: [any, any, number] = [
{ {
blockNumber: 0, blockNumber: 0,
args: { args: {
...@@ -135,6 +142,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () ...@@ -135,6 +142,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
}, },
}, },
null, null,
0,
] ]
const output1 = handleEventsTransactionEnqueued.parseEvent(...input1) const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
......
import { expect } from '../../../../setup' import { expect } from '../../../../setup'
/* Imports: Internal */
import { l2Block } from '../../../examples/l2-data' import { l2Block } from '../../../examples/l2-data'
import { handleSequencerBlock } from '../../../../../src/services/l2-ingestion/handlers/transaction' import { handleSequencerBlock } from '../../../../../src/services/l2-ingestion/handlers/transaction'
......
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