Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/beige-keys-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eth-optimism/data-transport-layer": patch
---

Parse and index the value field in the data transport layer
5 changes: 5 additions & 0 deletions .changeset/brown-bananas-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eth-optimism/l2geth": patch
---

Add value parsing to the rollup client
5 changes: 5 additions & 0 deletions .changeset/tough-lamps-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eth-optimism/core-utils": patch
---

Update toRpcHexString to accept ethers.BigNumber and add tests
8 changes: 6 additions & 2 deletions l2geth/rollup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type transaction struct {
BatchIndex uint64 `json:"batchIndex"`
BlockNumber uint64 `json:"blockNumber"`
Timestamp uint64 `json:"timestamp"`
Value hexutil.Uint64 `json:"value"`
GasLimit uint64 `json:"gasLimit"`
Target common.Address `json:"target"`
Origin *common.Address `json:"origin"`
Expand Down Expand Up @@ -104,6 +105,7 @@ type signature struct {
// it means that the decoding failed.
type decoded struct {
Signature signature `json:"sig"`
Value hexutil.Uint64 `json:"value"`
GasLimit uint64 `json:"gasLimit"`
GasPrice uint64 `json:"gasPrice"`
Nonce uint64 `json:"nonce"`
Expand Down Expand Up @@ -228,6 +230,7 @@ func enqueueToTransaction(enqueue *Enqueue) (*types.Transaction, error) {
}
data := *enqueue.Data

// enqueue transactions have no value
value := big.NewInt(0)
tx := types.NewTransaction(nonce, target, value, gasLimit, big.NewInt(0), data)

Expand Down Expand Up @@ -303,7 +306,7 @@ func batchedTransactionToTransaction(res *transaction, signer *types.EIP155Signe
if res.Decoded != nil {
nonce := res.Decoded.Nonce
to := res.Decoded.Target
value := new(big.Int)
value := new(big.Int).SetUint64(uint64(res.Decoded.Value))
// Note: there are two gas limits, one top level and
// another on the raw transaction itself. Maybe maxGasLimit
// for the top level?
Expand Down Expand Up @@ -357,7 +360,8 @@ func batchedTransactionToTransaction(res *transaction, signer *types.EIP155Signe
gasLimit := res.GasLimit
data := res.Data
origin := res.Origin
tx := types.NewTransaction(nonce, target, big.NewInt(0), gasLimit, big.NewInt(0), data)
value := new(big.Int).SetUint64(uint64(res.Value))
tx := types.NewTransaction(nonce, target, value, gasLimit, big.NewInt(0), data)
txMeta := types.NewTransactionMeta(
new(big.Int).SetUint64(res.BlockNumber),
res.Timestamp,
Expand Down
15 changes: 11 additions & 4 deletions packages/core-utils/src/common/hex-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ export const toHexString = (inp: Buffer | string | number | null): string => {
}
}

export const toRpcHexString = (n: number): string => {
if (n === 0) {
return '0x0'
export const toRpcHexString = (n: number | BigNumber): string => {
let num
if (typeof n === 'number') {
num = '0x' + n.toString(16)
} else {
return '0x' + toHexString(n).slice(2).replace(/^0+/, '')
num = n.toHexString()
}

if (num === '0x0') {
return num
} else {
return num.replace(/^0x0/, '0x')
}
}

Expand Down
24 changes: 23 additions & 1 deletion packages/core-utils/test/common/hex-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from '../setup'
import { BigNumber } from 'ethers'

/* Imports: Internal */
import { getRandomHexString } from '../../src'
import { getRandomHexString, toRpcHexString } from '../../src'

describe('getRandomHexString', () => {
const random = global.Math.random
Expand All @@ -18,3 +19,24 @@ describe('getRandomHexString', () => {
expect(getRandomHexString(8)).to.equal('0x' + '88'.repeat(8))
})
})

describe('toRpcHexString', () => {
it('should parse 0', () => {
expect(toRpcHexString(0)).to.deep.equal('0x0')
expect(toRpcHexString(BigNumber.from(0))).to.deep.equal('0x0')
})

it('should parse non 0', () => {
const cases = [
{ input: 2, output: '0x2' },
{ input: BigNumber.from(2), output: '0x2' },
{ input: 100, output: '0x64' },
{ input: BigNumber.from(100), output: '0x64' },
{ input: 300, output: '0x12c' },
{ input: BigNumber.from(300), output: '0x12c' },
]
for (const test of cases) {
expect(toRpcHexString(test.input)).to.deep.equal(test.output)
}
})
Comment on lines +29 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use it.each here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't built into mocha to my knowledge. Would require adding another dependency. If it can run in parallel that would be nice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. I'm used to it from Jest.

})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ctcCoder,
fromHexString,
toHexString,
toRpcHexString,
TxType,
EventArgsSequencerBatchAppended,
} from '@eth-optimism/core-utils'
Expand Down Expand Up @@ -120,6 +121,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet<
data: toHexString(sequencerTransaction),
queueOrigin: 'sequencer',
type,
value: decoded.value,
queueIndex: null,
decoded,
confirmed: true,
Expand Down Expand Up @@ -152,6 +154,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet<
data: '0x',
queueOrigin: 'l1',
type: 'EIP155',
value: '0x0',
queueIndex: queueIndex.toNumber(),
decoded: null,
confirmed: true,
Expand Down Expand Up @@ -249,6 +252,7 @@ const maybeDecodeSequencerBatchTransaction = (
nonce: BigNumber.from(decodedTx.nonce).toNumber(),
gasPrice: BigNumber.from(decodedTx.gasPrice).toNumber(),
gasLimit: BigNumber.from(decodedTx.gasLimit).toNumber(),
value: toRpcHexString(decodedTx.value),
target: toHexString(decodedTx.to), // Maybe null this out for creations?
data: toHexString(decodedTx.data),
sig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const handleSequencerBlock = {
let transactionEntry: Partial<TransactionEntry> = {
// Legacy support.
index: transactionIndex,
value: transaction.value,
batchIndex: null,
blockNumber: BigNumber.from(transaction.l1BlockNumber).toNumber(),
timestamp: BigNumber.from(transaction.l1Timestamp).toNumber(),
Expand All @@ -47,6 +48,7 @@ export const handleSequencerBlock = {
r: padHexString(transaction.r, 32),
s: padHexString(transaction.s, 32),
},
value: transaction.value,
gasLimit: BigNumber.from(transaction.gas).toNumber(),
gasPrice: BigNumber.from(transaction.gasPrice).toNumber(), // ?
nonce: BigNumber.from(transaction.nonce).toNumber(),
Expand Down
2 changes: 2 additions & 0 deletions packages/data-transport-layer/src/types/database-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface DecodedSequencerBatchTransaction {
s: string
v: number
}
value: string
gasLimit: number
gasPrice: number
nonce: number
Expand Down Expand Up @@ -31,6 +32,7 @@ export interface TransactionEntry {
gasLimit: number
target: string
origin: string
value: string
queueOrigin: 'sequencer' | 'l1'
queueIndex: number | null
type: 'EIP155' | 'ETH_SIGN' | null
Expand Down