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