Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6961805
fix: empty proposal contains block info
CHr15F0x Nov 13, 2025
860d947
test: update justfile, remove test-consensus dep from other targets
CHr15F0x Nov 18, 2025
729dd61
test(p2p_task_tests): update the test + handler fixes
CHr15F0x Nov 18, 2025
9c0d741
chore: clippy
CHr15F0x Nov 19, 2025
2103b6d
refactor: extract common code into fn
CHr15F0x Nov 19, 2025
7f6ebe7
fixup: enforce order of the first 2 parts only
CHr15F0x Nov 20, 2025
1922010
chore: clippy
CHr15F0x Nov 20, 2025
0c516a9
fixup: review related changes
CHr15F0x Nov 20, 2025
7d7d9b0
test(p2p_task): handle incoming proposal part proptest
CHr15F0x Nov 27, 2025
b396a5d
refactor: make upper layers generic over block executor
CHr15F0x Nov 27, 2025
972500c
refactor: make upper layers generic over transaction mapper and trans…
CHr15F0x Nov 27, 2025
6174465
test(handler_proptest): fixup invalid proposal generation
CHr15F0x Nov 27, 2025
5c1a745
test(handler_proptest): fixup empty proposal generation
CHr15F0x Nov 27, 2025
a7399ea
test(handler_proptest): first attempts at running the proptest
CHr15F0x Nov 27, 2025
b7521c8
test(handler_proptest): add fake execution and execution failure trigger
CHr15F0x Nov 28, 2025
4801f0b
fixup! test(handler_proptest): add fake execution and execution failu…
CHr15F0x Nov 28, 2025
39b923c
fix(p2p_task): regressions in handle_incoming_proposal_part
CHr15F0x Nov 28, 2025
22f9235
chore(p2p_task): rename handler_proptests to handler_proptest
CHr15F0x Nov 28, 2025
b2b4f3d
chore: typo
CHr15F0x Nov 28, 2025
3ebadbe
chore: clippy
CHr15F0x Nov 28, 2025
d746eb4
test(handler_proptest): add another regression seed
CHr15F0x Nov 28, 2025
d2fb4f1
test: update justfile
CHr15F0x Nov 28, 2025
df8ae65
test(task_tests): fixup test_proposal_fin_deferred_until_transactions…
CHr15F0x Nov 28, 2025
fc4d47c
refactor: rename task_tests to back p2p_task_test
CHr15F0x Nov 28, 2025
431a76c
fixup! test(task_tests): fixup test_proposal_fin_deferred_until_trans…
CHr15F0x Nov 28, 2025
5270090
fixup! test(task_tests): fixup test_proposal_fin_deferred_until_trans…
CHr15F0x Nov 28, 2025
acf1aaa
doc: update the description of handle_incoming_proposal_part
CHr15F0x Nov 28, 2025
d7051e9
test: remove a TODO which is invalid
CHr15F0x Dec 1, 2025
0f19195
fixup! test: update justfile
CHr15F0x Dec 2, 2025
01bfe7e
test(sync_handlers): add recovered proptest regressions file
CHr15F0x Dec 3, 2025
0982ce0
fixup: a misleading TODO
CHr15F0x Dec 3, 2025
0c9cd4b
chore: typo
CHr15F0x Dec 3, 2025
9c7aa34
refactor: remove validator empty stage, add default to p2p_proto::com…
CHr15F0x Dec 3, 2025
a910e88
feat: recover validator cache state
CHr15F0x Dec 4, 2025
6a8cf31
test(consensus): remove all but 1 ignore in consensus_3_nodes test
CHr15F0x Dec 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,9 @@ opt-level = 3
inherits = "dev"
incremental = false
debug = "line-tables-only"

# [profile.test.package.proptest]
# opt-level = 3

# [profile.test.package.rand_chacha]
# opt-level = 3
144 changes: 97 additions & 47 deletions crates/executor/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::types::{
transaction_declared_deprecated_class,
transaction_type,
BlockInfo,
Receipt,
ReceiptAndEvents,
StateDiff,
};
use crate::{ExecutionState, Transaction, TransactionExecutionError};
Expand All @@ -27,15 +27,66 @@ pub struct BlockExecutor {
next_txn_idx: usize,
}

