Skip to content

Commit

Permalink
Merge branch 'main' of github.com:informalsystems/malachite into main
Browse files Browse the repository at this point in the history
  • Loading branch information
josef-widder committed Nov 22, 2024
2 parents ca9527e + a37d307 commit f00bb62
Show file tree
Hide file tree
Showing 42 changed files with 239 additions and 355 deletions.
27 changes: 15 additions & 12 deletions code/Cargo.lock

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

10 changes: 7 additions & 3 deletions code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [
# Test
"crates/test",
"crates/test/mbt",
"crates/driver/test-utils",

# Starknet
"crates/starknet/*",
Expand All @@ -50,7 +51,7 @@ inherits = "release"
debug = true

[workspace.lints.rust]
unused_crate_dependencies = "warn"
# None for now

[workspace.dependencies]
malachite-actors = { version = "0.1.0", path = "crates/actors" }
Expand All @@ -67,11 +68,14 @@ malachite-metrics = { version = "0.1.0", path = "crates/metrics" }
malachite-node = { version = "0.1.0", path = "crates/node" }
malachite-proto = { version = "0.1.0", path = "crates/proto" }
malachite-round = { version = "0.1.0", path = "crates/round" }
malachite-test = { version = "0.1.0", path = "crates/test" }
malachite-test-mbt = { version = "0.1.0", path = "crates/test/mbt" }
malachite-vote = { version = "0.1.0", path = "crates/vote" }
malachite-signing-ed25519 = { version = "0.1.0", path = "crates/signing-ed25519" }

# Test
malachite-test = { version = "0.1.0", path = "crates/test" }
malachite-test-mbt = { version = "0.1.0", path = "crates/test/mbt" }
malachite-driver-test-utils = { version = "0.1.0", path = "crates/driver/test-utils" }

# Starknet
malachite-starknet-host = { version = "0.1.0", path = "crates/starknet/host" }
malachite-starknet-app = { version = "0.1.0", path = "crates/starknet/app" }
Expand Down
54 changes: 23 additions & 31 deletions code/crates/actors/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use malachite_common::{
CommitCertificate, Context, Round, SignedExtension, Timeout, TimeoutStep, ValidatorSet,
};
use malachite_config::TimeoutConfig;
use malachite_consensus::{Effect, Resume};
use malachite_consensus::{Effect, Resume, ValueToPropose};
use malachite_metrics::Metrics;

use crate::block_sync::BlockSyncRef;
Expand Down Expand Up @@ -233,7 +233,13 @@ where
.process_input(
&myself,
state,
ConsensusInput::ProposeValue(height, round, Round::Nil, value, extension),
ConsensusInput::Propose(ValueToPropose {
height,
round,
valid_round: Round::Nil,
value,
extension,
}),
)
.await;

Expand Down Expand Up @@ -296,14 +302,24 @@ where
return Ok(());
};

self.host.call_and_forward(
|reply_to| HostMsg::ProcessSyncedBlock {
height: block.certificate.height,
round: block.certificate.round,
validator_address: state.consensus.address().clone(),
block_bytes: block.block_bytes.clone(),
reply_to,
},
&myself,
|proposed| Msg::<Ctx>::ReceivedProposedValue(proposed),
None,
)?;

