Skip to content

Commit

Permalink
Merge pull request #8 from cartridge-gg/release-sync-v0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen authored Oct 3, 2024
2 parents b340ee7 + f4ca975 commit 15d781e
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ More expansive patch notes and explanations may be found in the specific [pathfi
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.14.4] - 2024-10-03

### Fixed

- Pathfinder stops syncing Sepolia testnet at block 218484 because of a block hash mismatch.

## [0.14.3] - 2024-09-23

### Fixed
Expand Down
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lto = true
opt-level = 3

[workspace.package]
version = "0.14.3"
version = "0.14.4"
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.80"
Expand Down
2 changes: 1 addition & 1 deletion crates/load-test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions crates/pathfinder/examples/verify_transaction_commitment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use std::num::NonZeroU32;

use anyhow::Context;
use pathfinder_common::BlockNumber;

/// Verify transaction hashes in a pathfinder database.
///
/// Iterates over all blocks in the database and verifies if the computed
/// transaction hashes match values we store for the block.
///
/// Usage:
/// `cargo run --release -p pathfinder --example verify_transaction_hashes
/// mainnet ./mainnet.sqlite 100`
fn main() -> anyhow::Result<()> {
let database_path = std::env::args().nth(1).unwrap();
let start_block = std::env::args().nth(2).unwrap_or("0".into());

let start_block = start_block
.parse::<u64>()
.context("Parse start block number")?;

let storage = pathfinder_storage::StorageBuilder::file(database_path.into())
.migrate()?
.create_pool(NonZeroU32::new(1).unwrap())
.unwrap();
let mut db = storage
.connection()
.context("Opening database connection")?;

let latest_block_number = {
let tx = db.transaction().unwrap();
tx.block_id(pathfinder_storage::BlockId::Latest)
.context("Fetching latest block number")?
.context("Latest block number does not exist")?
.0
};

println!("Verifying transaction commitments...");

for block_number in start_block..latest_block_number.get() {
if block_number % 10 == 0 {
println!("Block: {block_number}")
}

let tx = db.transaction().unwrap();
let block_id = pathfinder_storage::BlockId::Number(BlockNumber::new_or_panic(block_number));
let header = tx
.block_header(block_id)
.context("Fetching block header")?
.context("Block header missing")?;
let transactions = tx
.transaction_data_for_block(block_id)?
.context("Transaction data missing")?;
drop(tx);

let transactions = transactions
.into_iter()
.map(|(tx, _, _)| tx)
.collect::<Vec<_>>();
let computed_transaction_commitment =
pathfinder_lib::state::block_hash::calculate_transaction_commitment(
&transactions,
header.starknet_version,
)?;

if computed_transaction_commitment != header.transaction_commitment {
println!(
"Mismatch: block {block_number}, calculated {computed_transaction_commitment}",
);
}
}

println!("Done.");

Ok(())
}
8 changes: 7 additions & 1 deletion crates/pathfinder/src/state/block_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,13 @@ fn calculate_transaction_hash_with_signature(tx: &Transaction) -> Felt {
TransactionVariant::InvokeV3(tx) => tx.signature.as_slice(),
TransactionVariant::DeployV0(_)
| TransactionVariant::DeployV1(_)
| TransactionVariant::L1Handler(_) => &[TransactionSignatureElem::ZERO],
| TransactionVariant::L1Handler(_) => &[],
};

let signature = if signature.is_empty() {
&[TransactionSignatureElem::ZERO]
} else {
signature
};

let mut hasher = PoseidonHasher::new();
Expand Down

0 comments on commit 15d781e

Please sign in to comment.