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

7935: Add E2StoreReader #8329

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Matilda-Clerke
Copy link
Contributor

PR description

Adds an Es2StoreReader for reading e2 files such as era and era1 files

Fixed Issue(s)

#7935

* @param beaconState The beacon state
* @param slot The slot number
*/
public record E2BeaconState(byte[] beaconState, int slot) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need the beacon types as we won't be writing or reading the beacon data from anywhere

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 was initially writing a generic e2 file reader. Are we unlikely to use era files for populating the chain beyond the merge? I realise we can populate it through the p2p network, or potentially from portal, but it shouldn't be difficult to support this too.

* @param signedBeaconBlock The signed beacon block
* @param slot The slot number
*/
public record E2SignedBeaconBlock(byte[] signedBeaconBlock, int slot) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, we don't need this type

* @param startingSlot The first slot number indexed by this slot index
* @param indexes The indexes of the slots indexed by this slot index
*/
public record E2SlotIndex(long startingSlot, List<Long> indexes) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also don't need this

Comment on lines +24 to +38
void handleBeaconState(E2BeaconState beaconState);

/**
* Handles the supplied E2SlotIndex
*
* @param slotIndex the E2SlotIndex
*/
void handleSlotIndex(E2SlotIndex slotIndex);

/**
* Handles the supplied E2SignedBeaconBlock
*
* @param signedBeaconBlock the E2SignedBeaconBlock
*/
void handleSignedBeaconBlock(E2SignedBeaconBlock signedBeaconBlock);
Copy link
Contributor

Choose a reason for hiding this comment

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

can remove the beacon handlers, they won't be in the era1 files we use

Comment on lines +24 to +26
COMPRESSED_SIGNED_BEACON_BLOCK(new byte[] {0x01, 0x00}),
/** A snappy compressed, SSZ encoded, beacon state */
COMPRESSED_BEACON_STATE(new byte[] {0x02, 0x00}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Also can remove these as we don't need to parse era files

* @param header The execution block header
* @param slot The slot number
*/
public record E2ExecutionBlockHeader(byte[] header, int slot) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

slot should be blockIndex

* @param receipts The execution block's transaction receipts
* @param slot The slot number
*/
public record E2ExecutionBlockReceipts(byte[] receipts, int slot) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

slot should be blockIndex

import org.xerial.snappy.SnappyFramedInputStream;

/** Reads E2 store file such a .era and .era1 */
public class E2StoreReader {
Copy link
Contributor

Choose a reason for hiding this comment

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

Think it would be nicer to have this in the e2 package as it's not general io it's specific to era

Comment on lines +105 to +122
case COMPRESSED_BEACON_STATE -> {
byte[] compressedBeaconStateArray = inputStream.readNBytes(length);
try (SnappyFramedInputStream decompressionStream =
snappyFactory.createFramedInputStream(compressedBeaconStateArray)) {
// TODO: decode with SSZ
listener.handleBeaconState(
new E2BeaconState(decompressionStream.readAllBytes(), slot++));
}
}
case COMPRESSED_SIGNED_BEACON_BLOCK -> {
byte[] compressedSignedBeaconBlockArray = inputStream.readNBytes(length);
try (SnappyFramedInputStream decompressionStream =
snappyFactory.createFramedInputStream(compressedSignedBeaconBlockArray)) {
// TODO: decode with SSZ
listener.handleSignedBeaconBlock(
new E2SignedBeaconBlock(decompressionStream.readAllBytes(), slot++));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need to decode these

}
case COMPRESSED_EXECUTION_BLOCK_HEADER -> {
byte[] compressedExecutionBlockHeader = inputStream.readNBytes(length);
try (SnappyFramedInputStream decompressionStream =
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have already read the bytes it would be simpler to use SnappyCompressor.decompress to decompress snappy instead of creating the snappy input stream

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, the use of snappy framing means this won't work afaik. When I tried it on the beacon state initially, it failed to decompress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants