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
33 changes: 22 additions & 11 deletions crates/p2p/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ mod tests {
use libp2p::identity::Keypair;
use p2p_proto::common::{Address, Hash, L1DataAvailabilityMode};
use p2p_proto::consensus::{
BlockInfo,
ProposalFin,
ProposalInit,
ProposalPart,
Expand All @@ -260,8 +259,11 @@ mod tests {
let height_and_round: HeightAndRound = (1, 2).into();

// Create a sample proposal
let block_info = BlockInfo {
let proposal_init = ProposalInit {
height: 100,
round: 2,
valid_round: Some(1),
proposer: Address(Felt::from_hex_str("0x123").unwrap()),
timestamp: 1234567890,
builder: Address(Felt::from_hex_str("0x456").unwrap()),
l1_da_mode: L1DataAvailabilityMode::Calldata,
Expand All @@ -270,8 +272,10 @@ mod tests {
l1_data_gas_price_fri: 3000,
l1_gas_price_wei: 4000,
l1_data_gas_price_wei: 5000,
starknet_version: "".to_string(),
version_constant_commitment: Default::default(),
};
let proposal = ProposalPart::BlockInfo(block_info);
let proposal = ProposalPart::Init(proposal_init);

// Create messages
let messages =
Expand Down Expand Up @@ -301,8 +305,11 @@ mod tests {
let height_and_round: HeightAndRound = (1, 2).into();

// Create a sample proposal
let block_info = BlockInfo {
let proposal_init = ProposalInit {
height: 100,
round: 2,
valid_round: Some(1),
proposer: Address(Felt::from_hex_str("0x123").unwrap()),
timestamp: 1234567890,
builder: Address(Felt::from_hex_str("0x456").unwrap()),
l1_da_mode: L1DataAvailabilityMode::Calldata,
Expand All @@ -311,8 +318,10 @@ mod tests {
l1_data_gas_price_fri: 3000,
l1_gas_price_wei: 4000,
l1_data_gas_price_wei: 5000,
starknet_version: "".to_string(),
version_constant_commitment: Default::default(),
};
let proposal = ProposalPart::BlockInfo(block_info);
let proposal = ProposalPart::Init(proposal_init);

// Create a message
let message = StreamMessage {
Expand Down Expand Up @@ -496,20 +505,23 @@ mod tests {
round: 1,
proposal_commitment: Some(Hash(Felt::from_hex_str("0x123").unwrap())),
voter: Address(Felt::from_hex_str("0x456").unwrap()),
signature: Default::default(),
},
Vote {
vote_type: VoteType::Precommit,
height: 100,
round: 1,
proposal_commitment: Some(Hash(Felt::from_hex_str("0x789").unwrap())),
voter: Address(Felt::from_hex_str("0xabc").unwrap()),
signature: Default::default(),
},
Vote {
vote_type: VoteType::Prevote,
height: 101,
round: 2,
proposal_commitment: None, // NIL vote
voter: Address(Felt::from_hex_str("0xdef").unwrap()),
signature: Default::default(),
},
];
let mut rxs = Vec::new();
Expand Down Expand Up @@ -584,13 +596,8 @@ mod tests {
stream.push(ProposalPart::Init(ProposalInit {
height,
round,
proposer: p2p_proto::common::Address(Felt::from_hex_str("0x123").unwrap()),
valid_round: None,
}));

// BlockInfo
stream.push(ProposalPart::BlockInfo(BlockInfo {
height,
proposer: p2p_proto::common::Address(Felt::from_hex_str("0x123").unwrap()),
timestamp: 1234567890 + base,
builder: p2p_proto::common::Address(Felt::from_hex_str("0x456").unwrap()),
l1_da_mode: p2p_proto::common::L1DataAvailabilityMode::Calldata,
Expand All @@ -599,6 +606,8 @@ mod tests {
l1_data_gas_price_fri: 3000 + base as u128,
l1_gas_price_wei: 4000 + base as u128,
l1_data_gas_price_wei: 5000 + base as u128,
starknet_version: "".to_string(),
version_constant_commitment: Default::default(),
}));

// TransactionBatch (send a few)
Expand All @@ -621,6 +630,8 @@ mod tests {
// ProposalFin
stream.push(ProposalPart::Fin(ProposalFin {
proposal_commitment: p2p_proto::common::Hash(Felt::from_hex_str("0x69420abc").unwrap()),
executed_transaction_count: 3,
fin_payload: None,
}));

((height, round), stream)
Expand Down
9 changes: 7 additions & 2 deletions crates/p2p/src/consensus/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ mod tests {
#[test]
fn test_encode_decode() {
// Create a sample ProposalPart
let block_info = p2p_proto::consensus::BlockInfo {
let proposal_init = p2p_proto::consensus::ProposalInit {
height: 100,
round: 2,
valid_round: Some(1),
proposer: Address(Felt::from_hex_str("0x123").unwrap()),
timestamp: 1234567890,
builder: Address(Felt::from_hex_str("0x456").unwrap()),
l1_da_mode: L1DataAvailabilityMode::Calldata,
Expand All @@ -150,8 +153,10 @@ mod tests {
l1_data_gas_price_fri: 3000,
l1_gas_price_wei: 4000,
l1_data_gas_price_wei: 5000,
starknet_version: "".to_string(),
version_constant_commitment: Default::default(),
};
let proposal = p2p_proto::consensus::ProposalPart::BlockInfo(block_info);
let proposal = p2p_proto::consensus::ProposalPart::Init(proposal_init);

// Create a StreamMessage with the ProposalPart
let stream_message = StreamMessage {
Expand Down
72 changes: 43 additions & 29 deletions crates/p2p_proto/proto/consensus/consensus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ message Vote {
// This is optional since a vote can be NIL.
optional starknet.common.Hash proposal_commitment = 5;
starknet.common.Address voter = 6;
starknet.common.Hashes signature = 7;
}

message StreamMessage {
Expand All @@ -45,49 +46,62 @@ message StreamMessage {
}

message ProposalInit {
uint64 height = 1;
uint32 round = 2;
optional uint32 valid_round = 3;
starknet.common.Address proposer = 4;
}

message BlockInfo {
uint64 height = 1;
uint64 timestamp = 2;
starknet.common.Address builder = 3;
starknet.common.L1DataAvailabilityMode l1_da_mode = 4;
starknet.common.Uint128 l2_gas_price_fri = 5;
starknet.common.Uint128 l1_gas_price_fri = 6;
starknet.common.Uint128 l1_data_gas_price_fri = 7;
starknet.common.Uint128 l1_gas_price_wei = 8;
starknet.common.Uint128 l1_data_gas_price_wei = 9;
uint32 round = 2;
optional uint32 valid_round = 3;
starknet.common.Address proposer = 4;
uint64 timestamp = 5;
starknet.common.Address builder = 6;
starknet.common.L1DataAvailabilityMode l1_da_mode = 7;
starknet.common.Uint128 l2_gas_price_fri = 8;
starknet.common.Uint128 l1_gas_price_fri = 9;
starknet.common.Uint128 l1_data_gas_price_fri = 10;
starknet.common.Uint128 l1_gas_price_wei = 11;
starknet.common.Uint128 l1_data_gas_price_wei = 12;
string starknet_version = 13;
starknet.common.Hash version_constant_commitment = 14;
}

message TransactionBatch {
repeated ConsensusTransaction transactions = 1;
}

message CommitmentParts {
starknet.common.Felt252 concatenated_counts = 1;
optional starknet.common.Hash parent_commitment = 2;
starknet.common.Hash transaction_commitment = 3;
starknet.common.Hash event_commitment = 4;
starknet.common.Hash receipt_commitment = 5;
}

// L2 gas info for the block (next price and gas used).
message L2GasInfo {
starknet.common.Uint128 next_l2_gas_price_fri = 1;
uint64 l2_gas_used = 2;
}

// Optional payload carried in ProposalFin: commitment parts and L2 gas.
message ProposalFinPayload {
CommitmentParts commitment_parts = 1;
optional L2GasInfo l2_gas_info = 2;
}

message ProposalFin {
// Identifies a Starknet block based on the content streamed in the proposal.
starknet.common.Hash proposal_commitment = 1;
// Number of executed transactions in the proposal.
uint64 executed_transaction_count = 2;
optional ProposalFinPayload fin_payload = 3;
}

// Network format:
// 1. First message is ProposalInit
// 2. Last message is ProposalFin
//
// Empty block - no other messages sent.
//
// Block with transactions:
// 3. block_info is sent once
// 4. transactions is sent repeatedly
// 5. executed_transaction_count is sent once
// 1. First message is ProposalInit (init, includes all block metadata)
// 2. transactions is sent repeatedly (for non-empty blocks)
// 3. Last message is ProposalFin
message ProposalPart {
oneof message {
ProposalInit init = 1;
ProposalFin fin = 2;
BlockInfo block_info = 3;
TransactionBatch transactions = 4;
uint64 executed_transaction_count = 5;
ProposalInit init = 1;
ProposalFin fin = 2;
TransactionBatch transactions = 3;
}
}
4 changes: 3 additions & 1 deletion crates/p2p_proto/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ impl<T> Dummy<T> for Hash256 {
}
}

#[derive(Debug, Clone, PartialEq, Eq, ToProtobuf, TryFromProtobuf, Dummy)]
#[derive(
Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, ToProtobuf, TryFromProtobuf, Dummy,
)]
#[protobuf(name = "crate::proto::common::Hashes")]
pub struct Hashes {
pub items: Vec<Hash>,
Expand Down
Loading
Loading