type ReceiptAndEvents = (Receipt, Vec<pathfinder_common::event::Event>);
pub trait BlockExecutorExt {
fn new(
chain_id: ChainId,
block_info: BlockInfo,
eth_fee_address: ContractAddress,
strk_fee_address: ContractAddress,
db_conn: pathfinder_storage::Connection,
) -> anyhow::Result<Self>
where
Self: Sized;

/// Create a new BlockExecutor from a StateUpdate
/// This allows reconstructing an executor from a stored state diff
/// checkpoint
fn new_with_pending_state(
chain_id: ChainId,
block_info: BlockInfo,
eth_fee_address: ContractAddress,
strk_fee_address: ContractAddress,
db_conn: pathfinder_storage::Connection,
pending_state: std::sync::Arc<pathfinder_common::StateUpdate>,
) -> anyhow::Result<Self>
where
Self: Sized;

/// Evecute a batch of transactions in the current block.
fn execute(
&mut self,
txns: Vec<Transaction>,
) -> Result<Vec<ReceiptAndEvents>, TransactionExecutionError>;

fn finalize(self) -> anyhow::Result<StateDiff>;

/// This allows for setting the correct starting index for chained executors
fn set_transaction_index(&mut self, index: usize);

/// Extract state diff without consuming the executor
/// This allows extracting the diff for rollback scenarios without losing
/// the executor
///
/// Note: This method does NOT call `executor.finalize()`, which means it
/// doesn't include stateful compression changes (system contract 0x2
/// updates). These changes are only needed when finalizing the proposal
/// for commitment computation, not for intermediate diff extraction
/// during batch execution.
fn extract_state_diff(&self) -> anyhow::Result<StateDiff>;
}