if let Err(e) = self
.process_input(
&myself,
state,
ConsensusInput::ReceivedSyncedBlock(
block.block_bytes,
block.certificate,
),
ConsensusInput::CommitCertificate(block.certificate),
)
.await
{
Expand Down Expand Up @@ -404,7 +420,7 @@ where

Msg::ReceivedProposedValue(value) => {
let result = self
.process_input(&myself, state, ConsensusInput::ReceivedProposedValue(value))
.process_input(&myself, state, ConsensusInput::ProposedValue(value))
.await;

if let Err(e) = result {
Expand Down Expand Up @@ -601,30 +617,6 @@ where

Ok(Resume::Continue)
}

Effect::SyncedBlock {
height,
round,
validator_address,
block_bytes,
} => {
debug!(%height, "Consensus received synced block, sending to host");

self.host.call_and_forward(
|reply_to| HostMsg::ProcessSyncedBlockBytes {
height,
round,
validator_address,
block_bytes,
reply_to,
},
myself,
|proposed| Msg::<Ctx>::ReceivedProposedValue(proposed),
None,
)?;

Ok(Resume::Continue)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/crates/actors/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub enum HostMsg<Ctx: Context> {
},

// Synced block
ProcessSyncedBlockBytes {
ProcessSyncedBlock {
height: Ctx::Height,
round: Round,
validator_address: Ctx::Address,
Expand Down
2 changes: 1 addition & 1 deletion code/crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![no_std]
#![forbid(unsafe_code)]
#![deny(unused_crate_dependencies, trivial_casts, trivial_numeric_casts)]
#![deny(trivial_casts, trivial_numeric_casts)]
#![warn(
missing_docs,
rustdoc::broken_intra_doc_links,
Expand Down
4 changes: 3 additions & 1 deletion code/crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ malachite-driver.workspace = true
malachite-metrics.workspace = true

async-recursion = { workspace = true }
bytes = { workspace = true, features = ["serde"] }
genawaiter = { workspace = true }
derive-where = { workspace = true }
libp2p-identity = { workspace = true, features = ["peerid"] }
Expand All @@ -27,3 +26,6 @@ tracing = { workspace = true }

[lints]
workspace = true

[dev-dependencies]
malachite-test = { workspace = true }
10 changes: 0 additions & 10 deletions code/crates/consensus/src/effect.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bytes::Bytes;
use derive_where::derive_where;

use malachite_common::*;
Expand Down Expand Up @@ -62,15 +61,6 @@ where
/// Consensus has decided on a value
/// Resume with: [`Resume::Continue`]
Decide { certificate: CommitCertificate<Ctx> },

/// Consensus has received a synced decided block
/// Resume with: [`Resume::Continue`]
SyncedBlock {
height: Ctx::Height,
round: Round,
validator_address: Ctx::Address,
block_bytes: Bytes,
},
}

/// A value with which the consensus process can be resumed after yielding an [`Effect`].
Expand Down
34 changes: 10 additions & 24 deletions code/crates/consensus/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ use crate::prelude::*;
mod decide;
mod driver;
mod proposal;
mod propose_value;
mod received_proposed_value;
mod propose;
mod proposed_value;
mod signature;
mod start_height;
mod synced_block;
mod sync;
mod timeout;
mod validator_set;
mod vote;

use proposal::on_proposal;
use propose_value::propose_value;
use received_proposed_value::on_received_proposed_value;
use propose::on_propose;
use proposed_value::on_proposed_value;
use start_height::reset_and_start_height;
use synced_block::on_received_synced_block;
use sync::on_commit_certificate;
use timeout::on_timeout_elapsed;
use vote::on_vote;

Expand Down Expand Up @@ -48,25 +48,11 @@ where
}
Input::Vote(vote) => on_vote(co, state, metrics, vote).await,
Input::Proposal(proposal) => on_proposal(co, state, metrics, proposal).await,
Input::ProposeValue(height, round, valid_round, value, extension) => {
propose_value(
co,
state,
metrics,
height,
round,
valid_round,
value,
extension,
)
.await
}
Input::Propose(value) => on_propose(co, state, metrics, value).await,
Input::TimeoutElapsed(timeout) => on_timeout_elapsed(co, state, metrics, timeout).await,
Input::ReceivedProposedValue(value) => {
on_received_proposed_value(co, state, metrics, value).await
}
Input::ReceivedSyncedBlock(block_bytes, commits) => {
on_received_synced_block(co, state, metrics, block_bytes, commits).await
Input::ProposedValue(value) => on_proposed_value(co, state, metrics, value).await,
Input::CommitCertificate(certificate) => {
on_commit_certificate(co, state, metrics, certificate).await
}
}
}
16 changes: 13 additions & 3 deletions code/crates/consensus/src/handle/decide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ where
let proposal_round = proposal.round();
let value = proposal.value();

// Restore the commits. Note that they will be removed from `state`
let commits = state.restore_precommits(height, proposal_round, value);
// We only decide proposals for the current height
assert_eq!(height, state.driver.height());

// Clean proposals and values
state.remove_full_proposals(height);
Expand Down Expand Up @@ -46,7 +46,17 @@ where
}
}

let certificate = CommitCertificate::new(height, proposal_round, value.id(), commits);
// Look for an existing certificate
let certificate = state
.driver
.get_certificate(proposal_round, value.id())
.cloned()
.unwrap_or_else(|| {
// Restore the commits. Note that they will be removed from `state`
let commits = state.restore_precommits(height, proposal_round, value);
// TODO: should we verify we have 2/3rd commits?
CommitCertificate::new(height, proposal_round, value.id(), commits)
});

perform!(co, Effect::Decide { certificate });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use crate::prelude::*;

use crate::handle::driver::apply_driver_input;
use crate::types::ProposedValue;
use crate::types::{ProposedValue, ValueToPropose};

#[allow(clippy::too_many_arguments)]
pub async fn propose_value<Ctx>(
pub async fn on_propose<Ctx>(
co: &Co<Ctx>,
state: &mut State<Ctx>,
metrics: &Metrics,
height: Ctx::Height,
round: Round,
valid_round: Round,
value: Ctx::Value,
extension: Option<SignedExtension<Ctx>>,
value: ValueToPropose<Ctx>,
) -> Result<(), Error<Ctx>>
where
Ctx: Context,
{
let ValueToPropose {
height,
round,
valid_round,
value,
extension,
} = value;

if state.driver.height() != height {
warn!(
"Ignoring proposal for height {height}, current height: {}",
Expand All @@ -41,7 +44,7 @@ where
height,
round,
valid_round,
validator_address: state.driver.address().clone(),
validator_address: state.address().clone(),
value: value.clone(),
validity: Validity::Valid,
extension,
Expand Down
Loading

0 comments on commit f00bb62

Please sign in to comment.