diff --git a/Cargo.lock b/Cargo.lock index d2f18dcd..7d2aff27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1541,6 +1541,18 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "config" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68578f196d2a33ff61b27fae256c3164f65e36382648e30666dde05b8cc9dfdf" +dependencies = [ + "nom", + "pathdiff", + "serde", + "toml 0.8.19", +] + [[package]] name = "const-hex" version = "1.14.0" @@ -3432,6 +3444,105 @@ dependencies = [ "serde", ] +[[package]] +name = "informalsystems-malachitebft-config" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "298211c1623c3c52053985d5142889467ebfc69d1353b58adf3efaf1991f879d" +dependencies = [ + "bytesize", + "config", + "humantime-serde", + "informalsystems-malachitebft-core-types", + "multiaddr", + "serde", +] + +[[package]] +name = "informalsystems-malachitebft-core-consensus" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d30e3ac751eea2722a48628e5942df1d479b9294286cd68cf5c2cc837f50dc6" +dependencies = [ + "async-recursion", + "derive-where", + "genawaiter", + "informalsystems-malachitebft-core-driver", + "informalsystems-malachitebft-core-types", + "informalsystems-malachitebft-metrics", + "informalsystems-malachitebft-peer", + "multiaddr", + "thiserror 2.0.3", + "tracing", +] + +[[package]] +name = "informalsystems-malachitebft-core-driver" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6be2dc3e680a9ae3fc3f679b9be48276614d85227b79bfa1401b2c4fa739436a" +dependencies = [ + "derive-where", + "informalsystems-malachitebft-core-state-machine", + "informalsystems-malachitebft-core-types", + "informalsystems-malachitebft-core-votekeeper", + "thiserror 2.0.3", +] + +[[package]] +name = "informalsystems-malachitebft-core-state-machine" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9efb2e03d77dc1c74341fbf2ce7c361dde971c48aa0b518218392ab5ddbac0" +dependencies = [ + "derive-where", + "displaydoc", + "informalsystems-malachitebft-core-types", +] + +[[package]] +name = "informalsystems-malachitebft-core-types" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d291b3b39cdbf972bba3706458f9009dac26341c638270d3b62b77213a075a" +dependencies = [ + "bytes", + "derive-where", + "thiserror 2.0.3", +] + +[[package]] +name = "informalsystems-malachitebft-core-votekeeper" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64fa18f6a2f9165bdd2777e3e48355948db66da5f3d7ba50e7e6d7ac520d18f3" +dependencies = [ + "derive-where", + "informalsystems-malachitebft-core-types", + "thiserror 2.0.3", +] + +[[package]] +name = "informalsystems-malachitebft-metrics" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2c8c07b0209939dacf44613af1badccae12d426181ce542f06f50692318d312" +dependencies = [ + "informalsystems-malachitebft-core-state-machine", + "prometheus-client", +] + +[[package]] +name = "informalsystems-malachitebft-peer" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bba9c096458e76678ea52c1956523e749a5a9740bda98716f3ba224139ba61e" +dependencies = [ + "bs58", + "multihash", + "thiserror 2.0.3", +] + [[package]] name = "inlinable_string" version = "0.1.15" @@ -4129,85 +4240,6 @@ dependencies = [ "libc", ] -[[package]] -name = "malachite-common" -version = "0.1.0" -dependencies = [ - "bytes", - "derive-where", -] - -[[package]] -name = "malachite-config" -version = "0.1.0" -dependencies = [ - "bytesize", - "humantime-serde", - "malachite-common", - "multiaddr", - "serde", -] - -[[package]] -name = "malachite-consensus" -version = "0.1.0" -dependencies = [ - "async-recursion", - "derive-where", - "genawaiter", - "libp2p-identity", - "malachite-common", - "malachite-driver", - "malachite-metrics", - "multiaddr", - "thiserror 1.0.69", - "tracing", -] - -[[package]] -name = "malachite-driver" -version = "0.1.0" -dependencies = [ - "derive-where", - "malachite-common", - "malachite-round", - "malachite-vote", -] - -[[package]] -name = "malachite-metrics" -version = "0.1.0" -dependencies = [ - "malachite-round", - "prometheus-client", -] - -[[package]] -name = "malachite-node" -version = "0.1.0" -dependencies = [ - "malachite-common", - "rand", - "serde", -] - -[[package]] -name = "malachite-round" -version = "0.1.0" -dependencies = [ - "derive-where", - "displaydoc", - "malachite-common", -] - -[[package]] -name = "malachite-vote" -version = "0.1.0" -dependencies = [ - "derive-where", - "malachite-common", -] - [[package]] name = "match_cfg" version = "0.1.0" @@ -4321,9 +4353,9 @@ dependencies = [ [[package]] name = "multihash" -version = "0.19.2" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc41f430805af9d1cf4adae4ed2149c759b877b01d909a1f40256188d09345d2" +checksum = "6b430e7953c29dd6a09afc29ff0bb69c6e306329ee6794700aee27b76a1aea8d" dependencies = [ "core2", "unsigned-varint 0.8.0", @@ -4737,6 +4769,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" +[[package]] +name = "pathdiff" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" + [[package]] name = "pear" version = "0.2.9" @@ -6173,13 +6211,12 @@ dependencies = [ "hex", "humantime", "humantime-serde", + "informalsystems-malachitebft-config", + "informalsystems-malachitebft-core-consensus", + "informalsystems-malachitebft-core-types", + "informalsystems-malachitebft-metrics", "itertools 0.13.0", "libp2p", - "malachite-common", - "malachite-config", - "malachite-consensus", - "malachite-metrics", - "malachite-node", "once_cell", "parking_lot", "pre-commit", @@ -6948,9 +6985,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "log", "pin-project-lite", @@ -6960,9 +6997,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", @@ -6971,9 +7008,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", "valuable", diff --git a/Cargo.toml b/Cargo.toml index b156080a..d9ad1bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,11 +25,10 @@ async-trait = "0.1.68" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt", "json"] } hex = "0.4.3" ractor = "0.11.2" -malachite-consensus = { path = "../malachite/code/crates/consensus" } -malachite-common = { path = "../malachite/code/crates/common" } -malachite-config = { path = "../malachite/code/crates/config" } -malachite-node = { path = "../malachite/code/crates/node" } -malachite-metrics = { path = "../malachite/code/crates/metrics" } +informalsystems-malachitebft-core-consensus = { version = "0.0.1" } +informalsystems-malachitebft-core-types = { version = "0.0.1"} +informalsystems-malachitebft-config = { version = "0.0.1"} +informalsystems-malachitebft-metrics = { version = "0.0.1" } blake3 = "1.4.1" tracing = "0.1.40" thiserror = "1.0.66" diff --git a/src/consensus/consensus.rs b/src/consensus/consensus.rs index 2ee55545..2e17ca2b 100644 --- a/src/consensus/consensus.rs +++ b/src/consensus/consensus.rs @@ -1,17 +1,21 @@ use async_trait::async_trait; +use informalsystems_malachitebft_core_types::{ + CommitCertificate, SigningProvider, ValidatorSet, ValueOrigin, +}; use libp2p::identity::ed25519::{Keypair, SecretKey}; -use malachite_common::ValidatorSet; use ractor::{Actor, ActorProcessingErr, ActorRef}; use std::time::Duration; use tokio::sync::mpsc; use tracing::{debug, error, info, warn}; -use malachite_common::{ - Context, Extension, Round, SignedProposal, SignedProposalPart, SignedVote, Timeout, TimeoutStep, +use informalsystems_malachitebft_config::TimeoutConfig; +use informalsystems_malachitebft_core_consensus::{ + Effect, ProposedValue, Resume, SignedConsensusMsg, ValueToPropose, +}; +use informalsystems_malachitebft_core_types::{ + Context, Extension, Round, SignedProposal, SignedProposalPart, SignedVote, Timeout, TimeoutKind, }; -use malachite_config::TimeoutConfig; -use malachite_consensus::{Effect, ProposedValue, Resume, SignedConsensusMsg}; -use malachite_metrics::Metrics; +use informalsystems_malachitebft_metrics::Metrics; use crate::consensus::timers::{TimeoutElapsed, TimerScheduler}; use crate::consensus::validator::ShardValidator; @@ -21,8 +25,8 @@ use crate::core::types::{ }; use crate::network::gossip::GossipEvent; use crate::proto::FullProposal; -pub use malachite_consensus::Params as ConsensusParams; -pub use malachite_consensus::State as ConsensusState; +pub use informalsystems_malachitebft_core_consensus::Params as ConsensusParams; +pub use informalsystems_malachitebft_core_consensus::State as ConsensusState; use ractor::time::send_after; use serde::{Deserialize, Serialize}; use tokio::time::Instant; @@ -136,22 +140,26 @@ impl Timeouts { self.config = config; } - fn duration_for(&self, step: TimeoutStep) -> Duration { + fn duration_for(&self, step: TimeoutKind) -> Duration { match step { - TimeoutStep::Propose => self.config.timeout_propose, - TimeoutStep::Prevote => self.config.timeout_prevote, - TimeoutStep::Precommit => self.config.timeout_precommit, - TimeoutStep::Commit => self.config.timeout_commit, + TimeoutKind::Propose => self.config.timeout_propose, + TimeoutKind::Prevote => self.config.timeout_prevote, + TimeoutKind::Precommit => self.config.timeout_precommit, + TimeoutKind::Commit => self.config.timeout_commit, + TimeoutKind::PrevoteTimeLimit => todo!(), + TimeoutKind::PrecommitTimeLimit => todo!(), } } - fn increase_timeout(&mut self, step: TimeoutStep) { + fn increase_timeout(&mut self, step: TimeoutKind) { let c = &mut self.config; match step { - TimeoutStep::Propose => c.timeout_propose += c.timeout_propose_delta, - TimeoutStep::Prevote => c.timeout_prevote += c.timeout_prevote_delta, - TimeoutStep::Precommit => c.timeout_precommit += c.timeout_precommit_delta, - TimeoutStep::Commit => (), + TimeoutKind::Propose => c.timeout_propose += c.timeout_propose_delta, + TimeoutKind::Prevote => c.timeout_prevote += c.timeout_prevote_delta, + TimeoutKind::Precommit => c.timeout_precommit += c.timeout_precommit_delta, + TimeoutKind::Commit => (), + TimeoutKind::PrevoteTimeLimit => todo!(), + TimeoutKind::PrecommitTimeLimit => todo!(), }; } } @@ -166,7 +174,7 @@ pub struct Consensus { // pub type ConsensusMsg = ConsensusMsg; -type ConsensusInput = malachite_consensus::Input; +type ConsensusInput = informalsystems_malachitebft_core_consensus::Input; pub struct State { /// Scheduler for timers @@ -223,7 +231,7 @@ impl Consensus { state: &mut State, input: ConsensusInput, ) -> Result<(), ActorProcessingErr> { - malachite_consensus::process!( + informalsystems_malachitebft_core_consensus::process!( input: input, state: &mut state.consensus, metrics: &self.metrics, @@ -250,7 +258,13 @@ impl Consensus { .process_input( &myself, state, - ConsensusInput::ProposeValue(height, round, value, None), + ConsensusInput::Propose(ValueToPropose { + height, + round, + valid_round: round, + value, + extension: todo!(), + }), ) .await; @@ -378,7 +392,7 @@ impl Consensus { .process_input( &myself, state, - ConsensusInput::ReceivedProposedValue(proposed_value), + ConsensusInput::ProposedValue(proposed_value, ValueOrigin::Consensus), ) .await; @@ -395,10 +409,10 @@ impl Consensus { return Ok(()); }; - state.timeouts.increase_timeout(timeout.step); + state.timeouts.increase_timeout(timeout.kind); - if matches!(timeout.step, TimeoutStep::Prevote | TimeoutStep::Precommit) { - warn!(step = ?timeout.step, "Timeout elapsed"); + if matches!(timeout.kind, TimeoutKind::Prevote | TimeoutKind::Precommit) { + warn!(step = ?timeout.kind, "Timeout elapsed"); } let result = self @@ -417,7 +431,11 @@ impl Consensus { value.value, value.height, value.round, self.params.address ); let result = self - .process_input(&myself, state, ConsensusInput::ReceivedProposedValue(value)) + .process_input( + &myself, + state, + ConsensusInput::ProposedValue(value, ValueOrigin::Sync), + ) .await; if let Err(e) = result { @@ -474,41 +492,78 @@ impl Consensus { effect: Effect, ) -> Result, ActorProcessingErr> { match effect { - Effect::ResetTimeouts => { + Effect::Publish(_, _) => { + todo!() + } + + Effect::RestreamValue(_, _, _, _, _, _) => { + todo!() + } + Effect::GetVoteSet(_, _, _) => { + todo!() + } + Effect::SendVoteSetResponse(_, _, _, _, _) => { + todo!() + } + Effect::PersistMessage(_, _) => { + todo!() + } + Effect::PersistTimeout(_, _) => { + todo!() + } + Effect::SignVote(_, _) => { + todo!() + } + Effect::SignProposal(_, _) => { + todo!() + } + Effect::VerifyCertificate(_, _, _, _) => { + todo!() + } + + Effect::ResetTimeouts(_) => { timeouts.reset(self.timeout_config); Ok(Resume::Continue) } - Effect::CancelAllTimeouts => { + Effect::CancelAllTimeouts(_) => { timers.cancel_all(); Ok(Resume::Continue) } - Effect::CancelTimeout(timeout) => { + Effect::CancelTimeout(timeout, _) => { timers.cancel(&timeout); Ok(Resume::Continue) } - Effect::ScheduleTimeout(timeout) => { - let duration = timeouts.duration_for(timeout.step); + Effect::ScheduleTimeout(timeout, _) => { + let duration = timeouts.duration_for(timeout.kind); timers.start_timer(timeout, duration); Ok(Resume::Continue) } - Effect::StartRound(height, round, proposer) => { + Effect::StartRound(height, round, proposer, _) => { debug!("Starting height: {height}, round: {round}, proposer: {proposer}"); shard_validator.start_round(height, round, proposer); Ok(Resume::Continue) } - Effect::VerifySignature(msg, pk) => { - use malachite_consensus::ConsensusMsg as Msg; + Effect::VerifySignature(msg, pk, _) => { + use informalsystems_malachitebft_core_consensus::ConsensusMsg as Msg; let start = Instant::now(); let valid = match msg.message { - Msg::Vote(v) => self.ctx.verify_signed_vote(&v, &msg.signature, &pk), - Msg::Proposal(p) => self.ctx.verify_signed_proposal(&p, &msg.signature, &pk), + Msg::Vote(v) => { + self.ctx + .signing_provider() + .verify_signed_vote(&v, &msg.signature, &pk) + } + Msg::Proposal(p) => { + self.ctx + .signing_provider() + .verify_signed_proposal(&p, &msg.signature, &pk) + } }; self.metrics @@ -518,33 +573,33 @@ impl Consensus { Ok(Resume::SignatureValidity(valid)) } - Effect::Broadcast(gossip_msg) => { - match gossip_msg { - SignedConsensusMsg::Proposal(proposal) => { - debug!( - "Broadcasting proposal gossip message: {:?} {:?} from {:?}", - proposal.height, proposal.round, proposal.proposer - ); - gossip_tx - .send(GossipEvent::BroadcastSignedProposal(proposal)) - .await?; - } - SignedConsensusMsg::Vote(vote) => { - debug!( - "Broadcasting vote gossip message: {:?} {:?} {:?} from {:?}", - vote.vote_type, vote.height, vote.round, vote.voter - ); - gossip_tx - .send(GossipEvent::BroadcastSignedVote(vote)) - .await?; - } - } - - Ok(Resume::Continue) - } - - Effect::GetValue(height, round, timeout) => { - let timeout = timeouts.duration_for(timeout.step); + //Not available in Effect anymore + // Effect::Broadcast(gossip_msg) => { + // match gossip_msg { + // SignedConsensusMsg::Proposal(proposal) => { + // debug!( + // "Broadcasting proposal gossip message: {:?} {:?} from {:?}", + // proposal.height, proposal.round, proposal.proposer + // ); + // gossip_tx + // .send(GossipEvent::BroadcastSignedProposal(proposal)) + // .await?; + // } + // SignedConsensusMsg::Vote(vote) => { + // debug!( + // "Broadcasting vote gossip message: {:?} {:?} {:?} from {:?}", + // vote.vote_type, vote.height, vote.round, vote.voter + // ); + // gossip_tx + // .send(GossipEvent::BroadcastSignedVote(vote)) + // .await?; + // } + // } + + // Ok(Resume::Continue) + // } + Effect::GetValue(height, round, timeout, _) => { + let timeout = timeouts.duration_for(timeout.kind); let full_proposal = shard_validator.propose_value(height, round, timeout).await; let value = full_proposal.shard_hash(); @@ -562,21 +617,23 @@ impl Consensus { Ok(Resume::Continue) } - Effect::GetValidatorSet(height) => Ok(Resume::ValidatorSet( - height, - Some(shard_validator.get_validator_set()), - )), - - Effect::Decide { - height, - round, - value, - commits, - } => { + Effect::GetValidatorSet(height, _) => Ok(Resume::ValidatorSet(Some( + shard_validator.get_validator_set(), + ))), + + Effect::Decide( + CommitCertificate { + height, + round, + value_id: value, + aggregated_signature: commits, + }, + _, + ) => { info!( "Deciding value: {value} for height: {height} at {:?} with {:?} commits", self.params.address, - commits.len() + commits.signatures.len() ); shard_validator.decide(height, round, value.clone()).await; let result = myself.cast(ConsensusMsg::StartHeight(height.increment())); diff --git a/src/consensus/proposer.rs b/src/consensus/proposer.rs index 2587bdaf..cb3903fd 100644 --- a/src/consensus/proposer.rs +++ b/src/consensus/proposer.rs @@ -7,7 +7,7 @@ use crate::proto::{BlocksRequest, ShardChunksRequest}; use crate::storage::store::engine::{BlockEngine, ShardEngine, ShardStateChange}; use crate::storage::store::BlockStorageError; use crate::utils::statsd_wrapper::StatsdClientWrapper; -use malachite_common::{Round, Validity}; +use informalsystems_malachitebft_core_types::{Round, Validity}; use prost::Message; use std::collections::BTreeMap; use std::time::Duration; diff --git a/src/consensus/validator.rs b/src/consensus/validator.rs index 6e9fc43f..692fc48d 100644 --- a/src/consensus/validator.rs +++ b/src/consensus/validator.rs @@ -4,8 +4,8 @@ use crate::core::types::{ SnapchainValidatorSet, }; use crate::proto::FullProposal; -use malachite_common::{Round, ValidatorSet}; -use malachite_consensus::ProposedValue; +use informalsystems_malachitebft_core_consensus::ProposedValue; +use informalsystems_malachitebft_core_types::{Round, ValidatorSet}; use std::collections::HashSet; use std::time::Duration; use tracing::error; @@ -134,7 +134,8 @@ impl ShardValidator { ProposedValue { height: full_proposal.height(), round: full_proposal.round(), - validator_address: full_proposal.proposer_address(), + valid_round: full_proposal.round(), + proposer: full_proposal.proposer_address(), value, validity, extension: None, diff --git a/src/core/types.rs b/src/core/types.rs index 5f7cd04e..8213fad7 100644 --- a/src/core/types.rs +++ b/src/core/types.rs @@ -1,10 +1,10 @@ use core::fmt; -use libp2p::identity::ed25519::Keypair; -use malachite_common; -use malachite_common::{ +use informalsystems_malachitebft_core_types::{self, Context, SignedMessage, SigningProvider}; +use informalsystems_malachitebft_core_types::{ Extension, NilOrVal, Round, SignedProposal, SignedProposalPart, SignedVote, Validator, VoteType, VotingPower, }; +use libp2p::identity::ed25519::Keypair; use prost::Message; use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Display}; @@ -48,7 +48,10 @@ pub trait ShardedContext { type ShardId: ShardId; } -pub trait SnapchainContext: malachite_common::Context + ShardedContext {} +pub trait SnapchainContext: + informalsystems_malachitebft_core_types::Context + ShardedContext +{ +} // TODO: Should validator keys be ECDSA? #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -86,11 +89,94 @@ impl fmt::Debug for Address { } } -impl malachite_common::Address for Address {} +impl informalsystems_malachitebft_core_types::Address for Address {} #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Ed25519 {} +#[derive(Debug)] +pub struct Ed25519Provider { + private_key: PrivateKey, +} + +impl Ed25519Provider { + pub fn new(private_key: PrivateKey) -> Self { + Self { private_key } + } +} + +impl SigningProvider for Ed25519Provider { + fn sign_vote( + &self, + vote: ::Vote, + ) -> SignedMessage< + SnapchainValidatorContext, + ::Vote, + > { + todo!() + } + + fn verify_signed_vote( + &self, + vote: &::Vote, + signature: &informalsystems_malachitebft_core_types::Signature, + public_key: &informalsystems_malachitebft_core_types::PublicKey, + ) -> bool { + todo!() + } + + fn sign_proposal( + &self, + proposal: ::Proposal, + ) -> SignedMessage< + SnapchainValidatorContext, + ::Proposal, + > { + todo!() + } + + fn verify_signed_proposal( + &self, + proposal: &::Proposal, + signature: &informalsystems_malachitebft_core_types::Signature, + public_key: &informalsystems_malachitebft_core_types::PublicKey, + ) -> bool { + todo!() + } + + fn sign_proposal_part( + &self, + proposal_part: ::ProposalPart, + ) -> SignedMessage::ProposalPart>{ + todo!() + } + + fn verify_signed_proposal_part( + &self, + proposal_part: &::ProposalPart, + signature: &informalsystems_malachitebft_core_types::Signature, + public_key: &informalsystems_malachitebft_core_types::PublicKey, + ) -> bool { + todo!() + } + + fn verify_commit_signature( + &self, + certificate: &informalsystems_malachitebft_core_types::CommitCertificate< + SnapchainValidatorContext, + >, + commit_sig: &informalsystems_malachitebft_core_types::CommitSignature< + SnapchainValidatorContext, + >, + validator: &::Validator, + ) -> Result< + VotingPower, + informalsystems_malachitebft_core_types::CertificateError, + > { + todo!() + } +} + pub struct InvalidSignatureError(); impl fmt::Display for InvalidSignatureError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -105,7 +191,7 @@ pub struct Signature(pub Vec); pub type PublicKey = libp2p::identity::ed25519::PublicKey; pub type PrivateKey = libp2p::identity::ed25519::SecretKey; -impl malachite_common::SigningScheme for Ed25519 { +impl informalsystems_malachitebft_core_types::SigningScheme for Ed25519 { type DecodingError = InvalidSignatureError; type Signature = Signature; type PublicKey = PublicKey; @@ -167,7 +253,7 @@ impl fmt::Display for Height { } } -impl malachite_common::Height for Height { +impl informalsystems_malachitebft_core_types::Height for Height { fn increment(&self) -> Self { self.increment() } @@ -175,6 +261,14 @@ impl malachite_common::Height for Height { fn as_u64(&self) -> u64 { self.block_number } + + fn increment_by(&self, n: u64) -> Self { + todo!() + } + + fn decrement_by(&self, n: u64) -> Option { + todo!() + } } // #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] @@ -195,7 +289,7 @@ impl fmt::Display for ShardHash { // } // } -impl malachite_common::Value for ShardHash { +impl informalsystems_malachitebft_core_types::Value for ShardHash { type Id = ShardHash; fn id(&self) -> Self::Id { @@ -243,7 +337,7 @@ impl FullProposal { } pub fn round(&self) -> Round { - Round::new(self.round) + Round::new(self.round.try_into().unwrap()) } } @@ -407,7 +501,7 @@ impl Vote { Self { vote_type, height: proto.height.unwrap(), - round: Round::new(proto.round), + round: Round::new(proto.round.try_into().unwrap()), voter: Address::from_vec(proto.voter), shard_hash, extension: None, @@ -442,9 +536,9 @@ impl Proposal { pub fn from_proto(proto: proto::Proposal) -> Self { Self { height: proto.height.unwrap(), - round: Round::new(proto.round), + round: Round::new(proto.round.try_into().unwrap()), shard_hash: proto.value.unwrap(), - pol_round: Round::new(proto.pol_round), + pol_round: Round::new(proto.pol_round.try_into().unwrap()), proposer: Address::from_vec(proto.proposer), } } @@ -487,7 +581,7 @@ impl ShardedContext for SnapchainValidatorContext { type ShardId = SnapchainShard; } -impl malachite_common::Context for SnapchainValidatorContext { +impl informalsystems_malachitebft_core_types::Context for SnapchainValidatorContext { type Address = Address; type Height = Height; type ProposalPart = ProposalPart; @@ -497,6 +591,7 @@ impl malachite_common::Context for SnapchainValidatorContext { type Value = ShardHash; type Vote = Vote; type SigningScheme = Ed25519; + type SigningProvider = Ed25519Provider; fn select_proposer<'a>( &self, @@ -520,55 +615,6 @@ impl malachite_common::Context for SnapchainValidatorContext { .expect("proposer_index is valid") } - fn sign_vote(&self, vote: Self::Vote) -> SignedVote { - let signature = self.keypair.sign(&vote.to_sign_bytes()); - SignedVote::new(vote, Signature(signature)) - } - - fn verify_signed_vote( - &self, - vote: &Vote, - signature: &Signature, - public_key: &PublicKey, - ) -> bool { - let valid = public_key.verify(&vote.to_sign_bytes(), &signature.0); - if !valid { - panic!("Invalid signature"); - } - valid - } - - fn sign_proposal(&self, proposal: Self::Proposal) -> SignedProposal { - let signature = self.keypair.sign(&proposal.to_sign_bytes()); - SignedProposal::new(proposal, Signature(signature)) - } - - fn verify_signed_proposal( - &self, - proposal: &Proposal, - signature: &Signature, - public_key: &PublicKey, - ) -> bool { - let valid = public_key.verify(&proposal.to_sign_bytes(), &signature.0); - if !valid { - panic!("Invalid signature"); - } - valid - } - - fn sign_proposal_part(&self, proposal_part: Self::ProposalPart) -> SignedProposalPart { - SignedProposalPart::new(proposal_part, Signature(vec![])) - } - - fn verify_signed_proposal_part( - &self, - _proposal_part: &ProposalPart, - _signature: &Signature, - _public_key: &PublicKey, - ) -> bool { - todo!() - } - fn new_proposal( height: Height, round: Round, @@ -602,11 +648,17 @@ impl malachite_common::Context for SnapchainValidatorContext { ) -> Vote { Vote::new_precommit(height, round, value_id, address) } + + fn signing_provider(&self) -> &Self::SigningProvider { + todo!() + } } impl SnapchainContext for SnapchainValidatorContext {} -impl malachite_common::ProposalPart for ProposalPart { +impl informalsystems_malachitebft_core_types::ProposalPart + for ProposalPart +{ fn is_first(&self) -> bool { // Only one part for now true @@ -617,7 +669,7 @@ impl malachite_common::ProposalPart for ProposalPart } } -impl malachite_common::Proposal for Proposal { +impl informalsystems_malachitebft_core_types::Proposal for Proposal { fn height(&self) -> Height { self.height } @@ -643,7 +695,7 @@ impl malachite_common::Proposal for Proposal { } } -impl malachite_common::Vote for Vote { +impl informalsystems_malachitebft_core_types::Vote for Vote { fn height(&self) -> Height { self.height } @@ -668,19 +720,23 @@ impl malachite_common::Vote for Vote { &self.voter } - fn extension(&self) -> Option<&Extension> { + fn extension( + &self, + ) -> std::option::Option<&SignedMessage> { None } - fn extend(self, extension: Extension) -> Self { + fn extend(self, extension: SignedMessage) -> Self { Self { - extension: Some(extension), + extension: Some(extension.message), ..self } } } -impl malachite_common::ValidatorSet for SnapchainValidatorSet { +impl informalsystems_malachitebft_core_types::ValidatorSet + for SnapchainValidatorSet +{ fn count(&self) -> usize { self.validators.len() } @@ -702,7 +758,9 @@ impl malachite_common::ValidatorSet for SnapchainVali } } -impl malachite_common::Validator for SnapchainValidator { +impl informalsystems_malachitebft_core_types::Validator + for SnapchainValidator +{ fn address(&self) -> &Address { &self.address } diff --git a/src/main.rs b/src/main.rs index e11ac77a..8c319b6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use malachite_metrics::{Metrics, SharedRegistry}; +use informalsystems_malachitebft_metrics::{Metrics, SharedRegistry}; use snapchain::connectors::onchain_events::{L1Client, RealL1Client}; use snapchain::consensus::consensus::SystemMessage; use snapchain::core::types::proto; diff --git a/src/network/gossip.rs b/src/network/gossip.rs index dcedeed0..8d433e7a 100644 --- a/src/network/gossip.rs +++ b/src/network/gossip.rs @@ -4,10 +4,10 @@ use crate::core::types::{ SnapchainValidatorContext, Vote, }; use futures::StreamExt; +use informalsystems_malachitebft_core_types::{SignedProposal, SignedVote}; use libp2p::identity::ed25519::Keypair; use libp2p::swarm::dial_opts::DialOpts; use libp2p::{gossipsub, noise, swarm::NetworkBehaviour, swarm::SwarmEvent, tcp, yamux, Swarm}; -use malachite_common::{SignedProposal, SignedVote}; use prost::Message; use serde::{Deserialize, Serialize}; use std::collections::hash_map::DefaultHasher; diff --git a/src/node/snapchain_node.rs b/src/node/snapchain_node.rs index c6353d82..0b837537 100644 --- a/src/node/snapchain_node.rs +++ b/src/node/snapchain_node.rs @@ -15,9 +15,10 @@ use crate::storage::store::stores::Stores; use crate::storage::store::BlockStore; use crate::storage::trie::merkle_trie; use crate::utils::statsd_wrapper::StatsdClientWrapper; +use informalsystems_malachitebft_config::TimeoutConfig; +use informalsystems_malachitebft_core_consensus::ValuePayload; +use informalsystems_malachitebft_metrics::Metrics; use libp2p::identity::ed25519::Keypair; -use malachite_config::TimeoutConfig; -use malachite_metrics::Metrics; use ractor::ActorRef; use std::collections::{BTreeMap, HashMap}; use std::sync::Arc; @@ -76,10 +77,11 @@ impl SnapchainNode { ); let shard_validator_set = SnapchainValidatorSet::new(vec![shard_validator]); let shard_consensus_params = ConsensusParams { - start_height: Height::new(shard.shard_id(), 1), + initial_height: Height::new(shard.shard_id(), 1), initial_validator_set: shard_validator_set, address: validator_address.clone(), threshold_params: Default::default(), + value_payload: ValuePayload::ProposalAndParts, }; let ctx = SnapchainValidatorContext::new(keypair.clone()); @@ -147,10 +149,11 @@ impl SnapchainNode { let block_validator_set = SnapchainValidatorSet::new(vec![block_validator]); let block_consensus_params = ConsensusParams { - start_height: Height::new(block_shard.shard_id(), 1), + initial_height: Height::new(block_shard.shard_id(), 1), initial_validator_set: block_validator_set, address: validator_address.clone(), threshold_params: Default::default(), + value_payload: ValuePayload::ProposalAndParts, }; let engine = BlockEngine::new(block_store.clone());