Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(code/starknet): Starknet interoperability #868

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions code/crates/network/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl Channel {

pub fn as_str(&self) -> &'static str {
match self {
Channel::Consensus => "/consensus",
Channel::ProposalParts => "/proposal_parts",
Channel::Consensus => "/consensus_votes",
Channel::ProposalParts => "/consensus_proposals",
Channel::Sync => "/sync",
}
}
Expand All @@ -50,17 +50,17 @@ impl Channel {

pub fn from_gossipsub_topic_hash(topic: &gossipsub::TopicHash) -> Option<Self> {
match topic.as_str() {
"/consensus" => Some(Channel::Consensus),
"/proposal_parts" => Some(Channel::ProposalParts),
"/consensus_votes" => Some(Channel::Consensus),
"/consensus_proposals" => Some(Channel::ProposalParts),
"/sync" => Some(Channel::Sync),
_ => None,
}
}

pub fn from_broadcast_topic(topic: &broadcast::Topic) -> Option<Self> {
match topic.as_ref() {
b"/consensus" => Some(Channel::Consensus),
b"/proposal_parts" => Some(Channel::ProposalParts),
b"/consensus_votes" => Some(Channel::Consensus),
b"/consensus_proposals" => Some(Channel::ProposalParts),
b"/sync" => Some(Channel::Sync),
_ => None,
}
Expand Down
8 changes: 5 additions & 3 deletions code/crates/starknet/host/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ async fn on_consensus_ready(
state: &mut HostState,
consensus: ConsensusRef<MockContext>,
) -> Result<(), ActorProcessingErr> {
let latest_block_height = state.block_store.last_height().unwrap_or_default();
let start_height = latest_block_height.increment();

let mut start_height = malachitebft_core_types::Height::INITIAL;
if state.block_store.last_height().is_some() {
let latest_block_height = state.block_store.last_height().unwrap_or_default();
start_height = latest_block_height.increment();
}
state.consensus = Some(consensus.clone());

tokio::time::sleep(Duration::from_millis(200)).await;
Expand Down
2 changes: 1 addition & 1 deletion code/crates/starknet/p2p-types/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Context for MockContext {
let height = height.as_u64() as usize;
let round = round.as_i64() as usize;

(height - 1 + round) % validator_set.count()
(height + round) % validator_set.count()
};

validator_set
Expand Down
2 changes: 1 addition & 1 deletion code/crates/starknet/p2p-types/src/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl fmt::Display for Height {

impl malachitebft_core_types::Height for Height {
const ZERO: Self = Self::new(0, 0);
const INITIAL: Self = Self::new(1, 0);
const INITIAL: Self = Self::new(0, 0);

fn increment_by(&self, n: u64) -> Self {
Self {
Expand Down
9 changes: 8 additions & 1 deletion code/crates/starknet/test/src/tests/n3f0.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::time::Duration;

use malachitebft_test_framework::TestParams;

use crate::TestBuilder;

#[tokio::test]
Expand All @@ -12,5 +14,10 @@ pub async fn all_correct_nodes() {
test.add_node().start().wait_until(HEIGHT).success();
test.add_node().start().wait_until(HEIGHT).success();

test.build().run(Duration::from_secs(30)).await
test.build()
.run_with_params(
Duration::from_secs(30), // Timeout for the whole test
TestParams::default(),
)
.await
}
Loading