Commit 8fee7bed authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

dtl: remove stringify from db logic + more overflow protection (#1010)

* dtl: remove stringify from db logic

* l2geth: overflow protection

* dtl: overflow protection

* chore: add changeset
parent 08873674
---
'@eth-optimism/l2geth': patch
'@eth-optimism/data-transport-layer': patch
---
Add extra overflow protection for the DTL types
...@@ -104,8 +104,8 @@ type decoded struct { ...@@ -104,8 +104,8 @@ type decoded struct {
Signature signature `json:"sig"` Signature signature `json:"sig"`
Value hexutil.Uint64 `json:"value"` Value hexutil.Uint64 `json:"value"`
GasLimit uint64 `json:"gasLimit,string"` GasLimit uint64 `json:"gasLimit,string"`
GasPrice uint64 `json:"gasPrice"` GasPrice uint64 `json:"gasPrice,string"`
Nonce uint64 `json:"nonce"` Nonce uint64 `json:"nonce,string"`
Target *common.Address `json:"target"` Target *common.Address `json:"target"`
Data hexutil.Bytes `json:"data"` Data hexutil.Bytes `json:"data"`
} }
......
...@@ -379,9 +379,7 @@ export class TransportDB { ...@@ -379,9 +379,7 @@ export class TransportDB {
if (index === null) { if (index === null) {
return null return null
} }
let entry = await this.db.get<TEntry>(`${key}:index`, index) return this.db.get<TEntry>(`${key}:index`, index)
entry = stringify(entry)
return entry
} }
private async _getEntries<TEntry extends Indexed>( private async _getEntries<TEntry extends Indexed>(
...@@ -389,28 +387,6 @@ export class TransportDB { ...@@ -389,28 +387,6 @@ export class TransportDB {
startIndex: number, startIndex: number,
endIndex: number endIndex: number
): Promise<TEntry[] | []> { ): Promise<TEntry[] | []> {
const entries = await this.db.range<TEntry>( return this.db.range<TEntry>(`${key}:index`, startIndex, endIndex)
`${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
} }
...@@ -240,8 +240,8 @@ const maybeDecodeSequencerBatchTransaction = ( ...@@ -240,8 +240,8 @@ const maybeDecodeSequencerBatchTransaction = (
const decodedTx = ethers.utils.parseTransaction(transaction) const decodedTx = ethers.utils.parseTransaction(transaction)
return { return {
nonce: BigNumber.from(decodedTx.nonce).toNumber(), nonce: BigNumber.from(decodedTx.nonce).toString(),
gasPrice: BigNumber.from(decodedTx.gasPrice).toNumber(), gasPrice: BigNumber.from(decodedTx.gasPrice).toString(),
gasLimit: BigNumber.from(decodedTx.gasLimit).toString(), gasLimit: BigNumber.from(decodedTx.gasLimit).toString(),
value: toRpcHexString(decodedTx.value), value: toRpcHexString(decodedTx.value),
target: toHexString(decodedTx.to), // Maybe null this out for creations? target: toHexString(decodedTx.to), // Maybe null this out for creations?
......
...@@ -49,8 +49,8 @@ export const handleSequencerBlock = { ...@@ -49,8 +49,8 @@ export const handleSequencerBlock = {
}, },
value: transaction.value, value: transaction.value,
gasLimit: BigNumber.from(transaction.gas).toString(), gasLimit: BigNumber.from(transaction.gas).toString(),
gasPrice: BigNumber.from(transaction.gasPrice).toNumber(), // ? gasPrice: BigNumber.from(transaction.gasPrice).toString(),
nonce: BigNumber.from(transaction.nonce).toNumber(), nonce: BigNumber.from(transaction.nonce).toString(),
target: transaction.to, target: transaction.to,
data: transaction.input, data: transaction.input,
} }
......
...@@ -6,8 +6,8 @@ export interface DecodedSequencerBatchTransaction { ...@@ -6,8 +6,8 @@ export interface DecodedSequencerBatchTransaction {
} }
value: string value: string
gasLimit: string gasLimit: string
gasPrice: number gasPrice: string
nonce: number nonce: string
target: string target: string
data: string data: string
} }
......
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