Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ members = [
"crates/tagged",
"crates/tagged-debug-derive",
"crates/util",
"crates/validator",
"crates/version",
]
exclude = ["crates/load-test", "utils/pathfinder-probe"]
Expand Down
4 changes: 3 additions & 1 deletion crates/pathfinder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path = "src/lib.rs"
cairo-native = ["pathfinder-executor/cairo-native"]
consensus-integration-tests = []
tokio-console = ["console-subscriber", "tokio/tracing"]
p2p = ["pathfinder-consensus"]
p2p = ["pathfinder-consensus", "pathfinder-validator/p2p"]

[dependencies]
anyhow = { workspace = true }
Expand Down Expand Up @@ -55,6 +55,7 @@ pathfinder-retry = { path = "../retry" }
pathfinder-rpc = { path = "../rpc" }
pathfinder-serde = { path = "../serde" }
pathfinder-storage = { path = "../storage" }
pathfinder-validator = { path = "../validator" }
pathfinder-version = { path = "../version" }
primitive-types = { workspace = true }
rand = { workspace = true }
Expand Down Expand Up @@ -91,6 +92,7 @@ pathfinder-compiler = { path = "../compiler" }
pathfinder-executor = { path = "../executor" }
pathfinder-rpc = { path = "../rpc" }
pathfinder-storage = { path = "../storage", features = ["small_aggregate_filters"] }
pathfinder-validator = { path = "../validator", features = ["skip-commitment-validation"] }
pretty_assertions_sorted = { workspace = true }
proptest = { workspace = true }
rstest = { workspace = true }
Expand Down
5 changes: 1 addition & 4 deletions crates/pathfinder/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ use p2p::consensus::Event;
use pathfinder_common::{consensus_info, ChainId};
use pathfinder_gas_price::L1GasPriceProvider;
use pathfinder_storage::Storage;
use pathfinder_validator::ValidatorWorkerPool;
use tokio::sync::{mpsc, watch};

use crate::config::integration_testing::InjectFailureConfig;
use crate::config::ConsensusConfig;
use crate::validator::ValidatorWorkerPool;
use crate::SyncMessageToConsensus;

mod error;
pub use error::{ProposalError, ProposalHandlingError};

#[cfg(feature = "p2p")]
mod inner;

Expand Down
7 changes: 3 additions & 4 deletions crates/pathfinder/src/consensus/inner/batch_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ use p2p_proto::consensus as proto_consensus;
use pathfinder_common::DecidedBlocks;
use pathfinder_gas_price::{L1GasPriceProvider, L2GasPriceProvider};
use pathfinder_storage::Storage;

use crate::consensus::ProposalHandlingError;
use crate::validator::{
use pathfinder_validator::error::ProposalHandlingError;
use pathfinder_validator::{
should_defer_validation,
TransactionExt,
ValidatorStage,
Expand Down Expand Up @@ -379,13 +378,13 @@ mod tests {
use pathfinder_crypto::Felt;
use pathfinder_executor::{ConcurrentStateReader, ExecutorWorkerPool};
use pathfinder_storage::StorageBuilder;
use pathfinder_validator::{ProdTransactionMapper, ValidatorBlockInfoStage};

use super::*;
use crate::consensus::inner::dummy_proposal::{
create_test_proposal_init,
create_transaction_batch,
};
use crate::validator::{ProdTransactionMapper, ValidatorBlockInfoStage};

/// Creates a worker pool for tests.
fn create_test_worker_pool() -> ValidatorWorkerPool {
Expand Down
2 changes: 1 addition & 1 deletion crates/pathfinder/src/consensus/inner/dummy_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use pathfinder_consensus::Round;
use pathfinder_crypto::Felt;
use pathfinder_executor::{ConcurrentStateReader, ExecutorWorkerPool};
use pathfinder_storage::Storage;
use pathfinder_validator::{ProdTransactionMapper, ValidatorBlockInfoStage};
use rand::seq::SliceRandom;
use rand::{thread_rng, Rng, SeedableRng};

use crate::devnet::{self, strictly_increasing_timestamp, Account};
use crate::validator::{ProdTransactionMapper, ValidatorBlockInfoStage};

// TODO consider waiting for the parent block to land in the decided blocks
/// Blocks consensus tasks's processing loop until the parent block of height is
Expand Down
28 changes: 13 additions & 15 deletions crates/pathfinder/src/consensus/inner/p2p_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ use pathfinder_consensus::{
use pathfinder_executor::{ConcurrentStateReader, ExecutorWorkerPool};
use pathfinder_gas_price::{L1GasPriceProvider, L2GasPriceConstants, L2GasPriceProvider};
use pathfinder_storage::{Storage, Transaction, TransactionBehavior};
use pathfinder_validator::error::{ProposalError, ProposalHandlingError};
use pathfinder_validator::{
should_defer_validation,
ProdTransactionMapper,
TransactionExt,
ValidatorBlockInfoStage,
ValidatorStage,
ValidatorWorkerPool,
};
use tokio::sync::{mpsc, watch};

use super::gossip_retry::{GossipHandler, GossipRetryConfig};
Expand All @@ -54,15 +63,6 @@ use crate::consensus::inner::batch_execution::{
ProposalCommitmentWithOrigin,
};
use crate::consensus::inner::create_empty_block;
use crate::consensus::{ProposalError, ProposalHandlingError};
use crate::validator::{
should_defer_validation,
ProdTransactionMapper,
TransactionExt,
ValidatorBlockInfoStage,
ValidatorStage,
ValidatorWorkerPool,
};
use crate::SyncMessageToConsensus;

#[cfg(test)]
Expand Down Expand Up @@ -427,8 +427,6 @@ pub fn spawn(
use pathfinder_common::StateCommitment;
use pathfinder_merkle_tree::starknet_state::update_starknet_state;

use crate::validator;

let starknet_version = block.header.starknet_version;
let state_commitment = update_starknet_state(
&main_db_tx,
Expand All @@ -451,12 +449,12 @@ pub fn spawn(
let resp = match state_commitment {
Ok(state_commitment) => {
if state_commitment == block.header.state_commitment {
validator::ValidationResult::Valid
pathfinder_validator::ValidationResult::Valid
} else {
validator::ValidationResult::Invalid
pathfinder_validator::ValidationResult::Invalid
}
}
Err(e) => validator::ValidationResult::Error(e),
Err(e) => pathfinder_validator::ValidationResult::Error(e),
};

reply
Expand Down Expand Up @@ -1593,13 +1591,13 @@ mod tests {
use pathfinder_crypto::Felt;
use pathfinder_executor::{ConcurrentStateReader, ExecutorWorkerPool};
use pathfinder_storage::StorageBuilder;
use pathfinder_validator::ValidatorWorkerPool;

use super::*;
use crate::consensus::inner::dummy_proposal::{
create_with_invalid_l1_handler_transactions,
ProposalCreationConfig,
};
use crate::validator::ValidatorWorkerPool;

/// Creates a worker pool for tests.
fn create_test_worker_pool() -> ValidatorWorkerPool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use pathfinder_common::{
use pathfinder_consensus::ConsensusCommand;
use pathfinder_crypto::Felt;
use pathfinder_storage::{Storage, StorageBuilder};
use pathfinder_validator::ValidatorWorkerPool;
use tokio::sync::{mpsc, watch};
use tokio::time::error::Elapsed;
use tokio::time::timeout;
Expand All @@ -41,7 +42,6 @@ use crate::consensus::inner::{
P2PTaskConfig,
P2PTaskEvent,
};
use crate::validator::ValidatorWorkerPool;
use crate::SyncMessageToConsensus;

/// Helper struct to setup and manage the test environment (databases,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use p2p::consensus::HeightAndRound;
use p2p_proto::consensus::{ProposalInit, ProposalPart};
use pathfinder_common::ContractAddress;

use crate::consensus::{ProposalError, ProposalHandlingError};
use pathfinder_validator::error::{ProposalError, ProposalHandlingError};

/// Validates the structure of incoming proposal parts and stores them.
///
Expand Down
12 changes: 6 additions & 6 deletions crates/pathfinder/src/devnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ use pathfinder_executor::{ConcurrentStateReader, ExecutorWorkerPool};
use pathfinder_merkle_tree::starknet_state::update_starknet_state;
use pathfinder_storage::pruning::BlockchainHistoryMode;
use pathfinder_storage::{Storage, StorageBuilder, TriePruneMode};

pub use crate::devnet::account::Account;
use crate::devnet::class::{preprocess_sierra, PrepocessedSierra};
use crate::devnet::fixtures::RESOURCE_BOUNDS;
use crate::validator::{
use pathfinder_validator::{
ProdTransactionMapper,
ValidatorBlockInfoStage,
ValidatorTransactionBatchStage,
ValidatorWorkerPool,
};

pub use crate::devnet::account::Account;
use crate::devnet::class::{preprocess_sierra, PrepocessedSierra};
use crate::devnet::fixtures::RESOURCE_BOUNDS;

mod account;
mod class;
mod contract;
Expand Down Expand Up @@ -440,11 +440,11 @@ pub mod tests {
use pathfinder_executor::{ConcurrentStateReader, ExecutorWorkerPool};
use pathfinder_merkle_tree::starknet_state::update_starknet_state;
use pathfinder_storage::{Storage, StorageBuilder};
use pathfinder_validator::{ProdTransactionMapper, ValidatorWorkerPool};
use tempfile::TempDir;

use crate::devnet::account::Account;
use crate::devnet::{fixtures, init_db, init_proposal_and_validator, BootDb};
use crate::validator::{ProdTransactionMapper, ValidatorWorkerPool};

#[test_log::test]
fn init_declare_deploy_invoke_hello_abi() {
Expand Down
4 changes: 1 addition & 3 deletions crates/pathfinder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pub mod monitoring;
pub mod p2p_network;
pub mod state;
pub mod sync;
pub mod validator;

pub enum SyncMessageToConsensus {
/// Ask consensus for the finalized and **decided upon** block with given
/// number. The only difference from a committed block is that the state
Expand Down Expand Up @@ -37,4 +35,4 @@ pub enum SyncMessageToConsensus {
pub type ConsensusFinalizedBlockReply =
tokio::sync::oneshot::Sender<Option<Box<pathfinder_common::ConsensusFinalizedL2Block>>>;

pub type ValidateBlockReply = tokio::sync::oneshot::Sender<validator::ValidationResult>;
pub type ValidateBlockReply = tokio::sync::oneshot::Sender<pathfinder_validator::ValidationResult>;
38 changes: 38 additions & 0 deletions crates/validator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "pathfinder-validator"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
rust-version = { workspace = true }

[features]
p2p = []
skip-commitment-validation = []

[dependencies]
anyhow = { workspace = true }
p2p = { path = "../p2p" }
p2p_proto = { path = "../p2p_proto" }
pathfinder-block-commitments = { path = "../block-commitments" }
pathfinder-class-hash = { path = "../class-hash" }
pathfinder-common = { path = "../common" }
pathfinder-compiler = { path = "../compiler" }
pathfinder-executor = { path = "../executor" }
pathfinder-gas-price = { path = "../gas-price" }
pathfinder-rpc = { path = "../rpc" }
pathfinder-storage = { path = "../storage" }
rayon = { workspace = true }
serde_json = { workspace = true }
starknet_api = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
pathfinder-common = { path = "../common", features = ["full-serde"] }
pathfinder-crypto = { path = "../crypto" }
pathfinder-executor = { path = "../executor" }
pathfinder-storage = { path = "../storage", features = ["small_aggregate_filters"] }
rstest = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use pathfinder_storage::StorageError;

use crate::validator::WrongValidatorStageError;
use crate::WrongValidatorStageError;

/// Errors that can occur when handling incoming proposal parts.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ use pathfinder_gas_price::{
L2GasPriceValidationResult,
};

use crate::consensus::ProposalHandlingError;
pub mod error;

use crate::error::ProposalHandlingError;

/// TODO: Use this type as validation result.
pub enum ValidationResult {
Expand Down Expand Up @@ -275,7 +277,7 @@ impl ValidatorBlockInfoStage {
///
/// Used only for testing and dummy proposal creation.
#[cfg(any(test, feature = "p2p"))]
pub(crate) fn skip_validation(
pub fn skip_validation(
Comment thread
zvolin marked this conversation as resolved.
self,
block_info: BlockInfo,
main_storage: Storage,
Expand Down Expand Up @@ -767,7 +769,7 @@ impl ValidatorTransactionBatchStage {
// Skip commitment validation in tests when using dummy commitment (ZERO)
// This allows e2e tests to focus on batch execution logic without commitment
// complexity
#[cfg(test)]
#[cfg(any(test, feature = "skip-commitment-validation"))]
if expected_proposal_commitment.0.is_zero() {
return Ok(block);
}
Expand Down Expand Up @@ -1194,7 +1196,7 @@ mod tests {
use rstest::rstest;

use super::*;
use crate::consensus::ProposalError;
use crate::error::ProposalError;

/// Creates a worker pool for tests.
fn create_test_worker_pool() -> ValidatorWorkerPool {
Expand Down
Loading