Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

develop: ci fix, some last backwards compatibility removals #1834

Merged
merged 13 commits into from
Apr 5, 2022
16 changes: 13 additions & 3 deletions packages/client/lib/service/fullethereumservice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hardfork } from '@ethereumjs/common'
import { bigIntToBuffer } from 'ethereumjs-util'
import { bigIntToBuffer, rlp } from 'ethereumjs-util'
import { EthereumService, EthereumServiceOptions } from './ethereumservice'
import { FullSynchronizer } from '../sync/fullsync'
import { EthProtocol } from '../net/protocol/ethprotocol'
Expand All @@ -10,6 +10,7 @@ import { Miner } from '../miner'
import { VMExecution } from '../execution'
import { Event } from '../types'
import type { Block } from '@ethereumjs/block'
import type { PostByzantiumTxReceipt, PreByzantiumTxReceipt } from '@ethereumjs/vm/dist/types'

interface FullEthereumServiceOptions extends EthereumServiceOptions {
/* Serve LES requests (default: false) */
Expand Down Expand Up @@ -190,9 +191,18 @@ export class FullEthereumService extends EthereumService {
for (const hash of hashes) {
const blockReceipts = await receiptsManager.getReceipts(hash, true, true)
if (!blockReceipts) continue
blockReceipts.forEach((r) => (r.gasUsed = bigIntToBuffer(r.gasUsed) as any))
receipts.push(...blockReceipts)
receiptsSize += Buffer.byteLength(JSON.stringify(blockReceipts))
const receiptsBuffer = Buffer.concat(
receipts.map((r) =>
rlp.encode([
(r as PreByzantiumTxReceipt).stateRoot ?? (r as PostByzantiumTxReceipt).status,
bigIntToBuffer(r.gasUsed),
r.bitvector,
r.logs,
])
)
)
receiptsSize += Buffer.byteLength(receiptsBuffer)
Copy link
Member

Choose a reason for hiding this comment

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

Could you drop a short note what's happening here?

Does this fix some concrete issues? Can't oversee this on a first look.

Copy link
Contributor Author

@ryanio ryanio Apr 5, 2022

Choose a reason for hiding this comment

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

ah yeah, actually you commented on an old version of this code, if you look at the final state in this PR i made it much more simple by using our existing encodeReceipt function. this is simply keeping track of the size of the GetReceipts devp2p response, so we can respect capping at 10mib as the spec suggests.

// From spec: The recommended soft limit for Receipts responses is 2 MiB.
if (receiptsSize >= 2097152) {
break
Expand Down