diff --git a/crates/sequencing/papyrus_consensus/src/manager_test.rs b/crates/sequencing/papyrus_consensus/src/manager_test.rs index e186c23f0e1..7d16c370dba 100644 --- a/crates/sequencing/papyrus_consensus/src/manager_test.rs +++ b/crates/sequencing/papyrus_consensus/src/manager_test.rs @@ -22,7 +22,6 @@ use papyrus_protobuf::consensus::{ }; use papyrus_test_utils::{get_rng, GetTestInstance}; use starknet_api::block::{BlockHash, BlockNumber}; -use starknet_api::transaction::Transaction; use starknet_types_core::felt::Felt; use super::{run_consensus, MultiHeightManager}; @@ -52,7 +51,6 @@ mock! { #[async_trait] impl ConsensusContext for TestContext { - type ProposalChunk = Transaction; type ProposalPart = ProposalPart; async fn build_proposal( diff --git a/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs b/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs index ee5f2cd0627..f32c58b1756 100644 --- a/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs +++ b/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs @@ -11,7 +11,7 @@ use super::SingleHeightConsensus; use crate::config::TimeoutsConfig; use crate::single_height_consensus::{ShcEvent, ShcReturn, ShcTask}; use crate::state_machine::StateMachineEvent; -use crate::test_utils::{precommit, prevote, MockProposalPart, MockTestContext, TestBlock}; +use crate::test_utils::{precommit, prevote, MockTestContext, TestBlock, TestProposalPart}; use crate::types::{ConsensusError, ValidatorId, DEFAULT_VALIDATOR_ID}; lazy_static! { @@ -69,7 +69,7 @@ async fn handle_proposal( ) -> ShcReturn { // Send the proposal from the peer. let (mut content_sender, content_receiver) = mpsc::channel(CHANNEL_SIZE); - content_sender.send(MockProposalPart(1)).await.unwrap(); + content_sender.send(TestProposalPart(1)).await.unwrap(); shc.handle_proposal(context, PROPOSAL_INIT.clone(), content_receiver).await.unwrap() } diff --git a/crates/sequencing/papyrus_consensus/src/test_utils.rs b/crates/sequencing/papyrus_consensus/src/test_utils.rs index 32ea37b75ff..e05afdb6e72 100644 --- a/crates/sequencing/papyrus_consensus/src/test_utils.rs +++ b/crates/sequencing/papyrus_consensus/src/test_utils.rs @@ -8,14 +8,7 @@ use papyrus_protobuf::converters::ProtobufConversionError; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_types_core::felt::Felt; -use crate::types::{ - ConsensusContext, - ConsensusError, - ProposalContentId, - Round, - ValidatorId, - DEFAULT_VALIDATOR_ID, -}; +use crate::types::{ConsensusContext, ConsensusError, ProposalContentId, Round, ValidatorId}; /// Define a consensus block which can be used to enable auto mocking Context. #[derive(Debug, PartialEq, Clone)] @@ -25,36 +18,45 @@ pub struct TestBlock { } #[derive(Debug, PartialEq, Clone)] -pub struct MockProposalPart(pub u64); - -impl From for MockProposalPart { +pub enum TestProposalPart { + Init(ProposalInit), + Fin(ProposalFin), +} +impl From for TestProposalPart { fn from(init: ProposalInit) -> Self { - MockProposalPart(init.height.0) + TestProposalPart::Init(init) } } -impl TryFrom for ProposalInit { +impl TryFrom for ProposalInit { type Error = ProtobufConversionError; - fn try_from(part: MockProposalPart) -> Result { - Ok(ProposalInit { - height: BlockNumber(part.0), - proposer: DEFAULT_VALIDATOR_ID.into(), - ..Default::default() - }) + fn try_from(part: TestProposalPart) -> Result { + match part { + TestProposalPart::Init(init) => Ok(init), + _ => Err(ProtobufConversionError::WrongEnumVariant { + type_description: "TestProposalPart", + expected: "Init", + value_as_str: format!("{:?}", part), + }), + } } } -impl From for Vec { - fn from(part: MockProposalPart) -> Vec { - vec![u8::try_from(part.0).expect("Invalid MockProposalPart conversion")] +impl From for Vec { + fn from(part: TestProposalPart) -> Vec { + let init = match part { + TestProposalPart::Init(init) => init, + _ => panic!("Invalid TestProposalPart conversion"), + }; + >::try_from(init).expect("Invalid MockProposalPart conversion") } } -impl TryFrom> for MockProposalPart { +impl TryFrom> for TestProposalPart { type Error = ProtobufConversionError; fn try_from(value: Vec) -> Result { - Ok(MockProposalPart(value[0].into())) + Ok(TestProposalPart::Init(value.try_into()?)) } } @@ -64,8 +66,7 @@ mock! { #[async_trait] impl ConsensusContext for TestContext { - type ProposalChunk = u32; - type ProposalPart = MockProposalPart; + type ProposalPart = TestProposalPart; async fn build_proposal( &mut self, @@ -79,7 +80,7 @@ mock! { round: Round, proposer: ValidatorId, timeout: Duration, - content: mpsc::Receiver + content: mpsc::Receiver ) -> oneshot::Receiver<(ProposalContentId, ProposalFin)>; async fn repropose( diff --git a/crates/sequencing/papyrus_consensus/src/types.rs b/crates/sequencing/papyrus_consensus/src/types.rs index 797100b6f4d..561aabd5e06 100644 --- a/crates/sequencing/papyrus_consensus/src/types.rs +++ b/crates/sequencing/papyrus_consensus/src/types.rs @@ -30,10 +30,8 @@ pub const DEFAULT_VALIDATOR_ID: u64 = 100; /// Interface for consensus to call out to the node. #[async_trait] pub trait ConsensusContext { - /// The chunks of content returned when iterating the proposal. - // In practice I expect this to match the type sent to the network - // (papyrus_protobuf::ConsensusMessage), and not to be specific to just the block's content. - type ProposalChunk; // TODO(guyn): deprecate this (and replace by ProposalPart) + /// The parts of the proposal that are streamed in. + /// Must contain at least the ProposalInit and ProposalFin. type ProposalPart: TryFrom, Error = ProtobufConversionError> + Into> + TryInto diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs index 9a34d1af07c..5581abac189 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs @@ -82,7 +82,6 @@ impl PapyrusConsensusContext { #[async_trait] impl ConsensusContext for PapyrusConsensusContext { - type ProposalChunk = Transaction; type ProposalPart = ProposalPart; async fn build_proposal( diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs index 293d53414e3..92e45cd85db 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs @@ -40,7 +40,6 @@ use starknet_api::block::{ NonzeroGasPrice, }; use starknet_api::executable_transaction::Transaction as ExecutableTransaction; -use starknet_api::transaction::Transaction; use starknet_batcher_types::batcher_types::{ DecisionReachedInput, GetProposalContent, @@ -134,8 +133,6 @@ impl SequencerConsensusContext { #[async_trait] impl ConsensusContext for SequencerConsensusContext { - // TODO(guyn): Switch to ProposalPart when done with the streaming integration. - type ProposalChunk = Vec; type ProposalPart = ProposalPart; async fn build_proposal(