impl BlockExecutor {
pub fn new(
/// Create a new BlockExecutor with a pre-existing initial state
/// This allows for executor chaining where the new executor starts with
/// the final state of a previous executor
#[cfg(test)]
pub fn new_with_initial_state(
chain_id: ChainId,
block_info: BlockInfo,
eth_fee_address: ContractAddress,
strk_fee_address: ContractAddress,
db_conn: pathfinder_storage::Connection,
initial_state: PathfinderExecutionState<ConcurrentStorageAdapter>,
) -> anyhow::Result<Self> {
let execution_state = ExecutionState::validation(
chain_id,
Expand All @@ -47,12 +98,12 @@ impl BlockExecutor {
None,
);
let storage_adapter = ConcurrentStorageAdapter::new(db_conn);
let executor = create_executor(storage_adapter, execution_state)?;
let initial_state = executor
.block_state
.as_ref()
.expect(BLOCK_STATE_ACCESS_ERR)
.clone();
let mut executor = create_executor(storage_adapter, execution_state)?;

// Set the initial state
if let Some(block_state) = executor.block_state.as_mut() {
*block_state = initial_state.clone();
}

Ok(Self {
executor,
Expand All @@ -62,16 +113,36 @@ impl BlockExecutor {
})
}

/// Create a new BlockExecutor with a pre-existing initial state
/// This allows for executor chaining where the new executor starts with
/// the final state of a previous executor
pub fn new_with_initial_state(
/// Get the final state of the executor
/// This allows for state extraction before finalizing
#[cfg(test)]
fn get_final_state(
&self,
) -> anyhow::Result<PathfinderExecutionState<ConcurrentStorageAdapter>> {
let final_state = self
.executor
.block_state
.as_ref()
.expect(BLOCK_STATE_ACCESS_ERR)
.clone();
Ok(final_state)
}

/// Get the current transaction index
/// This allows for tracking transaction indices across chained executors
#[cfg(test)]
pub fn get_transaction_index(&self) -> usize {
self.next_txn_idx
}
}

impl BlockExecutorExt for BlockExecutor {
fn new(
chain_id: ChainId,
block_info: BlockInfo,
eth_fee_address: ContractAddress,
strk_fee_address: ContractAddress,
db_conn: pathfinder_storage::Connection,
initial_state: PathfinderExecutionState<ConcurrentStorageAdapter>,
) -> anyhow::Result<Self> {
let execution_state = ExecutionState::validation(
chain_id,
Expand All @@ -83,12 +154,12 @@ impl BlockExecutor {
None,
);
let storage_adapter = ConcurrentStorageAdapter::new(db_conn);
let mut executor = create_executor(storage_adapter, execution_state)?;

// Set the initial state
if let Some(block_state) = executor.block_state.as_mut() {
*block_state = initial_state.clone();
}
let executor = create_executor(storage_adapter, execution_state)?;
let initial_state = executor
.block_state
.as_ref()
.expect(BLOCK_STATE_ACCESS_ERR)
.clone();

Ok(Self {
executor,
Expand All @@ -101,7 +172,7 @@ impl BlockExecutor {
/// Create a new BlockExecutor from a StateUpdate
/// This allows reconstructing an executor from a stored state diff
/// checkpoint
pub fn new_with_pending_state(
fn new_with_pending_state(
chain_id: ChainId,
block_info: BlockInfo,
eth_fee_address: ContractAddress,
Expand Down Expand Up @@ -135,7 +206,7 @@ impl BlockExecutor {
}

/// Evecute a batch of transactions in the current block.
pub fn execute(
fn execute(
&mut self,
txns: Vec<Transaction>,
) -> Result<Vec<ReceiptAndEvents>, TransactionExecutionError> {
Expand Down Expand Up @@ -196,7 +267,7 @@ impl BlockExecutor {
}

/// Finalizes block execution and returns the state diff for the block.
pub fn finalize(self) -> anyhow::Result<StateDiff> {
fn finalize(self) -> anyhow::Result<StateDiff> {
let Self {
mut executor,
initial_state,
Expand All @@ -216,29 +287,9 @@ impl BlockExecutor {
Ok(diff)
}

/// Get the final state of the executor
/// This allows for state extraction before finalizing
pub fn get_final_state(
&self,
) -> anyhow::Result<PathfinderExecutionState<ConcurrentStorageAdapter>> {
let final_state = self
.executor
.block_state
.as_ref()
.expect(BLOCK_STATE_ACCESS_ERR)
.clone();
Ok(final_state)
}

/// Get the current transaction index
/// This allows for tracking transaction indices across chained executors
pub fn get_transaction_index(&self) -> usize {
self.next_txn_idx
}

/// Set the transaction index
/// This allows for setting the correct starting index for chained executors
pub fn set_transaction_index(&mut self, index: usize) {
fn set_transaction_index(&mut self, index: usize) {
self.next_txn_idx = index;
}

Expand All @@ -251,7 +302,7 @@ impl BlockExecutor {
/// updates). These changes are only needed when finalizing the proposal
/// for commitment computation, not for intermediate diff extraction
/// during batch execution.
pub fn extract_state_diff(&self) -> anyhow::Result<StateDiff> {
fn extract_state_diff(&self) -> anyhow::Result<StateDiff> {
let current_state = self
.executor
.block_state
Expand All @@ -272,7 +323,6 @@ impl BlockExecutor {

#[cfg(test)]
mod tests {

use pathfinder_common::state_update::StateUpdateData;
use pathfinder_common::transaction::{L1HandlerTransaction, TransactionVariant};
use pathfinder_common::{
Expand All @@ -288,7 +338,7 @@ mod tests {
use pathfinder_storage::StorageBuilder;

use crate::execution_state::create_executor;
use crate::BlockExecutor;
use crate::{BlockExecutor, BlockExecutorExt as _};

// Fee token addresses (same as in pathfinder_rpc::context)
const ETH_FEE_TOKEN_ADDRESS: ContractAddress =
Expand Down
2 changes: 1 addition & 1 deletion crates/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) mod state_reader;
pub(crate) mod transaction;
pub mod types;

pub use block::BlockExecutor;
pub use block::{BlockExecutor, BlockExecutorExt};
// re-export blockifier transaction type since it's exposed on our API
pub use blockifier::blockifier_versioned_constants::{VersionedConstants, VersionedConstantsError};
pub use blockifier::transaction::account_transaction::{
Expand Down
2 changes: 2 additions & 0 deletions crates/executor/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct Receipt {
pub transaction_index: TransactionIndex,
}

pub type ReceiptAndEvents = (Receipt, Vec<pathfinder_common::event::Event>);

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct BlockInfo {
pub number: BlockNumber,
Expand Down
7 changes: 6 additions & 1 deletion crates/p2p_proto/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ use crate::{proto, ToProtobuf, TryFromProtobuf};
)]
pub struct Hash(pub Felt);

impl Hash {
pub const ZERO: Self = Self(Felt::ZERO);
}

impl std::fmt::Display for Hash {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
Expand Down Expand Up @@ -81,8 +85,9 @@ pub struct BlockId {
pub hash: Hash,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Dummy)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Dummy)]
pub enum L1DataAvailabilityMode {
#[default]
Calldata,
Blob,
}
Expand Down
Loading
Loading