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

Fix parsing of blocks in .era #3899

Merged
merged 4 commits into from
Mar 4, 2025
Merged

Fix parsing of blocks in .era #3899

merged 4 commits into from
Mar 4, 2025

Conversation

acolytec3
Copy link
Contributor

@acolytec3 acolytec3 commented Mar 3, 2025

2 updates

  • fixes a bug in how the block slotIndex offsets were computed for missed slots (i.e. when a Beacon Block wasn't produced for a given slot)
  • Updates micro-eth-signer to v0.14.0 across the monorepo so we can remove the SSZ types for the pre-Deneb forks (since Paul has kindly added them to m-eth

Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.95%. Comparing base (0a419c3) to head (0ba85aa).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 76.80% <ø> (ø)
blockchain 85.43% <ø> (ø)
client 66.23% <ø> (ø)
common 90.80% <ø> (ø)
devp2p 76.33% <ø> (ø)
ethash 81.04% <ø> (ø)
evm 68.61% <ø> (ø)
genesis 99.84% <ø> (ø)
mpt 59.68% <ø> (+0.03%) ⬆️
rlp 69.70% <ø> (ø)
statemanager 66.85% <ø> (ø)
tx 81.20% <ø> (ø)
util 79.30% <ø> (ø)
vm 57.44% <ø> (ø)
wallet 83.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

else if (slot < ssz.ForkSlots.Capella)
return ssz.BellatrixSignedBeaconBlock.decode(data.data as Uint8Array)
else if (slot < ssz.ForkSlots.Deneb)
return ssz.CapellaSignedBeaconBlock.decode(data.data as Uint8Array)
else return ssz.ETH2_TYPES.SignedBeaconBlock.decode(data.data as Uint8Array)
Copy link
Contributor

Choose a reason for hiding this comment

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

so the eth2_types has latest i.e. deneb in this case?
hopefully microsigner can provider the better api to get types for some slot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Per my other comment, will work with Paul on a better structure for these

else if (stateSlot < ForkSlots.Capella)
return BellatrixBeaconState.decode(data.data as Uint8Array)
else if (stateSlot < ForkSlots.Deneb) return CapellaBeaconState.decode(data.data as Uint8Array)
if (stateSlot < ssz.ForkSlots.Altair) return ssz.Phase0BeaconState.decode(data.data as Uint8Array)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this if else still works if two/more forks are scheduled on the same slot, but adding a comment to that effect will be helpful to a third reader or may be (much) later to ourselves as well lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I'm not sure what you mean. This code can't stay static and will have to update with more forks down the line. There's probably a better way to do this but I haven't set up a forkFinder sort of helper method and I really want to do another pr to meth to put all the fork specific containers under a ssz.ETH2_TYPES['fork'].containerType structure and not the way it is now where everything is exported from the base

@@ -40,7 +27,8 @@ export const readSlotIndex = (bytes: Uint8Array): SlotIndex => {

for (let i = 0; i < count; i++) {
const slotEntry = slotIndexEntry.data.subarray((i + 1) * 8, (i + 2) * 8)
const slotOffset = Number(new DataView(slotEntry.slice(0, 8).buffer).getBigInt64(0, true))
let slotOffset = Number(new DataView(slotEntry.slice(0, 8).buffer).getBigInt64(0, true))
if (slotOffset === -1 * recordStart) slotOffset = 0 // If offset is the same as the block record start, this is a skipped slot
Copy link
Contributor

@g11tech g11tech Mar 4, 2025

Choose a reason for hiding this comment

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

UPDATE: so the era spec offset 0 encoding for missed data/block might mean absolute 0 offset which then makes sense here. In that case I would suggest pushing undefined in slotOffsets to make it type friendly way of detecting skipped data/slots


previous comment:

slotoffset can be a negative number? ah so all offsets are negative numbers reading file from back

but this doesn't make sense as some block/state could be recordStart bytes to the left of the slot index

image

}
throw err
}
if (indices.blockSlotIndex!.slotOffsets[x] === 0) continue // skip empty slots
Copy link
Contributor

@g11tech g11tech Mar 4, 2025

Choose a reason for hiding this comment

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

ok so this is handled here 👍 , may be the equality indices.blockSlotIndex!.slotOffsets[x] === -1 *indices.blockSlotIndex!.recordStart should be moved here instead of pushing 0 over there. whatever seems more cleaner to you

or how about pushing undefined in slotOffsets than 0 ? that is more type friendly way of dealing with skipped slots

Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

lgtm

@acolytec3 acolytec3 merged commit 38444f8 into master Mar 4, 2025
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants