From 1293825cee3bd79ec3cd66a985b77febcbf66824 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Tue, 1 Jun 2021 16:12:33 -0700 Subject: [PATCH] backwards compatible dtl syncing (#986) * kovan: fix attempt * kovan: db fix * kovan: types are strings from db * l2geth: parse things as strings * chore: add changeset * dtl: also stringify the range query * geth: dereference * geth: assign err * dtl: handle null * dtl: fix unit tests --- .changeset/nasty-dots-grow.md | 6 ++++ l2geth/rollup/client.go | 4 +-- .../src/db/transport-db.ts | 29 +++++++++++++++++-- .../handlers/sequencer-batch-appended.ts | 6 ++-- .../handlers/transaction-enqueued.ts | 2 +- .../l2-ingestion/handlers/transaction.ts | 4 +-- .../src/types/database-types.ts | 4 +-- .../src/types/event-handler-types.ts | 2 +- .../handlers/sequencer-batch-appended.spec.ts | 2 +- .../handlers/transaction-enqueued.spec.ts | 4 +-- 10 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 .changeset/nasty-dots-grow.md diff --git a/.changeset/nasty-dots-grow.md b/.changeset/nasty-dots-grow.md new file mode 100644 index 000000000000..417ca35c1d1f --- /dev/null +++ b/.changeset/nasty-dots-grow.md @@ -0,0 +1,6 @@ +--- +'@eth-optimism/l2geth': patch +'@eth-optimism/data-transport-layer': patch +--- + +Fix gasLimit overflow diff --git a/l2geth/rollup/client.go b/l2geth/rollup/client.go index 2e6402bfd4e6..4a1a0f5b14e5 100644 --- a/l2geth/rollup/client.go +++ b/l2geth/rollup/client.go @@ -69,7 +69,7 @@ type transaction struct { BlockNumber uint64 `json:"blockNumber"` Timestamp uint64 `json:"timestamp"` Value hexutil.Uint64 `json:"value"` - GasLimit uint64 `json:"gasLimit"` + GasLimit uint64 `json:"gasLimit,string"` Target common.Address `json:"target"` Origin *common.Address `json:"origin"` Data hexutil.Bytes `json:"data"` @@ -84,7 +84,7 @@ type Enqueue struct { Index *uint64 `json:"ctcIndex"` Target *common.Address `json:"target"` Data *hexutil.Bytes `json:"data"` - GasLimit *uint64 `json:"gasLimit"` + GasLimit *uint64 `json:"gasLimit,string"` Origin *common.Address `json:"origin"` BlockNumber *uint64 `json:"blockNumber"` Timestamp *uint64 `json:"timestamp"` diff --git a/packages/data-transport-layer/src/db/transport-db.ts b/packages/data-transport-layer/src/db/transport-db.ts index be80e6314b55..777ba4423dde 100644 --- a/packages/data-transport-layer/src/db/transport-db.ts +++ b/packages/data-transport-layer/src/db/transport-db.ts @@ -379,8 +379,9 @@ export class TransportDB { if (index === null) { return null } - - return this.db.get(`${key}:index`, index) + let entry = await this.db.get(`${key}:index`, index) + entry = stringify(entry) + return entry } private async _getEntries( @@ -388,6 +389,28 @@ export class TransportDB { startIndex: number, endIndex: number ): Promise { - return this.db.range(`${key}:index`, startIndex, endIndex) + const entries = await this.db.range( + `${key}:index`, + startIndex, + endIndex + ) + const results = [] + for (const entry of entries) { + results.push(stringify(entry)) + } + return results + } +} + +function stringify(entry) { + if (entry === null || entry === undefined) { + return entry + } + if (entry.gasLimit) { + entry.gasLimit = BigNumber.from(entry.gasLimit).toString() + } + if (entry.decoded) { + entry.decoded.gasLimit = BigNumber.from(entry.decoded.gasLimit).toString() } + return entry } diff --git a/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts b/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts index 71b483f4dcde..23230efd02fe 100644 --- a/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts +++ b/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts @@ -69,7 +69,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet< submitter: l1Transaction.from, l1TransactionHash: l1Transaction.hash, l1TransactionData: l1Transaction.data, - gasLimit: SEQUENCER_GAS_LIMIT, + gasLimit: `${SEQUENCER_GAS_LIMIT}`, prevTotalElements: batchSubmissionEvent.args._prevTotalElements, batchIndex: batchSubmissionEvent.args._batchIndex, @@ -115,7 +115,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet< batchIndex: extraData.batchIndex.toNumber(), blockNumber: BigNumber.from(context.blockNumber).toNumber(), timestamp: BigNumber.from(context.timestamp).toNumber(), - gasLimit: BigNumber.from(extraData.gasLimit).toNumber(), + gasLimit: BigNumber.from(extraData.gasLimit).toString(), target: SEQUENCER_ENTRYPOINT_ADDRESS, origin: null, data: toHexString(sequencerTransaction), @@ -147,7 +147,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet< batchIndex: extraData.batchIndex.toNumber(), blockNumber: BigNumber.from(0).toNumber(), timestamp: BigNumber.from(0).toNumber(), - gasLimit: BigNumber.from(0).toNumber(), + gasLimit: BigNumber.from(0).toString(), target: constants.AddressZero, origin: constants.AddressZero, data: '0x', diff --git a/packages/data-transport-layer/src/services/l1-ingestion/handlers/transaction-enqueued.ts b/packages/data-transport-layer/src/services/l1-ingestion/handlers/transaction-enqueued.ts index e343a7e78fbf..7e6bcb9b2b66 100644 --- a/packages/data-transport-layer/src/services/l1-ingestion/handlers/transaction-enqueued.ts +++ b/packages/data-transport-layer/src/services/l1-ingestion/handlers/transaction-enqueued.ts @@ -17,7 +17,7 @@ export const handleEventsTransactionEnqueued: EventHandlerSet< index: event.args._queueIndex.toNumber(), target: event.args._target, data: event.args._data, - gasLimit: event.args._gasLimit.toNumber(), + gasLimit: event.args._gasLimit.toString(), origin: event.args._l1TxOrigin, blockNumber: BigNumber.from(event.blockNumber).toNumber(), timestamp: event.args._timestamp.toNumber(), diff --git a/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts b/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts index 0022afc285d7..be127cc2d0dd 100644 --- a/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts +++ b/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts @@ -57,7 +57,7 @@ export const handleSequencerBlock = { transactionEntry = { ...transactionEntry, - gasLimit: SEQUENCER_GAS_LIMIT, // ? + gasLimit: `${SEQUENCER_GAS_LIMIT}`, // ? target: SEQUENCER_ENTRYPOINT_ADDRESS, origin: null, data: serialize( @@ -82,7 +82,7 @@ export const handleSequencerBlock = { } else { transactionEntry = { ...transactionEntry, - gasLimit: BigNumber.from(transaction.gas).toNumber(), + gasLimit: BigNumber.from(transaction.gas).toString(), target: ethers.utils.getAddress(transaction.to), origin: ethers.utils.getAddress(transaction.l1TxOrigin), data: transaction.input, diff --git a/packages/data-transport-layer/src/types/database-types.ts b/packages/data-transport-layer/src/types/database-types.ts index 32e52288ee4f..470b402c3590 100644 --- a/packages/data-transport-layer/src/types/database-types.ts +++ b/packages/data-transport-layer/src/types/database-types.ts @@ -16,7 +16,7 @@ export interface EnqueueEntry { index: number target: string data: string - gasLimit: number + gasLimit: string origin: string blockNumber: number timestamp: number @@ -28,7 +28,7 @@ export interface TransactionEntry { data: string blockNumber: number timestamp: number - gasLimit: number + gasLimit: string target: string origin: string value: string diff --git a/packages/data-transport-layer/src/types/event-handler-types.ts b/packages/data-transport-layer/src/types/event-handler-types.ts index 8b2e190b6efd..82bf5bf7f198 100644 --- a/packages/data-transport-layer/src/types/event-handler-types.ts +++ b/packages/data-transport-layer/src/types/event-handler-types.ts @@ -40,7 +40,7 @@ export interface SequencerBatchAppendedExtraData { submitter: string l1TransactionData: string l1TransactionHash: string - gasLimit: number + gasLimit: string // Stuff from TransactionBatchAppended. prevTotalElements: BigNumber diff --git a/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/sequencer-batch-appended.spec.ts b/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/sequencer-batch-appended.spec.ts index 0a6690bf832e..813f3c65c63a 100644 --- a/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/sequencer-batch-appended.spec.ts +++ b/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/sequencer-batch-appended.spec.ts @@ -18,7 +18,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended', submitter: '0xfd7d4de366850c08ee2cba32d851385a3071ec8d', l1TransactionHash: '0x6effe006836b841205ace4d99d7ae1b74ee96aac499a3f358b97fccd32ee9af2', - gasLimit: 548976, + gasLimit: '548976', prevTotalElements: BigNumber.from(73677), batchIndex: BigNumber.from(743), batchSize: BigNumber.from(101), diff --git a/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/transaction-enqueued.spec.ts b/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/transaction-enqueued.spec.ts index 52e5da27739e..b14d6ba505b9 100644 --- a/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/transaction-enqueued.spec.ts +++ b/packages/data-transport-layer/test/unit-tests/services/l1-ingestion/handlers/transaction-enqueued.spec.ts @@ -93,7 +93,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () } }) - it('should have a gasLimit equal to the integer value of the _gasLimit argument', () => { + it('should have a gasLimit equal to the string value of the _gasLimit argument', () => { for ( let i = 0; i < Number.MAX_SAFE_INTEGER; @@ -113,7 +113,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', () const output1 = handleEventsTransactionEnqueued.parseEvent(...input1) - const expected1 = BigNumber.from(i).toNumber() + const expected1 = BigNumber.from(i).toString() expect(output1).to.have.property('gasLimit', expected1) }