Skip to content

Commit

Permalink
Add handler for Bedrock genesis block in receipts reader
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Nov 18, 2023
1 parent 7a3295a commit bf08693
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
/target

# Datadir
crates/db-utils/testdata/geth
crates/db-utils/testdata/bedrock
21 changes: 16 additions & 5 deletions crates/db-utils/goerli-testdata.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
#!/bin/bash

echo "Downloading Bedrock Goerli datadir from gcloud..."

# Download the Bedrock Goerli datadir from gcloud
echo "Downloading Bedrock Goerli datadir from gcloud..."
curl -L https://datadirs.optimism.io/goerli-bedrock.tar.zst --output goerli-bedrock.tar.zst

echo "Done. Untarring..."

# Untar the datadir
tar --zstd -xvf goerli-bedrock.tar.zst -C testdata
mkdir -p testdata/bedrock
tar --zstd -xvf goerli-bedrock.tar.zst -C testdata/bedrock
rm goerli-bedrock.tar.zst

echo "Done."

# echo "----------------------------------------------------------------------------------"
#
# # Download the Legacy Optimism Goerli datadir from gcloud
# echo "Downloading Legacy Optimism Goerli Archival datadir from gcloud..."
# curl -L https://datadirs.optimism.io/goerli-legacy-archival.tar.zst --output goerli-legacy-archival.tar.zst
# echo "Done Untarring..."
#
# # Untar the datadir
# mkdir -p testdata/legacy-archival
# tar --zstd -xvf goerli-legacy-archival.tar.zst -C testdata/legacy-archival
# rm goerli-legacy-archival.tar.zst
# echo "Done."
17 changes: 11 additions & 6 deletions crates/db-utils/src/leveldb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ impl GethDBReader {
.ok_or(anyhow::anyhow!("Receipts RLP not found"))?;
let rlp_buf = &mut receipts_rlp.as_slice();

// Outer list - consume the header, we don't care about it.
alloy_rlp::Header::decode(rlp_buf)?;
// Outer list - consume the header, we don't care about it. The only block that has a
// zero-length outer list is the Bedrock genesis block.
let outer_header = alloy_rlp::Header::decode(rlp_buf)?;
if outer_header.payload_length == 0 {
return Ok(Vec::default());
}

// Inner list
let rlp_header = alloy_rlp::Header::decode(rlp_buf)?;
let payload_len = rlp_header.payload_length;
Expand Down Expand Up @@ -159,13 +164,13 @@ mod db_test {
use leveldb::{database::Database, options::Options};
use std::path::PathBuf;

const TEST_BLOCK_NO: u64 = 4_000_000;
const TEST_BLOCK_NO: u64 = 4_061_224;

#[test]
#[ignore]
fn sanity_read_header() {
let mut db_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
db_path.push("testdata/geth/chaindata");
db_path.push("testdata/bedrock/geth/chaindata");

let options = Options::new();
let database: Database<DBKey> = Database::open(db_path.as_path(), options).unwrap();
Expand All @@ -178,7 +183,7 @@ mod db_test {
#[ignore]
fn sanity_read_block() {
let mut db_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
db_path.push("testdata/geth/chaindata");
db_path.push("testdata/bedrock/geth/chaindata");

let options = Options::new();
let database: Database<DBKey> = Database::open(db_path.as_path(), options).unwrap();
Expand All @@ -191,7 +196,7 @@ mod db_test {
#[ignore]
fn sanity_read_receipts() {
let mut db_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
db_path.push("testdata/geth/chaindata");
db_path.push("testdata/bedrock/geth/chaindata");

let options = Options::new();
let database: Database<DBKey> = Database::open(db_path.as_path(), options).unwrap();
Expand Down

0 comments on commit bf08693

Please sign in to comment.